Type &
ASTContext::getConstantArrayType(Type *EltTy,long length)
{
- std::cerr<<"ASTContext::getConstantArrayType: TODO "<<length<<std::endl;
+ std::cerr<<"ASTContext::getConstantArrayType: TODO len: "<<length<<std::endl;
ConstantArrayType *cat = new ConstantArrayType(EltTy,length);
+ m_ConstantArrays.push_back(cat);
//Todo implement
- return CharTy;
+ return *cat;
}
Type &
//
// This is wrong. I should check from which context is the parameter.
// Only if the parameter name is from global context
- std::cerr<<"ERROR: CodeGenFunction::EmitOutputStmt Parameter is StringLiteral NOT GOOD missing declaration "<<u->getString()<<std::endl;
+ std::cerr<<"ERROR: CodeGenFunction::EmitOutputStmt Parameter is StringLiteral NOT GOOD missing declaration "<<u->getString();
+ if (u->isConstantArray)
+ {
+ std::cerr<<" const "<<std::endl;
+ }
+ else
+ std::cerr<<" not const"<<std::endl;
value = m_CGM.getOrCreateGlobal(u->getString(),false);
if (c)
{
if ( AST::StringLiteral *u = dynamic_cast<AST::StringLiteral *>(*it) )
{
//
- // This is wrong. I should check from which context is the parameter.
+ // TODO This is wrong. I should check from which context is the parameter.
// Only if the parameter name is from global context
std::cerr<<"ERROR: CodeGenFunction::EmitCallExpr Parameter is StringLiteral NOT GOOD missing declaration "<<u->getString()<<std::endl;
- value = m_CGM.getOrCreateGlobal(u->getString(),false);
+
+ value = m_CGM.getOrCreateGlobal(u->getString(),u->isConstantArray,u->getType());
+#if 1
+ if (u->isConstantArray)
+ {
+ aeb::lds::Constant *co = aeb::lds::ConstantDataArray::getString(
+ const_cast<aeb::lds::Type *>(value->getType())
+ ,u->getString().c_str());
+ reinterpret_cast<GlobalVariable *>(value)->setInitializer(co);
+ }
+#endif
if (c)
{
// Call c function there is no definition or body
AST::ParmVarDecl *pv = dynamic_cast<AST::ParmVarDecl *>(u->getDecl());
if (pv)
{
- value = getCurrentFunction()->getArgument(pv->getName());
- if (value)
- {
+ value = getCurrentFunction()->getArgument(pv->getName());
+ if (value)
+ {
std::cout<<"CodeGenFunction::EmitCallExpr "<<d->getName()<<" FOUND Param "<<pv->getName()<<" Idx="<<ParamIdx<<" PV Type NULL ? "<<(pv->getType() == NULL)<<std::endl;
- } else
- {
+ } else
+ {
std::cout<<"CodeGenFunction::EmitCallExpr ERROR function call parameter not globalVariable !!!!!! "<<ParamIdx<<std::endl;
value = m_CGM.getOrCreateGlobal(nv);
- }
+ }
} else
- {
+ {
//TODO BAD AND WRONG IT's A PARAMETER FROM THE CURRENT CALL STACK
value = m_CGM.getOrCreateGlobal(nv);
- }
+ }
#ifdef CG_DEBUG
std::cout<<"CodeGenFunction::EmittCallExpr call "<<d->getName()<<" Param NamedDecl: "<<nv->getName()<<" "<<std::endl;
#endif
if (pv->getType() != NULL)
{
#if 1
- iTy = getType().ConvertType(pv->getType());
+ iTy = getType().ConvertType(pv->getType());
#else
// std::cout<<"CodeGenModule::EmitGlobalFunctionDefinition "<<pv->getName()<<" Has type ";
switch (pv->getType()->getClass())
}
+ aeb::lds::Constant *
+ CodeGenModule::getInitializerFromVarDecl(const AST::VarDecl &D)
+ {
+ aeb::lds::Constant *co = NULL;
+ if (D.hasInit())
+ {
+ AST::Expr *E = const_cast<AST::VarDecl &>(D).getInit();
+ AST::Expr::EvalResult r;
+ E->evalute(r);
+ aeb::lds::Type *vTy = getType().ConvertType(E->getType());
+
+ switch (vTy->getTypeID())
+ {
+ case aeb::lds::Type::IntegerTyID :
+ co = aeb::lds::ConstantInt::getInteger(
+ vTy
+ ,r.u.l);
+ break;
+ case aeb::lds::Type::ArrayTyID :
+ co = aeb::lds::ConstantDataArray::getString(
+ vTy
+ ,reinterpret_cast<AST::StringLiteral *>(E)->getString().c_str());
+ break;
+ default:
+ std::cerr<<"getInitializer For: "<<D.getName()<<" No Type"<<std::endl;
+ }
+ }
+ return co;
+ }
+
/**
*
*/
std::cout<<" "<<D->getName()<<std::endl;
aeb::lds::Type *Ty = getType().ConvertType(D->getType());
GV =m_Module->insertGlobal(D->getName(),true,Ty);
- }
+ // Is there a default value
+ if (aeb::lds::Constant *co = getInitializerFromVarDecl(*D))
+ {
+ GV->setInitializer(co);
+ }
+ }
/**
*
*/
,D->getName());
aeb::lds::Type *Ty = getType().ConvertType(D->getType());
GV =m_Module->insertGlobal(D->getName(),false,Ty);
+ // Is there a default value
+ if (aeb::lds::Constant *co = getInitializerFromVarDecl(*D))
+ {
+ GV->setInitializer(co);
+ }
}
/**
*
GlobalVariable * CodeGenModule::getOrCreateGlobal(const std::string &_flag,bool constant,void *_Ty )
{
GlobalVariable *GV;
- std::cout<<"CodeGenModule::getOrCreateGlobal deprecated: "<<_flag<<std::endl;
- GV =m_Module->insertGlobal(_flag,constant);
+ if (_Ty != NULL)
+ {
+ std::cout<<"CodeGenModule::getOrCreateGlobal deprecated: "<<_flag<<std::endl;
+ } else
+ {
+ std::cout<<"CodeGenModule::getOrCreateGlobal "<<_flag<<" _Ty == NULL"<<std::endl;
+ }
+ aeb::lds::Type *Ty = getType().ConvertType(static_cast<AST::Type *>(_Ty));
+ GV =m_Module->insertGlobal(_flag,constant,Ty);
return GV;
}
#endif
GlobalVariable *GV;
aeb::lds::Type *Ty = getType().ConvertType(D->getType());
//std::cout<<"CodeGenModule::getOrCreateGlobal "<<D->getName()<<std::endl;
- GV =m_Module->insertGlobal(D->getName(),Ty);
+ GV =m_Module->insertGlobal(D->getName(),false,Ty);
return GV;
}
}
AST::TypedefType *TDTy = dynamic_cast<AST::TypedefType *>(Ty);
AST::TypedefDecl *td = static_cast<AST::TypedefDecl *>(TDTy->getDecl());
return ConvertType(td->getBaseType());
+ }else if ( Ty->getClass() == AST::Type::ConstantArray ||
+ Ty->getClass() == AST::Type::Array)
+ {
+ AST::ArrayType *ArTy = dynamic_cast<AST::ArrayType *>(Ty);
+ const AST::Type *ElType = ArTy->getElementType();
+ // Recursive call BAD
+ return ConvertType(const_cast<AST::Type *>(ElType));
}else
{
std::cerr<<"CodeGenType::ConvertType Not builtin TODO return NULL not good"<<std::endl;
}
} else
{
- std::cerr<<"CodeGenType::ConvertType Not Type return NULL not good"<<std::endl;
+ std::cerr<<"CodeGenType::ConvertType Ty==NULL return NULL not good"<<std::endl;
return NULL;
}
}
ADD_LIBRARY(commonIR
LdsInstruction.cpp
BasicBlock.cpp
+ Constant.cpp
Transition.cpp
Argument.cpp
GlobalVariable.cpp
--- /dev/null
+#include <iostream>
+#include <algorithm>
+#include <cassert>
+#include <vector>
+#include "IR/Value.h"
+#include "IR/Type.h"
+#if 0
+#include "IR/Transition.h"
+#include "IR/Behavior.h"
+#include "IR/Function.h"
+#include "IR/Signal.h"
+#include "IR/Argument.h"
+#include "IR/BasicBlock.h"
+#endif
+#define FUNCTION_SYMTAB
+// May be Create TraitsSigArgumentImpl.h
+#include "IR/Constant.h"
+namespace aeb {
+ // Template instantiation
+namespace lds {
+
+
+/**
+ * ConstantInt
+ *
+ */
+ConstantInt::ConstantInt(Type *Ty,unsigned long _vTy,long l)
+ : ConstantData(Ty,_vTy) , m_Value(l)
+{
+}
+
+Constant *
+ConstantInt::getInteger(Type *Ty,long _v)
+{
+ return new ConstantInt(Ty,ConstantIntVal, _v);
+}
+
+/**
+ * ConstantDataArray Implementation
+ *
+ */
+ConstantDataArray::ConstantDataArray(Type *Ty,unsigned _vTy)
+ : ConstantData(Ty,_vTy)
+{
+}
+
+Constant *
+ConstantDataArray::getString(Type *Ty,const char *_val)
+{
+ Constant *c = new ConstantDataArray(Ty,ConstantArrayVal);
+ c->setName(_val);
+ return c;
+}
+
+}
+}
+
+
+
void
GlobalVariable::setInitializer(Constant *InitVal)
{
+ if (InitVal)
+ {
+ Op<0>().set(InitVal);
+ } else
+ { // Null may be reset
+ }
}
Constant *
GlobalVariable::getInitializer()
{
- return NULL;
+ return static_cast<Constant *>(Op<0>().get());
}
}
void setInit(Expr *e)
{ m_Init = e; } ;
///
- Expr *getInit(Expr *e)
+ Expr *getInit()
{ return dynamic_cast<AST::Expr *>(m_Init); };
};
/*
* May be set this function virtual. It might need more
* memory
*/
- bool evalute(EvalResult &result) ;
+ virtual bool evalute(EvalResult &result) ;
/**
* evaluate constant expression should exist too
*/
* In term should return an APValue or Value type
*/
unsigned int get_value() const { return m_value; };
+
+ virtual bool evalute(EvalResult &result)
+ { result.u.l = m_value; return true; }
protected:
unsigned int m_value;
std::string m_string;
public:
bool isConstantArray;
- StringLiteral(const std::string &s,Type *_t)
- : isConstantArray(false), Expr(StringLiteralClass,_t),m_string(s) {
+ StringLiteral(const std::string &s,Type *_t,bool _isConst = false)
+ : isConstantArray(_isConst), Expr(StringLiteralClass,_t),m_string(s) {
}
std::string getString() const {return m_string; } ;
#endif
GlobalVariable * getOrCreateGlobal(const AST::ValueDecl *D);
protected:
+ private:
+ aeb::lds::Constant *getInitializerFromVarDecl(const AST::VarDecl &D);
};
}
: User(Ty,vty,u,nbOperand) {}
public:
+
+};
+
+
+/**
+ *
+ *
+ */
+class ConstantData : public Constant
+{
+ friend class Constant;
+ protected:
+ ConstantData(Type *Ty,unsigned _vTy) : Constant(Ty,_vTy,NULL,0) {}
+ protected:
+ void * operator new(size_t S) { return User::operator new (S,0) ; }
+ public:
+ void operator delete(void *_ptr) { return User::operator delete(_ptr) ; }
+
+ ConstantData(const ConstantData &_c) = delete;
+};
+
+/**
+ *
+ *
+ */
+class ConstantInt : public ConstantData
+{
+ friend class Constant;
+ private:
+ long m_Value;
+ ConstantInt(Type *Ty,unsigned long _vTy,long _d = 0) ;
+ protected:
+
+ public:
+ ConstantInt(const ConstantInt &_c) = delete;
// Need some basic Constructors
- Constant *getInteger(Type *Ty,long _value) { return NULL ; };
+ static Constant *getInteger(Type *Ty,long _value) ;
+
+ inline long getValue() { return m_Value ; }
+};
+
+/**
+ *
+ *
+ */
+class ConstantDataArray : public ConstantData
+{
+ private:
+ ConstantDataArray(Type *Ty,unsigned vTy);
+ // For test purpose
+ std::string m_Value;
+ public:
+
+ ConstantDataArray(const ConstantDataArray &_c) = delete;
+ /**
+ *
+ */
+ static Constant *getString(Type *_Ty,const char *_value);
};
*/
class GlobalVariable : public aeb::dlilist_node<GlobalVariable> , public Constant {
protected:
- friend class SymbolTableListTraits<GlobalVariable>;
+ friend class SymbolTableListTraits<GlobalVariable>;
// TODO the information bellow are stored in Value
Module *m_Parent;
bool m_IsConstant : 1; /* Is it a constant Global Variable */
GlobalVariable(const GlobalVariable &_g) : Constant(*this) {}
public:
GlobalVariable(const std::string &flg , bool constant,Type *_Ty = NULL);
-#if 0
- : m_IsConstant(constant)
- , Constant(_Ty, GlobalVariableVal,OperandTraits<GlobalVariable>::op_begin(this),1)
- , m_Parent(NULL)
- { Value::setName(flg); } ;
-#endif
+
virtual ~GlobalVariable() {} ;
inline bool hasInitializer() const { return false; };
TimeTyID ,
DurationTyID,
FunctionTyID,
- StructTyID ,
+ StructTyID ,
ArrayTyID ,
PointerTyID
};