Mercurial > projects > ldc
annotate gen/typinf.cpp @ 311:9967a3270837 trunk
[svn r332] Fix codegen for continue within switch.
author | ChristianK |
---|---|
date | Sat, 28 Jun 2008 18:37:27 +0200 |
parents | ebaf65fc4726 |
children | aaade6ded589 |
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" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
38 #include "gen/llvmhelpers.h" |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
39 #include "gen/arrays.h" |
100 | 40 #include "gen/structs.h" |
106 | 41 #include "gen/classes.h" |
1 | 42 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
43 #include "ir/irvar.h" |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
44 |
1 | 45 /******************************************* |
46 * Get a canonicalized form of the TypeInfo for use with the internal | |
47 * runtime library routines. Canonicalized in that static arrays are | |
48 * represented as dynamic arrays, enums are represented by their | |
49 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
50 * so we can use the custom internal ones more. | |
51 */ | |
52 | |
53 Expression *Type::getInternalTypeInfo(Scope *sc) | |
54 { TypeInfoDeclaration *tid; | |
55 Expression *e; | |
56 Type *t; | |
57 static TypeInfoDeclaration *internalTI[TMAX]; | |
58 | |
59 //printf("Type::getInternalTypeInfo() %s\n", toChars()); | |
60 t = toBasetype(); | |
61 switch (t->ty) | |
62 { | |
63 case Tsarray: | |
64 t = t->next->arrayOf(); // convert to corresponding dynamic array type | |
65 break; | |
66 | |
67 case Tclass: | |
68 if (((TypeClass *)t)->sym->isInterfaceDeclaration()) | |
69 break; | |
70 goto Linternal; | |
71 | |
72 case Tarray: | |
73 if (t->next->ty != Tclass) | |
74 break; | |
75 goto Linternal; | |
76 | |
77 case Tfunction: | |
78 case Tdelegate: | |
79 case Tpointer: | |
80 Linternal: | |
81 tid = internalTI[t->ty]; | |
82 if (!tid) | |
83 { tid = new TypeInfoDeclaration(t, 1); | |
84 internalTI[t->ty] = tid; | |
85 } | |
86 e = new VarExp(0, tid); | |
52 | 87 //e = e->addressOf(sc); |
1 | 88 e->type = tid->type; // do this so we don't get redundant dereference |
89 return e; | |
90 | |
91 default: | |
92 break; | |
93 } | |
94 //printf("\tcalling getTypeInfo() %s\n", t->toChars()); | |
95 return t->getTypeInfo(sc); | |
96 } | |
97 | |
98 | |
99 /**************************************************** | |
100 * Get the exact TypeInfo. | |
101 */ | |
102 | |
103 Expression *Type::getTypeInfo(Scope *sc) | |
104 { | |
105 Expression *e; | |
106 Type *t; | |
107 | |
108 //printf("Type::getTypeInfo() %p, %s\n", this, toChars()); | |
109 t = merge(); // do this since not all Type's are merge'd | |
110 if (!t->vtinfo) | |
111 { t->vtinfo = t->getTypeInfoDeclaration(); | |
112 assert(t->vtinfo); | |
113 | |
114 /* If this has a custom implementation in std/typeinfo, then | |
115 * do not generate a COMDAT for it. | |
116 */ | |
117 if (!t->builtinTypeInfo()) | |
118 { // Generate COMDAT | |
119 if (sc) // if in semantic() pass | |
120 { // Find module that will go all the way to an object file | |
121 Module *m = sc->module->importedFrom; | |
122 m->members->push(t->vtinfo); | |
123 } | |
124 else // if in obj generation pass | |
125 { | |
126 t->vtinfo->toObjFile(); | |
127 } | |
128 } | |
129 } | |
130 e = new VarExp(0, t->vtinfo); | |
131 //e = e->addressOf(sc); | |
132 e->type = t->vtinfo->type; // do this so we don't get redundant dereference | |
133 return e; | |
134 } | |
135 | |
52 | 136 enum RET TypeFunction::retStyle() |
137 { | |
138 return RETstack; | |
139 } | |
1 | 140 |
141 TypeInfoDeclaration *Type::getTypeInfoDeclaration() | |
142 { | |
143 //printf("Type::getTypeInfoDeclaration() %s\n", toChars()); | |
144 return new TypeInfoDeclaration(this, 0); | |
145 } | |
146 | |
52 | 147 TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration() |
1 | 148 { |
52 | 149 return new TypeInfoTypedefDeclaration(this); |
1 | 150 } |
151 | |
52 | 152 TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration() |
153 { | |
154 return new TypeInfoPointerDeclaration(this); | |
155 } | |
1 | 156 |
157 TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration() | |
158 { | |
159 return new TypeInfoArrayDeclaration(this); | |
160 } | |
161 | |
162 TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration() | |
163 { | |
164 return new TypeInfoStaticArrayDeclaration(this); | |
165 } | |
166 | |
167 TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration() | |
168 { | |
169 return new TypeInfoAssociativeArrayDeclaration(this); | |
170 } | |
171 | |
52 | 172 TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration() |
173 { | |
174 return new TypeInfoStructDeclaration(this); | |
175 } | |
1 | 176 |
177 TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration() | |
178 { | |
179 if (sym->isInterfaceDeclaration()) | |
180 return new TypeInfoInterfaceDeclaration(this); | |
181 else | |
182 return new TypeInfoClassDeclaration(this); | |
183 } | |
184 | |
185 TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration() | |
186 { | |
187 return new TypeInfoEnumDeclaration(this); | |
188 } | |
189 | |
190 TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration() | |
191 { | |
192 return new TypeInfoFunctionDeclaration(this); | |
193 } | |
194 | |
195 TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration() | |
196 { | |
197 return new TypeInfoDelegateDeclaration(this); | |
198 } | |
199 | |
200 TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration() | |
201 { | |
202 return new TypeInfoTupleDeclaration(this); | |
203 } | |
204 | |
205 | |
206 /* ========================================================================= */ | |
207 | |
208 /* These decide if there's an instance for them already in std.typeinfo, | |
209 * because then the compiler doesn't need to build one. | |
210 */ | |
211 | |
212 int Type::builtinTypeInfo() | |
213 { | |
214 return 0; | |
215 } | |
216 | |
217 int TypeBasic::builtinTypeInfo() | |
218 { | |
219 return 1; | |
220 } | |
221 | |
222 int TypeDArray::builtinTypeInfo() | |
223 { | |
52 | 224 return next->isTypeBasic() != NULL; |
1 | 225 } |
226 | |
227 /* ========================================================================= */ | |
228 | |
229 /*************************************** | |
230 * Create a static array of TypeInfo references | |
231 * corresponding to an array of Expression's. | |
232 * Used to supply hidden _arguments[] value for variadic D functions. | |
233 */ | |
234 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
235 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) |
1 | 236 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
237 assert(0); // done elsewhere in llvmdc |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
238 return NULL; |
1 | 239 } |
240 | |
52 | 241 /* ========================================================================= */ |
242 | |
243 ////////////////////////////////////////////////////////////////////////////// | |
244 // MAGIC PLACE | |
245 ////////////////////////////////////////////////////////////////////////////// | |
246 | |
247 void TypeInfoDeclaration::toObjFile() | |
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 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
|
250 } |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
251 |
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
|
252 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
|
253 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
254 if (tid->ir.resolved) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
255 tid->ir.resolved = true; |
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
|
256 |
132 | 257 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars()); |
52 | 258 LOG_SCOPE; |
65 | 259 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
260 tid->ir.irGlobal = new IrGlobal(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
|
261 |
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 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
|
263 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
264 |
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
|
265 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
|
266 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
267 if (tid->ir.declared) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
268 tid->ir.declared = true; |
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
|
269 |
132 | 270 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars()); |
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
|
271 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
|
272 |
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
|
273 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
|
274 |
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
|
275 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
|
276 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
|
277 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
278 // 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
|
279 if (tid->tinfo->builtinTypeInfo()) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
280 LLValue* found = gIR->module->getNamedGlobal(mangled); |
132 | 281 if (!found) |
282 { | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
283 const LLType* t = LLOpaqueType::get(); |
132 | 284 llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module); |
285 assert(g); | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
286 /*if (!tid->ir.irGlobal) |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
287 tid->ir.irGlobal = new IrGlobal(tid);*/ |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
288 tid->ir.irGlobal->value = g; |
132 | 289 mangled.append("__TYPE"); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
290 gIR->module->addTypeName(mangled, tid->ir.irGlobal->value->getType()->getContainedType(0)); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
291 Logger::println("Got typeinfo var: %s", tid->ir.irGlobal->value->getName().c_str()); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
292 tid->ir.initialized = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
293 tid->ir.defined = true; |
132 | 294 } |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
295 else if (!tid->ir.irGlobal->value) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
296 tid->ir.irGlobal->value = found; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
297 tid->ir.initialized = true; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
298 tid->ir.defined = true; |
132 | 299 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
300 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
301 // custom typedef |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
302 else { |
106 | 303 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
|
304 gIR->constInitList.push_back(tid); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
305 } |
52 | 306 } |
307 | |
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
|
308 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
|
309 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
310 if (tid->ir.initialized) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
311 tid->ir.initialized = true; |
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 |
132 | 313 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars()); |
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
|
314 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
|
315 |
106 | 316 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
|
317 } |
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
|
318 |
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
|
319 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
|
320 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
321 if (tid->ir.defined) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
322 tid->ir.defined = true; |
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
|
323 |
132 | 324 Logger::println("DtoDefineTypeInfo(%s)", tid->toChars()); |
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
|
325 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
|
326 |
106 | 327 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
|
328 } |
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
|
329 |
52 | 330 /* ========================================================================= */ |
331 | |
332 void TypeInfoDeclaration::toDt(dt_t **pdt) | |
333 { | |
106 | 334 assert(0 && "TypeInfoDeclaration::toDt"); |
335 } | |
336 | |
337 void TypeInfoDeclaration::llvmDeclare() | |
338 { | |
339 assert(0 && "TypeInfoDeclaration::llvmDeclare"); | |
340 } | |
341 | |
342 void TypeInfoDeclaration::llvmDefine() | |
343 { | |
344 assert(0 && "TypeInfoDeclaration::llvmDeclare"); | |
52 | 345 } |
346 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
347 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
348 |
106 | 349 void TypeInfoTypedefDeclaration::llvmDeclare() |
52 | 350 { |
106 | 351 Logger::println("TypeInfoTypedefDeclaration::llvmDeclare() %s", toChars()); |
352 LOG_SCOPE; | |
353 | |
354 ClassDeclaration* base = Type::typeinfotypedef; | |
355 DtoResolveClass(base); | |
356 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
357 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 358 |
359 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
360 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 361 } |
362 | |
363 void TypeInfoTypedefDeclaration::llvmDefine() | |
364 { | |
365 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars()); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
366 LOG_SCOPE; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
367 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
368 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
|
369 DtoForceConstInitDsymbol(base); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
370 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
371 const LLStructType* stype = isaStruct(base->type->ir.type->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
|
372 Logger::cout() << "got stype: " << *stype << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
373 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
374 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
375 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
376 sinits.push_back(base->ir.irStruct->vtbl); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
377 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
378 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
379 sinits.push_back(getNullPtr(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
380 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
381 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
383 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
384 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
385 // TypeInfo base |
290
ebaf65fc4726
[svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents:
275
diff
changeset
|
386 sd->basetype = sd->basetype->merge(); // DMD does this! |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
387 LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
388 assert(castbase->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
389 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
390 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
391 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
392 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
|
393 sinits.push_back(DtoConstString(name)); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
394 assert(sinits.back()->getType() == stype->getElementType(3)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
395 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
396 // void[] init |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
397 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
398 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
|
399 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
400 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), getNullPtr(initpt))); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
401 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
402 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
403 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
404 LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
405 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
406 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
|
407 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
408 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
409 size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); |
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
|
410 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
|
411 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
412 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
413 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
414 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
415 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 416 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
417 |
106 | 418 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
419 { | |
420 assert(0); | |
52 | 421 } |
422 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
423 /* ========================================================================= */ |
52 | 424 |
106 | 425 void TypeInfoEnumDeclaration::llvmDeclare() |
52 | 426 { |
106 | 427 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); |
428 LOG_SCOPE; | |
429 | |
430 ClassDeclaration* base = Type::typeinfoenum; | |
431 DtoResolveClass(base); | |
432 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
433 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 434 |
435 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
436 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 437 } |
438 | |
439 void TypeInfoEnumDeclaration::llvmDefine() | |
440 { | |
441 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
442 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
443 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
444 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
|
445 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
446 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
447 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
448 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
449 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
450 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
451 sinits.push_back(base->ir.irStruct->vtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
452 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
453 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
454 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
455 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
456 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
458 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
460 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
461 LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
462 assert(castbase->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
463 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
465 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
466 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
|
467 sinits.push_back(DtoConstString(name)); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
468 assert(sinits.back()->getType() == stype->getElementType(3)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
469 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
470 // void[] init |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
471 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
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
|
472 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
|
473 { |
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
|
474 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
|
475 } |
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
|
476 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
|
477 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
478 const LLType* memty = DtoType(sd->memtype); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
479 LLConstant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); |
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
|
480 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
|
481 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
|
482 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
483 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
484 size_t cisize = getTypeStoreSize(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
|
485 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
|
486 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
487 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
488 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
489 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
490 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 491 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
492 |
106 | 493 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
494 { | |
495 assert(0); | |
52 | 496 } |
497 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
498 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
499 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
500 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
106 | 501 { |
502 ClassDeclaration* base = cd; | |
503 DtoResolveClass(base); | |
504 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
505 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 506 |
507 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
508 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); |
106 | 509 } |
510 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
511 static LLConstant* 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
|
512 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
513 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
|
514 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
515 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
516 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
517 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
518 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
519 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
520 sinits.push_back(base->ir.irStruct->vtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
521 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
522 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
523 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
524 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
525 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
526 LLConstant* castbase = DtoTypeInfoOf(basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
527 assert(castbase->getType() == stype->getElementType(2)); |
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 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
531 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
532 isaGlobalVar(tid->ir.irGlobal->value)->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 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
605 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 606 |
607 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
608 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 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 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
621 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
52 | 622 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
623 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
624 std::vector<LLConstant*> sinits; |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
625 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
626 sinits.push_back(base->ir.irStruct->vtbl); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
627 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
628 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
629 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
630 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
631 // value typeinfo |
52 | 632 assert(tinfo->ty == Tsarray); |
633 TypeSArray *tc = (TypeSArray *)tinfo; | |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
634 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
635 assert(castbase->getType() == stype->getElementType(2)); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
636 sinits.push_back(castbase); |
52 | 637 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
638 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
639 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
640 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
641 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
642 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
643 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 644 } |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
645 |
106 | 646 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
647 { | |
648 assert(0); | |
52 | 649 } |
650 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
651 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
652 |
106 | 653 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
654 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
655 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
656 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
657 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
658 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
659 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
660 DtoResolveClass(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
661 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
662 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
663 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
664 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
665 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
666 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 667 } |
668 | |
669 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
670 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
671 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
672 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
673 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
674 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
675 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
676 DtoForceConstInitDsymbol(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
677 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
678 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
679 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
680 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
681 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
682 std::vector<LLConstant*> sinits; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
683 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
684 sinits.push_back(base->ir.irStruct->vtbl); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
685 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
686 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
687 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
688 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
689 // get type |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
690 assert(tinfo->ty == Taarray); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
691 TypeAArray *tc = (TypeAArray *)tinfo; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
692 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
693 // value typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
694 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
695 assert(castbase->getType() == stype->getElementType(2)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
696 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
697 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
698 // key typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
699 castbase = DtoTypeInfoOf(tc->index, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
700 assert(castbase->getType() == stype->getElementType(3)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
701 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
702 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
703 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
704 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
705 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 706 } |
707 | |
52 | 708 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
709 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
710 assert(0); |
52 | 711 } |
712 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
713 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
714 |
106 | 715 void TypeInfoFunctionDeclaration::llvmDeclare() |
716 { | |
717 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
718 LOG_SCOPE; | |
719 | |
720 assert(tinfo->ty == Tfunction); | |
721 TypeFunction *tc = (TypeFunction *)tinfo; | |
722 | |
723 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
724 } | |
725 | |
726 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 727 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
728 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
729 LOG_SCOPE; |
52 | 730 |
731 assert(tinfo->ty == Tfunction); | |
732 TypeFunction *tc = (TypeFunction *)tinfo; | |
733 | |
106 | 734 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
735 } | |
736 | |
737 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
738 { | |
739 assert(0); | |
52 | 740 } |
741 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
742 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
743 |
106 | 744 void TypeInfoDelegateDeclaration::llvmDeclare() |
745 { | |
746 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
747 LOG_SCOPE; | |
748 | |
749 assert(tinfo->ty == Tdelegate); | |
750 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
751 | |
752 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
753 } | |
754 | |
755 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 756 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
757 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
758 LOG_SCOPE; |
52 | 759 |
760 assert(tinfo->ty == Tdelegate); | |
761 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
762 | |
106 | 763 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
764 } | |
765 | |
766 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
767 { | |
768 assert(0); | |
52 | 769 } |
770 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
771 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
772 |
106 | 773 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 774 { |
106 | 775 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
776 LOG_SCOPE; | |
777 | |
778 assert(tinfo->ty == Tstruct); | |
779 TypeStruct *tc = (TypeStruct *)tinfo; | |
780 StructDeclaration *sd = tc->sym; | |
781 DtoResolveDsymbol(sd); | |
782 | |
783 ClassDeclaration* base = Type::typeinfostruct; | |
784 DtoResolveClass(base); | |
785 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
786 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 787 |
788 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
789 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 790 } |
791 | |
792 void TypeInfoStructDeclaration::llvmDefine() | |
793 { | |
794 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 795 LOG_SCOPE; |
796 | |
797 assert(tinfo->ty == Tstruct); | |
798 TypeStruct *tc = (TypeStruct *)tinfo; | |
799 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
|
800 DtoForceConstInitDsymbol(sd); |
72 | 801 |
802 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
|
803 DtoForceConstInitDsymbol(base); |
72 | 804 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
805 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
72 | 806 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
807 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
808 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
809 sinits.push_back(base->ir.irStruct->vtbl); |
72 | 810 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
811 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
812 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
813 |
72 | 814 // char[] name |
815 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
|
816 sinits.push_back(DtoConstString(name)); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
817 //Logger::println("************** A"); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
818 assert(sinits.back()->getType() == stype->getElementType(2)); |
72 | 819 |
820 // void[] init | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
821 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
822 #if 0 |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
823 // the implementation of TypeInfo_Struct uses this to determine size. :/ |
72 | 824 if (sd->zeroInit) // 0 initializer, or the same as the base type |
825 { | |
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
|
826 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 827 } |
828 else | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
829 #endif |
72 | 830 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
831 size_t cisize = getTypeStoreSize(tc->ir.type->get()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
832 LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, 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
|
833 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 834 } |
835 | |
836 // toX functions ground work | |
837 FuncDeclaration *fd; | |
838 FuncDeclaration *fdx; | |
839 TypeFunction *tf; | |
840 Type *ta; | |
841 Dsymbol *s; | |
842 | |
843 static TypeFunction *tftohash; | |
844 static TypeFunction *tftostring; | |
845 | |
846 if (!tftohash) | |
847 { | |
848 Scope sc; | |
849 | |
850 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
851 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
852 | |
853 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
854 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
855 } | |
856 | |
857 TypeFunction *tfeqptr; | |
858 { | |
859 Scope sc; | |
860 Arguments *arguments = new Arguments; | |
861 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
862 | |
863 arguments->push(arg); | |
864 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
865 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
866 } | |
867 | |
868 #if 0 | |
869 TypeFunction *tfeq; | |
870 { | |
871 Scope sc; | |
872 Array *arguments = new Array; | |
873 Argument *arg = new Argument(In, tc, NULL, NULL); | |
874 | |
875 arguments->push(arg); | |
876 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
877 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
878 } | |
879 #endif | |
880 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
881 //Logger::println("************** B"); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
882 const LLPointerType* ptty = isaPointer(stype->getElementType(4)); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
883 assert(ptty); |
72 | 884 |
885 s = search_function(sd, Id::tohash); | |
886 fdx = s ? s->isFuncDeclaration() : NULL; | |
887 if (fdx) | |
888 { | |
889 fd = fdx->overloadExactMatch(tftohash); | |
890 if (fd) { | |
132 | 891 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
892 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
893 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 894 assert(c); |
895 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
896 sinits.push_back(c); | |
897 } | |
898 else { | |
899 //fdx->error("must be declared as extern (D) uint toHash()"); | |
900 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
901 } | |
902 } | |
903 else { | |
904 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
905 } | |
906 | |
907 s = search_function(sd, Id::eq); | |
908 fdx = s ? s->isFuncDeclaration() : NULL; | |
909 for (int i = 0; i < 2; i++) | |
910 { | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
911 //Logger::println("************** C %d", i); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
912 ptty = isaPointer(stype->getElementType(5+i)); |
72 | 913 if (fdx) |
914 { | |
915 fd = fdx->overloadExactMatch(tfeqptr); | |
916 if (fd) { | |
132 | 917 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
918 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
919 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 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 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
937 //Logger::println("************** D"); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
938 ptty = isaPointer(stype->getElementType(7)); |
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) { | |
132 | 945 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
946 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
947 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 948 assert(c); |
949 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
950 sinits.push_back(c); | |
951 } | |
952 else { | |
953 //fdx->error("must be declared as extern (D) char[] toString()"); | |
954 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
955 } | |
956 } | |
957 else { | |
958 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
959 } | |
960 | |
961 // 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
|
962 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 963 |
964 // create the symbol | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
965 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
966 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 967 } |
968 | |
969 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | |
970 { | |
971 assert(0); | |
52 | 972 } |
973 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
974 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
975 |
106 | 976 void TypeInfoClassDeclaration::llvmDeclare() |
977 { | |
978 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
979 LOG_SCOPE; | |
980 | |
981 // init typeinfo class | |
982 ClassDeclaration* base = Type::typeinfoclass; | |
983 assert(base); | |
984 DtoResolveClass(base); | |
985 | |
986 // get type of typeinfo class | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
987 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 988 |
989 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
990 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 991 } |
992 | |
993 void TypeInfoClassDeclaration::llvmDefine() | |
994 { | |
995 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
996 LOG_SCOPE; | |
997 | |
998 // init typeinfo class | |
999 ClassDeclaration* base = Type::typeinfoclass; | |
1000 assert(base); | |
1001 DtoForceConstInitDsymbol(base); | |
1002 | |
1003 // get type of typeinfo class | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1004 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 1005 |
1006 // initializer vector | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1007 std::vector<LLConstant*> sinits; |
106 | 1008 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1009 sinits.push_back(base->ir.irStruct->vtbl); |
106 | 1010 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1011 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1012 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1013 |
106 | 1014 // get classinfo |
1015 assert(tinfo->ty == Tclass); | |
1016 TypeClass *tc = (TypeClass *)tinfo; | |
163
a8cd9bc1021a
[svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents:
157
diff
changeset
|
1017 DtoForceDeclareDsymbol(tc->sym); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1018 assert(tc->sym->ir.irStruct->classInfo); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1019 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
106 | 1020 |
1021 // create the symbol | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1022 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1023 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1024 } |
1025 | |
52 | 1026 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
1027 { | |
106 | 1028 assert(0); |
52 | 1029 } |
1030 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1031 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1032 |
106 | 1033 void TypeInfoInterfaceDeclaration::llvmDeclare() |
1034 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1035 Logger::println("TypeInfoInterfaceDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1036 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1037 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1038 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1039 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1040 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1041 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1042 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1043 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1044 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1045 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1046 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1047 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1048 } |
1049 | |
1050 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1051 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1052 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1053 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1054 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1055 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1056 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1057 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1058 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1059 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1060 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1061 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1062 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1063 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1064 std::vector<LLConstant*> sinits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1065 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1066 sinits.push_back(base->ir.irStruct->vtbl); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1067 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1068 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1069 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1070 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1071 // get classinfo |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1072 assert(tinfo->ty == Tclass); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1073 TypeClass *tc = (TypeClass *)tinfo; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1074 assert(tc->sym->ir.irStruct->classInfo); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1075 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1076 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1077 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1078 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1079 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1080 } |
1081 | |
52 | 1082 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1083 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1084 assert(0); |
52 | 1085 } |
1086 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1087 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1088 |
106 | 1089 void TypeInfoTupleDeclaration::llvmDeclare() |
1090 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1091 Logger::println("TypeInfoTupleDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1092 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1093 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1094 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1095 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1096 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1097 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1098 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1099 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1100 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1101 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1102 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1103 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1104 } |
1105 | |
1106 void TypeInfoTupleDeclaration::llvmDefine() | |
1107 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1108 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1109 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1110 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1111 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1112 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1113 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1114 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1115 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1116 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1117 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1118 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1119 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1120 std::vector<LLConstant*> sinits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1121 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1122 sinits.push_back(base->ir.irStruct->vtbl); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1123 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1124 // monitor |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1125 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
1126 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1127 // create elements array |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1128 assert(tinfo->ty == Ttuple); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1129 TypeTuple *tu = (TypeTuple *)tinfo; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1130 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1131 size_t dim = tu->arguments->dim; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1132 std::vector<LLConstant*> arrInits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1133 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1134 const LLType* tiTy = Type::typeinfo->type->ir.type->get(); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1135 tiTy = getPtrToType(tiTy); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1136 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1137 for (size_t i = 0; i < dim; i++) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1138 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1139 Argument *arg = (Argument *)tu->arguments->data[i]; |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1140 LLConstant* castbase = DtoTypeInfoOf(arg->type, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1141 assert(castbase->getType() == tiTy); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1142 arrInits.push_back(castbase); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1143 } |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1144 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1145 // build array type |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1146 const LLArrayType* arrTy = LLArrayType::get(tiTy, dim); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1147 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1148 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1149 // build the slice |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1150 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1151 sinits.push_back(slice); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1152 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1153 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1154 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1155 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1156 } |
1157 | |
52 | 1158 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1159 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1160 assert(0); |
52 | 1161 } |