Mercurial > projects > ldc
annotate gen/typinf.cpp @ 108:288fe1029e1f trunk
[svn r112] Fixed 'case 1,2,3:' style case statements.
Fixed a bunch of bugs with return/break/continue in loops.
Fixed support for the DMDFE hidden implicit return value variable. This can be needed for some foreach statements where the loop body is converted to a nested delegate, but also possibly returns from the function.
Added std.math to phobos.
Added AA runtime support code, done ground work for implementing AAs.
Several other bugfixes.
author | lindquist |
---|---|
date | Tue, 20 Nov 2007 05:29:20 +0100 |
parents | 5b5194b25f33 |
children | 5ab8e92611f9 |
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 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
358 std::vector<llvm::Constant*> sinits; |
100 | 359 sinits.push_back(base->llvmVtbl); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
360 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
361 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
362 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
363 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
364 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
365 // TypeInfo base |
96 | 366 //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
|
367 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
368 Logger::println("generating base typeinfo"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
369 //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
|
370 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
371 sd->basetype->getTypeInfo(NULL); // generate vtinfo |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
372 assert(sd->basetype->vtinfo); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
373 if (!sd->basetype->vtinfo->llvmValue) |
106 | 374 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
|
375 |
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
|
376 assert(sd->basetype->vtinfo->llvmValue); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
377 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
|
378 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); |
100 | 379 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
380 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
381 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
383 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
|
384 sinits.push_back(DtoConstString(name)); |
100 | 385 assert(sinits.back()->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
386 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
387 // void[] init |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
388 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
|
389 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
|
390 { |
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
|
391 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
|
392 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
393 else |
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 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
|
396 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
403 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
404 // create the symbol |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
405 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 406 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
407 } | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
408 |
106 | 409 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
410 { | |
411 assert(0); | |
52 | 412 } |
413 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
414 /* ========================================================================= */ |
52 | 415 |
106 | 416 void TypeInfoEnumDeclaration::llvmDeclare() |
52 | 417 { |
106 | 418 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); |
419 LOG_SCOPE; | |
420 | |
421 ClassDeclaration* base = Type::typeinfoenum; | |
422 DtoResolveClass(base); | |
423 | |
424 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
425 | |
426 // create the symbol | |
427 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
428 } | |
429 | |
430 void TypeInfoEnumDeclaration::llvmDefine() | |
431 { | |
432 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
433 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
434 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
435 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
|
436 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
437 |
100 | 438 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
|
439 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
440 std::vector<llvm::Constant*> sinits; |
100 | 441 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
442 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
443 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
444 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
446 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
447 // TypeInfo base |
96 | 448 //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
|
449 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
450 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
451 //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
|
452 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
453 sd->memtype->getTypeInfo(NULL); // generate vtinfo |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
454 assert(sd->memtype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
455 if (!sd->memtype->vtinfo->llvmValue) |
106 | 456 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
|
457 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
458 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
|
459 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); |
100 | 460 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
461 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
462 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
463 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 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
|
465 sinits.push_back(DtoConstString(name)); |
100 | 466 assert(sinits.back()->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
467 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
468 // 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
|
469 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
|
470 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
|
471 { |
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
|
472 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
|
473 } |
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
|
474 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
|
475 { |
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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
485 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
486 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
487 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 488 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
489 } | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
490 |
106 | 491 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
492 { | |
493 assert(0); | |
52 | 494 } |
495 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
496 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
497 |
106 | 498 static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
499 { | |
500 ClassDeclaration* base = cd; | |
501 DtoResolveClass(base); | |
502 | |
503 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
504 | |
505 // create the symbol | |
506 tid->llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); | |
507 } | |
508 | |
509 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
|
510 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
511 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
|
512 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
513 |
100 | 514 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
|
515 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
516 std::vector<llvm::Constant*> sinits; |
100 | 517 sinits.push_back(base->llvmVtbl); |
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 // TypeInfo base |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
520 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
521 basetype->getTypeInfo(NULL); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
522 assert(basetype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
523 if (!basetype->vtinfo->llvmValue) |
106 | 524 DtoForceDeclareDsymbol(basetype->vtinfo); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
525 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
|
526 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); |
100 | 527 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
528 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
529 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
530 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
531 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 532 isaGlobalVar(tid->llvmValue)->setInitializer(tiInit); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
533 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
534 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
535 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
536 |
106 | 537 void TypeInfoPointerDeclaration::llvmDeclare() |
52 | 538 { |
106 | 539 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); |
540 LOG_SCOPE; | |
541 | |
542 assert(tinfo->ty == Tpointer); | |
543 TypePointer *tc = (TypePointer *)tinfo; | |
544 | |
545 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer); | |
546 } | |
547 | |
548 void TypeInfoPointerDeclaration::llvmDefine() | |
549 { | |
550 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
551 LOG_SCOPE; |
52 | 552 |
553 assert(tinfo->ty == Tpointer); | |
554 TypePointer *tc = (TypePointer *)tinfo; | |
555 | |
106 | 556 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
557 } | |
558 | |
559 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | |
560 { | |
561 assert(0); | |
52 | 562 } |
563 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
564 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
565 |
106 | 566 void TypeInfoArrayDeclaration::llvmDeclare() |
52 | 567 { |
106 | 568 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
569 LOG_SCOPE; |
52 | 570 |
571 assert(tinfo->ty == Tarray); | |
572 TypeDArray *tc = (TypeDArray *)tinfo; | |
573 | |
106 | 574 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray); |
575 } | |
576 | |
577 void TypeInfoArrayDeclaration::llvmDefine() | |
578 { | |
579 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars()); | |
580 LOG_SCOPE; | |
581 | |
582 assert(tinfo->ty == Tarray); | |
583 TypeDArray *tc = (TypeDArray *)tinfo; | |
584 | |
585 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); | |
586 } | |
587 | |
588 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | |
589 { | |
590 assert(0); | |
52 | 591 } |
592 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
593 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
594 |
106 | 595 void TypeInfoStaticArrayDeclaration::llvmDeclare() |
596 { | |
597 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | |
598 LOG_SCOPE; | |
599 | |
600 // init typeinfo class | |
601 ClassDeclaration* base = Type::typeinfostaticarray; | |
602 DtoResolveClass(base); | |
603 | |
604 // get type of typeinfo class | |
605 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
606 | |
607 // create the symbol | |
608 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
609 } | |
610 | |
611 void TypeInfoStaticArrayDeclaration::llvmDefine() | |
52 | 612 { |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
613 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
614 LOG_SCOPE; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
615 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
616 // init typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
617 ClassDeclaration* base = Type::typeinfostaticarray; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
618 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
619 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
620 // get type of typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
621 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
52 | 622 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
623 // initializer vector |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
624 std::vector<llvm::Constant*> sinits; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
625 // first is always the vtable |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
626 sinits.push_back(base->llvmVtbl); |
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 // value typeinfo |
52 | 629 assert(tinfo->ty == Tsarray); |
630 TypeSArray *tc = (TypeSArray *)tinfo; | |
631 tc->next->getTypeInfo(NULL); | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
632 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
633 // get symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
634 assert(tc->next->vtinfo); |
106 | 635 DtoForceDeclareDsymbol(tc->next->vtinfo); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
636 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
637 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
638 sinits.push_back(castbase); |
52 | 639 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
640 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
641 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
642 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
643 // create the symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
644 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
106 | 645 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
646 } | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
647 |
106 | 648 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
649 { | |
650 assert(0); | |
52 | 651 } |
652 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
653 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
654 |
106 | 655 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
656 { | |
657 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | |
658 } | |
659 | |
660 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
661 { | |
662 assert(0 && "TypeInfoAssociativeArrayDeclaration"); | |
663 } | |
664 | |
52 | 665 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
666 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
667 assert(0 && "TypeInfoAssociativeArrayDeclaration"); |
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 /* |
52 | 670 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); |
671 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray | |
672 dtdword(pdt, 0); // monitor | |
673 | |
674 assert(tinfo->ty == Taarray); | |
675 | |
676 TypeAArray *tc = (TypeAArray *)tinfo; | |
677 | |
678 tc->next->getTypeInfo(NULL); | |
679 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
680 | |
681 tc->index->getTypeInfo(NULL); | |
682 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
683 */ |
52 | 684 } |
685 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
686 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
687 |
106 | 688 void TypeInfoFunctionDeclaration::llvmDeclare() |
689 { | |
690 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
691 LOG_SCOPE; | |
692 | |
693 assert(tinfo->ty == Tfunction); | |
694 TypeFunction *tc = (TypeFunction *)tinfo; | |
695 | |
696 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
697 } | |
698 | |
699 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 700 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
701 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
702 LOG_SCOPE; |
52 | 703 |
704 assert(tinfo->ty == Tfunction); | |
705 TypeFunction *tc = (TypeFunction *)tinfo; | |
706 | |
106 | 707 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
708 } | |
709 | |
710 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
711 { | |
712 assert(0); | |
52 | 713 } |
714 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
715 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
716 |
106 | 717 void TypeInfoDelegateDeclaration::llvmDeclare() |
718 { | |
719 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
720 LOG_SCOPE; | |
721 | |
722 assert(tinfo->ty == Tdelegate); | |
723 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
724 | |
725 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
726 } | |
727 | |
728 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 729 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
730 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
731 LOG_SCOPE; |
52 | 732 |
733 assert(tinfo->ty == Tdelegate); | |
734 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
735 | |
106 | 736 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
737 } | |
738 | |
739 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
740 { | |
741 assert(0); | |
52 | 742 } |
743 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
744 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
745 |
106 | 746 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 747 { |
106 | 748 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
749 LOG_SCOPE; | |
750 | |
751 assert(tinfo->ty == Tstruct); | |
752 TypeStruct *tc = (TypeStruct *)tinfo; | |
753 StructDeclaration *sd = tc->sym; | |
754 DtoResolveDsymbol(sd); | |
755 | |
756 ClassDeclaration* base = Type::typeinfostruct; | |
757 DtoResolveClass(base); | |
758 | |
759 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); | |
760 | |
761 // create the symbol | |
762 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
763 } | |
764 | |
765 void TypeInfoStructDeclaration::llvmDefine() | |
766 { | |
767 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 768 LOG_SCOPE; |
769 | |
770 assert(tinfo->ty == Tstruct); | |
771 TypeStruct *tc = (TypeStruct *)tinfo; | |
772 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
|
773 DtoForceConstInitDsymbol(sd); |
72 | 774 |
775 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
|
776 DtoForceConstInitDsymbol(base); |
72 | 777 |
100 | 778 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); |
72 | 779 |
780 std::vector<llvm::Constant*> sinits; | |
781 sinits.push_back(base->llvmVtbl); | |
782 | |
783 // char[] name | |
784 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
|
785 sinits.push_back(DtoConstString(name)); |
73 | 786 Logger::println("************** A"); |
72 | 787 assert(sinits.back()->getType() == stype->getElementType(1)); |
788 | |
789 // void[] init | |
790 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | |
791 if (sd->zeroInit) // 0 initializer, or the same as the base type | |
792 { | |
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
|
793 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 794 } |
795 else | |
796 { | |
797 assert(sd->llvmInitZ); | |
100 | 798 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); |
72 | 799 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(tc->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
|
800 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 801 } |
802 | |
803 // toX functions ground work | |
804 FuncDeclaration *fd; | |
805 FuncDeclaration *fdx; | |
806 TypeFunction *tf; | |
807 Type *ta; | |
808 Dsymbol *s; | |
809 | |
810 static TypeFunction *tftohash; | |
811 static TypeFunction *tftostring; | |
812 | |
813 if (!tftohash) | |
814 { | |
815 Scope sc; | |
816 | |
817 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
818 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
819 | |
820 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
821 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
822 } | |
823 | |
824 TypeFunction *tfeqptr; | |
825 { | |
826 Scope sc; | |
827 Arguments *arguments = new Arguments; | |
828 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
829 | |
830 arguments->push(arg); | |
831 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
832 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
833 } | |
834 | |
835 #if 0 | |
836 TypeFunction *tfeq; | |
837 { | |
838 Scope sc; | |
839 Array *arguments = new Array; | |
840 Argument *arg = new Argument(In, tc, NULL, NULL); | |
841 | |
842 arguments->push(arg); | |
843 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
844 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
845 } | |
846 #endif | |
847 | |
73 | 848 Logger::println("************** B"); |
96 | 849 const llvm::PointerType* ptty = isaPointer(stype->getElementType(3)); |
72 | 850 |
851 s = search_function(sd, Id::tohash); | |
852 fdx = s ? s->isFuncDeclaration() : NULL; | |
853 if (fdx) | |
854 { | |
855 fd = fdx->overloadExactMatch(tftohash); | |
856 if (fd) { | |
857 assert(fd->llvmValue != 0); | |
858 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
859 assert(c); | |
860 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
861 sinits.push_back(c); | |
862 } | |
863 else { | |
864 //fdx->error("must be declared as extern (D) uint toHash()"); | |
865 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
866 } | |
867 } | |
868 else { | |
869 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
870 } | |
871 | |
872 s = search_function(sd, Id::eq); | |
873 fdx = s ? s->isFuncDeclaration() : NULL; | |
874 for (int i = 0; i < 2; i++) | |
875 { | |
73 | 876 Logger::println("************** C %d", i); |
96 | 877 ptty = isaPointer(stype->getElementType(4+i)); |
72 | 878 if (fdx) |
879 { | |
880 fd = fdx->overloadExactMatch(tfeqptr); | |
881 if (fd) { | |
882 assert(fd->llvmValue != 0); | |
883 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
884 assert(c); | |
885 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
886 sinits.push_back(c); | |
887 } | |
888 else { | |
889 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
890 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
891 } | |
892 } | |
893 else { | |
894 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
895 } | |
896 | |
897 s = search_function(sd, Id::cmp); | |
898 fdx = s ? s->isFuncDeclaration() : NULL; | |
899 } | |
900 | |
73 | 901 Logger::println("************** D"); |
96 | 902 ptty = isaPointer(stype->getElementType(6)); |
72 | 903 s = search_function(sd, Id::tostring); |
904 fdx = s ? s->isFuncDeclaration() : NULL; | |
905 if (fdx) | |
906 { | |
907 fd = fdx->overloadExactMatch(tftostring); | |
908 if (fd) { | |
909 assert(fd->llvmValue != 0); | |
910 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
911 assert(c); | |
912 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
913 sinits.push_back(c); | |
914 } | |
915 else { | |
916 //fdx->error("must be declared as extern (D) char[] toString()"); | |
917 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
918 } | |
919 } | |
920 else { | |
921 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
922 } | |
923 | |
924 // 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
|
925 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 926 |
927 // create the symbol | |
928 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
73 | 929 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 930 |
106 | 931 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
932 } | |
933 | |
934 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | |
935 { | |
936 assert(0); | |
52 | 937 } |
938 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
939 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
940 |
106 | 941 void TypeInfoClassDeclaration::llvmDeclare() |
942 { | |
943 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
944 LOG_SCOPE; | |
945 | |
946 // init typeinfo class | |
947 ClassDeclaration* base = Type::typeinfoclass; | |
948 assert(base); | |
949 DtoResolveClass(base); | |
950 | |
951 // get type of typeinfo class | |
952 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
953 | |
954 // create the symbol | |
955 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
956 } | |
957 | |
958 void TypeInfoClassDeclaration::llvmDefine() | |
959 { | |
960 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
961 LOG_SCOPE; | |
962 | |
963 // init typeinfo class | |
964 ClassDeclaration* base = Type::typeinfoclass; | |
965 assert(base); | |
966 DtoForceConstInitDsymbol(base); | |
967 | |
968 // get type of typeinfo class | |
969 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
970 | |
971 // initializer vector | |
972 std::vector<llvm::Constant*> sinits; | |
973 // first is always the vtable | |
974 sinits.push_back(base->llvmVtbl); | |
975 | |
976 // get classinfo | |
977 assert(tinfo->ty == Tclass); | |
978 TypeClass *tc = (TypeClass *)tinfo; | |
979 assert(tc->sym->llvmClass); | |
980 sinits.push_back(tc->sym->llvmClass); | |
981 | |
982 // create the symbol | |
983 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
984 isaGlobalVar(llvmValue)->setInitializer(tiInit); | |
985 } | |
986 | |
52 | 987 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
988 { | |
106 | 989 assert(0); |
52 | 990 } |
991 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
992 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
993 |
106 | 994 void TypeInfoInterfaceDeclaration::llvmDeclare() |
995 { | |
996 assert(0 && "TypeInfoTupleDeclaration"); | |
997 } | |
998 | |
999 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1000 { | |
1001 assert(0 && "TypeInfoTupleDeclaration"); | |
1002 } | |
1003 | |
52 | 1004 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1005 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1006 assert(0 && "TypeInfoInterfaceDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1007 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1008 /* |
52 | 1009 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); |
1010 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
1011 dtdword(pdt, 0); // monitor | |
1012 | |
1013 assert(tinfo->ty == Tclass); | |
1014 | |
1015 TypeClass *tc = (TypeClass *)tinfo; | |
1016 Symbol *s; | |
1017 | |
1018 if (!tc->sym->vclassinfo) | |
1019 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
1020 s = tc->sym->vclassinfo->toSymbol(); | |
1021 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1022 */ |
52 | 1023 } |
1024 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1025 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1026 |
106 | 1027 void TypeInfoTupleDeclaration::llvmDeclare() |
1028 { | |
1029 assert(0 && "TypeInfoTupleDeclaration"); | |
1030 } | |
1031 | |
1032 void TypeInfoTupleDeclaration::llvmDefine() | |
1033 { | |
1034 assert(0 && "TypeInfoTupleDeclaration"); | |
1035 } | |
1036 | |
52 | 1037 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1038 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1039 assert(0 && "TypeInfoTupleDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1040 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1041 /* |
52 | 1042 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars()); |
1043 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
1044 dtdword(pdt, 0); // monitor | |
1045 | |
1046 assert(tinfo->ty == Ttuple); | |
1047 | |
1048 TypeTuple *tu = (TypeTuple *)tinfo; | |
1049 | |
1050 size_t dim = tu->arguments->dim; | |
1051 dtdword(pdt, dim); // elements.length | |
1052 | |
1053 dt_t *d = NULL; | |
1054 for (size_t i = 0; i < dim; i++) | |
1055 { Argument *arg = (Argument *)tu->arguments->data[i]; | |
1056 Expression *e = arg->type->getTypeInfo(NULL); | |
1057 e = e->optimize(WANTvalue); | |
1058 e->toDt(&d); | |
1059 } | |
1060 | |
1061 Symbol *s; | |
1062 s = static_sym(); | |
1063 s->Sdt = d; | |
1064 outdata(s); | |
1065 | |
1066 dtxoff(pdt, s, 0, TYnptr); // elements.ptr | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1067 */ |
52 | 1068 } |