Mercurial > projects > ldc
annotate gen/typinf.cpp @ 275:665b81613475 trunk
[svn r296] Removed: the 'suite' dir, it never took off!
Fixed: foreach statement, key-type checks were buggy.
Fixed: setting LLVMDC versions on the command line is now an error.
Fixed: array compare runtime had incorrect param attrs on call.
Fixed: index expressions on dynamic array slices w/o storage was broken.
Fixed: scope classes had incorrect finalization in some cases.
Fixed: when outputting !ClassInfoS !OffsetTypeInfoS, static class members were trying to be included, crashing the compiler.
Fixed: calling LLVMDC with -inline but not any -O option caused assertion failure.
Changed: the runtime now uses a single interface to "get" to !TypeInfoS, part of eliminating duplicate !TypeInfo codegen.
author | lindquist |
---|---|
date | Thu, 19 Jun 2008 17:30:32 +0200 |
parents | a95056b3c996 |
children | ebaf65fc4726 |
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 |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
386 LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
387 assert(castbase->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
388 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
389 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
390 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
395 // 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
|
396 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
397 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
|
398 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
399 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
|
400 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
401 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
402 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
403 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
|
404 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
411 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
412 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
413 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
414 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 415 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
416 |
106 | 417 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
418 { | |
419 assert(0); | |
52 | 420 } |
421 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
422 /* ========================================================================= */ |
52 | 423 |
106 | 424 void TypeInfoEnumDeclaration::llvmDeclare() |
52 | 425 { |
106 | 426 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); |
427 LOG_SCOPE; | |
428 | |
429 ClassDeclaration* base = Type::typeinfoenum; | |
430 DtoResolveClass(base); | |
431 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
432 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 433 |
434 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
435 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 436 } |
437 | |
438 void TypeInfoEnumDeclaration::llvmDefine() | |
439 { | |
440 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
441 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
442 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
443 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
|
444 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
446 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
|
447 |
115
5ba6d286c941
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents:
113
diff
changeset
|
448 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
449 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
450 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
|
451 |
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
|
452 // 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
|
453 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
|
454 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
455 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
456 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
458 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
460 LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
461 assert(castbase->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
462 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
463 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
469 // 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
|
470 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
|
471 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
|
472 { |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
473 sinits.push_back(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
|
474 } |
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 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
|
476 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
477 const LLType* memty = DtoType(sd->memtype); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
486 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
487 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
488 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
489 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 490 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
491 |
106 | 492 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
493 { | |
494 assert(0); | |
52 | 495 } |
496 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
497 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
498 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
499 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
106 | 500 { |
501 ClassDeclaration* base = cd; | |
502 DtoResolveClass(base); | |
503 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
504 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 505 |
506 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
507 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); |
106 | 508 } |
509 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
510 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
|
511 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
512 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
|
513 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
514 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
515 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
|
516 |
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
|
517 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
518 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
519 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
|
520 |
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
|
521 // 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
|
522 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
|
523 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
524 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
525 LLConstant* castbase = DtoTypeInfoOf(basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
526 assert(castbase->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
527 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
528 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
529 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
530 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
531 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
|
532 } |
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 |
106 | 536 void TypeInfoPointerDeclaration::llvmDeclare() |
52 | 537 { |
106 | 538 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); |
539 LOG_SCOPE; | |
540 | |
541 assert(tinfo->ty == Tpointer); | |
542 TypePointer *tc = (TypePointer *)tinfo; | |
543 | |
544 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer); | |
545 } | |
546 | |
547 void TypeInfoPointerDeclaration::llvmDefine() | |
548 { | |
549 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
550 LOG_SCOPE; |
52 | 551 |
552 assert(tinfo->ty == Tpointer); | |
553 TypePointer *tc = (TypePointer *)tinfo; | |
554 | |
106 | 555 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
556 } | |
557 | |
558 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | |
559 { | |
560 assert(0); | |
52 | 561 } |
562 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
563 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
564 |
106 | 565 void TypeInfoArrayDeclaration::llvmDeclare() |
52 | 566 { |
106 | 567 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
568 LOG_SCOPE; |
52 | 569 |
570 assert(tinfo->ty == Tarray); | |
571 TypeDArray *tc = (TypeDArray *)tinfo; | |
572 | |
106 | 573 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray); |
574 } | |
575 | |
576 void TypeInfoArrayDeclaration::llvmDefine() | |
577 { | |
578 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars()); | |
579 LOG_SCOPE; | |
580 | |
581 assert(tinfo->ty == Tarray); | |
582 TypeDArray *tc = (TypeDArray *)tinfo; | |
583 | |
584 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); | |
585 } | |
586 | |
587 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | |
588 { | |
589 assert(0); | |
52 | 590 } |
591 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
592 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
593 |
106 | 594 void TypeInfoStaticArrayDeclaration::llvmDeclare() |
595 { | |
596 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | |
597 LOG_SCOPE; | |
598 | |
599 // init typeinfo class | |
600 ClassDeclaration* base = Type::typeinfostaticarray; | |
601 DtoResolveClass(base); | |
602 | |
603 // 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
|
604 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 605 |
606 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
607 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 608 } |
609 | |
610 void TypeInfoStaticArrayDeclaration::llvmDefine() | |
52 | 611 { |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
612 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
613 LOG_SCOPE; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
614 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
615 // init typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
616 ClassDeclaration* base = Type::typeinfostaticarray; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
617 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
618 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
619 // 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
|
620 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
52 | 621 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
622 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
623 std::vector<LLConstant*> sinits; |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
624 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
625 sinits.push_back(base->ir.irStruct->vtbl); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
626 |
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
|
627 // 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
|
628 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
|
629 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
630 // value typeinfo |
52 | 631 assert(tinfo->ty == Tsarray); |
632 TypeSArray *tc = (TypeSArray *)tinfo; | |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
633 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
634 assert(castbase->getType() == stype->getElementType(2)); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
635 sinits.push_back(castbase); |
52 | 636 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
637 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
638 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
639 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
640 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
641 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
642 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 643 } |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
644 |
106 | 645 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
646 { | |
647 assert(0); | |
52 | 648 } |
649 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
650 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
651 |
106 | 652 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
653 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
654 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
655 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
656 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
657 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
658 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
659 DtoResolveClass(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
660 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
661 // 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
|
662 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
|
663 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
664 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
665 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 666 } |
667 | |
668 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
669 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
670 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
671 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
672 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
673 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
674 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
675 DtoForceConstInitDsymbol(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
676 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
677 // 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
|
678 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
|
679 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
680 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
681 std::vector<LLConstant*> sinits; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
682 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
683 sinits.push_back(base->ir.irStruct->vtbl); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
684 |
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
|
685 // 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
|
686 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
|
687 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
688 // get type |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
689 assert(tinfo->ty == Taarray); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
690 TypeAArray *tc = (TypeAArray *)tinfo; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
691 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
692 // value typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
693 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
694 assert(castbase->getType() == stype->getElementType(2)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
695 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
696 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
697 // key typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
698 castbase = DtoTypeInfoOf(tc->index, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
699 assert(castbase->getType() == stype->getElementType(3)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
700 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
701 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
702 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
703 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
704 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 705 } |
706 | |
52 | 707 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
708 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
709 assert(0); |
52 | 710 } |
711 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
712 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
713 |
106 | 714 void TypeInfoFunctionDeclaration::llvmDeclare() |
715 { | |
716 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
717 LOG_SCOPE; | |
718 | |
719 assert(tinfo->ty == Tfunction); | |
720 TypeFunction *tc = (TypeFunction *)tinfo; | |
721 | |
722 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
723 } | |
724 | |
725 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 726 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
727 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
728 LOG_SCOPE; |
52 | 729 |
730 assert(tinfo->ty == Tfunction); | |
731 TypeFunction *tc = (TypeFunction *)tinfo; | |
732 | |
106 | 733 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
734 } | |
735 | |
736 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
737 { | |
738 assert(0); | |
52 | 739 } |
740 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
741 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
742 |
106 | 743 void TypeInfoDelegateDeclaration::llvmDeclare() |
744 { | |
745 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
746 LOG_SCOPE; | |
747 | |
748 assert(tinfo->ty == Tdelegate); | |
749 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
750 | |
751 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
752 } | |
753 | |
754 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 755 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
756 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
757 LOG_SCOPE; |
52 | 758 |
759 assert(tinfo->ty == Tdelegate); | |
760 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
761 | |
106 | 762 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
763 } | |
764 | |
765 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
766 { | |
767 assert(0); | |
52 | 768 } |
769 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
770 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
771 |
106 | 772 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 773 { |
106 | 774 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
775 LOG_SCOPE; | |
776 | |
777 assert(tinfo->ty == Tstruct); | |
778 TypeStruct *tc = (TypeStruct *)tinfo; | |
779 StructDeclaration *sd = tc->sym; | |
780 DtoResolveDsymbol(sd); | |
781 | |
782 ClassDeclaration* base = Type::typeinfostruct; | |
783 DtoResolveClass(base); | |
784 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
785 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 786 |
787 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
788 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 789 } |
790 | |
791 void TypeInfoStructDeclaration::llvmDefine() | |
792 { | |
793 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 794 LOG_SCOPE; |
795 | |
796 assert(tinfo->ty == Tstruct); | |
797 TypeStruct *tc = (TypeStruct *)tinfo; | |
798 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
|
799 DtoForceConstInitDsymbol(sd); |
72 | 800 |
801 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
|
802 DtoForceConstInitDsymbol(base); |
72 | 803 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
804 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
72 | 805 |
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
|
806 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
807 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
808 sinits.push_back(base->ir.irStruct->vtbl); |
72 | 809 |
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
|
810 // 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
|
811 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
|
812 |
72 | 813 // char[] name |
814 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
|
815 sinits.push_back(DtoConstString(name)); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
816 //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
|
817 assert(sinits.back()->getType() == stype->getElementType(2)); |
72 | 818 |
819 // 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
|
820 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
821 #if 0 |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
822 // the implementation of TypeInfo_Struct uses this to determine size. :/ |
72 | 823 if (sd->zeroInit) // 0 initializer, or the same as the base type |
824 { | |
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
|
825 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 826 } |
827 else | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
828 #endif |
72 | 829 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
830 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
|
831 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
|
832 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 833 } |
834 | |
835 // toX functions ground work | |
836 FuncDeclaration *fd; | |
837 FuncDeclaration *fdx; | |
838 TypeFunction *tf; | |
839 Type *ta; | |
840 Dsymbol *s; | |
841 | |
842 static TypeFunction *tftohash; | |
843 static TypeFunction *tftostring; | |
844 | |
845 if (!tftohash) | |
846 { | |
847 Scope sc; | |
848 | |
849 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
850 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
851 | |
852 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
853 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
854 } | |
855 | |
856 TypeFunction *tfeqptr; | |
857 { | |
858 Scope sc; | |
859 Arguments *arguments = new Arguments; | |
860 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
861 | |
862 arguments->push(arg); | |
863 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
864 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
865 } | |
866 | |
867 #if 0 | |
868 TypeFunction *tfeq; | |
869 { | |
870 Scope sc; | |
871 Array *arguments = new Array; | |
872 Argument *arg = new Argument(In, tc, NULL, NULL); | |
873 | |
874 arguments->push(arg); | |
875 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
876 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
877 } | |
878 #endif | |
879 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
880 //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
|
881 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
|
882 assert(ptty); |
72 | 883 |
884 s = search_function(sd, Id::tohash); | |
885 fdx = s ? s->isFuncDeclaration() : NULL; | |
886 if (fdx) | |
887 { | |
888 fd = fdx->overloadExactMatch(tftohash); | |
889 if (fd) { | |
132 | 890 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
891 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
892 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 893 assert(c); |
894 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
895 sinits.push_back(c); | |
896 } | |
897 else { | |
898 //fdx->error("must be declared as extern (D) uint toHash()"); | |
899 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
900 } | |
901 } | |
902 else { | |
903 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
904 } | |
905 | |
906 s = search_function(sd, Id::eq); | |
907 fdx = s ? s->isFuncDeclaration() : NULL; | |
908 for (int i = 0; i < 2; i++) | |
909 { | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
910 //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
|
911 ptty = isaPointer(stype->getElementType(5+i)); |
72 | 912 if (fdx) |
913 { | |
914 fd = fdx->overloadExactMatch(tfeqptr); | |
915 if (fd) { | |
132 | 916 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
917 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
918 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 919 assert(c); |
920 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
921 sinits.push_back(c); | |
922 } | |
923 else { | |
924 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
925 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
926 } | |
927 } | |
928 else { | |
929 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
930 } | |
931 | |
932 s = search_function(sd, Id::cmp); | |
933 fdx = s ? s->isFuncDeclaration() : NULL; | |
934 } | |
935 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
936 //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
|
937 ptty = isaPointer(stype->getElementType(7)); |
72 | 938 s = search_function(sd, Id::tostring); |
939 fdx = s ? s->isFuncDeclaration() : NULL; | |
940 if (fdx) | |
941 { | |
942 fd = fdx->overloadExactMatch(tftostring); | |
943 if (fd) { | |
132 | 944 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
945 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
946 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 947 assert(c); |
948 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
949 sinits.push_back(c); | |
950 } | |
951 else { | |
952 //fdx->error("must be declared as extern (D) char[] toString()"); | |
953 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
954 } | |
955 } | |
956 else { | |
957 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
958 } | |
959 | |
960 // uint m_flags; | |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
961 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 962 |
963 // create the symbol | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
964 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 965 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 966 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
967 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 968 } |
969 | |
970 void TypeInfoStructDeclaration::toDt(dt_t **pdt) | |
971 { | |
972 assert(0); | |
52 | 973 } |
974 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
975 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
976 |
106 | 977 void TypeInfoClassDeclaration::llvmDeclare() |
978 { | |
979 Logger::println("TypeInfoClassDeclaration::llvmDeclare() %s", toChars()); | |
980 LOG_SCOPE; | |
981 | |
982 // init typeinfo class | |
983 ClassDeclaration* base = Type::typeinfoclass; | |
984 assert(base); | |
985 DtoResolveClass(base); | |
986 | |
987 // get type of typeinfo class | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
988 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 989 |
990 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
991 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 992 } |
993 | |
994 void TypeInfoClassDeclaration::llvmDefine() | |
995 { | |
996 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); | |
997 LOG_SCOPE; | |
998 | |
999 // init typeinfo class | |
1000 ClassDeclaration* base = Type::typeinfoclass; | |
1001 assert(base); | |
1002 DtoForceConstInitDsymbol(base); | |
1003 | |
1004 // get type of typeinfo class | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
1005 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 1006 |
1007 // initializer vector | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1008 std::vector<LLConstant*> sinits; |
106 | 1009 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1010 sinits.push_back(base->ir.irStruct->vtbl); |
106 | 1011 |
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
|
1012 // 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
|
1013 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
|
1014 |
106 | 1015 // get classinfo |
1016 assert(tinfo->ty == Tclass); | |
1017 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
|
1018 DtoForceDeclareDsymbol(tc->sym); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1019 assert(tc->sym->ir.irStruct->classInfo); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1020 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
106 | 1021 |
1022 // create the symbol | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1023 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1024 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1025 } |
1026 | |
52 | 1027 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
1028 { | |
106 | 1029 assert(0); |
52 | 1030 } |
1031 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1032 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1033 |
106 | 1034 void TypeInfoInterfaceDeclaration::llvmDeclare() |
1035 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1036 Logger::println("TypeInfoInterfaceDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1037 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1038 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1039 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1040 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1041 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1042 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1043 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1044 // 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
|
1045 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1046 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1047 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1048 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1049 } |
1050 | |
1051 void TypeInfoInterfaceDeclaration::llvmDefine() | |
1052 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1053 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1054 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1055 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1056 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1057 ClassDeclaration* base = Type::typeinfointerface; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1058 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1059 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1060 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1061 // 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
|
1062 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1063 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1064 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1065 std::vector<LLConstant*> sinits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1066 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1067 sinits.push_back(base->ir.irStruct->vtbl); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1068 |
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
|
1069 // 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
|
1070 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
|
1071 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1072 // get classinfo |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1073 assert(tinfo->ty == Tclass); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1074 TypeClass *tc = (TypeClass *)tinfo; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1075 assert(tc->sym->ir.irStruct->classInfo); |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1076 sinits.push_back(tc->sym->ir.irStruct->classInfo); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1077 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1078 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1079 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1080 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1081 } |
1082 | |
52 | 1083 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
1084 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1085 assert(0); |
52 | 1086 } |
1087 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1088 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1089 |
106 | 1090 void TypeInfoTupleDeclaration::llvmDeclare() |
1091 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1092 Logger::println("TypeInfoTupleDeclaration::llvmDeclare() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1093 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1094 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1095 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1096 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1097 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1098 DtoResolveClass(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1099 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1100 // 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
|
1101 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1102 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1103 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1104 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 1105 } |
1106 | |
1107 void TypeInfoTupleDeclaration::llvmDefine() | |
1108 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1109 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars()); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1110 LOG_SCOPE; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1111 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1112 // init typeinfo class |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1113 ClassDeclaration* base = Type::typeinfotypelist; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1114 assert(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1115 DtoForceConstInitDsymbol(base); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1116 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1117 // 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
|
1118 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1119 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1120 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1121 std::vector<LLConstant*> sinits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1122 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1123 sinits.push_back(base->ir.irStruct->vtbl); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1124 |
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
|
1125 // 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
|
1126 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
|
1127 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1128 // create elements array |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1129 assert(tinfo->ty == Ttuple); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1130 TypeTuple *tu = (TypeTuple *)tinfo; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1131 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1132 size_t dim = tu->arguments->dim; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1133 std::vector<LLConstant*> arrInits; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1134 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1135 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
|
1136 tiTy = getPtrToType(tiTy); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1137 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1138 for (size_t i = 0; i < dim; i++) |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1139 { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1140 Argument *arg = (Argument *)tu->arguments->data[i]; |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1141 LLConstant* castbase = DtoTypeInfoOf(arg->type, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1142 assert(castbase->getType() == tiTy); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
1143 arrInits.push_back(castbase); |
113
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 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1146 // 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
|
1147 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
|
1148 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1149 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1150 // build the slice |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1151 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1152 sinits.push_back(slice); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1153 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1154 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1155 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1156 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1157 } |
1158 | |
52 | 1159 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1160 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1161 assert(0); |
52 | 1162 } |