Mercurial > projects > ldc
comparison gen/toir.cpp @ 433:b5f55f471e0b
Move DeclarationExp code into a helper function so it can call itself for template mixin members.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Wed, 30 Jul 2008 09:21:06 +0200 |
parents | e763821ab244 |
children | 74101be2a553 |
comparison
equal
deleted
inserted
replaced
432:ecf70fe065b9 | 433:b5f55f471e0b |
---|---|
42 DValue* DeclarationExp::toElem(IRState* p) | 42 DValue* DeclarationExp::toElem(IRState* p) |
43 { | 43 { |
44 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars()); | 44 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars()); |
45 LOG_SCOPE; | 45 LOG_SCOPE; |
46 | 46 |
47 // variable declaration | 47 return DtoDeclarationExp(declaration); |
48 if (VarDeclaration* vd = declaration->isVarDeclaration()) | |
49 { | |
50 Logger::println("VarDeclaration"); | |
51 | |
52 // static | |
53 if (vd->isDataseg()) | |
54 { | |
55 vd->toObjFile(0); // TODO: multiobj | |
56 } | |
57 else | |
58 { | |
59 if (global.params.llvmAnnotate) | |
60 DtoAnnotation(toChars()); | |
61 | |
62 Logger::println("vdtype = %s", vd->type->toChars()); | |
63 | |
64 // referenced by nested delegate? | |
65 if (vd->nestedref) { | |
66 Logger::println("has nestedref set"); | |
67 assert(vd->ir.irLocal); | |
68 vd->ir.irLocal->value = p->func()->decl->ir.irFunc->nestedVar; | |
69 assert(vd->ir.irLocal->value); | |
70 assert(vd->ir.irLocal->nestedIndex >= 0); | |
71 } | |
72 // normal stack variable, allocate storage on the stack if it has not already been done | |
73 else if(!vd->ir.irLocal) { | |
74 const LLType* lltype = DtoType(vd->type); | |
75 | |
76 llvm::Value* allocainst; | |
77 if(gTargetData->getTypeSizeInBits(lltype) == 0) | |
78 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); | |
79 else | |
80 allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); | |
81 | |
82 //allocainst->setAlignment(vd->type->alignsize()); // TODO | |
83 vd->ir.irLocal = new IrLocal(vd); | |
84 vd->ir.irLocal->value = allocainst; | |
85 | |
86 if (global.params.symdebug) | |
87 { | |
88 DtoDwarfLocalVariable(allocainst, vd); | |
89 } | |
90 } | |
91 | |
92 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n'; | |
93 DValue* ie = DtoInitializer(vd->init); | |
94 } | |
95 | |
96 return new DVarValue(vd, vd->ir.getIrValue(), true); | |
97 } | |
98 // struct declaration | |
99 else if (StructDeclaration* s = declaration->isStructDeclaration()) | |
100 { | |
101 Logger::println("StructDeclaration"); | |
102 DtoForceConstInitDsymbol(s); | |
103 } | |
104 // function declaration | |
105 else if (FuncDeclaration* f = declaration->isFuncDeclaration()) | |
106 { | |
107 Logger::println("FuncDeclaration"); | |
108 DtoForceDeclareDsymbol(f); | |
109 } | |
110 // alias declaration | |
111 else if (AliasDeclaration* a = declaration->isAliasDeclaration()) | |
112 { | |
113 Logger::println("AliasDeclaration - no work"); | |
114 // do nothing | |
115 } | |
116 // enum | |
117 else if (EnumDeclaration* e = declaration->isEnumDeclaration()) | |
118 { | |
119 Logger::println("EnumDeclaration - no work"); | |
120 // do nothing | |
121 } | |
122 // class | |
123 else if (ClassDeclaration* e = declaration->isClassDeclaration()) | |
124 { | |
125 Logger::println("ClassDeclaration"); | |
126 DtoForceConstInitDsymbol(e); | |
127 } | |
128 // typedef | |
129 else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration()) | |
130 { | |
131 Logger::println("TypedefDeclaration"); | |
132 DtoTypeInfoOf(tdef->type, false); | |
133 } | |
134 // attribute declaration | |
135 else if (AttribDeclaration* a = declaration->isAttribDeclaration()) | |
136 { | |
137 Logger::println("AttribDeclaration"); | |
138 for (int i=0; i < a->decl->dim; ++i) | |
139 { | |
140 DtoForceDeclareDsymbol((Dsymbol*)a->decl->data[i]); | |
141 } | |
142 } | |
143 // mixin declaration | |
144 else if (TemplateMixin* m = declaration->isTemplateMixin()) | |
145 { | |
146 Logger::println("TemplateMixin"); | |
147 for (int i=0; i < m->members->dim; ++i) | |
148 { | |
149 DtoForceDeclareDsymbol((Dsymbol*)m->members->data[i]); | |
150 } | |
151 } | |
152 // unsupported declaration | |
153 else | |
154 { | |
155 error("Unimplemented DeclarationExp type. kind: %s", declaration->kind()); | |
156 assert(0); | |
157 } | |
158 return 0; | |
159 } | 48 } |
160 | 49 |
161 ////////////////////////////////////////////////////////////////////////////////////////// | 50 ////////////////////////////////////////////////////////////////////////////////////////// |
162 | 51 |
163 DValue* VarExp::toElem(IRState* p) | 52 DValue* VarExp::toElem(IRState* p) |