Mercurial > projects > ldc
annotate gen/toobj.cpp @ 98:6789050b5ad1 trunk
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
Now uses the DMD _adEq(void[], void[], TypeInfo) runtime function for array equality comparison.
author | lindquist |
---|---|
date | Wed, 14 Nov 2007 23:39:10 +0100 |
parents | ce7ed8f59b99 |
children | 5071469303d4 |
rev | line source |
---|---|
1 | 1 |
2 // Copyright (c) 1999-2004 by Digital Mars | |
3 // All Rights Reserved | |
4 // written by Walter Bright | |
5 // www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <cstddef> | |
11 #include <iostream> | |
12 #include <fstream> | |
13 | |
40 | 14 #include "gen/llvm.h" |
1 | 15 #include "llvm/Analysis/Verifier.h" |
16 #include "llvm/Bitcode/ReaderWriter.h" | |
17 #include "llvm/Target/TargetMachine.h" | |
18 #include "llvm/Target/TargetMachineRegistry.h" | |
19 | |
20 #include "mars.h" | |
21 #include "module.h" | |
22 #include "mtype.h" | |
23 #include "declaration.h" | |
24 #include "statement.h" | |
25 #include "enum.h" | |
26 #include "aggregate.h" | |
27 #include "init.h" | |
28 #include "attrib.h" | |
29 #include "id.h" | |
30 #include "import.h" | |
31 #include "template.h" | |
18 | 32 #include "scope.h" |
1 | 33 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
34 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
35 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
36 #include "gen/tollvm.h" |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
63
diff
changeset
|
37 #include "gen/arrays.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
38 #include "gen/structs.h" |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
39 #include "gen/todebug.h" |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
40 #include "gen/runtime.h" |
1 | 41 |
42 ////////////////////////////////////////////////////////////////////////////////////////// | |
43 | |
44 void | |
45 Module::genobjfile() | |
46 { | |
47 Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n'; | |
48 LOG_SCOPE; | |
49 | |
6 | 50 // start by deleting the old object file |
1 | 51 deleteObjFile(); |
52 | |
18 | 53 // create a new ir state |
1 | 54 IRState ir; |
55 gIR = &ir; | |
56 ir.dmodule = this; | |
57 | |
6 | 58 // name the module |
1 | 59 std::string mname(toChars()); |
60 if (md != 0) | |
61 mname = md->toChars(); | |
62 ir.module = new llvm::Module(mname); | |
63 | |
6 | 64 // set target stuff |
1 | 65 std::string target_triple(global.params.tt_arch); |
66 target_triple.append(global.params.tt_os); | |
67 ir.module->setTargetTriple(target_triple); | |
68 ir.module->setDataLayout(global.params.data_layout); | |
69 | |
73 | 70 // heavily inspired by tools/llc/llc.cpp:200-230 |
71 const llvm::TargetMachineRegistry::Entry* targetEntry; | |
72 std::string targetError; | |
73 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError); | |
74 assert(targetEntry && "Failed to find a static target for module"); | |
75 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features | |
76 assert(targetPtr.get() && "Could not allocate target machine!"); | |
77 llvm::TargetMachine &targetMachine = *targetPtr.get(); | |
78 gTargetData = targetMachine.getTargetData(); | |
1 | 79 |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
80 // debug info |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
81 if (global.params.symdebug) { |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
82 RegisterDwarfSymbols(ir.module); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
83 ir.dmodule->llvmCompileUnit = DtoDwarfCompileUnit(this,true); |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
84 } |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
85 |
6 | 86 // process module members |
1 | 87 for (int k=0; k < members->dim; k++) { |
88 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
89 assert(dsym); | |
90 dsym->toObjFile(); | |
91 } | |
92 | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
93 // check if there are queued function definitions, if so process their bodies now |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
94 if (!ir.funcQueue.empty()) { |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
95 size_t n = ir.funcQueue.size(); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
96 for (size_t i=0; i<n; ++i) { |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
97 ir.funcQueue[i]->toObjFile(); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
98 } |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
99 } |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
100 |
89 | 101 // generate ModuleInfo |
102 genmoduleinfo(); | |
103 | |
1 | 104 gTargetData = 0; |
105 | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
106 // emit the llvm main function if necessary |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
107 if (ir.emitMain) { |
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:
77
diff
changeset
|
108 DtoMain(); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
109 } |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
110 |
6 | 111 // verify the llvm |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
112 if (!global.params.novalidate) { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
113 std::string verifyErr; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
114 Logger::println("Verifying module..."); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
115 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
116 { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
117 error("%s", verifyErr.c_str()); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
118 fatal(); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
119 } |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
120 else { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
121 Logger::println("Verification passed!"); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
122 } |
1 | 123 } |
124 | |
125 // run passes | |
126 // TODO | |
127 | |
52 | 128 // write bytecode |
129 { | |
130 Logger::println("Writing LLVM bitcode\n"); | |
131 std::ofstream bos(bcfile->name->toChars(), std::ios::binary); | |
132 llvm::WriteBitcodeToFile(ir.module, bos); | |
133 } | |
1 | 134 |
52 | 135 // disassemble ? |
136 if (global.params.disassemble) { | |
137 Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars()); | |
138 std::ofstream aos(llfile->name->toChars()); | |
139 ir.module->print(aos); | |
140 } | |
1 | 141 |
142 delete ir.module; | |
143 gIR = NULL; | |
144 } | |
145 | |
146 /* ================================================================== */ | |
147 | |
148 // Put out instance of ModuleInfo for this Module | |
149 | |
150 void Module::genmoduleinfo() | |
151 { | |
89 | 152 // The layout is: |
153 // { | |
154 // void **vptr; | |
155 // monitor_t monitor; | |
156 // char[] name; // class name | |
157 // ModuleInfo importedModules[]; | |
158 // ClassInfo localClasses[]; | |
159 // uint flags; // initialization state | |
160 // void *ctor; | |
161 // void *dtor; | |
162 // void *unitTest; | |
163 // } | |
164 | |
165 if (moduleinfo) { | |
166 Logger::println("moduleinfo"); | |
167 } | |
168 if (vmoduleinfo) { | |
169 Logger::println("vmoduleinfo"); | |
170 } | |
171 if (needModuleInfo()) { | |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
172 Logger::attention("module info is needed but skipped"); |
89 | 173 } |
174 | |
175 | |
176 /* | |
177 Symbol *msym = toSymbol(); | |
178 unsigned offset; | |
179 unsigned sizeof_ModuleInfo = 12 * PTRSIZE; | |
180 | |
181 ////////////////////////////////////////////// | |
182 | |
183 csym->Sclass = SCglobal; | |
184 csym->Sfl = FLdata; | |
185 | |
186 // The layout is: | |
187 // { | |
188 // void **vptr; | |
189 // monitor_t monitor; | |
190 // char[] name; // class name | |
191 // ModuleInfo importedModules[]; | |
192 // ClassInfo localClasses[]; | |
193 // uint flags; // initialization state | |
194 // void *ctor; | |
195 // void *dtor; | |
196 // void *unitTest; | |
197 // } | |
198 dt_t *dt = NULL; | |
199 | |
200 if (moduleinfo) | |
201 dtxoff(&dt, moduleinfo->toVtblSymbol(), 0, TYnptr); // vtbl for ModuleInfo | |
202 else | |
203 dtdword(&dt, 0); // BUG: should be an assert() | |
204 dtdword(&dt, 0); // monitor | |
205 | |
206 // name[] | |
207 char *name = toPrettyChars(); | |
208 size_t namelen = strlen(name); | |
209 dtdword(&dt, namelen); | |
210 dtabytes(&dt, TYnptr, 0, namelen + 1, name); | |
211 | |
212 ClassDeclarations aclasses; | |
213 int i; | |
214 | |
215 //printf("members->dim = %d\n", members->dim); | |
216 for (i = 0; i < members->dim; i++) | |
217 { | |
218 Dsymbol *member; | |
219 | |
220 member = (Dsymbol *)members->data[i]; | |
221 //printf("\tmember '%s'\n", member->toChars()); | |
222 member->addLocalClass(&aclasses); | |
223 } | |
224 | |
225 // importedModules[] | |
226 int aimports_dim = aimports.dim; | |
227 for (i = 0; i < aimports.dim; i++) | |
228 { Module *m = (Module *)aimports.data[i]; | |
229 if (!m->needModuleInfo()) | |
230 aimports_dim--; | |
231 } | |
232 dtdword(&dt, aimports_dim); | |
233 if (aimports.dim) | |
234 dtxoff(&dt, csym, sizeof_ModuleInfo, TYnptr); | |
235 else | |
236 dtdword(&dt, 0); | |
237 | |
238 // localClasses[] | |
239 dtdword(&dt, aclasses.dim); | |
240 if (aclasses.dim) | |
241 dtxoff(&dt, csym, sizeof_ModuleInfo + aimports_dim * PTRSIZE, TYnptr); | |
242 else | |
243 dtdword(&dt, 0); | |
244 | |
245 if (needmoduleinfo) | |
246 dtdword(&dt, 0); // flags (4 means MIstandalone) | |
247 else | |
248 dtdword(&dt, 4); // flags (4 means MIstandalone) | |
249 | |
250 if (sctor) | |
251 dtxoff(&dt, sctor, 0, TYnptr); | |
252 else | |
253 dtdword(&dt, 0); | |
254 | |
255 if (sdtor) | |
256 dtxoff(&dt, sdtor, 0, TYnptr); | |
257 else | |
258 dtdword(&dt, 0); | |
259 | |
260 if (stest) | |
261 dtxoff(&dt, stest, 0, TYnptr); | |
262 else | |
263 dtdword(&dt, 0); | |
264 | |
265 ////////////////////////////////////////////// | |
266 | |
267 for (i = 0; i < aimports.dim; i++) | |
268 { | |
269 Module *m; | |
270 | |
271 m = (Module *)aimports.data[i]; | |
272 if (m->needModuleInfo()) | |
273 { Symbol *s = m->toSymbol(); | |
274 s->Sflags |= SFLweak; | |
275 dtxoff(&dt, s, 0, TYnptr); | |
276 } | |
277 } | |
278 | |
279 for (i = 0; i < aclasses.dim; i++) | |
280 { | |
281 ClassDeclaration *cd; | |
282 | |
283 cd = (ClassDeclaration *)aclasses.data[i]; | |
284 dtxoff(&dt, cd->toSymbol(), 0, TYnptr); | |
285 } | |
286 | |
287 csym->Sdt = dt; | |
288 #if ELFOBJ | |
289 // Cannot be CONST because the startup code sets flag bits in it | |
290 csym->Sseg = DATA; | |
291 #endif | |
292 outdata(csym); | |
293 | |
294 ////////////////////////////////////////////// | |
295 | |
296 obj_moduleinfo(msym); | |
297 */ | |
1 | 298 } |
299 | |
300 /* ================================================================== */ | |
301 | |
302 void Dsymbol::toObjFile() | |
303 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
304 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars()); |
1 | 305 } |
306 | |
307 /* ================================================================== */ | |
308 | |
309 void Declaration::toObjFile() | |
310 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
311 Logger::println("Ignoring Declaration::toObjFile for %s", toChars()); |
1 | 312 } |
313 | |
314 /* ================================================================== */ | |
315 | |
316 void InterfaceDeclaration::toObjFile() | |
317 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
318 Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); |
1 | 319 } |
320 | |
321 /* ================================================================== */ | |
322 | |
323 void StructDeclaration::toObjFile() | |
324 { | |
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:
77
diff
changeset
|
325 TypeStruct* ts = (TypeStruct*)DtoDType(type); |
1 | 326 if (llvmType != 0) |
327 return; | |
328 | |
329 static int sdi = 0; | |
330 Logger::print("StructDeclaration::toObjFile(%d): %s\n", sdi++, toChars()); | |
331 LOG_SCOPE; | |
332 | |
333 gIR->structs.push_back(IRStruct(ts)); | |
334 | |
335 for (int k=0; k < members->dim; k++) { | |
336 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
337 dsym->toObjFile(); |
1 | 338 } |
339 | |
73 | 340 Logger::println("doing struct fields"); |
341 | |
96 | 342 const llvm::StructType* structtype = 0; |
73 | 343 std::vector<llvm::Constant*> fieldinits; |
344 | |
345 if (gIR->topstruct().offsets.empty()) | |
346 { | |
347 std::vector<const llvm::Type*> fieldtypes; | |
348 Logger::println("has no fields"); | |
349 fieldtypes.push_back(llvm::Type::Int8Ty); | |
350 fieldinits.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
351 structtype = llvm::StructType::get(fieldtypes); | |
352 } | |
353 else | |
23 | 354 { |
73 | 355 Logger::println("has fields"); |
356 std::vector<const llvm::Type*> fieldtypes; | |
357 unsigned prevsize = (unsigned)-1; | |
358 unsigned lastoffset = (unsigned)-1; | |
359 const llvm::Type* fieldtype = NULL; | |
360 llvm::Constant* fieldinit = NULL; | |
361 size_t fieldpad = 0; | |
362 int idx = 0; | |
363 for (IRStruct::OffsetMap::iterator i=gIR->topstruct().offsets.begin(); i!=gIR->topstruct().offsets.end(); ++i) { | |
364 // first iteration | |
365 if (lastoffset == (unsigned)-1) { | |
366 lastoffset = i->first; | |
367 assert(lastoffset == 0); | |
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:
77
diff
changeset
|
368 fieldtype = DtoType(i->second.var->type); |
73 | 369 fieldinit = i->second.init; |
370 prevsize = gTargetData->getTypeSize(fieldtype); | |
371 i->second.var->llvmFieldIndex = idx; | |
372 } | |
373 // colliding offset? | |
374 else if (lastoffset == i->first) { | |
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:
77
diff
changeset
|
375 const llvm::Type* t = DtoType(i->second.var->type); |
73 | 376 size_t s = gTargetData->getTypeSize(t); |
377 if (s > prevsize) { | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
378 fieldpad += s - prevsize; |
73 | 379 prevsize = s; |
380 } | |
381 llvmHasUnions = true; | |
382 i->second.var->llvmFieldIndex = idx; | |
383 } | |
384 // intersecting offset? | |
385 else if (i->first < (lastoffset + prevsize)) { | |
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:
77
diff
changeset
|
386 const llvm::Type* t = DtoType(i->second.var->type); |
73 | 387 size_t s = gTargetData->getTypeSize(t); |
388 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size | |
389 llvmHasUnions = true; | |
390 i->second.var->llvmFieldIndex = idx; | |
391 i->second.var->llvmFieldIndexOffset = (i->first - lastoffset) / s; | |
392 } | |
393 // fresh offset | |
394 else { | |
395 // commit the field | |
396 fieldtypes.push_back(fieldtype); | |
397 fieldinits.push_back(fieldinit); | |
398 if (fieldpad) { | |
399 // match up with below | |
400 std::vector<llvm::Constant*> vals(fieldpad, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
401 llvm::Constant* c = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad), vals); | |
402 fieldtypes.push_back(c->getType()); | |
403 fieldinits.push_back(c); | |
404 idx++; | |
405 } | |
406 | |
407 idx++; | |
408 | |
409 // start new | |
410 lastoffset = i->first; | |
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:
77
diff
changeset
|
411 fieldtype = DtoType(i->second.var->type); |
73 | 412 fieldinit = i->second.init; |
413 prevsize = gTargetData->getTypeSize(fieldtype); | |
414 i->second.var->llvmFieldIndex = idx; | |
415 fieldpad = 0; | |
416 } | |
417 } | |
418 fieldtypes.push_back(fieldtype); | |
419 fieldinits.push_back(fieldinit); | |
420 if (fieldpad) { | |
421 // match up with above | |
422 std::vector<llvm::Constant*> vals(fieldpad, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
423 llvm::Constant* c = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad), vals); | |
424 fieldtypes.push_back(c->getType()); | |
425 fieldinits.push_back(c); | |
426 } | |
427 | |
428 Logger::println("creating struct type"); | |
429 structtype = llvm::StructType::get(fieldtypes); | |
23 | 430 } |
431 | |
1 | 432 // refine abstract types for stuff like: struct S{S* next;} |
433 if (gIR->topstruct().recty != 0) | |
434 { | |
435 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
436 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
96 | 437 structtype = isaStruct(pa.get()); |
1 | 438 } |
439 | |
440 ts->llvmType = structtype; | |
441 llvmType = structtype; | |
442 | |
443 if (parent->isModule()) { | |
444 gIR->module->addTypeName(mangle(),ts->llvmType); | |
445 } | |
446 | |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
447 llvmUnion = new DUnion; // uses gIR->topstruct() |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
448 |
1 | 449 // generate static data |
450 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
451 llvm::Constant* _init = 0; | |
452 | |
453 // always generate the constant initalizer | |
454 if (!zeroInit) { | |
455 Logger::println("Not zero initialized"); | |
73 | 456 //assert(tk == gIR->gIR->topstruct()().size()); |
1 | 457 #ifndef LLVMD_NO_LOGGER |
73 | 458 Logger::cout() << "struct type: " << *structtype << '\n'; |
459 for (size_t k=0; k<fieldinits.size(); ++k) { | |
1 | 460 Logger::cout() << "Type:" << '\n'; |
73 | 461 Logger::cout() << *fieldinits[k]->getType() << '\n'; |
1 | 462 Logger::cout() << "Value:" << '\n'; |
73 | 463 Logger::cout() << *fieldinits[k] << '\n'; |
1 | 464 } |
465 Logger::cout() << "Initializer printed" << '\n'; | |
466 #endif | |
73 | 467 llvmInitZ = llvm::ConstantStruct::get(structtype,fieldinits); |
1 | 468 } |
469 else { | |
470 Logger::println("Zero initialized"); | |
471 llvmInitZ = llvm::ConstantAggregateZero::get(structtype); | |
472 } | |
473 | |
474 // only provide the constant initializer for the defining module | |
475 if (getModule() == gIR->dmodule) | |
476 { | |
477 _init = llvmInitZ; | |
478 } | |
479 | |
73 | 480 std::string initname("_D"); |
481 initname.append(mangle()); | |
482 initname.append("6__initZ"); | |
1 | 483 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, _init, initname, gIR->module); |
484 ts->llvmInit = initvar; | |
485 | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
486 // generate member function definitions |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
487 gIR->topstruct().queueFuncs = false; |
73 | 488 IRStruct::FuncDeclVector& mfs = gIR->topstruct().funcs; |
1 | 489 size_t n = mfs.size(); |
490 for (size_t i=0; i<n; ++i) { | |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
491 //mfs[i]->toObjFile(); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
492 gIR->funcQueue.push_back(mfs[i]); |
1 | 493 } |
494 | |
495 llvmDModule = gIR->dmodule; | |
496 | |
497 gIR->structs.pop_back(); | |
498 | |
499 // generate typeinfo | |
73 | 500 if (getModule() == gIR->dmodule && llvmInternal != LLVMnotypeinfo) |
72 | 501 type->getTypeInfo(NULL); |
1 | 502 } |
503 | |
504 /* ================================================================== */ | |
505 | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
506 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
507 { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
508 // start at the bottom of the inheritance chain |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
509 if (cd->baseClass != 0) { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
510 unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx); |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
511 if (o != (unsigned)-1) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
512 return o; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
513 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
514 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
515 // check this class |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
516 unsigned i; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
517 for (i=0; i<cd->fields.dim; ++i) { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
518 VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i]; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
519 if (os == vd->offset) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
520 return i+idx; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
521 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
522 idx += i; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
523 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
524 return (unsigned)-1; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
525 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
526 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
527 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
528 { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
529 unsigned idx = 0; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
530 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
531 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
532 result.push_back(r+1); // vtable is 0 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
533 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
534 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
535 /* ================================================================== */ |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
536 |
1 | 537 static void LLVM_AddBaseClassData(BaseClasses* bcs) |
538 { | |
539 // add base class data members first | |
540 for (int j=0; j<bcs->dim; j++) | |
541 { | |
542 BaseClass* bc = (BaseClass*)(bcs->data[j]); | |
543 assert(bc); | |
40 | 544 Logger::println("Adding base class members of %s", bc->base->toChars()); |
545 LOG_SCOPE; | |
546 | |
1 | 547 LLVM_AddBaseClassData(&bc->base->baseclasses); |
548 for (int k=0; k < bc->base->members->dim; k++) { | |
549 Dsymbol* dsym = (Dsymbol*)(bc->base->members->data[k]); | |
550 if (dsym->isVarDeclaration()) | |
551 { | |
552 dsym->toObjFile(); | |
553 } | |
554 } | |
555 } | |
556 } | |
557 | |
558 void ClassDeclaration::toObjFile() | |
559 { | |
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:
77
diff
changeset
|
560 TypeClass* ts = (TypeClass*)DtoDType(type); |
1 | 561 if (ts->llvmType != 0 || llvmInProgress) |
562 return; | |
563 | |
564 llvmInProgress = true; | |
565 | |
566 static int fdi = 0; | |
567 Logger::print("ClassDeclaration::toObjFile(%d): %s\n", fdi++, toChars()); | |
568 LOG_SCOPE; | |
569 | |
6 | 570 gIR->structs.push_back(IRStruct(ts)); |
1 | 571 gIR->classes.push_back(this); |
572 | |
573 // add vtable | |
9 | 574 llvm::PATypeHolder pa = llvm::OpaqueType::get(); |
575 const llvm::Type* vtabty = llvm::PointerType::get(pa); | |
73 | 576 |
577 std::vector<const llvm::Type*> fieldtypes; | |
578 fieldtypes.push_back(vtabty); | |
579 | |
580 std::vector<llvm::Constant*> fieldinits; | |
581 fieldinits.push_back(0); | |
1 | 582 |
583 // base classes first | |
584 LLVM_AddBaseClassData(&baseclasses); | |
585 | |
586 // then add own members | |
587 for (int k=0; k < members->dim; k++) { | |
588 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
589 dsym->toObjFile(); | |
590 } | |
591 | |
73 | 592 // fill out fieldtypes/inits |
593 for (IRStruct::OffsetMap::iterator i=gIR->topstruct().offsets.begin(); i!=gIR->topstruct().offsets.end(); ++i) { | |
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:
77
diff
changeset
|
594 fieldtypes.push_back(DtoType(i->second.var->type)); |
73 | 595 fieldinits.push_back(i->second.init); |
596 } | |
597 | |
96 | 598 const llvm::StructType* structtype = llvm::StructType::get(fieldtypes); |
6 | 599 // refine abstract types for stuff like: class C {C next;} |
600 if (gIR->topstruct().recty != 0) | |
601 { | |
602 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
603 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
96 | 604 structtype = isaStruct(pa.get()); |
6 | 605 } |
606 | |
1 | 607 ts->llvmType = structtype; |
608 llvmType = structtype; | |
609 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
610 bool needs_definition = false; |
1 | 611 if (parent->isModule()) { |
612 gIR->module->addTypeName(mangle(),ts->llvmType); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
613 needs_definition = (getModule() == gIR->dmodule); |
1 | 614 } |
615 else { | |
616 assert(0 && "class parent is not a module"); | |
617 } | |
618 | |
9 | 619 // generate vtable |
620 llvm::GlobalVariable* svtblVar = 0; | |
621 std::vector<llvm::Constant*> sinits; | |
622 std::vector<const llvm::Type*> sinits_ty; | |
623 sinits.reserve(vtbl.dim); | |
624 sinits_ty.reserve(vtbl.dim); | |
625 | |
626 for (int k=0; k < vtbl.dim; k++) | |
627 { | |
628 Dsymbol* dsym = (Dsymbol*)vtbl.data[k]; | |
629 assert(dsym); | |
630 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; | |
631 | |
632 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
633 fd->toObjFile(); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
634 assert(fd->llvmValue); |
9 | 635 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue); |
636 sinits.push_back(c); | |
637 sinits_ty.push_back(c->getType()); | |
638 } | |
639 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
640 const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
641 llvm::Constant* c = llvm::Constant::getNullValue(cty); | |
642 sinits.push_back(c); | |
643 sinits_ty.push_back(cty); | |
644 } | |
645 else | |
646 assert(0); | |
647 } | |
648 | |
649 const llvm::StructType* svtbl_ty = 0; | |
650 if (!sinits.empty()) | |
651 { | |
652 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
653 | |
52 | 654 std::string varname("_D"); |
655 varname.append(mangle()); | |
656 varname.append("6__vtblZ"); | |
657 | |
9 | 658 std::string styname(mangle()); |
659 styname.append("__vtblTy"); | |
660 | |
661 svtbl_ty = llvm::StructType::get(sinits_ty); | |
662 gIR->module->addTypeName(styname, svtbl_ty); | |
663 svtblVar = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); | |
664 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
665 llvmConstVtbl = llvm::cast<llvm::ConstantStruct>(llvm::ConstantStruct::get(svtbl_ty, sinits)); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
666 if (needs_definition) |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
667 svtblVar->setInitializer(llvmConstVtbl); |
9 | 668 llvmVtbl = svtblVar; |
669 } | |
670 | |
671 //////////////////////////////////////////////////////////////////////////////// | |
672 | |
673 // refine for final vtable type | |
674 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(svtbl_ty); | |
96 | 675 svtbl_ty = isaStruct(pa.get()); |
676 structtype = isaStruct(gIR->topstruct().recty.get()); | |
9 | 677 ts->llvmType = structtype; |
678 llvmType = structtype; | |
679 | |
680 // generate initializer | |
681 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
682 llvm::Constant* _init = 0; | |
683 | |
684 // first field is always the vtable | |
685 assert(svtblVar != 0); | |
73 | 686 fieldinits[0] = svtblVar; |
9 | 687 |
73 | 688 llvmInitZ = _init = llvm::ConstantStruct::get(structtype,fieldinits); |
9 | 689 assert(_init); |
52 | 690 |
691 std::string initname("_D"); | |
692 initname.append(mangle()); | |
693 initname.append("6__initZ"); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
694 //Logger::cout() << *_init << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
695 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, NULL, initname, gIR->module); |
9 | 696 ts->llvmInit = initvar; |
697 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
698 if (needs_definition) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
699 initvar->setInitializer(_init); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
700 // generate member functions |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
701 gIR->topstruct().queueFuncs = false; |
73 | 702 IRStruct::FuncDeclVector& mfs = gIR->topstruct().funcs; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
703 size_t n = mfs.size(); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
704 for (size_t i=0; i<n; ++i) { |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
705 //mfs[i]->toObjFile(); |
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
96
diff
changeset
|
706 gIR->funcQueue.push_back(mfs[i]); |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
707 } |
1 | 708 } |
709 | |
710 gIR->classes.pop_back(); | |
711 gIR->structs.pop_back(); | |
712 | |
713 llvmInProgress = false; | |
89 | 714 |
715 // if (ClassDeclaration::classinfo != this) | |
716 // DtoClassInfo(this); | |
1 | 717 } |
718 | |
719 /****************************************** | |
720 * Get offset of base class's vtbl[] initializer from start of csym. | |
721 * Returns ~0 if not this csym. | |
722 */ | |
723 | |
724 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc) | |
725 { | |
726 return ~0; | |
727 } | |
728 | |
729 /* ================================================================== */ | |
730 | |
731 void VarDeclaration::toObjFile() | |
732 { | |
40 | 733 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars()); |
1 | 734 LOG_SCOPE; |
735 llvm::Module* M = gIR->module; | |
736 | |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
737 if (aliassym) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
738 { |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
739 Logger::println("alias sym"); |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
740 toAlias()->toObjFile(); |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
741 return; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
742 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
743 |
1 | 744 // global variable or magic |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
745 if (isDataseg()) |
1 | 746 { |
40 | 747 if (llvmTouched) return; |
748 else llvmTouched = true; | |
749 | |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
750 bool _isconst = false; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
751 if (isConst() && (init && !init->isExpInitializer())) |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
752 _isconst = true; |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
753 |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
754 llvm::GlobalValue::LinkageTypes _linkage; |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
755 bool istempl = false; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
756 if ((storage_class & STCcomdat) || (parent && DtoIsTemplateInstance(parent))) { |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
757 _linkage = llvm::GlobalValue::WeakLinkage; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
758 istempl = true; |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
759 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
760 else if (parent && parent->isFuncDeclaration()) |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
761 _linkage = llvm::GlobalValue::InternalLinkage; |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
762 else |
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:
77
diff
changeset
|
763 _linkage = DtoLinkage(protection, storage_class); |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
764 |
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:
77
diff
changeset
|
765 Type* t = DtoDType(type); |
40 | 766 |
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:
77
diff
changeset
|
767 const llvm::Type* _type = DtoType(t); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
768 assert(_type); |
1 | 769 |
770 llvm::Constant* _init = 0; | |
771 bool _signed = !type->isunsigned(); | |
772 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
773 Logger::println("Creating global variable"); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
774 std::string _name(mangle()); |
52 | 775 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
776 bool emitRTstaticInit = false; |
40 | 777 |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
778 if (!(storage_class & STCextern) && (getModule() == gIR->dmodule || istempl)) |
52 | 779 { |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
780 if (parent && parent->isFuncDeclaration() && init && init->isExpInitializer()) { |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
781 _init = DtoConstInitializer(t, NULL); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
782 emitRTstaticInit = true; |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
783 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
784 else { |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
785 _init = DtoConstInitializer(t, init); |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
786 } |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
787 |
52 | 788 //Logger::cout() << "initializer: " << *_init << '\n'; |
789 if (_type != _init->getType()) { | |
790 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | |
791 // zero initalizer | |
792 if (_init->isNullValue()) | |
793 _init = llvm::Constant::getNullValue(_type); | |
794 // pointer to global constant (struct.init) | |
795 else if (llvm::isa<llvm::GlobalVariable>(_init)) | |
796 { | |
797 assert(_init->getType()->getContainedType(0) == _type); | |
798 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); | |
799 assert(t->ty == Tstruct); | |
800 TypeStruct* ts = (TypeStruct*)t; | |
801 assert(ts->sym->llvmInitZ); | |
802 _init = ts->sym->llvmInitZ; | |
803 } | |
804 // array single value init | |
96 | 805 else if (isaArray(_type)) |
52 | 806 { |
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:
77
diff
changeset
|
807 _init = DtoConstStaticArray(_type, _init); |
52 | 808 } |
809 else { | |
810 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; | |
811 //assert(0); | |
812 } | |
1 | 813 } |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
814 } |
52 | 815 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
816 if (_init && _init->getType() != _type) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
817 _type = _init->getType(); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
818 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,_init,_name,M); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
819 llvmValue = gvar; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
820 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
821 if (emitRTstaticInit) |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
822 DtoLazyStaticInit(istempl, gvar, init, t); |
1 | 823 |
40 | 824 llvmDModule = gIR->dmodule; |
1 | 825 |
826 //if (storage_class & STCprivate) | |
827 // gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility); | |
828 } | |
829 | |
830 // inside aggregate declaration. declare a field. | |
831 else | |
832 { | |
833 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | |
834 | |
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:
77
diff
changeset
|
835 Type* t = DtoDType(type); |
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:
77
diff
changeset
|
836 const llvm::Type* _type = DtoType(t); |
1 | 837 |
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:
77
diff
changeset
|
838 llvm::Constant*_init = DtoConstInitializer(t, init); |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
839 assert(_init); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
840 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; |
40 | 841 if (_type != _init->getType()) |
1 | 842 { |
40 | 843 if (t->ty == Tsarray) |
1 | 844 { |
96 | 845 const llvm::ArrayType* arrty = isaArray(_type); |
1 | 846 uint64_t n = arrty->getNumElements(); |
847 std::vector<llvm::Constant*> vals(n,_init); | |
848 _init = llvm::ConstantArray::get(arrty, vals); | |
849 } | |
40 | 850 else if (t->ty == Tarray) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
851 { |
96 | 852 assert(isaStruct(_type)); |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
853 _init = llvm::ConstantAggregateZero::get(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
854 } |
40 | 855 else if (t->ty == Tstruct) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
856 { |
96 | 857 const llvm::StructType* structty = isaStruct(_type); |
40 | 858 TypeStruct* ts = (TypeStruct*)t; |
9 | 859 assert(ts); |
860 assert(ts->sym); | |
6 | 861 assert(ts->sym->llvmInitZ); |
862 _init = ts->sym->llvmInitZ; | |
863 } | |
40 | 864 else if (t->ty == Tclass) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
865 { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
866 _init = llvm::Constant::getNullValue(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
867 } |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
868 else { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
869 Logger::println("failed for type %s", type->toChars()); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
870 assert(0); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
871 } |
1 | 872 } |
73 | 873 |
874 // add the field in the IRStruct | |
875 gIR->topstruct().offsets.insert(std::make_pair(offset, IRStruct::Offset(this,_init))); | |
1 | 876 } |
877 | |
878 Logger::println("VarDeclaration::toObjFile is done"); | |
879 } | |
880 | |
881 /* ================================================================== */ | |
882 | |
883 void TypedefDeclaration::toObjFile() | |
884 { | |
885 static int tdi = 0; | |
886 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars()); | |
887 LOG_SCOPE; | |
888 | |
52 | 889 // generate typeinfo |
72 | 890 type->getTypeInfo(NULL); |
1 | 891 } |
892 | |
893 /* ================================================================== */ | |
894 | |
895 void EnumDeclaration::toObjFile() | |
896 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
897 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); |
1 | 898 } |
899 | |
900 /* ================================================================== */ | |
901 | |
902 void FuncDeclaration::toObjFile() | |
903 { | |
18 | 904 if (llvmDModule) { |
9 | 905 assert(llvmValue != 0); |
1 | 906 return; |
907 } | |
908 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
909 if (llvmRunTimeHack) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
910 Logger::println("runtime hack func chars: %s", toChars()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
911 if (!llvmValue) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
912 llvmValue = LLVM_D_GetRuntimeFunction(gIR->module, toChars()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
913 return; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
914 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
915 |
63
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
916 if (isUnitTestDeclaration()) { |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
917 Logger::attention("ignoring unittest declaration: %s", toChars()); |
63
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
918 return; |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
919 } |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
920 |
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:
77
diff
changeset
|
921 Type* t = DtoDType(type); |
55
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
922 TypeFunction* f = (TypeFunction*)t; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
923 |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
924 bool declareOnly = false; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
925 if (parent) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
926 { |
55
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
927 if (TemplateInstance* tinst = parent->isTemplateInstance()) { |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
928 TemplateDeclaration* tempdecl = tinst->tempdecl; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
929 if (tempdecl->llvmInternal == LLVMva_start) |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
930 { |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
931 Logger::println("magic va_start found"); |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
932 llvmInternal = LLVMva_start; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
933 declareOnly = true; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
934 } |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
935 else if (tempdecl->llvmInternal == LLVMva_arg) |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
936 { |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
937 Logger::println("magic va_arg found"); |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
938 llvmInternal = LLVMva_arg; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
939 return; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
940 } |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
941 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
942 } |
55
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
943 |
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:
77
diff
changeset
|
944 llvm::Function* func = DtoDeclareFunction(this); |
9 | 945 |
55
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
946 if (declareOnly) |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
947 return; |
0ccfae271c45
[svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents:
54
diff
changeset
|
948 |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
949 if (!gIR->structs.empty() && gIR->topstruct().queueFuncs) { |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
950 if (!llvmQueued) { |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
951 Logger::println("queueing %s", toChars()); |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
952 gIR->topstruct().funcs.push_back(this); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
953 llvmQueued = true; |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
954 } |
10 | 955 return; // we wait with the definition as they might invoke a virtual method and the vtable is not yet complete |
1 | 956 } |
957 | |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
958 // debug info |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
959 if (global.params.symdebug) { |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
960 Module* mo = getModule(); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
961 if (!mo->llvmCompileUnit) { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
962 mo->llvmCompileUnit = DtoDwarfCompileUnit(mo,false); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
963 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
964 llvmDwarfSubProgram = DtoDwarfSubProgram(this, mo->llvmCompileUnit); |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
965 } |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
966 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
967 assert(f->llvmType); |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
968 const llvm::FunctionType* functype = llvm::cast<llvm::FunctionType>(llvmValue->getType()->getContainedType(0)); |
1 | 969 |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
970 // template instances should have weak linkage |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
971 if (parent && DtoIsTemplateInstance(parent)) { |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
972 func->setLinkage(llvm::GlobalValue::WeakLinkage); |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
973 } |
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
974 |
1 | 975 // only members of the current module maybe be defined |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
976 if (getModule() == gIR->dmodule || DtoIsTemplateInstance(parent)) |
1 | 977 { |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
978 llvmDModule = gIR->dmodule; |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
979 |
1 | 980 // handle static constructor / destructor |
981 if (isStaticCtorDeclaration() || isStaticDtorDeclaration()) { | |
982 const llvm::ArrayType* sctor_type = llvm::ArrayType::get(llvm::PointerType::get(functype),1); | |
983 //Logger::cout() << "static ctor type: " << *sctor_type << '\n'; | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
984 |
1 | 985 llvm::Constant* sctor_func = llvm::cast<llvm::Constant>(llvmValue); |
986 //Logger::cout() << "static ctor func: " << *sctor_func << '\n'; | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
987 |
74 | 988 llvm::Constant* sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_func,1); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
989 |
1 | 990 //Logger::cout() << "static ctor init: " << *sctor_init << '\n'; |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
991 |
1 | 992 // output the llvm.global_ctors array |
993 const char* varname = isStaticCtorDeclaration() ? "_d_module_ctor_array" : "_d_module_dtor_array"; | |
994 llvm::GlobalVariable* sctor_arr = new llvm::GlobalVariable(sctor_type, false, llvm::GlobalValue::AppendingLinkage, sctor_init, varname, gIR->module); | |
995 } | |
996 | |
997 // function definition | |
74 | 998 if (fbody != 0) |
1 | 999 { |
40 | 1000 gIR->functions.push_back(IRFunction(this)); |
1001 gIR->func().func = func; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1002 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1003 // first make absolutely sure the type is up to date |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1004 f->llvmType = llvmValue->getType()->getContainedType(0); |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1005 |
52 | 1006 //Logger::cout() << "func type: " << *f->llvmType << '\n'; |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
1007 |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1008 // this handling |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1009 if (f->llvmUsesThis) { |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1010 Logger::println("uses this"); |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1011 if (f->llvmRetInPtr) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1012 llvmThisVar = ++func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1013 else |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1014 llvmThisVar = func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1015 assert(llvmThisVar != 0); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1016 } |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1017 |
9 | 1018 if (isMain()) |
1019 gIR->emitMain = true; | |
1020 | |
40 | 1021 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func); |
1022 llvm::BasicBlock* endbb = new llvm::BasicBlock("endentry",func); | |
1 | 1023 |
1024 //assert(gIR->scopes.empty()); | |
40 | 1025 gIR->scopes.push_back(IRScope(beginbb, endbb)); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1026 |
1 | 1027 // create alloca point |
1028 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); | |
40 | 1029 gIR->func().allocapoint = f->llvmAllocaPoint; |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1030 |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1031 // give arguments storage |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1032 size_t n = Argument::dim(f->parameters); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1033 for (int i=0; i < n; ++i) { |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1034 Argument* arg = Argument::getNth(f->parameters, i); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1035 if (arg && arg->vardecl) { |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1036 VarDeclaration* vd = arg->vardecl; |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1037 if (!vd->llvmNeedsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)) |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1038 continue; |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1039 llvm::Value* a = vd->llvmValue; |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1040 assert(a); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1041 std::string s(a->getName()); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1042 Logger::println("giving argument '%s' storage", s.c_str()); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1043 s.append("_storage"); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1044 llvm::Value* v = new llvm::AllocaInst(a->getType(),s,f->llvmAllocaPoint); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1045 gIR->ir->CreateStore(a,v); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1046 vd->llvmValue = v; |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1047 } |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
1048 else { |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
89
diff
changeset
|
1049 Logger::attention("some unknown argument: %s", arg ? arg->toChars() : 0); |
85
f869c636a113
[svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents:
84
diff
changeset
|
1050 } |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1051 } |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1052 |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1053 // debug info |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1054 if (global.params.symdebug) DtoDwarfFuncStart(this); |
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1055 |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1056 llvm::Value* parentNested = NULL; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1057 if (FuncDeclaration* fd = toParent()->isFuncDeclaration()) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1058 parentNested = fd->llvmNested; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1059 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1060 |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1061 // construct nested variables struct |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1062 if (!llvmNestedVars.empty() || parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1063 std::vector<const llvm::Type*> nestTypes; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1064 int j = 0; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1065 if (parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1066 nestTypes.push_back(parentNested->getType()); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1067 j++; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1068 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1069 for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1070 VarDeclaration* vd = *i; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1071 vd->llvmNestedIndex = j++; |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1072 if (vd->isParameter()) { |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1073 assert(vd->llvmValue); |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1074 nestTypes.push_back(vd->llvmValue->getType()); |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1075 } |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1076 else { |
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:
77
diff
changeset
|
1077 nestTypes.push_back(DtoType(vd->type)); |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1078 } |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1079 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1080 const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1081 Logger::cout() << "nested var struct has type:" << '\n' << *nestSType; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1082 llvmNested = new llvm::AllocaInst(nestSType,"nestedvars",f->llvmAllocaPoint); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1083 if (parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1084 assert(llvmThisVar); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1085 llvm::Value* ptr = gIR->ir->CreateBitCast(llvmThisVar, parentNested->getType(), "tmp"); |
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:
77
diff
changeset
|
1086 gIR->ir->CreateStore(ptr, DtoGEPi(llvmNested, 0,0, "tmp")); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1087 } |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1088 for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) { |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1089 VarDeclaration* vd = *i; |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1090 if (vd->isParameter()) { |
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:
77
diff
changeset
|
1091 gIR->ir->CreateStore(vd->llvmValue, DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp")); |
68
c4b3f5d2cd9b
[svn r72] Calling a nested function that is not a delegate was not working.
lindquist
parents:
67
diff
changeset
|
1092 vd->llvmValue = llvmNested; |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1093 } |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
1094 } |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1095 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
1096 |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1097 // copy _argptr to a memory location |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1098 if (f->linkage == LINKd && f->varargs == 1) |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1099 { |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1100 llvm::Value* argptrmem = new llvm::AllocaInst(llvmArgPtr->getType(), "_argptrmem", gIR->topallocapoint()); |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1101 new llvm::StoreInst(llvmArgPtr, argptrmem, gIR->scopebb()); |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1102 llvmArgPtr = argptrmem; |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1103 } |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
1104 |
1 | 1105 // output function body |
1106 fbody->toIR(gIR); | |
1107 | |
1108 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement | |
1109 // in automatically, so we do it here. | |
40 | 1110 if (!isMain()) { |
52 | 1111 if (!gIR->scopereturned()) { |
40 | 1112 // pass the previous block into this block |
82
d8dd47ef3973
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents:
81
diff
changeset
|
1113 if (global.params.symdebug) DtoDwarfFuncEnd(this); |
40 | 1114 if (func->getReturnType() == llvm::Type::VoidTy) { |
1115 new llvm::ReturnInst(gIR->scopebb()); | |
1116 } | |
52 | 1117 else { |
1118 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); | |
1119 } | |
40 | 1120 } |
1 | 1121 } |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
1122 |
1 | 1123 // erase alloca point |
1124 f->llvmAllocaPoint->eraseFromParent(); | |
1125 f->llvmAllocaPoint = 0; | |
40 | 1126 gIR->func().allocapoint = 0; |
1 | 1127 |
1128 gIR->scopes.pop_back(); | |
1129 | |
1130 // get rid of the endentry block, it's never used | |
9 | 1131 assert(!func->getBasicBlockList().empty()); |
1 | 1132 func->getBasicBlockList().pop_back(); |
1133 | |
1134 // if the last block is empty now, it must be unreachable or it's a bug somewhere else | |
9 | 1135 // would be nice to figure out how to assert that this is correct |
1 | 1136 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back(); |
1137 if (lastbb->empty()) { | |
52 | 1138 if (lastbb->getNumUses() == 0) |
1139 lastbb->eraseFromParent(); | |
1140 else { | |
1141 new llvm::UnreachableInst(lastbb); | |
1142 /*if (func->getReturnType() == llvm::Type::VoidTy) { | |
1143 new llvm::ReturnInst(lastbb); | |
1144 } | |
1145 else { | |
1146 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), lastbb); | |
1147 }*/ | |
1148 } | |
1 | 1149 } |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
1150 |
40 | 1151 gIR->functions.pop_back(); |
1 | 1152 } |
1153 } | |
1154 } |