Mercurial > projects > ldc
annotate gen/typinf.cpp @ 109:5ab8e92611f9 trunk
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions.
Fixed initialization of array of structs.
Fixed slice assignment where LHS is slice but RHS is dynamic array.
Fixed problems with result of assignment expressions.
Fixed foreach problems with key type mismatches.
author | lindquist |
---|---|
date | Wed, 21 Nov 2007 04:13:15 +0100 |
parents | 5b5194b25f33 |
children | e8da7856a260 |
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 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
657 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
658 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
659 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
660 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
661 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
662 DtoResolveClass(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
663 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
664 // get type of typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
665 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
666 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
667 // create the symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
668 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 669 } |
670 | |
671 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
672 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
673 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
674 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
675 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
676 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
677 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
678 DtoForceConstInitDsymbol(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
679 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
680 // get type of typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
681 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
682 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
683 // initializer vector |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
684 std::vector<llvm::Constant*> sinits; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
685 // first is always the vtable |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
686 sinits.push_back(base->llvmVtbl); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
687 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
688 // get type |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
689 assert(tinfo->ty == Taarray); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
690 TypeAArray *tc = (TypeAArray *)tinfo; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
691 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
692 // value typeinfo |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
693 tc->next->getTypeInfo(NULL); |
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 symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
696 assert(tc->next->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
697 DtoForceDeclareDsymbol(tc->next->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
698 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
699 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
700 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
701 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
702 // key typeinfo |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
703 tc->index->getTypeInfo(NULL); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
704 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
705 // get symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
706 assert(tc->index->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
707 DtoForceDeclareDsymbol(tc->index->vtinfo); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
708 castbase = isaConstant(tc->index->vtinfo->llvmValue); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
709 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
710 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
711 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
712 // create the symbol |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
713 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
714 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
106 | 715 } |
716 | |
52 | 717 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
718 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
719 assert(0); |
52 | 720 } |
721 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
722 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
723 |
106 | 724 void TypeInfoFunctionDeclaration::llvmDeclare() |
725 { | |
726 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
727 LOG_SCOPE; | |
728 | |
729 assert(tinfo->ty == Tfunction); | |
730 TypeFunction *tc = (TypeFunction *)tinfo; | |
731 | |
732 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
733 } | |
734 | |
735 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 736 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
737 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
738 LOG_SCOPE; |
52 | 739 |
740 assert(tinfo->ty == Tfunction); | |
741 TypeFunction *tc = (TypeFunction *)tinfo; | |
742 | |
106 | 743 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
744 } | |
745 | |
746 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
747 { | |
748 assert(0); | |
52 | 749 } |
750 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
751 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
752 |
106 | 753 void TypeInfoDelegateDeclaration::llvmDeclare() |
754 { | |
755 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
756 LOG_SCOPE; | |
757 | |
758 assert(tinfo->ty == Tdelegate); | |
759 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
760 | |
761 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
762 } | |
763 | |
764 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 765 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
766 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
767 LOG_SCOPE; |
52 | 768 |
769 assert(tinfo->ty == Tdelegate); | |
770 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
771 | |
106 | 772 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
773 } | |
774 | |
775 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
776 { | |
777 assert(0); | |
52 | 778 } |
779 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
780 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
781 |
106 | 782 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 783 { |
106 | 784 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
785 LOG_SCOPE; | |
786 | |
787 assert(tinfo->ty == Tstruct); | |
788 TypeStruct *tc = (TypeStruct *)tinfo; | |
789 StructDeclaration *sd = tc->sym; | |
790 DtoResolveDsymbol(sd); | |
791 | |
792 ClassDeclaration* base = Type::typeinfostruct; | |
793 DtoResolveClass(base); | |
794 | |
795 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); | |
796 | |
797 // create the symbol | |
798 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
799 } | |
800 | |
801 void TypeInfoStructDeclaration::llvmDefine() | |
802 { | |
803 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 804 LOG_SCOPE; |
805 | |
806 assert(tinfo->ty == Tstruct); | |
807 TypeStruct *tc = (TypeStruct *)tinfo; | |
808 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
|
809 DtoForceConstInitDsymbol(sd); |
72 | 810 |
811 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
|
812 DtoForceConstInitDsymbol(base); |
72 | 813 |
100 | 814 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); |
72 | 815 |
816 std::vector<llvm::Constant*> sinits; | |
817 sinits.push_back(base->llvmVtbl); | |
818 | |
819 // char[] name | |
820 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
|
821 sinits.push_back(DtoConstString(name)); |
73 | 822 Logger::println("************** A"); |
72 | 823 assert(sinits.back()->getType() == stype->getElementType(1)); |
824 | |
825 // void[] init | |
826 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | |
827 if (sd->zeroInit) // 0 initializer, or the same as the base type | |
828 { | |
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
|
829 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 830 } |
831 else | |
832 { | |
833 assert(sd->llvmInitZ); | |
100 | 834 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); |
72 | 835 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
|
836 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 837 } |
838 | |
839 // toX functions ground work | |
840 FuncDeclaration *fd; | |
841 FuncDeclaration *fdx; | |
842 TypeFunction *tf; | |
843 Type *ta; | |
844 Dsymbol *s; | |
845 | |
846 static TypeFunction *tftohash; | |
847 static TypeFunction *tftostring; | |
848 | |
849 if (!tftohash) | |
850 { | |
851 Scope sc; | |
852 | |
853 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
854 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
855 | |
856 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
857 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
858 } | |
859 | |
860 TypeFunction *tfeqptr; | |
861 { | |
862 Scope sc; | |
863 Arguments *arguments = new Arguments; | |
864 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
865 | |
866 arguments->push(arg); | |
867 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
868 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
869 } | |
870 | |
871 #if 0 | |
872 TypeFunction *tfeq; | |
873 { | |
874 Scope sc; | |
875 Array *arguments = new Array; | |
876 Argument *arg = new Argument(In, tc, NULL, NULL); | |
877 | |
878 arguments->push(arg); | |
879 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
880 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
881 } | |
882 #endif | |
883 | |
73 | 884 Logger::println("************** B"); |
96 | 885 const llvm::PointerType* ptty = isaPointer(stype->getElementType(3)); |
72 | 886 |
887 s = search_function(sd, Id::tohash); | |
888 fdx = s ? s->isFuncDeclaration() : NULL; | |
889 if (fdx) | |
890 { | |
891 fd = fdx->overloadExactMatch(tftohash); | |
892 if (fd) { | |
893 assert(fd->llvmValue != 0); | |
894 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
895 assert(c); | |
896 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
897 sinits.push_back(c); | |
898 } | |
899 else { | |
900 //fdx->error("must be declared as extern (D) uint toHash()"); | |
901 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
902 } | |
903 } | |
904 else { | |
905 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
906 } | |
907 | |
908 s = search_function(sd, Id::eq); | |
909 fdx = s ? s->isFuncDeclaration() : NULL; | |
910 for (int i = 0; i < 2; i++) | |
911 { | |
73 | 912 Logger::println("************** C %d", i); |
96 | 913 ptty = isaPointer(stype->getElementType(4+i)); |
72 | 914 if (fdx) |
915 { | |
916 fd = fdx->overloadExactMatch(tfeqptr); | |
917 if (fd) { | |
918 assert(fd->llvmValue != 0); | |
919 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
920 assert(c); | |
921 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
922 sinits.push_back(c); | |
923 } | |
924 else { | |
925 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
926 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
927 } | |
928 } | |
929 else { | |
930 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
931 } | |
932 | |
933 s = search_function(sd, Id::cmp); | |
934 fdx = s ? s->isFuncDeclaration() : NULL; | |
935 } | |
936 | |
73 | 937 Logger::println("************** D"); |
96 | 938 ptty = isaPointer(stype->getElementType(6)); |
72 | 939 s = search_function(sd, Id::tostring); |
940 fdx = s ? s->isFuncDeclaration() : NULL; | |
941 if (fdx) | |
942 { | |
943 fd = fdx->overloadExactMatch(tftostring); | |
944 if (fd) { | |
945 assert(fd->llvmValue != 0); | |
946 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
947 assert(c); | |
948 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
949 sinits.push_back(c); | |
950 } | |
951 else { | |
952 //fdx->error("must be declared as extern (D) char[] toString()"); | |
953 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
954 } | |
955 } | |
956 else { | |
957 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
958 } | |
959 | |
960 // 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
|
961 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 962 |
963 // create the symbol | |
964 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
73 | 965 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 966 |
106 | 967 isaGlobalVar(llvmValue)->setInitializer(tiInit); |
968 } | |
969 | |
970 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | |
971 { | |
972 assert(0); | |
52 | 973 } |
974 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
975 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
976 |
106 | 977 void TypeInfoClassDeclaration::llvmDeclare() |
978 { | |
979 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
980 LOG_SCOPE; | |
981 | |
982 // init typeinfo class | |
983 ClassDeclaration* base = Type::typeinfoclass; | |
984 assert(base); | |
985 DtoResolveClass(base); | |
986 | |
987 // get type of typeinfo class | |
988 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
989 | |
990 // create the symbol | |
991 llvmValue = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); | |
992 } | |
993 | |
994 void TypeInfoClassDeclaration::llvmDefine() | |
995 { | |
996 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
997 LOG_SCOPE; | |
998 | |
999 // init typeinfo class | |
1000 ClassDeclaration* base = Type::typeinfoclass; | |
1001 assert(base); | |
1002 DtoForceConstInitDsymbol(base); | |
1003 | |
1004 // get type of typeinfo class | |
1005 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); | |
1006 | |
1007 // initializer vector | |
1008 std::vector<llvm::Constant*> sinits; | |
1009 // first is always the vtable | |
1010 sinits.push_back(base->llvmVtbl); | |
1011 | |
1012 // get classinfo | |
1013 assert(tinfo->ty == Tclass); | |
1014 TypeClass *tc = (TypeClass *)tinfo; | |
1015 assert(tc->sym->llvmClass); | |
1016 sinits.push_back(tc->sym->llvmClass); | |
1017 | |
1018 // create the symbol | |
1019 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
1020 isaGlobalVar(llvmValue)->setInitializer(tiInit); | |
1021 } | |
1022 | |
52 | 1023 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
1024 { | |
106 | 1025 assert(0); |
52 | 1026 } |
1027 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1028 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1029 |
106 | 1030 void TypeInfoInterfaceDeclaration::llvmDeclare() |
1031 { | |
1032 assert(0 && "TypeInfoTupleDeclaration"); | |
1033 } | |
1034 | |
1035 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1036 { | |
1037 assert(0 && "TypeInfoTupleDeclaration"); | |
1038 } | |
1039 | |
52 | 1040 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1041 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1042 assert(0 && "TypeInfoInterfaceDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1043 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1044 /* |
52 | 1045 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); |
1046 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
1047 dtdword(pdt, 0); // monitor | |
1048 | |
1049 assert(tinfo->ty == Tclass); | |
1050 | |
1051 TypeClass *tc = (TypeClass *)tinfo; | |
1052 Symbol *s; | |
1053 | |
1054 if (!tc->sym->vclassinfo) | |
1055 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
1056 s = tc->sym->vclassinfo->toSymbol(); | |
1057 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
|
1058 */ |
52 | 1059 } |
1060 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1061 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1062 |
106 | 1063 void TypeInfoTupleDeclaration::llvmDeclare() |
1064 { | |
1065 assert(0 && "TypeInfoTupleDeclaration"); | |
1066 } | |
1067 | |
1068 void TypeInfoTupleDeclaration::llvmDefine() | |
1069 { | |
1070 assert(0 && "TypeInfoTupleDeclaration"); | |
1071 } | |
1072 | |
52 | 1073 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1074 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1075 assert(0 && "TypeInfoTupleDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1076 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1077 /* |
52 | 1078 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars()); |
1079 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
1080 dtdword(pdt, 0); // monitor | |
1081 | |
1082 assert(tinfo->ty == Ttuple); | |
1083 | |
1084 TypeTuple *tu = (TypeTuple *)tinfo; | |
1085 | |
1086 size_t dim = tu->arguments->dim; | |
1087 dtdword(pdt, dim); // elements.length | |
1088 | |
1089 dt_t *d = NULL; | |
1090 for (size_t i = 0; i < dim; i++) | |
1091 { Argument *arg = (Argument *)tu->arguments->data[i]; | |
1092 Expression *e = arg->type->getTypeInfo(NULL); | |
1093 e = e->optimize(WANTvalue); | |
1094 e->toDt(&d); | |
1095 } | |
1096 | |
1097 Symbol *s; | |
1098 s = static_sym(); | |
1099 s->Sdt = d; | |
1100 outdata(s); | |
1101 | |
1102 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
|
1103 */ |
52 | 1104 } |