Implement a rough AddrExp::toConstElem()

This commit is contained in:
Christian Kamm
2008-08-02 22:54:36 +02:00
parent 41d6279a64
commit ad8e9ae852
2 changed files with 13 additions and 0 deletions

View File

@@ -865,6 +865,8 @@ struct AddrExp : UnaExp
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *optimize(int result);
// LLVMDC
virtual llvm::Constant *toConstElem(IRState *irs);
};
struct PtrExp : UnaExp

View File

@@ -847,6 +847,17 @@ DValue* AddrExp::toElem(IRState* p)
return new DFieldValue(type, v->getLVal(), false);
}
LLConstant* AddrExp::toConstElem(IRState* p)
{
assert(e1->op == TOKvar);
VarExp* vexp = (VarExp*)e1;
VarDeclaration* vd = vexp->var->isVarDeclaration();
assert(vd);
LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue());
assert(llc);
return llc;
}
//////////////////////////////////////////////////////////////////////////////////////////
DValue* PtrExp::toElem(IRState* p)