Mercurial > projects > ldc
annotate gen/typinf.cpp @ 715:30b42a283c8e
Removed TypeOpaque from DMD.
Changed runtime functions taking opaque[] to void[].
Implemented proper type painting, to avoid "resizing" array casts in runtime calls that previously took opaque[].
Implemented dynamic arrays as first class types, this implements proper ABI for these types on x86.
Added dwarf region end after call to assert function, fixes some problems with llvm not allowing this to be missing.
Reverted change to WithStatement from rev [704] it breaks MiniD, mini/with2.d needs to be fixed some other way...
Fixed tango bug 1339 in runtime, problem with _adReverseChar on invalid UTF-8.
Disabled .bc generation in the compiler runtime part, genobj.d triggers some llvm bug when using debug info. the .o seems to work fine.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:55:33 +0200 |
parents | 6aaa3d3c1183 |
children | f04dde6e882c |
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 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
622
diff
changeset
|
11 // Modifications for LDC: |
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
|
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 { | |
336 | 126 t->vtinfo->toObjFile(0); // TODO: multiobj |
1 | 127 } |
128 } | |
129 } | |
130 e = new VarExp(0, t->vtinfo); | |
381
6590ec13f14d
Fixed root cause for Invalid BitCasts. DtoCanLoad continues to return false
Christian Kamm <kamm incasoftware de>
parents:
379
diff
changeset
|
131 //e = e->addressOf(sc); |
6590ec13f14d
Fixed root cause for Invalid BitCasts. DtoCanLoad continues to return false
Christian Kamm <kamm incasoftware de>
parents:
379
diff
changeset
|
132 //e->type = t->vtinfo->type; // do this so we don't get redundant dereference |
1 | 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 { |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
622
diff
changeset
|
237 assert(0); // done elsewhere in LDC |
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 | |
336 | 247 void TypeInfoDeclaration::toObjFile(int multiobj) |
52 | 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()); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
522
diff
changeset
|
372 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
522
diff
changeset
|
373 Logger::cout() << "got stype: " << *stype << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
374 |
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
|
375 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
376 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
377 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
|
378 |
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
|
379 // 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
|
380 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
|
381 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
383 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
384 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
385 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
386 // TypeInfo base |
290
ebaf65fc4726
[svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents:
275
diff
changeset
|
387 sd->basetype = sd->basetype->merge(); // DMD does this! |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
388 LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
389 assert(castbase->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
390 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
391 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
392 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
397 // 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
|
398 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
399 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
|
400 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
401 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
|
402 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
403 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
404 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
405 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
|
406 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
413 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
414 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
415 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
416 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 417 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
418 |
106 | 419 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
420 { | |
421 assert(0); | |
52 | 422 } |
423 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
424 /* ========================================================================= */ |
52 | 425 |
106 | 426 void TypeInfoEnumDeclaration::llvmDeclare() |
52 | 427 { |
106 | 428 Logger::println("TypeInfoEnumDeclaration::llvmDeclare() %s", toChars()); |
429 LOG_SCOPE; | |
430 | |
431 ClassDeclaration* base = Type::typeinfoenum; | |
432 DtoResolveClass(base); | |
433 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
434 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 435 |
436 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
437 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 438 } |
439 | |
440 void TypeInfoEnumDeclaration::llvmDefine() | |
441 { | |
442 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
443 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
444 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 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
|
446 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
447 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
448 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
|
449 |
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
|
450 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
451 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
452 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
|
453 |
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 // 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
|
455 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
|
456 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
458 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
460 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
461 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
462 LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
463 assert(castbase->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
465 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
466 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
471 // 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
|
472 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
|
473 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
|
474 { |
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
|
475 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
|
476 } |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
477 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
|
478 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
479 const LLType* memty = DtoType(sd->memtype); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
488 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
489 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
490 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
491 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 492 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
493 |
106 | 494 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) |
495 { | |
496 assert(0); | |
52 | 497 } |
498 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
499 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
500 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
501 static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) |
106 | 502 { |
503 ClassDeclaration* base = cd; | |
504 DtoResolveClass(base); | |
505 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
506 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 507 |
508 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
509 tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); |
106 | 510 } |
511 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
512 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
|
513 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
514 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
|
515 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
516 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
517 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
|
518 |
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
|
519 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
520 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
521 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
|
522 |
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 // 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
|
524 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
|
525 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
526 // TypeInfo base |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
527 LLConstant* castbase = DtoTypeInfoOf(basetype, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
528 assert(castbase->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
529 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
530 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
531 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
532 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
533 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
|
534 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
535 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
536 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
537 |
106 | 538 void TypeInfoPointerDeclaration::llvmDeclare() |
52 | 539 { |
106 | 540 Logger::println("TypeInfoPointerDeclaration::llvmDeclare() %s", toChars()); |
541 LOG_SCOPE; | |
542 | |
543 assert(tinfo->ty == Tpointer); | |
544 TypePointer *tc = (TypePointer *)tinfo; | |
545 | |
546 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfopointer); | |
547 } | |
548 | |
549 void TypeInfoPointerDeclaration::llvmDefine() | |
550 { | |
551 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars()); | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
552 LOG_SCOPE; |
52 | 553 |
554 assert(tinfo->ty == Tpointer); | |
555 TypePointer *tc = (TypePointer *)tinfo; | |
556 | |
106 | 557 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
558 } | |
559 | |
560 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) | |
561 { | |
562 assert(0); | |
52 | 563 } |
564 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
565 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
566 |
106 | 567 void TypeInfoArrayDeclaration::llvmDeclare() |
52 | 568 { |
106 | 569 Logger::println("TypeInfoArrayDeclaration::llvmDeclare() %s", toChars()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
570 LOG_SCOPE; |
52 | 571 |
572 assert(tinfo->ty == Tarray); | |
573 TypeDArray *tc = (TypeDArray *)tinfo; | |
574 | |
106 | 575 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoarray); |
576 } | |
577 | |
578 void TypeInfoArrayDeclaration::llvmDefine() | |
579 { | |
580 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars()); | |
581 LOG_SCOPE; | |
582 | |
583 assert(tinfo->ty == Tarray); | |
584 TypeDArray *tc = (TypeDArray *)tinfo; | |
585 | |
586 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfoarray); | |
587 } | |
588 | |
589 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) | |
590 { | |
591 assert(0); | |
52 | 592 } |
593 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
594 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
595 |
106 | 596 void TypeInfoStaticArrayDeclaration::llvmDeclare() |
597 { | |
598 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); | |
599 LOG_SCOPE; | |
600 | |
601 // init typeinfo class | |
602 ClassDeclaration* base = Type::typeinfostaticarray; | |
603 DtoResolveClass(base); | |
604 | |
605 // 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
|
606 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 607 |
608 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
609 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 610 } |
611 | |
612 void TypeInfoStaticArrayDeclaration::llvmDefine() | |
52 | 613 { |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
614 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
615 LOG_SCOPE; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
616 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
617 // init typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
618 ClassDeclaration* base = Type::typeinfostaticarray; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
619 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
620 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
621 // 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
|
622 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
52 | 623 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
624 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
625 std::vector<LLConstant*> sinits; |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
626 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
627 sinits.push_back(base->ir.irStruct->vtbl); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
628 |
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 // 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
|
630 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
|
631 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
632 // value typeinfo |
52 | 633 assert(tinfo->ty == Tsarray); |
634 TypeSArray *tc = (TypeSArray *)tinfo; | |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
635 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
636 assert(castbase->getType() == stype->getElementType(2)); |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
637 sinits.push_back(castbase); |
52 | 638 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
639 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
640 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
641 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
642 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
643 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
644 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 645 } |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
646 |
106 | 647 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
648 { | |
649 assert(0); | |
52 | 650 } |
651 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
652 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
653 |
106 | 654 void TypeInfoAssociativeArrayDeclaration::llvmDeclare() |
655 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
656 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
657 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
658 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
659 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
660 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
661 DtoResolveClass(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
662 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
663 // 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
|
664 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
|
665 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
666 // create the symbol |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
667 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 668 } |
669 | |
670 void TypeInfoAssociativeArrayDeclaration::llvmDefine() | |
671 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
672 Logger::println("TypeInfoAssociativeArrayDeclaration::toDt() %s", toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
673 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
674 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
675 // init typeinfo class |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
676 ClassDeclaration* base = Type::typeinfoassociativearray; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
677 DtoForceConstInitDsymbol(base); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
678 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
679 // get type of typeinfo class |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
680 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
|
681 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
682 // initializer vector |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
683 std::vector<LLConstant*> sinits; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
684 // first is always the vtable |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
685 sinits.push_back(base->ir.irStruct->vtbl); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
686 |
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 // 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
|
688 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
|
689 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
690 // get type |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
691 assert(tinfo->ty == Taarray); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
692 TypeAArray *tc = (TypeAArray *)tinfo; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
693 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
694 // value typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
695 LLConstant* castbase = DtoTypeInfoOf(tc->next, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
696 assert(castbase->getType() == stype->getElementType(2)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
697 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
698 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
699 // key typeinfo |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
700 castbase = DtoTypeInfoOf(tc->index, true); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
701 assert(castbase->getType() == stype->getElementType(3)); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
702 sinits.push_back(castbase); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
703 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
704 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
705 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
706 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 707 } |
708 | |
52 | 709 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
710 { | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
106
diff
changeset
|
711 assert(0); |
52 | 712 } |
713 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
714 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
715 |
106 | 716 void TypeInfoFunctionDeclaration::llvmDeclare() |
717 { | |
718 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); | |
719 LOG_SCOPE; | |
720 | |
721 assert(tinfo->ty == Tfunction); | |
722 TypeFunction *tc = (TypeFunction *)tinfo; | |
723 | |
724 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfofunction); | |
725 } | |
726 | |
727 void TypeInfoFunctionDeclaration::llvmDefine() | |
52 | 728 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
729 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
730 LOG_SCOPE; |
52 | 731 |
732 assert(tinfo->ty == Tfunction); | |
733 TypeFunction *tc = (TypeFunction *)tinfo; | |
734 | |
106 | 735 LLVM_D_Define_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
736 } | |
737 | |
738 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) | |
739 { | |
740 assert(0); | |
52 | 741 } |
742 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
743 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
744 |
106 | 745 void TypeInfoDelegateDeclaration::llvmDeclare() |
746 { | |
747 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); | |
748 LOG_SCOPE; | |
749 | |
750 assert(tinfo->ty == Tdelegate); | |
751 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
752 | |
753 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfodelegate); | |
754 } | |
755 | |
756 void TypeInfoDelegateDeclaration::llvmDefine() | |
52 | 757 { |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
758 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
759 LOG_SCOPE; |
52 | 760 |
761 assert(tinfo->ty == Tdelegate); | |
762 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
763 | |
106 | 764 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
765 } | |
766 | |
767 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) | |
768 { | |
769 assert(0); | |
52 | 770 } |
771 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
772 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
773 |
106 | 774 void TypeInfoStructDeclaration::llvmDeclare() |
52 | 775 { |
106 | 776 Logger::println("TypeInfoStructDeclaration::llvmDeclare() %s", toChars()); |
777 LOG_SCOPE; | |
778 | |
779 assert(tinfo->ty == Tstruct); | |
780 TypeStruct *tc = (TypeStruct *)tinfo; | |
781 StructDeclaration *sd = tc->sym; | |
782 DtoResolveDsymbol(sd); | |
783 | |
784 ClassDeclaration* base = Type::typeinfostruct; | |
785 DtoResolveClass(base); | |
786 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
787 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
106 | 788 |
789 // create the symbol | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
790 this->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); |
106 | 791 } |
792 | |
793 void TypeInfoStructDeclaration::llvmDefine() | |
794 { | |
795 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars()); | |
72 | 796 LOG_SCOPE; |
797 | |
798 assert(tinfo->ty == Tstruct); | |
799 TypeStruct *tc = (TypeStruct *)tinfo; | |
800 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
|
801 DtoForceConstInitDsymbol(sd); |
72 | 802 |
803 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
|
804 DtoForceConstInitDsymbol(base); |
72 | 805 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
213
diff
changeset
|
806 const LLStructType* stype = isaStruct(base->type->ir.type->get()); |
72 | 807 |
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
|
808 // vtbl |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
809 std::vector<LLConstant*> sinits; |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
810 sinits.push_back(base->ir.irStruct->vtbl); |
72 | 811 |
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 // 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
|
813 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
|
814 |
72 | 815 // char[] name |
816 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
|
817 sinits.push_back(DtoConstString(name)); |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
818 //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
|
819 assert(sinits.back()->getType() == stype->getElementType(2)); |
72 | 820 |
821 // 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
|
822 const LLPointerType* initpt = getPtrToType(LLType::Int8Ty); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
823 #if 0 |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
824 // the implementation of TypeInfo_Struct uses this to determine size. :/ |
72 | 825 if (sd->zeroInit) // 0 initializer, or the same as the base type |
826 { | |
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
|
827 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 828 } |
829 else | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
830 #endif |
72 | 831 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
832 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
|
833 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
|
834 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 835 } |
836 | |
837 // toX functions ground work | |
838 FuncDeclaration *fd; | |
839 FuncDeclaration *fdx; | |
840 TypeFunction *tf; | |
841 Type *ta; | |
842 Dsymbol *s; | |
843 | |
844 static TypeFunction *tftohash; | |
845 static TypeFunction *tftostring; | |
846 | |
847 if (!tftohash) | |
848 { | |
849 Scope sc; | |
850 | |
851 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
852 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
853 | |
854 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
855 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
856 } | |
857 | |
858 TypeFunction *tfeqptr; | |
859 { | |
860 Scope sc; | |
861 Arguments *arguments = new Arguments; | |
862 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
863 | |
864 arguments->push(arg); | |
865 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
866 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
867 } | |
868 | |
869 #if 0 | |
870 TypeFunction *tfeq; | |
871 { | |
872 Scope sc; | |
873 Array *arguments = new Array; | |
874 Argument *arg = new Argument(In, tc, NULL, NULL); | |
875 | |
876 arguments->push(arg); | |
877 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
878 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
879 } | |
880 #endif | |
881 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
882 //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
|
883 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
|
884 assert(ptty); |
72 | 885 |
886 s = search_function(sd, Id::tohash); | |
887 fdx = s ? s->isFuncDeclaration() : NULL; | |
888 if (fdx) | |
889 { | |
890 fd = fdx->overloadExactMatch(tftohash); | |
891 if (fd) { | |
132 | 892 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
893 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
894 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 895 assert(c); |
896 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
897 sinits.push_back(c); | |
898 } | |
899 else { | |
900 //fdx->error("must be declared as extern (D) uint toHash()"); | |
901 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
902 } | |
903 } | |
904 else { | |
905 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
906 } | |
907 | |
908 s = search_function(sd, Id::eq); | |
909 fdx = s ? s->isFuncDeclaration() : NULL; | |
910 for (int i = 0; i < 2; i++) | |
911 { | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
912 //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
|
913 ptty = isaPointer(stype->getElementType(5+i)); |
72 | 914 if (fdx) |
915 { | |
916 fd = fdx->overloadExactMatch(tfeqptr); | |
917 if (fd) { | |
132 | 918 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
919 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
920 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 921 assert(c); |
922 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
923 sinits.push_back(c); | |
924 } | |
925 else { | |
926 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
927 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
928 } | |
929 } | |
930 else { | |
931 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
932 } | |
933 | |
934 s = search_function(sd, Id::cmp); | |
935 fdx = s ? s->isFuncDeclaration() : NULL; | |
936 } | |
937 | |
110
e8da7856a260
[svn r114] Implemented the ClassInfo.offTi member.
lindquist
parents:
109
diff
changeset
|
938 //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
|
939 ptty = isaPointer(stype->getElementType(7)); |
72 | 940 s = search_function(sd, Id::tostring); |
941 fdx = s ? s->isFuncDeclaration() : NULL; | |
942 if (fdx) | |
943 { | |
944 fd = fdx->overloadExactMatch(tftostring); | |
945 if (fd) { | |
132 | 946 DtoForceDeclareDsymbol(fd); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
947 assert(fd->ir.irFunc->func != 0); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
948 LLConstant* c = isaConstant(fd->ir.irFunc->func); |
72 | 949 assert(c); |
950 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
951 sinits.push_back(c); | |
952 } | |
953 else { | |
954 //fdx->error("must be declared as extern (D) char[] toString()"); | |
955 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
956 } | |
957 } | |
958 else { | |
959 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
960 } | |
961 | |
962 // 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
|
963 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 964 |
965 // create the symbol | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
966 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
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 |
522
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1150 // need the pointer to the first element of arrC, so create a global for it |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1151 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1152 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrTy,true,_linkage,arrC,".tupleelements",gIR->module); |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1153 |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1154 // get pointer to first element |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1155 llvm::ConstantInt* zero = DtoConstSize_t(0); |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1156 LLConstant* idxs[2] = { zero, zero }; |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1157 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar, idxs, 2); |
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1158 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1159 // build the slice |
522
cd4eeb6cc5f6
Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents:
508
diff
changeset
|
1160 LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrptr); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1161 sinits.push_back(slice); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1162 |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1163 // create the symbol |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
173
diff
changeset
|
1164 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
163
diff
changeset
|
1165 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); |
106 | 1166 } |
1167 | |
52 | 1168 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
1169 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
110
diff
changeset
|
1170 assert(0); |
52 | 1171 } |