Mercurial > projects > ldc
annotate gen/typinf.cpp @ 105:182b41f56b7f trunk
[svn r109] Fixed support for static array TypeInfo
author | lindquist |
---|---|
date | Mon, 19 Nov 2007 03:39:46 +0100 |
parents | 027b8d8b71ec |
children | 5b5194b25f33 |
rev | line source |
---|---|
1 | 1 |
2 | |
3 // Copyright (c) 1999-2004 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
11 // Modifications for LLVMDC: |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
12 // Copyright (c) 2007 by Tomas Lindquist Olsen |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
13 // tomas at famolsen dk |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
14 |
1 | 15 #include <cstdio> |
16 #include <cassert> | |
17 | |
52 | 18 #include "gen/llvm.h" |
19 | |
1 | 20 #include "mars.h" |
21 #include "module.h" | |
22 #include "mtype.h" | |
23 #include "scope.h" | |
24 #include "init.h" | |
25 #include "expression.h" | |
26 #include "attrib.h" | |
27 #include "declaration.h" | |
28 #include "template.h" | |
29 #include "id.h" | |
30 #include "enum.h" | |
31 #include "import.h" | |
32 #include "aggregate.h" | |
33 | |
52 | 34 #include "gen/irstate.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
35 #include "gen/logger.h" |
52 | 36 #include "gen/runtime.h" |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
37 #include "gen/tollvm.h" |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
38 #include "gen/arrays.h" |
100 | 39 #include "gen/structs.h" |
1 | 40 |
41 /******************************************* | |
42 * Get a canonicalized form of the TypeInfo for use with the internal | |
43 * runtime library routines. Canonicalized in that static arrays are | |
44 * represented as dynamic arrays, enums are represented by their | |
45 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
46 * so we can use the custom internal ones more. | |
47 */ | |
48 | |
49 Expression *Type::getInternalTypeInfo(Scope *sc) | |
50 { TypeInfoDeclaration *tid; | |
51 Expression *e; | |
52 Type *t; | |
53 static TypeInfoDeclaration *internalTI[TMAX]; | |
54 | |
55 //printf("Type::getInternalTypeInfo() %s\n", toChars()); | |
56 t = toBasetype(); | |
57 switch (t->ty) | |
58 { | |
59 case Tsarray: | |
60 t = t->next->arrayOf(); // convert to corresponding dynamic array type | |
61 break; | |
62 | |
63 case Tclass: | |
64 if (((TypeClass *)t)->sym->isInterfaceDeclaration()) | |
65 break; | |
66 goto Linternal; | |
67 | |
68 case Tarray: | |
69 if (t->next->ty != Tclass) | |
70 break; | |
71 goto Linternal; | |
72 | |
73 case Tfunction: | |
74 case Tdelegate: | |
75 case Tpointer: | |
76 Linternal: | |
77 tid = internalTI[t->ty]; | |
78 if (!tid) | |
79 { tid = new TypeInfoDeclaration(t, 1); | |
80 internalTI[t->ty] = tid; | |
81 } | |
82 e = new VarExp(0, tid); | |
52 | 83 //e = e->addressOf(sc); |
1 | 84 e->type = tid->type; // do this so we don't get redundant dereference |
85 return e; | |
86 | |
87 default: | |
88 break; | |
89 } | |
90 //printf("\tcalling getTypeInfo() %s\n", t->toChars()); | |
91 return t->getTypeInfo(sc); | |
92 } | |
93 | |
94 | |
95 /**************************************************** | |
96 * Get the exact TypeInfo. | |
97 */ | |
98 | |
99 Expression *Type::getTypeInfo(Scope *sc) | |
100 { | |
101 Expression *e; | |
102 Type *t; | |
103 | |
104 //printf("Type::getTypeInfo() %p, %s\n", this, toChars()); | |
105 t = merge(); // do this since not all Type's are merge'd | |
106 if (!t->vtinfo) | |
107 { t->vtinfo = t->getTypeInfoDeclaration(); | |
108 assert(t->vtinfo); | |
109 | |
110 /* If this has a custom implementation in std/typeinfo, then | |
111 * do not generate a COMDAT for it. | |
112 */ | |
113 if (!t->builtinTypeInfo()) | |
114 { // Generate COMDAT | |
115 if (sc) // if in semantic() pass | |
116 { // Find module that will go all the way to an object file | |
117 Module *m = sc->module->importedFrom; | |
118 m->members->push(t->vtinfo); | |
119 } | |
120 else // if in obj generation pass | |
121 { | |
122 t->vtinfo->toObjFile(); | |
123 } | |
124 } | |
125 } | |
126 e = new VarExp(0, t->vtinfo); | |
127 //e = e->addressOf(sc); | |
128 e->type = t->vtinfo->type; // do this so we don't get redundant dereference | |
129 return e; | |
130 } | |
131 | |
52 | 132 enum RET TypeFunction::retStyle() |
133 { | |
134 return RETstack; | |
135 } | |
1 | 136 |
137 TypeInfoDeclaration *Type::getTypeInfoDeclaration() | |
138 { | |
139 //printf("Type::getTypeInfoDeclaration() %s\n", toChars()); | |
140 return new TypeInfoDeclaration(this, 0); | |
141 } | |
142 | |
52 | 143 TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration() |
1 | 144 { |
52 | 145 return new TypeInfoTypedefDeclaration(this); |
1 | 146 } |
147 | |
52 | 148 TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration() |
149 { | |
150 return new TypeInfoPointerDeclaration(this); | |
151 } | |
1 | 152 |
153 TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration() | |
154 { | |
155 return new TypeInfoArrayDeclaration(this); | |
156 } | |
157 | |
158 TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration() | |
159 { | |
160 return new TypeInfoStaticArrayDeclaration(this); | |
161 } | |
162 | |
163 TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration() | |
164 { | |
165 return new TypeInfoAssociativeArrayDeclaration(this); | |
166 } | |
167 | |
52 | 168 TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration() |
169 { | |
170 return new TypeInfoStructDeclaration(this); | |
171 } | |
1 | 172 |
173 TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration() | |
174 { | |
175 if (sym->isInterfaceDeclaration()) | |
176 return new TypeInfoInterfaceDeclaration(this); | |
177 else | |
178 return new TypeInfoClassDeclaration(this); | |
179 } | |
180 | |
181 TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration() | |
182 { | |
183 return new TypeInfoEnumDeclaration(this); | |
184 } | |
185 | |
186 TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration() | |
187 { | |
188 return new TypeInfoFunctionDeclaration(this); | |
189 } | |
190 | |
191 TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration() | |
192 { | |
193 return new TypeInfoDelegateDeclaration(this); | |
194 } | |
195 | |
196 TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration() | |
197 { | |
198 return new TypeInfoTupleDeclaration(this); | |
199 } | |
200 | |
201 | |
202 /* ========================================================================= */ | |
203 | |
204 /* These decide if there's an instance for them already in std.typeinfo, | |
205 * because then the compiler doesn't need to build one. | |
206 */ | |
207 | |
208 int Type::builtinTypeInfo() | |
209 { | |
210 return 0; | |
211 } | |
212 | |
213 int TypeBasic::builtinTypeInfo() | |
214 { | |
215 return 1; | |
216 } | |
217 | |
218 int TypeDArray::builtinTypeInfo() | |
219 { | |
52 | 220 return next->isTypeBasic() != NULL; |
1 | 221 } |
222 | |
223 /* ========================================================================= */ | |
224 | |
225 /*************************************** | |
226 * Create a static array of TypeInfo references | |
227 * corresponding to an array of Expression's. | |
228 * Used to supply hidden _arguments[] value for variadic D functions. | |
229 */ | |
230 | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
231 Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) |
1 | 232 { |
233 assert(0); | |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
234 return NULL; |
1 | 235 } |
236 | |
52 | 237 /* ========================================================================= */ |
238 | |
239 ////////////////////////////////////////////////////////////////////////////// | |
240 // MAGIC PLACE | |
241 ////////////////////////////////////////////////////////////////////////////// | |
242 | |
243 void TypeInfoDeclaration::toObjFile() | |
244 { | |
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
|
245 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
|
246 } |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
54
diff
changeset
|
247 |
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
|
248 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
|
249 { |
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 if (tid->llvmResolved) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
251 tid->llvmResolved = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
252 |
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 Logger::println("* DtoResolveTypeInfo(%s)", tid->toChars()); |
52 | 254 LOG_SCOPE; |
65 | 255 |
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 tid->llvmIRGlobal = new IRGlobal(tid); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
257 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
258 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
|
259 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
260 |
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 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
|
262 { |
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 if (tid->llvmDeclared) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
264 tid->llvmDeclared = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
265 |
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 Logger::println("* DtoDeclareTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
267 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
|
268 |
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 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
|
270 |
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 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
|
272 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
|
273 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
274 // 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
|
275 if (tid->tinfo->builtinTypeInfo()) { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
276 tid->llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangled.c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
277 assert(tid->llvmValue); |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
278 mangled.append("__TYPE"); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
279 gIR->module->addTypeName(mangled, tid->llvmValue->getType()->getContainedType(0)); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
280 Logger::println("Got typeinfo var: %s", tid->llvmValue->getName().c_str()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
281 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
282 tid->llvmDefined = true; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
283 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
284 // custom typedef |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
285 else { |
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
|
286 gIR->constInitList.push_back(tid); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
287 } |
52 | 288 } |
289 | |
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
|
290 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
|
291 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
292 if (tid->llvmInitialized) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
293 tid->llvmInitialized = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
294 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
295 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
296 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
|
297 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
298 tid->toDt(NULL); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
299 |
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
|
300 tid->llvmDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
301 //gIR->defineList.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
|
302 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
303 |
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 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
|
305 { |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
306 if (tid->llvmDefined) return; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
307 tid->llvmDefined = true; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
308 |
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 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
310 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
|
311 |
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 assert(0); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
313 } |
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 |
52 | 315 /* ========================================================================= */ |
316 | |
317 void TypeInfoDeclaration::toDt(dt_t **pdt) | |
318 { | |
319 assert(0 && "TypeInfoDeclaration"); | |
320 } | |
321 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
322 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
323 |
52 | 324 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) |
325 { | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
326 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
327 LOG_SCOPE; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
328 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
329 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
|
330 DtoForceConstInitDsymbol(base); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
331 |
100 | 332 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
333 Logger::cout() << "got stype: " << *stype << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
334 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
335 std::vector<llvm::Constant*> sinits; |
100 | 336 sinits.push_back(base->llvmVtbl); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
337 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
338 assert(tinfo->ty == Ttypedef); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
339 TypeTypedef *tc = (TypeTypedef *)tinfo; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
340 TypedefDeclaration *sd = tc->sym; |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
341 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
342 // TypeInfo base |
96 | 343 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
344 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
345 Logger::println("generating base typeinfo"); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
346 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
347 |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
348 sd->basetype->getTypeInfo(NULL); // generate vtinfo |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
349 assert(sd->basetype->vtinfo); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
350 if (!sd->basetype->vtinfo->llvmValue) |
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
|
351 DtoForceConstInitDsymbol(sd->basetype->vtinfo); |
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
|
352 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
353 assert(sd->basetype->vtinfo->llvmValue); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
354 assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
355 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->llvmValue); |
100 | 356 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
357 sinits.push_back(castbase); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
358 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
359 // char[] name |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
360 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
|
361 sinits.push_back(DtoConstString(name)); |
100 | 362 assert(sinits.back()->getType() == stype->getElementType(2)); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
363 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
364 // void[] init |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
365 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
366 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
|
367 { |
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
|
368 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
369 } |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
370 else |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
371 { |
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
|
372 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
373 std::string ciname(sd->mangle()); |
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
374 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
|
375 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
69
2b5a2eaa88be
[svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents:
65
diff
changeset
|
376 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
377 size_t cisize = gTargetData->getTypeSize(DtoType(sd->basetype)); |
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
378 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
|
379 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
380 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
381 // create the symbol |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
382 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 383 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
384 |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
385 llvmValue = gvar; |
52 | 386 } |
387 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
388 /* ========================================================================= */ |
52 | 389 |
390 void TypeInfoEnumDeclaration::toDt(dt_t **pdt) | |
391 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
392 Logger::println("TypeInfoTypedefDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
393 LOG_SCOPE; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
394 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
395 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
|
396 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
397 |
100 | 398 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
399 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
400 std::vector<llvm::Constant*> sinits; |
100 | 401 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
402 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
403 assert(tinfo->ty == Tenum); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
404 TypeEnum *tc = (TypeEnum *)tinfo; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
405 EnumDeclaration *sd = tc->sym; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
406 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
407 // TypeInfo base |
96 | 408 //const llvm::PointerType* basept = isaPointer(initZ->getOperand(1)->getType()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
409 //sinits.push_back(llvm::ConstantPointerNull::get(basept)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
410 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
411 //sd->basetype = sd->basetype->merge(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
412 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
413 sd->memtype->getTypeInfo(NULL); // generate vtinfo |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
414 assert(sd->memtype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
415 if (!sd->memtype->vtinfo->llvmValue) |
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
|
416 DtoForceConstInitDsymbol(sd->memtype->vtinfo); |
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
|
417 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
418 assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
419 llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->llvmValue); |
100 | 420 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
421 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
422 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
423 // char[] name |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
424 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
|
425 sinits.push_back(DtoConstString(name)); |
100 | 426 assert(sinits.back()->getType() == stype->getElementType(2)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
427 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
428 // void[] init |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
429 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
430 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
|
431 { |
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
|
432 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
|
433 } |
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
|
434 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
|
435 { |
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
|
436 const llvm::Type* memty = DtoType(sd->memtype); |
71
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
437 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
438 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
|
439 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
|
440 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
441 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
53d3086b5ad3
[svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents:
69
diff
changeset
|
442 size_t cisize = gTargetData->getTypeSize(memty); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
443 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
|
444 } |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
445 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
446 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
447 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 448 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
449 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
450 llvmValue = gvar; |
52 | 451 } |
452 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
453 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
454 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
455 static llvm::Constant* LLVM_D_Create_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
456 { |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
457 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
|
458 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
459 |
100 | 460 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
461 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
462 std::vector<llvm::Constant*> sinits; |
100 | 463 sinits.push_back(base->llvmVtbl); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
464 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
465 // TypeInfo base |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
466 Logger::println("generating base typeinfo"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
467 basetype->getTypeInfo(NULL); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
468 assert(basetype->vtinfo); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
469 if (!basetype->vtinfo->llvmValue) |
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
|
470 DtoForceConstInitDsymbol(basetype->vtinfo); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
471 assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue)); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
472 llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->llvmValue); |
100 | 473 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
474 sinits.push_back(castbase); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
475 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
476 // create the symbol |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
477 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
73 | 478 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,tid->toChars(),gIR->module); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
479 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
480 tid->llvmValue = gvar; |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
481 } |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
482 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
483 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
484 |
52 | 485 void TypeInfoPointerDeclaration::toDt(dt_t **pdt) |
486 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
487 Logger::println("TypeInfoPointerDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
488 LOG_SCOPE; |
52 | 489 |
490 assert(tinfo->ty == Tpointer); | |
491 TypePointer *tc = (TypePointer *)tinfo; | |
492 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
493 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfopointer); |
52 | 494 } |
495 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
496 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
497 |
52 | 498 void TypeInfoArrayDeclaration::toDt(dt_t **pdt) |
499 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
500 Logger::println("TypeInfoArrayDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
501 LOG_SCOPE; |
52 | 502 |
503 assert(tinfo->ty == Tarray); | |
504 TypeDArray *tc = (TypeDArray *)tinfo; | |
505 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
506 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfoarray); |
52 | 507 } |
508 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
509 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
510 |
52 | 511 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) |
512 { | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
513 Logger::println("TypeInfoStaticArrayDeclaration::toDt() %s", toChars()); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
514 LOG_SCOPE; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
515 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
516 // init typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
517 ClassDeclaration* base = Type::typeinfostaticarray; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
518 DtoForceConstInitDsymbol(base); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
519 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
520 // get type of typeinfo class |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
521 const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); |
52 | 522 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
523 // initializer vector |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
524 std::vector<llvm::Constant*> sinits; |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
525 // first is always the vtable |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
526 sinits.push_back(base->llvmVtbl); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
527 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
528 // value typeinfo |
52 | 529 assert(tinfo->ty == Tsarray); |
530 TypeSArray *tc = (TypeSArray *)tinfo; | |
531 tc->next->getTypeInfo(NULL); | |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
532 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
533 // get symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
534 assert(tc->next->vtinfo); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
535 DtoForceConstInitDsymbol(tc->next->vtinfo); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
536 llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
537 castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
538 sinits.push_back(castbase); |
52 | 539 |
105
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
540 // length |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
541 sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
542 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
543 // create the symbol |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
544 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
545 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
546 |
182b41f56b7f
[svn r109] Fixed support for static array TypeInfo
lindquist
parents:
102
diff
changeset
|
547 llvmValue = gvar; |
52 | 548 } |
549 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
550 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
551 |
52 | 552 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) |
553 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
554 assert(0 && "TypeInfoAssociativeArrayDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
555 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
556 /* |
52 | 557 //printf("TypeInfoAssociativeArrayDeclaration::toDt()\n"); |
558 dtxoff(pdt, Type::typeinfoassociativearray->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray | |
559 dtdword(pdt, 0); // monitor | |
560 | |
561 assert(tinfo->ty == Taarray); | |
562 | |
563 TypeAArray *tc = (TypeAArray *)tinfo; | |
564 | |
565 tc->next->getTypeInfo(NULL); | |
566 dtxoff(pdt, tc->next->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
567 | |
568 tc->index->getTypeInfo(NULL); | |
569 dtxoff(pdt, tc->index->vtinfo->toSymbol(), 0, TYnptr); // TypeInfo for array of type | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
570 */ |
52 | 571 } |
572 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
573 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
574 |
52 | 575 void TypeInfoFunctionDeclaration::toDt(dt_t **pdt) |
576 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
577 Logger::println("TypeInfoFunctionDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
578 LOG_SCOPE; |
52 | 579 |
580 assert(tinfo->ty == Tfunction); | |
581 TypeFunction *tc = (TypeFunction *)tinfo; | |
582 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
583 LLVM_D_Create_TypeInfoBase(tc->next, this, Type::typeinfofunction); |
52 | 584 } |
585 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
586 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
587 |
52 | 588 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) |
589 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
590 Logger::println("TypeInfoDelegateDeclaration::toDt() %s", toChars()); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
591 LOG_SCOPE; |
52 | 592 |
593 assert(tinfo->ty == Tdelegate); | |
594 TypeDelegate *tc = (TypeDelegate *)tinfo; | |
595 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
596 LLVM_D_Create_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); |
52 | 597 } |
598 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
599 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
600 |
52 | 601 void TypeInfoStructDeclaration::toDt(dt_t **pdt) |
602 { | |
72 | 603 Logger::println("TypeInfoStructDeclaration::toDt() %s", toChars()); |
604 LOG_SCOPE; | |
605 | |
606 assert(tinfo->ty == Tstruct); | |
607 TypeStruct *tc = (TypeStruct *)tinfo; | |
608 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
|
609 DtoForceConstInitDsymbol(sd); |
72 | 610 |
611 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
|
612 DtoForceConstInitDsymbol(base); |
72 | 613 |
100 | 614 const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); |
72 | 615 |
616 std::vector<llvm::Constant*> sinits; | |
617 sinits.push_back(base->llvmVtbl); | |
618 | |
619 // char[] name | |
620 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
|
621 sinits.push_back(DtoConstString(name)); |
73 | 622 Logger::println("************** A"); |
72 | 623 assert(sinits.back()->getType() == stype->getElementType(1)); |
624 | |
625 // void[] init | |
626 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | |
627 if (sd->zeroInit) // 0 initializer, or the same as the base type | |
628 { | |
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
|
629 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
72 | 630 } |
631 else | |
632 { | |
633 assert(sd->llvmInitZ); | |
100 | 634 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); |
72 | 635 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(tc->llvmInit, initpt); |
81
3587401b6eeb
[svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents:
73
diff
changeset
|
636 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
72 | 637 } |
638 | |
639 // toX functions ground work | |
640 FuncDeclaration *fd; | |
641 FuncDeclaration *fdx; | |
642 TypeFunction *tf; | |
643 Type *ta; | |
644 Dsymbol *s; | |
645 | |
646 static TypeFunction *tftohash; | |
647 static TypeFunction *tftostring; | |
648 | |
649 if (!tftohash) | |
650 { | |
651 Scope sc; | |
652 | |
653 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd); | |
654 tftohash = (TypeFunction *)tftohash->semantic(0, &sc); | |
655 | |
656 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd); | |
657 tftostring = (TypeFunction *)tftostring->semantic(0, &sc); | |
658 } | |
659 | |
660 TypeFunction *tfeqptr; | |
661 { | |
662 Scope sc; | |
663 Arguments *arguments = new Arguments; | |
664 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL); | |
665 | |
666 arguments->push(arg); | |
667 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
668 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc); | |
669 } | |
670 | |
671 #if 0 | |
672 TypeFunction *tfeq; | |
673 { | |
674 Scope sc; | |
675 Array *arguments = new Array; | |
676 Argument *arg = new Argument(In, tc, NULL, NULL); | |
677 | |
678 arguments->push(arg); | |
679 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
680 tfeq = (TypeFunction *)tfeq->semantic(0, &sc); | |
681 } | |
682 #endif | |
683 | |
73 | 684 Logger::println("************** B"); |
96 | 685 const llvm::PointerType* ptty = isaPointer(stype->getElementType(3)); |
72 | 686 |
687 s = search_function(sd, Id::tohash); | |
688 fdx = s ? s->isFuncDeclaration() : NULL; | |
689 if (fdx) | |
690 { | |
691 fd = fdx->overloadExactMatch(tftohash); | |
692 if (fd) { | |
693 assert(fd->llvmValue != 0); | |
694 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
695 assert(c); | |
696 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
697 sinits.push_back(c); | |
698 } | |
699 else { | |
700 //fdx->error("must be declared as extern (D) uint toHash()"); | |
701 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
702 } | |
703 } | |
704 else { | |
705 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
706 } | |
707 | |
708 s = search_function(sd, Id::eq); | |
709 fdx = s ? s->isFuncDeclaration() : NULL; | |
710 for (int i = 0; i < 2; i++) | |
711 { | |
73 | 712 Logger::println("************** C %d", i); |
96 | 713 ptty = isaPointer(stype->getElementType(4+i)); |
72 | 714 if (fdx) |
715 { | |
716 fd = fdx->overloadExactMatch(tfeqptr); | |
717 if (fd) { | |
718 assert(fd->llvmValue != 0); | |
719 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
720 assert(c); | |
721 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
722 sinits.push_back(c); | |
723 } | |
724 else { | |
725 //fdx->error("must be declared as extern (D) int %s(%s*)", fdx->toChars(), sd->toChars()); | |
726 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
727 } | |
728 } | |
729 else { | |
730 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
731 } | |
732 | |
733 s = search_function(sd, Id::cmp); | |
734 fdx = s ? s->isFuncDeclaration() : NULL; | |
735 } | |
736 | |
73 | 737 Logger::println("************** D"); |
96 | 738 ptty = isaPointer(stype->getElementType(6)); |
72 | 739 s = search_function(sd, Id::tostring); |
740 fdx = s ? s->isFuncDeclaration() : NULL; | |
741 if (fdx) | |
742 { | |
743 fd = fdx->overloadExactMatch(tftostring); | |
744 if (fd) { | |
745 assert(fd->llvmValue != 0); | |
746 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); | |
747 assert(c); | |
748 c = llvm::ConstantExpr::getBitCast(c, ptty); | |
749 sinits.push_back(c); | |
750 } | |
751 else { | |
752 //fdx->error("must be declared as extern (D) char[] toString()"); | |
753 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
754 } | |
755 } | |
756 else { | |
757 sinits.push_back(llvm::ConstantPointerNull::get(ptty)); | |
758 } | |
759 | |
760 // 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
|
761 sinits.push_back(DtoConstUint(tc->hasPointers())); |
72 | 762 |
763 // create the symbol | |
764 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | |
73 | 765 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); |
72 | 766 |
767 llvmValue = gvar; | |
52 | 768 } |
769 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
770 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
771 |
52 | 772 void TypeInfoClassDeclaration::toDt(dt_t **pdt) |
773 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
774 assert(0 && "TypeInfoClassDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
775 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
776 /* |
52 | 777 //printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars()); |
778 dtxoff(pdt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass | |
779 dtdword(pdt, 0); // monitor | |
780 | |
781 assert(tinfo->ty == Tclass); | |
782 | |
783 TypeClass *tc = (TypeClass *)tinfo; | |
784 Symbol *s; | |
785 | |
786 if (!tc->sym->vclassinfo) | |
787 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
788 s = tc->sym->vclassinfo->toSymbol(); | |
789 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
790 */ |
52 | 791 } |
792 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
793 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
794 |
52 | 795 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) |
796 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
797 assert(0 && "TypeInfoInterfaceDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
798 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
799 /* |
52 | 800 //printf("TypeInfoInterfaceDeclaration::toDt() %s\n", tinfo->toChars()); |
801 dtxoff(pdt, Type::typeinfointerface->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
802 dtdword(pdt, 0); // monitor | |
803 | |
804 assert(tinfo->ty == Tclass); | |
805 | |
806 TypeClass *tc = (TypeClass *)tinfo; | |
807 Symbol *s; | |
808 | |
809 if (!tc->sym->vclassinfo) | |
810 tc->sym->vclassinfo = new ClassInfoDeclaration(tc->sym); | |
811 s = tc->sym->vclassinfo->toSymbol(); | |
812 dtxoff(pdt, s, 0, TYnptr); // ClassInfo for tinfo | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
813 */ |
52 | 814 } |
815 | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
816 /* ========================================================================= */ |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
817 |
52 | 818 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) |
819 { | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
820 assert(0 && "TypeInfoTupleDeclaration"); |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
821 |
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
822 /* |
52 | 823 //printf("TypeInfoTupleDeclaration::toDt() %s\n", tinfo->toChars()); |
824 dtxoff(pdt, Type::typeinfotypelist->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface | |
825 dtdword(pdt, 0); // monitor | |
826 | |
827 assert(tinfo->ty == Ttuple); | |
828 | |
829 TypeTuple *tu = (TypeTuple *)tinfo; | |
830 | |
831 size_t dim = tu->arguments->dim; | |
832 dtdword(pdt, dim); // elements.length | |
833 | |
834 dt_t *d = NULL; | |
835 for (size_t i = 0; i < dim; i++) | |
836 { Argument *arg = (Argument *)tu->arguments->data[i]; | |
837 Expression *e = arg->type->getTypeInfo(NULL); | |
838 e = e->optimize(WANTvalue); | |
839 e->toDt(&d); | |
840 } | |
841 | |
842 Symbol *s; | |
843 s = static_sym(); | |
844 s->Sdt = d; | |
845 outdata(s); | |
846 | |
847 dtxoff(pdt, s, 0, TYnptr); // elements.ptr | |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
848 */ |
52 | 849 } |