Mercurial > projects > ldc
annotate gen/typinf.cpp @ 121:9c79b61fb638 trunk
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
Unit tests are now implemented.
author | lindquist |
---|---|
date | Tue, 27 Nov 2007 03:09:36 +0100 |
parents | 5ba6d286c941 |
children | 1700239cab2e |
rev | line source |
---|---|
1 | 1 |
2 | |
3 // Copyright (c) 1999-2004 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
11 // Modifications for LLVMDC: |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
12 // Copyright (c) 2007 by Tomas Lindquist Olsen |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
13 // tomas at famolsen dk |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
14 |
1 | 15 #include <cstdio> |
16 #include <cassert> | |
17 | |
52 | 18 #include "gen/llvm.h" |
19 | |
1 | 20 #include "mars.h" |
21 #include "module.h" | |
22 #include "mtype.h" | |
23 #include "scope.h" | |
24 #include "init.h" | |
25 #include "expression.h" | |
26 #include "attrib.h" | |
27 #include "declaration.h" | |
28 #include "template.h" | |
29 #include "id.h" | |
30 #include "enum.h" | |
31 #include "import.h" | |
32 #include "aggregate.h" | |
33 | |
52 | 34 #include "gen/irstate.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
35 #include "gen/logger.h" |
52 | 36 #include "gen/runtime.h" |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
37 #include "gen/tollvm.h" |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
38 #include "gen/arrays.h" |
100 | 39 #include "gen/structs.h" |
106 | 40 #include "gen/classes.h" |
1 | 41 |
42 /******************************************* | |
43 * Get a canonicalized form of the TypeInfo for use with the internal | |
44 * runtime library routines. Canonicalized in that static arrays are | |
45 * represented as dynamic arrays, enums are represented by their | |
46 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
47 * so we can use the custom internal ones more. | |
48 */ | |
49 | |
50 Expression *Type::getInternalTypeInfo(Scope *sc) | |
51 { TypeInfoDeclaration *tid; | |
52 Expression *e; | |
53 Type *t; | |
54 static TypeInfoDeclaration *internalTI[TMAX]; | |
55 | |
56 //printf("Type::getInternalTypeInfo() %s\n", toChars()); | |
57 t = toBasetype(); | |
58 switch (t->ty) | |
59 { | |
60 case Tsarray: | |
61 t = t->next->arrayOf(); // convert to corresponding dynamic array type | |
62 break; | |
63 | |
64 case Tclass: | |
65 if (((TypeClass *)t)->sym->isInterfaceDeclaration()) | |
66 break; | |
67 goto Linternal; | |
68 | |
69 case Tarray: | |
70 if (t->next->ty != Tclass) | |
71 break; | |
72 goto Linternal; | |
73 | |
74 case Tfunction: | |
75 case Tdelegate: | |
76 case Tpointer: | |
77 Linternal: | |
78 tid = internalTI[t->ty]; | |
79 if (!tid) | |
80 { tid = new TypeInfoDeclaration(t, 1); | |
81 internalTI[t->ty] = tid; | |
82 } | |
83 e = new VarExp(0, tid); | |
52 | 84 //e = e->addressOf(sc); |
1 | 85 e->type = tid->type; // do this so we don't get redundant dereference |
86 return e; | |
87 | |
88 default: | |
89 break; | |
90 } | |
91 //printf("\tcalling getTypeInfo() %s\n", t->toChars()); | |
92 return t->getTypeInfo(sc); | |
93 } | |
94 | |
95 | |
96 /**************************************************** | |
97 * Get the exact TypeInfo. | |
98 */ | |
99 | |
100 Expression *Type::getTypeInfo(Scope *sc) | |
101 { | |
102 Expression *e; | |
103 Type *t; | |
104 | |
105 //printf("Type::getTypeInfo() %p, %s\n", this, toChars()); | |
106 t = merge(); // do this since not all Type's are merge'd | |
107 if (!t->vtinfo) | |
108 { t->vtinfo = t->getTypeInfoDeclaration(); | |
109 assert(t->vtinfo); | |
110 | |
111 /* If this has a custom implementation in std/typeinfo, then | |
112 * do not generate a COMDAT for it. | |
113 */ | |
114 if (!t->builtinTypeInfo()) | |
115 { // Generate COMDAT | |
116 if (sc) // if in semantic() pass | |
117 { // Find module that will go all the way to an object file | |
118 Module *m = sc->module->importedFrom; | |
119 m->members->push(t->vtinfo); | |
120 } | |
121 else // if in obj generation pass | |
122 { | |
123 t->vtinfo->toObjFile(); | |
124 } | |
125 } | |
126 } | |
127 e = new VarExp(0, t->vtinfo); | |
128 //e = e->addressOf(sc); | |
129 e->type = t->vtinfo->type; // do this so we don't get redundant dereference | |
130 return e; | |
131 } | |
132 | |
52 | 133 enum RET TypeFunction::retStyle() |
134 { | |
135 return RETstack; | |
136 } | |
1 | 137 |
138 TypeInfoDeclaration *Type::getTypeInfoDeclaration() | |
139 { | |
140 //printf("Type::getTypeInfoDeclaration() %s\n", toChars()); | |
141 return new TypeInfoDeclaration(this, 0); | |
142 } | |
143 | |
52 | 144 TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration() |
1 | 145 { |
52 | 146 return new TypeInfoTypedefDeclaration(this); |
1 | 147 } |
148 | |
52 | 149 TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration() |
150 { | |
151 return new TypeInfoPointerDeclaration(this); | |
152 } | |
1 | 153 |
154 TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration() | |
155 { | |
156 return new TypeInfoArrayDeclaration(this); | |
157 } | |
158 | |
159 TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration() | |
160 { | |
161 return new TypeInfoStaticArrayDeclaration(this); | |
162 } | |
163 | |
164 TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration() | |
165 { | |
166 return new TypeInfoAssociativeArrayDeclaration(this); | |
167 } | |
168 | |
52 | 169 TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration() |
170 { | |
171 return new TypeInfoStructDeclaration(this); | |
172 } | |
1 | 173 |
174 TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration() | |
175 { | |
176 if (sym->isInterfaceDeclaration()) | |
177 return new TypeInfoInterfaceDeclaration(this); | |
178 else | |
179 return new TypeInfoClassDeclaration(this); | |
180 } | |
181 | |
182 TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration() | |
183 { | |
184 return new TypeInfoEnumDeclaration(this); | |
185 } | |
186 | |
187 TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration() | |
188 { | |
189 return new TypeInfoFunctionDeclaration(this); | |
190 } | |
191 | |
192 TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration() | |
193 { | |
194 return new TypeInfoDelegateDeclaration(this); | |
195 } | |
196 | |
197 TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration() | |
198 { | |
199 return new TypeInfoTupleDeclaration(this); | |
200 } | |
201 | |
202 | |
203 /* ========================================================================= */ | |
204 | |
205 /* These decide if there's an instance for them already in std.typeinfo, | |
206 * because then the compiler doesn't need to build one. | |
207 */ | |
208 | |
209 int Type::builtinTypeInfo() | |
210 { | |
211 return 0; | |
212 } | |
213 | |
214 int TypeBasic::builtinTypeInfo() | |
215 { | |
216 return 1; | |
217 } | |
218 | |
219 int TypeDArray::builtinTypeInfo() | |
220 { | |
52 | 221 return next->isTypeBasic() != NULL; |
1 | 222 } |
223 | |
224 /* ========================================================================= */ | |
225 | |
226 /*************************************** | |
227 * Create a static array of TypeInfo references | |
228 * corresponding to an array of Expression's. | |
229 * Used to supply hidden _arguments[] value for variadic D functions. | |
230 */ | |
231 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
232 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) |
1 | 233 { |
234 assert(0); | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
235 return NULL; |
1 | 236 } |
237 | |
52 | 238 /* ========================================================================= */ |
239 | |
240 ////////////////////////////////////////////////////////////////////////////// | |
241 // MAGIC PLACE | |
242 ////////////////////////////////////////////////////////////////////////////// | |
243 | |
244 void TypeInfoDeclaration::toObjFile() | |
245 { | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
246 gIR->resolveList.push_back(this); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
247 } |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
248 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
249 void DtoResolveTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
250 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
251 if (tid->llvmResolved) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
252 tid->llvmResolved = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
253 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
254 Logger::println("* DtoResolveTypeInfo(%s)", tid->toChars()); |
52 | 255 LOG_SCOPE; |
65 | 256 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
257 tid->llvmIRGlobal = new IRGlobal(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
258 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
259 gIR->declareList.push_back(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
260 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
261 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
262 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
263 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
264 if (tid->llvmDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
265 tid->llvmDeclared = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
266 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
267 Logger::println("* DtoDeclareTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
268 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
269 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
270 std::string mangled(tid->mangle()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
271 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
272 Logger::println("type = '%s'", tid->tinfo->toChars()); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
273 Logger::println("typeinfo mangle: %s", mangled.c_str()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
274 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
275 // this is a declaration of a builtin __initZ var |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
276 if (tid->tinfo->builtinTypeInfo()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
277 tid->llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangled.c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
278 assert(tid->llvmValue); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
279 mangled.append("__TYPE"); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
280 gIR->module->addTypeName(mangled, tid->llvmValue->getType()->getContainedType(0)); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
281 Logger::println("Got typeinfo var: %s", tid->llvmValue->getName().c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
282 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
283 tid->llvmDefined = true; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
284 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
285 // custom typedef |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
286 else { |
106 | 287 tid->llvmDeclare(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
288 gIR->constInitList.push_back(tid); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
289 } |
52 | 290 } |
291 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
292 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
293 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
294 if (tid->llvmInitialized) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
295 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
296 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
297 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
298 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
299 |
106 | 300 gIR->defineList.push_back(tid); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
301 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
302 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
303 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
304 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
305 if (tid->llvmDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
306 tid->llvmDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
307 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
308 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
309 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
310 |
106 | 311 tid->llvmDefine(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
312 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
313 |
52 | 314 /* ========================================================================= */ |
315 | |
316 void TypeInfoDeclaration::toDt(dt_t **pdt) | |
317 { | |
106 | 318 assert(0 && "TypeInfoDeclaration::toDt"); |
319 } | |
320 | |
321 void TypeInfoDeclaration::llvmDeclare() | |
322 { | |
323 assert(0 && "TypeInfoDeclaration::llvmDeclare"); | |
324 } | |
325 | |
326 void TypeInfoDeclaration::llvmDefine() | |
327 { | |
328 assert(0 && "TypeInfoDeclaration::llvmDeclare"); | |
52 | 329 } |
330 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
331 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
332 |
106 | 333 void TypeInfoTypedefDeclaration::llvmDeclare() |
52 | 334 { |
106 | 335 Logger::println("TypeInfoTypedefDeclaration::llvmDeclare() %s", toChars()); |
336 LOG_SCOPE; | |
337 | |
338 ClassDeclaration* base = Type::typeinfotypedef; | |
339 DtoResolveClass(base); | |
340 | |
341 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
342 | |
343 // create the symbol | |
344 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
345 } | |
346 | |
347 void TypeInfoTypedefDeclaration::llvmDefine() | |
348 { | |
349 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
350 LOG_SCOPE; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
351 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
352 ClassDeclaration* base = Type::typeinfotypedef; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
353 DtoForceConstInitDsymbol(base); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
354 |
100 | 355 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
356 Logger::cout() << "got stype: " << *stype << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
357 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
358 // vtbl |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
359 std::vector<llvm::Constant*> sinits; |
100 | 360 sinits.push_back(base->llvmVtbl); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
361 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
362 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
363 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
364 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
365 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
366 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
367 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
368 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
369 // TypeInfo base |
96 | 370 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
371 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
372 Logger::println("generating base typeinfo"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
373 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
374 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
375 sd->basetype->getTypeInfo(NULL); // generate vtinfo |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
376 assert(sd->basetype->vtinfo); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
377 if (!sd->basetype->vtinfo->llvmValue) |
106 | 378 DtoForceDeclareDsymbol(sd->basetype->vtinfo); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
379 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
380 assert(sd->basetype->vtinfo->llvmValue); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
381 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
383 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
384 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
385 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
386 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
387 char *name = sd->toPrettyChars(); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
388 sinits.push_back(DtoConstString(name)); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
389 assert(sinits.back()->getType() == stype->getElementType(3)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
390 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
391 // void[] init |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
392 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
393 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
394 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
395 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
396 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
397 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
398 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
399 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
400 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
401 ciname.append("__init"); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
402 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
403 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
404 size_t cisize = gTargetData->getTypeSize(DtoType(sd->basetype)); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
405 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
406 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
407 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
408 // create the symbol |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
409 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 410 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
411 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
412 |
106 | 413 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
414 { | |
415 assert(0); | |
52 | 416 } |
417 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
418 /* ========================================================================= */ |
52 | 419 |
106 | 420 void TypeInfoEnumDeclaration::llvmDeclare() |
52 | 421 { |
106 | 422 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); |
423 LOG_SCOPE; | |
424 | |
425 ClassDeclaration* base = Type::typeinfoenum; | |
426 DtoResolveClass(base); | |
427 | |
428 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
429 | |
430 // create the symbol | |
431 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
432 } | |
433 | |
434 void TypeInfoEnumDeclaration::llvmDefine() | |
435 { | |
436 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
437 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
438 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
439 ClassDeclaration* base = Type::typeinfoenum; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
440 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
441 |
100 | 442 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
443 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
444 // vtbl |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 std::vector<llvm::Constant*> sinits; |
100 | 446 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
447 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
448 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
449 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
450 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
451 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
452 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
453 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
454 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
455 // TypeInfo base |
96 | 456 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
458 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
460 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
461 sd->memtype->getTypeInfo(NULL); // generate vtinfo |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
462 assert(sd->memtype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
463 if (!sd->memtype->vtinfo->llvmValue) |
106 | 464 DtoForceDeclareDsymbol(sd->memtype->vtinfo); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
465 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
466 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
467 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
468 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
469 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
470 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
471 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
472 char *name = sd->toPrettyChars(); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
473 sinits.push_back(DtoConstString(name)); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
474 assert(sinits.back()->getType() == stype->getElementType(3)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
475 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
476 // void[] init |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
477 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
478 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
479 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
480 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
481 } |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
482 else |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
483 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
484 const llvm::Type* memty = DtoType(sd->memtype); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
485 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
486 std::string ciname(sd->mangle()); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
487 ciname.append("__init"); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
488 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
489 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
490 size_t cisize = gTargetData->getTypeSize(memty); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
491 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
492 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
493 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
494 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
495 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 496 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
497 } | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
498 |
106 | 499 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
500 { | |
501 assert(0); | |
52 | 502 } |
503 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
504 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
505 |
106 | 506 static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
507 { | |
508 ClassDeclaration* base = cd; | |
509 DtoResolveClass(base); | |
510 | |
511 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
512 | |
513 // create the symbol | |
514 tid->llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); | |
515 } | |
516 | |
517 static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
518 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
519 ClassDeclaration* base = cd; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
520 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
521 |
100 | 522 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
523 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
524 // vtbl |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
525 std::vector<llvm::Constant*> sinits; |
100 | 526 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
527 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
528 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
529 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
530 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
531 // TypeInfo base |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
532 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
533 basetype->getTypeInfo(NULL); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
534 assert(basetype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
535 if (!basetype->vtinfo->llvmValue) |
106 | 536 DtoForceDeclareDsymbol(basetype->vtinfo); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
537 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
538 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
539 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
540 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
541 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
542 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
543 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 544 isaGlobalVar(tid->llvmValue)->setInitializer(tiInit); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
545 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
546 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
547 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
548 |
106 | 549 void TypeInfoPointerDeclaration::llvmDeclare() |
52 | 550 { |
106 | 551 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); |
552 LOG_SCOPE; | |
553 | |
554 assert(tinfo->ty == Tpointer); | |
555 TypePointer *tc = (TypePointer *)tinfo; | |
556 | |
557 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer); | |
558 } | |
559 | |
560 void TypeInfoPointerDeclaration::llvmDefine() | |
561 { | |
562 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
563 LOG_SCOPE; |
52 | 564 |
565 assert(tinfo->ty == Tpointer); | |
566 TypePointer *tc = (TypePointer *)tinfo; | |
567 | |
106 | 568 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
569 } | |
570 | |
571 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | |
572 { | |
573 assert(0); | |
52 | 574 } |
575 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
576 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
577 |
106 | 578 void TypeInfoArrayDeclaration::llvmDeclare() |
52 | 579 { |
106 | 580 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
581 LOG_SCOPE; |
52 | 582 |
583 assert(tinfo->ty == Tarray); | |
584 TypeDArray *tc = (TypeDArray *)tinfo; | |
585 | |
106 | 586 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray); |
587 } | |
588 | |
589 void TypeInfoArrayDeclaration::llvmDefine() | |
590 { | |
591 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars()); | |
592 LOG_SCOPE; | |
593 | |
594 assert(tinfo->ty == Tarray); | |
595 TypeDArray *tc = (TypeDArray *)tinfo; | |
596 | |
597 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); | |
598 } | |
599 | |
600 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | |
601 { | |
602 assert(0); | |
52 | 603 } |
604 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
605 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
606 |
106 | 607 void TypeInfoStaticArrayDeclaration::llvmDeclare() |
608 { | |
609 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | |
610 LOG_SCOPE; | |
611 | |
612 // init typeinfo class | |
613 ClassDeclaration* base = Type::typeinfostaticarray; | |
614 DtoResolveClass(base); | |
615 | |
616 // get type of typeinfo class | |
617 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
618 | |
619 // create the symbol | |
620 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
621 } | |
622 | |
623 void TypeInfoStaticArrayDeclaration::llvmDefine() | |
52 | 624 { |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
625 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
626 LOG_SCOPE; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
627 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
628 // init typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
629 ClassDeclaration* base = Type::typeinfostaticarray; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
630 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
631 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
632 // get type of typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
633 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
52 | 634 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
635 // initializer vector |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
636 std::vector<llvm::Constant*> sinits; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
637 // first is always the vtable |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
638 sinits.push_back(base->llvmVtbl); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
639 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
640 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
641 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
642 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
643 // value typeinfo |
52 | 644 assert(tinfo->ty == Tsarray); |
645 TypeSArray *tc = (TypeSArray *)tinfo; | |
646 tc->next->getTypeInfo(NULL); | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
647 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
648 // get symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
649 assert(tc->next->vtinfo); |
106 | 650 DtoForceDeclareDsymbol(tc->next->vtinfo); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
651 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
652 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
653 sinits.push_back(castbase); |
52 | 654 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
655 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
656 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
657 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
658 // create the symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
659 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 660 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
661 } | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
662 |
106 | 663 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
664 { | |
665 assert(0); | |
52 | 666 } |
667 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
668 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
669 |
106 | 670 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
671 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
672 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
673 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
674 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
675 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
676 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
677 DtoResolveClass(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
678 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
679 // get type of typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
680 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
681 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
682 // create the symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
683 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 684 } |
685 | |
686 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
687 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
688 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
689 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
690 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
691 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
692 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
693 DtoForceConstInitDsymbol(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
694 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
695 // get type of typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
696 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
697 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
698 // initializer vector |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
699 std::vector<llvm::Constant*> sinits; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
700 // first is always the vtable |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
701 sinits.push_back(base->llvmVtbl); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
702 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
703 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
704 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
705 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
706 // get type |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
707 assert(tinfo->ty == Taarray); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
708 TypeAArray *tc = (TypeAArray *)tinfo; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
709 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
710 // value typeinfo |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
711 tc->next->getTypeInfo(NULL); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
712 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
713 // get symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
714 assert(tc->next->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
715 DtoForceDeclareDsymbol(tc->next->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
716 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
717 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
718 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
719 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
720 // key typeinfo |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
721 tc->index->getTypeInfo(NULL); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
722 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
723 // get symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
724 assert(tc->index->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
725 DtoForceDeclareDsymbol(tc->index->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
726 castbase = isaConstant(tc->index->vtinfo->llvmValue); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
727 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
728 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
729 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
730 // create the symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
731 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
732 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
106 | 733 } |
734 | |
52 | 735 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
736 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
737 assert(0); |
52 | 738 } |
739 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
740 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
741 |
106 | 742 void TypeInfoFunctionDeclaration::llvmDeclare() |
743 { | |
744 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
745 LOG_SCOPE; | |
746 | |
747 assert(tinfo->ty == Tfunction); | |
748 TypeFunction *tc = (TypeFunction *)tinfo; | |
749 | |
750 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
751 } | |
752 | |
753 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 754 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
755 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
756 LOG_SCOPE; |
52 | 757 |
758 assert(tinfo->ty == Tfunction); | |
759 TypeFunction *tc = (TypeFunction *)tinfo; | |
760 | |
106 | 761 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
762 } | |
763 | |
764 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
765 { | |
766 assert(0); | |
52 | 767 } |
768 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
769 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
770 |
106 | 771 void TypeInfoDelegateDeclaration::llvmDeclare() |
772 { | |
773 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
774 LOG_SCOPE; | |
775 | |
776 assert(tinfo->ty == Tdelegate); | |
777 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
778 | |
779 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
780 } | |
781 | |
782 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 783 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
784 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
785 LOG_SCOPE; |
52 | 786 |
787 assert(tinfo->ty == Tdelegate); | |
788 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
789 | |
106 | 790 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
791 } | |
792 | |
793 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
794 { | |
795 assert(0); | |
52 | 796 } |
797 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
798 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
799 |
106 | 800 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 801 { |
106 | 802 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
803 LOG_SCOPE; | |
804 | |
805 assert(tinfo->ty == Tstruct); | |
806 TypeStruct *tc = (TypeStruct *)tinfo; | |
807 StructDeclaration *sd = tc->sym; | |
808 DtoResolveDsymbol(sd); | |
809 | |
810 ClassDeclaration* base = Type::typeinfostruct; | |
811 DtoResolveClass(base); | |
812 | |
813 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); | |
814 | |
815 // create the symbol | |
816 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
817 } | |
818 | |
819 void TypeInfoStructDeclaration::llvmDefine() | |
820 { | |
821 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 822 LOG_SCOPE; |
823 | |
824 assert(tinfo->ty == Tstruct); | |
825 TypeStruct *tc = (TypeStruct *)tinfo; | |
826 StructDeclaration *sd = tc->sym; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
827 DtoForceConstInitDsymbol(sd); |
72 | 828 |
829 ClassDeclaration* base = Type::typeinfostruct; | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
830 DtoForceConstInitDsymbol(base); |
72 | 831 |
100 | 832 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); |
72 | 833 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
834 // vtbl |
72 | 835 std::vector<llvm::Constant*> sinits; |
836 sinits.push_back(base->llvmVtbl); | |
837 | |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
838 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
839 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
840 |
72 | 841 // char[] name |
842 char *name = sd->toPrettyChars(); | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
843 sinits.push_back(DtoConstString(name)); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
844 //Logger::println("************** A"); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
845 assert(sinits.back()->getType() == stype->getElementType(2)); |
72 | 846 |
847 // void[] init | |
848 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | |
849 if (sd->zeroInit) // 0 initializer, or the same as the base type | |
850 { | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
851 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 852 } |
853 else | |
854 { | |
100 | 855 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
115
diff
changeset
|
856 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->llvmInit, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
857 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 858 } |
859 | |
860 // toX functions ground work | |
861 FuncDeclaration *fd; | |
862 FuncDeclaration *fdx; | |
863 TypeFunction *tf; | |
864 Type *ta; | |
865 Dsymbol *s; | |
866 | |
867 static TypeFunction *tftohash; | |
868 static TypeFunction *tftostring; | |
869 | |
870 if (!tftohash) | |
871 { | |
872 Scope sc; | |
873 | |
874 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
875 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
876 | |
877 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
878 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
879 } | |
880 | |
881 TypeFunction *tfeqptr; | |
882 { | |
883 Scope sc; | |
884 Arguments *arguments = new Arguments; | |
885 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
886 | |
887 arguments->push(arg); | |
888 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
889 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
890 } | |
891 | |
892 #if 0 | |
893 TypeFunction *tfeq; | |
894 { | |
895 Scope sc; | |
896 Array *arguments = new Array; | |
897 Argument *arg = new Argument(In, tc, NULL, NULL); | |
898 | |
899 arguments->push(arg); | |
900 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
901 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
902 } | |
903 #endif | |
904 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
905 //Logger::println("************** B"); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
906 const llvm::PointerType* ptty = isaPointer(stype->getElementType(4)); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
907 assert(ptty); |
72 | 908 |
909 s = search_function(sd, Id::tohash); | |
910 fdx = s ? s->isFuncDeclaration() : NULL; | |
911 if (fdx) | |
912 { | |
913 fd = fdx->overloadExactMatch(tftohash); | |
914 if (fd) { | |
915 assert(fd->llvmValue != 0); | |
916 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
917 assert(c); | |
918 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
919 sinits.push_back(c); | |
920 } | |
921 else { | |
922 //fdx->error("must be declared as extern (D) uint toHash()"); | |
923 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
924 } | |
925 } | |
926 else { | |
927 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
928 } | |
929 | |
930 s = search_function(sd, Id::eq); | |
931 fdx = s ? s->isFuncDeclaration() : NULL; | |
932 for (int i = 0; i < 2; i++) | |
933 { | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
934 //Logger::println("************** C %d", i); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
935 ptty = isaPointer(stype->getElementType(5+i)); |
72 | 936 if (fdx) |
937 { | |
938 fd = fdx->overloadExactMatch(tfeqptr); | |
939 if (fd) { | |
940 assert(fd->llvmValue != 0); | |
941 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
942 assert(c); | |
943 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
944 sinits.push_back(c); | |
945 } | |
946 else { | |
947 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
948 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
949 } | |
950 } | |
951 else { | |
952 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
953 } | |
954 | |
955 s = search_function(sd, Id::cmp); | |
956 fdx = s ? s->isFuncDeclaration() : NULL; | |
957 } | |
958 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
959 //Logger::println("************** D"); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
960 ptty = isaPointer(stype->getElementType(7)); |
72 | 961 s = search_function(sd, Id::tostring); |
962 fdx = s ? s->isFuncDeclaration() : NULL; | |
963 if (fdx) | |
964 { | |
965 fd = fdx->overloadExactMatch(tftostring); | |
966 if (fd) { | |
967 assert(fd->llvmValue != 0); | |
968 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
969 assert(c); | |
970 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
971 sinits.push_back(c); | |
972 } | |
973 else { | |
974 //fdx->error("must be declared as extern (D) char[] toString()"); | |
975 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
976 } | |
977 } | |
978 else { | |
979 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
980 } | |
981 | |
982 // uint m_flags; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
983 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 984 |
985 // create the symbol | |
986 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
73 | 987 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 988 |
106 | 989 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
990 } | |
991 | |
992 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | |
993 { | |
994 assert(0); | |
52 | 995 } |
996 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
997 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
998 |
106 | 999 void TypeInfoClassDeclaration::llvmDeclare() |
1000 { | |
1001 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
1002 LOG_SCOPE; | |
1003 | |
1004 // init typeinfo class | |
1005 ClassDeclaration* base = Type::typeinfoclass; | |
1006 assert(base); | |
1007 DtoResolveClass(base); | |
1008 | |
1009 // get type of typeinfo class | |
1010 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
1011 | |
1012 // create the symbol | |
1013 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
1014 } | |
1015 | |
1016 void TypeInfoClassDeclaration::llvmDefine() | |
1017 { | |
1018 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
1019 LOG_SCOPE; | |
1020 | |
1021 // init typeinfo class | |
1022 ClassDeclaration* base = Type::typeinfoclass; | |
1023 assert(base); | |
1024 DtoForceConstInitDsymbol(base); | |
1025 | |
1026 // get type of typeinfo class | |
1027 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
1028 | |
1029 // initializer vector | |
1030 std::vector<llvm::Constant*> sinits; | |
1031 // first is always the vtable | |
1032 sinits.push_back(base->llvmVtbl); | |
1033 | |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1034 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1035 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1036 |
106 | 1037 // get classinfo |
1038 assert(tinfo->ty == Tclass); | |
1039 TypeClass *tc = (TypeClass *)tinfo; | |
1040 assert(tc->sym->llvmClass); | |
1041 sinits.push_back(tc->sym->llvmClass); | |
1042 | |
1043 // create the symbol | |
1044 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
1045 isaGlobalVar(llvmValue)->setInitializer(tiInit); | |
1046 } | |
1047 | |
52 | 1048 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
1049 { | |
106 | 1050 assert(0); |
52 | 1051 } |
1052 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1053 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1054 |
106 | 1055 void TypeInfoInterfaceDeclaration::llvmDeclare() |
1056 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1057 Logger::println("TypeInfoInterfaceDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1058 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1059 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1060 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1061 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1062 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1063 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1064 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1065 // get type of typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1066 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1067 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1068 // create the symbol |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1069 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1070 } |
1071 | |
1072 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1073 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1074 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1075 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1076 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1077 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1078 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1079 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1080 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1081 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1082 // get type of typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1083 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1084 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1085 // initializer vector |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1086 std::vector<llvm::Constant*> sinits; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1087 // first is always the vtable |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1088 sinits.push_back(base->llvmVtbl); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1089 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1090 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1091 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1092 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1093 // get classinfo |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1094 assert(tinfo->ty == Tclass); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1095 TypeClass *tc = (TypeClass *)tinfo; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1096 assert(tc->sym->llvmClass); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1097 sinits.push_back(tc->sym->llvmClass); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1098 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1099 // create the symbol |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1100 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1101 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
106 | 1102 } |
1103 | |
52 | 1104 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1105 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1106 assert(0); |
52 | 1107 } |
1108 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1109 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1110 |
106 | 1111 void TypeInfoTupleDeclaration::llvmDeclare() |
1112 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1113 Logger::println("TypeInfoTupleDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1114 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1115 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1116 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1117 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1118 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1119 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1120 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1121 // get type of typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1122 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1123 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1124 // create the symbol |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1125 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1126 } |
1127 | |
1128 void TypeInfoTupleDeclaration::llvmDefine() | |
1129 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1130 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1131 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1132 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1133 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1134 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1135 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1136 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1137 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1138 // get type of typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1139 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1140 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1141 // initializer vector |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1142 std::vector<llvm::Constant*> sinits; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1143 // first is always the vtable |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1144 sinits.push_back(base->llvmVtbl); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1145 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1146 // monitor |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1147 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); |
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1148 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1149 // create elements array |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1150 assert(tinfo->ty == Ttuple); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1151 TypeTuple *tu = (TypeTuple *)tinfo; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1152 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1153 size_t dim = tu->arguments->dim; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1154 std::vector<llvm::Constant*> arrInits; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1155 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1156 const llvm::Type* tiTy = Type::typeinfo->type->llvmType->get(); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1157 tiTy = llvm::PointerType::get(tiTy); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1158 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1159 for (size_t i = 0; i < dim; i++) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1160 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1161 Argument *arg = (Argument *)tu->arguments->data[i]; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1162 arg->type->getTypeInfo(NULL); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1163 DtoForceDeclareDsymbol(arg->type->vtinfo); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1164 assert(arg->type->vtinfo->llvmValue); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1165 llvm::Constant* c = isaConstant(arg->type->vtinfo->llvmValue); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1166 c = llvm::ConstantExpr::getBitCast(c, tiTy); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1167 arrInits.push_back(c); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1168 } |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1169 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1170 // build array type |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1171 const llvm::ArrayType* arrTy = llvm::ArrayType::get(tiTy, dim); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1172 llvm::Constant* arrC = llvm::ConstantArray::get(arrTy, arrInits); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1173 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1174 // build the slice |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1175 llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1176 sinits.push_back(slice); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1177 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1178 // create the symbol |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1179 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1180 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
106 | 1181 } |
1182 | |
52 | 1183 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1184 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1185 assert(0); |
52 | 1186 } |