Mercurial > projects > ldc
annotate gen/toobj.c @ 81:3587401b6eeb trunk
[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.
Changed: Renamed all the LLVM_Dto... helper function to just Dto...
author | lindquist |
---|---|
date | Thu, 01 Nov 2007 17:27:18 +0100 |
parents | 714057ff2dbb |
children | d8dd47ef3973 |
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/elem.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
36 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
37 #include "gen/tollvm.h" |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
63
diff
changeset
|
38 #include "gen/arrays.h" |
1 | 39 |
40 ////////////////////////////////////////////////////////////////////////////////////////// | |
41 | |
42 void | |
43 Module::genobjfile() | |
44 { | |
45 Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n'; | |
46 LOG_SCOPE; | |
47 | |
6 | 48 // start by deleting the old object file |
1 | 49 deleteObjFile(); |
50 | |
18 | 51 // create a new ir state |
1 | 52 IRState ir; |
53 gIR = &ir; | |
54 ir.dmodule = this; | |
55 | |
6 | 56 // name the module |
1 | 57 std::string mname(toChars()); |
58 if (md != 0) | |
59 mname = md->toChars(); | |
60 ir.module = new llvm::Module(mname); | |
61 | |
6 | 62 // set target stuff |
1 | 63 std::string target_triple(global.params.tt_arch); |
64 target_triple.append(global.params.tt_os); | |
65 ir.module->setTargetTriple(target_triple); | |
66 ir.module->setDataLayout(global.params.data_layout); | |
67 | |
73 | 68 // heavily inspired by tools/llc/llc.cpp:200-230 |
69 const llvm::TargetMachineRegistry::Entry* targetEntry; | |
70 std::string targetError; | |
71 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError); | |
72 assert(targetEntry && "Failed to find a static target for module"); | |
73 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features | |
74 assert(targetPtr.get() && "Could not allocate target machine!"); | |
75 llvm::TargetMachine &targetMachine = *targetPtr.get(); | |
76 gTargetData = targetMachine.getTargetData(); | |
1 | 77 |
6 | 78 // process module members |
1 | 79 for (int k=0; k < members->dim; k++) { |
80 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
81 assert(dsym); | |
82 dsym->toObjFile(); | |
83 } | |
84 | |
85 gTargetData = 0; | |
86 | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
87 // 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
|
88 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
|
89 DtoMain(); |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
90 } |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
91 |
6 | 92 // verify the llvm |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
93 if (!global.params.novalidate) { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
94 std::string verifyErr; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
95 Logger::println("Verifying module..."); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
96 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
97 { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
98 error("%s", verifyErr.c_str()); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
99 fatal(); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
100 } |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
101 else { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
102 Logger::println("Verification passed!"); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
103 } |
1 | 104 } |
105 | |
106 // run passes | |
107 // TODO | |
108 | |
52 | 109 // write bytecode |
110 { | |
111 Logger::println("Writing LLVM bitcode\n"); | |
112 std::ofstream bos(bcfile->name->toChars(), std::ios::binary); | |
113 llvm::WriteBitcodeToFile(ir.module, bos); | |
114 } | |
1 | 115 |
52 | 116 // disassemble ? |
117 if (global.params.disassemble) { | |
118 Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars()); | |
119 std::ofstream aos(llfile->name->toChars()); | |
120 ir.module->print(aos); | |
121 } | |
1 | 122 |
123 delete ir.module; | |
124 gIR = NULL; | |
125 } | |
126 | |
127 /* ================================================================== */ | |
128 | |
129 // Put out instance of ModuleInfo for this Module | |
130 | |
131 void Module::genmoduleinfo() | |
132 { | |
133 } | |
134 | |
135 /* ================================================================== */ | |
136 | |
137 void Dsymbol::toObjFile() | |
138 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
139 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars()); |
1 | 140 } |
141 | |
142 /* ================================================================== */ | |
143 | |
144 void Declaration::toObjFile() | |
145 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
146 Logger::println("Ignoring Declaration::toObjFile for %s", toChars()); |
1 | 147 } |
148 | |
149 /* ================================================================== */ | |
150 | |
151 void InterfaceDeclaration::toObjFile() | |
152 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
153 Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); |
1 | 154 } |
155 | |
156 /* ================================================================== */ | |
157 | |
158 void StructDeclaration::toObjFile() | |
159 { | |
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
|
160 TypeStruct* ts = (TypeStruct*)DtoDType(type); |
1 | 161 if (llvmType != 0) |
162 return; | |
163 | |
164 static int sdi = 0; | |
165 Logger::print("StructDeclaration::toObjFile(%d): %s\n", sdi++, toChars()); | |
166 LOG_SCOPE; | |
167 | |
168 gIR->structs.push_back(IRStruct(ts)); | |
169 | |
170 for (int k=0; k < members->dim; k++) { | |
171 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
172 dsym->toObjFile(); |
1 | 173 } |
174 | |
73 | 175 Logger::println("doing struct fields"); |
176 | |
177 llvm::StructType* structtype = 0; | |
178 std::vector<llvm::Constant*> fieldinits; | |
179 | |
180 if (gIR->topstruct().offsets.empty()) | |
181 { | |
182 std::vector<const llvm::Type*> fieldtypes; | |
183 Logger::println("has no fields"); | |
184 fieldtypes.push_back(llvm::Type::Int8Ty); | |
185 fieldinits.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
186 structtype = llvm::StructType::get(fieldtypes); | |
187 } | |
188 else | |
23 | 189 { |
73 | 190 Logger::println("has fields"); |
191 std::vector<const llvm::Type*> fieldtypes; | |
192 unsigned prevsize = (unsigned)-1; | |
193 unsigned lastoffset = (unsigned)-1; | |
194 const llvm::Type* fieldtype = NULL; | |
195 llvm::Constant* fieldinit = NULL; | |
196 size_t fieldpad = 0; | |
197 int idx = 0; | |
198 for (IRStruct::OffsetMap::iterator i=gIR->topstruct().offsets.begin(); i!=gIR->topstruct().offsets.end(); ++i) { | |
199 // first iteration | |
200 if (lastoffset == (unsigned)-1) { | |
201 lastoffset = i->first; | |
202 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
|
203 fieldtype = DtoType(i->second.var->type); |
73 | 204 fieldinit = i->second.init; |
205 prevsize = gTargetData->getTypeSize(fieldtype); | |
206 i->second.var->llvmFieldIndex = idx; | |
207 } | |
208 // colliding offset? | |
209 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
|
210 const llvm::Type* t = DtoType(i->second.var->type); |
73 | 211 size_t s = gTargetData->getTypeSize(t); |
212 if (s > prevsize) { | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
213 fieldpad += s - prevsize; |
73 | 214 prevsize = s; |
215 } | |
216 llvmHasUnions = true; | |
217 i->second.var->llvmFieldIndex = idx; | |
218 } | |
219 // intersecting offset? | |
220 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
|
221 const llvm::Type* t = DtoType(i->second.var->type); |
73 | 222 size_t s = gTargetData->getTypeSize(t); |
223 assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size | |
224 llvmHasUnions = true; | |
225 i->second.var->llvmFieldIndex = idx; | |
226 i->second.var->llvmFieldIndexOffset = (i->first - lastoffset) / s; | |
227 } | |
228 // fresh offset | |
229 else { | |
230 // commit the field | |
231 fieldtypes.push_back(fieldtype); | |
232 fieldinits.push_back(fieldinit); | |
233 if (fieldpad) { | |
234 // match up with below | |
235 std::vector<llvm::Constant*> vals(fieldpad, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
236 llvm::Constant* c = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad), vals); | |
237 fieldtypes.push_back(c->getType()); | |
238 fieldinits.push_back(c); | |
239 idx++; | |
240 } | |
241 | |
242 idx++; | |
243 | |
244 // start new | |
245 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
|
246 fieldtype = DtoType(i->second.var->type); |
73 | 247 fieldinit = i->second.init; |
248 prevsize = gTargetData->getTypeSize(fieldtype); | |
249 i->second.var->llvmFieldIndex = idx; | |
250 fieldpad = 0; | |
251 } | |
252 } | |
253 fieldtypes.push_back(fieldtype); | |
254 fieldinits.push_back(fieldinit); | |
255 if (fieldpad) { | |
256 // match up with above | |
257 std::vector<llvm::Constant*> vals(fieldpad, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
258 llvm::Constant* c = llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad), vals); | |
259 fieldtypes.push_back(c->getType()); | |
260 fieldinits.push_back(c); | |
261 } | |
262 | |
263 Logger::println("creating struct type"); | |
264 structtype = llvm::StructType::get(fieldtypes); | |
23 | 265 } |
266 | |
1 | 267 // refine abstract types for stuff like: struct S{S* next;} |
268 if (gIR->topstruct().recty != 0) | |
269 { | |
270 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
271 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
272 structtype = llvm::cast<llvm::StructType>(pa.get()); | |
273 } | |
274 | |
275 ts->llvmType = structtype; | |
276 llvmType = structtype; | |
277 | |
278 if (parent->isModule()) { | |
279 gIR->module->addTypeName(mangle(),ts->llvmType); | |
280 } | |
281 | |
282 // generate static data | |
283 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
284 llvm::Constant* _init = 0; | |
285 | |
286 // always generate the constant initalizer | |
287 if (!zeroInit) { | |
288 Logger::println("Not zero initialized"); | |
73 | 289 //assert(tk == gIR->gIR->topstruct()().size()); |
1 | 290 #ifndef LLVMD_NO_LOGGER |
73 | 291 Logger::cout() << "struct type: " << *structtype << '\n'; |
292 for (size_t k=0; k<fieldinits.size(); ++k) { | |
1 | 293 Logger::cout() << "Type:" << '\n'; |
73 | 294 Logger::cout() << *fieldinits[k]->getType() << '\n'; |
1 | 295 Logger::cout() << "Value:" << '\n'; |
73 | 296 Logger::cout() << *fieldinits[k] << '\n'; |
1 | 297 } |
298 Logger::cout() << "Initializer printed" << '\n'; | |
299 #endif | |
73 | 300 llvmInitZ = llvm::ConstantStruct::get(structtype,fieldinits); |
1 | 301 } |
302 else { | |
303 Logger::println("Zero initialized"); | |
304 llvmInitZ = llvm::ConstantAggregateZero::get(structtype); | |
305 } | |
306 | |
307 // only provide the constant initializer for the defining module | |
308 if (getModule() == gIR->dmodule) | |
309 { | |
310 _init = llvmInitZ; | |
311 } | |
312 | |
73 | 313 std::string initname("_D"); |
314 initname.append(mangle()); | |
315 initname.append("6__initZ"); | |
1 | 316 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, _init, initname, gIR->module); |
317 ts->llvmInit = initvar; | |
318 | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
319 // generate member function definitions |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
320 gIR->topstruct().queueFuncs = false; |
73 | 321 IRStruct::FuncDeclVector& mfs = gIR->topstruct().funcs; |
1 | 322 size_t n = mfs.size(); |
323 for (size_t i=0; i<n; ++i) { | |
324 mfs[i]->toObjFile(); | |
325 } | |
326 | |
327 llvmDModule = gIR->dmodule; | |
328 | |
329 gIR->structs.pop_back(); | |
330 | |
331 // generate typeinfo | |
73 | 332 if (getModule() == gIR->dmodule && llvmInternal != LLVMnotypeinfo) |
72 | 333 type->getTypeInfo(NULL); |
1 | 334 } |
335 | |
336 /* ================================================================== */ | |
337 | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
338 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
|
339 { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
340 // 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
|
341 if (cd->baseClass != 0) { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
342 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
|
343 if (o != (unsigned)-1) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
344 return o; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
345 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
346 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
347 // check this class |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
348 unsigned i; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
349 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
|
350 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
|
351 if (os == vd->offset) |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
352 return i+idx; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
353 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
354 idx += i; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
355 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
356 return (unsigned)-1; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
357 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
358 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
359 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
|
360 { |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
361 unsigned idx = 0; |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 } |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
366 |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
367 /* ================================================================== */ |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
74
diff
changeset
|
368 |
1 | 369 static void LLVM_AddBaseClassData(BaseClasses* bcs) |
370 { | |
371 // add base class data members first | |
372 for (int j=0; j<bcs->dim; j++) | |
373 { | |
374 BaseClass* bc = (BaseClass*)(bcs->data[j]); | |
375 assert(bc); | |
40 | 376 Logger::println("Adding base class members of %s", bc->base->toChars()); |
377 LOG_SCOPE; | |
378 | |
1 | 379 LLVM_AddBaseClassData(&bc->base->baseclasses); |
380 for (int k=0; k < bc->base->members->dim; k++) { | |
381 Dsymbol* dsym = (Dsymbol*)(bc->base->members->data[k]); | |
382 if (dsym->isVarDeclaration()) | |
383 { | |
384 dsym->toObjFile(); | |
385 } | |
386 } | |
387 } | |
388 } | |
389 | |
390 void ClassDeclaration::toObjFile() | |
391 { | |
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
|
392 TypeClass* ts = (TypeClass*)DtoDType(type); |
1 | 393 if (ts->llvmType != 0 || llvmInProgress) |
394 return; | |
395 | |
396 llvmInProgress = true; | |
397 | |
398 static int fdi = 0; | |
399 Logger::print("ClassDeclaration::toObjFile(%d): %s\n", fdi++, toChars()); | |
400 LOG_SCOPE; | |
401 | |
6 | 402 gIR->structs.push_back(IRStruct(ts)); |
1 | 403 gIR->classes.push_back(this); |
404 | |
405 // add vtable | |
9 | 406 llvm::PATypeHolder pa = llvm::OpaqueType::get(); |
407 const llvm::Type* vtabty = llvm::PointerType::get(pa); | |
73 | 408 |
409 std::vector<const llvm::Type*> fieldtypes; | |
410 fieldtypes.push_back(vtabty); | |
411 | |
412 std::vector<llvm::Constant*> fieldinits; | |
413 fieldinits.push_back(0); | |
1 | 414 |
415 // base classes first | |
416 LLVM_AddBaseClassData(&baseclasses); | |
417 | |
418 // then add own members | |
419 for (int k=0; k < members->dim; k++) { | |
420 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
421 dsym->toObjFile(); | |
422 } | |
423 | |
73 | 424 // fill out fieldtypes/inits |
425 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
|
426 fieldtypes.push_back(DtoType(i->second.var->type)); |
73 | 427 fieldinits.push_back(i->second.init); |
428 } | |
429 | |
430 llvm::StructType* structtype = llvm::StructType::get(fieldtypes); | |
6 | 431 // refine abstract types for stuff like: class C {C next;} |
432 if (gIR->topstruct().recty != 0) | |
433 { | |
434 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
435 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
436 structtype = llvm::cast<llvm::StructType>(pa.get()); | |
437 } | |
438 | |
1 | 439 ts->llvmType = structtype; |
440 llvmType = structtype; | |
441 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
442 bool needs_definition = false; |
1 | 443 if (parent->isModule()) { |
444 gIR->module->addTypeName(mangle(),ts->llvmType); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
445 needs_definition = (getModule() == gIR->dmodule); |
1 | 446 } |
447 else { | |
448 assert(0 && "class parent is not a module"); | |
449 } | |
450 | |
9 | 451 // generate vtable |
452 llvm::GlobalVariable* svtblVar = 0; | |
453 std::vector<llvm::Constant*> sinits; | |
454 std::vector<const llvm::Type*> sinits_ty; | |
455 sinits.reserve(vtbl.dim); | |
456 sinits_ty.reserve(vtbl.dim); | |
457 | |
458 for (int k=0; k < vtbl.dim; k++) | |
459 { | |
460 Dsymbol* dsym = (Dsymbol*)vtbl.data[k]; | |
461 assert(dsym); | |
462 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; | |
463 | |
464 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
465 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
|
466 assert(fd->llvmValue); |
9 | 467 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue); |
468 sinits.push_back(c); | |
469 sinits_ty.push_back(c->getType()); | |
470 } | |
471 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
472 const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
473 llvm::Constant* c = llvm::Constant::getNullValue(cty); | |
474 sinits.push_back(c); | |
475 sinits_ty.push_back(cty); | |
476 } | |
477 else | |
478 assert(0); | |
479 } | |
480 | |
481 const llvm::StructType* svtbl_ty = 0; | |
482 if (!sinits.empty()) | |
483 { | |
484 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
485 | |
52 | 486 std::string varname("_D"); |
487 varname.append(mangle()); | |
488 varname.append("6__vtblZ"); | |
489 | |
9 | 490 std::string styname(mangle()); |
491 styname.append("__vtblTy"); | |
492 | |
493 svtbl_ty = llvm::StructType::get(sinits_ty); | |
494 gIR->module->addTypeName(styname, svtbl_ty); | |
495 svtblVar = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); | |
496 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
497 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
|
498 if (needs_definition) |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
499 svtblVar->setInitializer(llvmConstVtbl); |
9 | 500 llvmVtbl = svtblVar; |
501 } | |
502 | |
503 //////////////////////////////////////////////////////////////////////////////// | |
504 | |
505 // refine for final vtable type | |
506 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(svtbl_ty); | |
507 svtbl_ty = llvm::cast<llvm::StructType>(pa.get()); | |
508 structtype = llvm::cast<llvm::StructType>(gIR->topstruct().recty.get()); | |
509 ts->llvmType = structtype; | |
510 llvmType = structtype; | |
511 | |
512 // generate initializer | |
513 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
514 llvm::Constant* _init = 0; | |
515 | |
516 // first field is always the vtable | |
517 assert(svtblVar != 0); | |
73 | 518 fieldinits[0] = svtblVar; |
9 | 519 |
73 | 520 llvmInitZ = _init = llvm::ConstantStruct::get(structtype,fieldinits); |
9 | 521 assert(_init); |
52 | 522 |
523 std::string initname("_D"); | |
524 initname.append(mangle()); | |
525 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
|
526 //Logger::cout() << *_init << '\n'; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
527 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, NULL, initname, gIR->module); |
9 | 528 ts->llvmInit = initvar; |
529 | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
530 if (needs_definition) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
531 initvar->setInitializer(_init); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
532 // generate member functions |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
533 gIR->topstruct().queueFuncs = false; |
73 | 534 IRStruct::FuncDeclVector& mfs = gIR->topstruct().funcs; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
535 size_t n = mfs.size(); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
536 for (size_t i=0; i<n; ++i) { |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
537 mfs[i]->toObjFile(); |
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
52
diff
changeset
|
538 } |
1 | 539 } |
540 | |
541 gIR->classes.pop_back(); | |
542 gIR->structs.pop_back(); | |
543 | |
544 llvmInProgress = false; | |
545 } | |
546 | |
547 /****************************************** | |
548 * Get offset of base class's vtbl[] initializer from start of csym. | |
549 * Returns ~0 if not this csym. | |
550 */ | |
551 | |
552 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc) | |
553 { | |
554 return ~0; | |
555 } | |
556 | |
557 /* ================================================================== */ | |
558 | |
559 void VarDeclaration::toObjFile() | |
560 { | |
40 | 561 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars()); |
1 | 562 LOG_SCOPE; |
563 llvm::Module* M = gIR->module; | |
564 | |
565 // global variable or magic | |
40 | 566 if (isDataseg() || parent->isModule()) |
1 | 567 { |
40 | 568 if (llvmTouched) return; |
569 else llvmTouched = true; | |
570 | |
1 | 571 bool _isconst = isConst(); |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
572 |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
573 llvm::GlobalValue::LinkageTypes _linkage; |
52 | 574 if (parent && parent->isFuncDeclaration()) |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
575 _linkage = llvm::GlobalValue::InternalLinkage; |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
576 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
|
577 _linkage = DtoLinkage(protection, storage_class); |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
578 |
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
|
579 Type* t = DtoDType(type); |
40 | 580 |
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
|
581 const llvm::Type* _type = DtoType(t); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
582 assert(_type); |
1 | 583 |
584 llvm::Constant* _init = 0; | |
585 bool _signed = !type->isunsigned(); | |
586 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
587 Logger::println("Creating global variable"); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
588 std::string _name(mangle()); |
52 | 589 |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
590 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,0,_name,M); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
591 llvmValue = gvar; |
40 | 592 |
52 | 593 // if extern don't emit initializer |
594 if (!(storage_class & STCextern)) | |
595 { | |
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
|
596 _init = DtoConstInitializer(t, init); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
597 |
52 | 598 //Logger::cout() << "initializer: " << *_init << '\n'; |
599 if (_type != _init->getType()) { | |
600 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | |
601 // zero initalizer | |
602 if (_init->isNullValue()) | |
603 _init = llvm::Constant::getNullValue(_type); | |
604 // pointer to global constant (struct.init) | |
605 else if (llvm::isa<llvm::GlobalVariable>(_init)) | |
606 { | |
607 assert(_init->getType()->getContainedType(0) == _type); | |
608 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); | |
609 assert(t->ty == Tstruct); | |
610 TypeStruct* ts = (TypeStruct*)t; | |
611 assert(ts->sym->llvmInitZ); | |
612 _init = ts->sym->llvmInitZ; | |
613 } | |
614 // array single value init | |
615 else if (llvm::isa<llvm::ArrayType>(_type)) | |
616 { | |
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
|
617 _init = DtoConstStaticArray(_type, _init); |
52 | 618 } |
619 else { | |
620 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; | |
621 //assert(0); | |
622 } | |
1 | 623 } |
52 | 624 |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
63
diff
changeset
|
625 Logger::cout() << "final init = " << *_init << '\n'; |
52 | 626 gvar->setInitializer(_init); |
1 | 627 } |
628 | |
40 | 629 llvmDModule = gIR->dmodule; |
1 | 630 |
631 //if (storage_class & STCprivate) | |
632 // gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility); | |
633 } | |
634 | |
635 // inside aggregate declaration. declare a field. | |
636 else | |
637 { | |
638 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | |
639 | |
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
|
640 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
|
641 const llvm::Type* _type = DtoType(t); |
1 | 642 |
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
|
643 llvm::Constant*_init = DtoConstInitializer(t, init); |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
644 assert(_init); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
645 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; |
40 | 646 if (_type != _init->getType()) |
1 | 647 { |
40 | 648 if (t->ty == Tsarray) |
1 | 649 { |
650 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type); | |
651 uint64_t n = arrty->getNumElements(); | |
652 std::vector<llvm::Constant*> vals(n,_init); | |
653 _init = llvm::ConstantArray::get(arrty, vals); | |
654 } | |
40 | 655 else if (t->ty == Tarray) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
656 { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
657 assert(llvm::isa<llvm::StructType>(_type)); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
658 _init = llvm::ConstantAggregateZero::get(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
659 } |
40 | 660 else if (t->ty == Tstruct) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
661 { |
6 | 662 const llvm::StructType* structty = llvm::cast<llvm::StructType>(_type); |
40 | 663 TypeStruct* ts = (TypeStruct*)t; |
9 | 664 assert(ts); |
665 assert(ts->sym); | |
6 | 666 assert(ts->sym->llvmInitZ); |
667 _init = ts->sym->llvmInitZ; | |
668 } | |
40 | 669 else if (t->ty == Tclass) |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
670 { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
671 _init = llvm::Constant::getNullValue(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
672 } |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
673 else { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
674 Logger::println("failed for type %s", type->toChars()); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
675 assert(0); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
676 } |
1 | 677 } |
73 | 678 |
679 // add the field in the IRStruct | |
680 gIR->topstruct().offsets.insert(std::make_pair(offset, IRStruct::Offset(this,_init))); | |
1 | 681 } |
682 | |
683 Logger::println("VarDeclaration::toObjFile is done"); | |
684 } | |
685 | |
686 /* ================================================================== */ | |
687 | |
688 void TypedefDeclaration::toObjFile() | |
689 { | |
690 static int tdi = 0; | |
691 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars()); | |
692 LOG_SCOPE; | |
693 | |
52 | 694 // generate typeinfo |
72 | 695 type->getTypeInfo(NULL); |
1 | 696 } |
697 | |
698 /* ================================================================== */ | |
699 | |
700 void EnumDeclaration::toObjFile() | |
701 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
702 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); |
1 | 703 } |
704 | |
705 /* ================================================================== */ | |
706 | |
707 void FuncDeclaration::toObjFile() | |
708 { | |
18 | 709 if (llvmDModule) { |
9 | 710 assert(llvmValue != 0); |
1 | 711 return; |
712 } | |
713 | |
63
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
714 if (isUnitTestDeclaration()) { |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
715 Logger::println("*** ATTENTION: ignoring unittest declaration: %s", toChars()); |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
716 return; |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
717 } |
2c39b5292cf3
[svn r67] Fixed ignore unittests instead of failing to compile
lindquist
parents:
58
diff
changeset
|
718 |
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
|
719 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
|
720 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
|
721 |
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
|
722 bool declareOnly = false; |
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
|
723 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
|
724 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
|
725 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
|
726 { |
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
|
727 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
|
728 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
|
729 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
|
730 } |
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
|
731 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
|
732 { |
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
|
733 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
|
734 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
|
735 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
|
736 } |
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
|
737 } |
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
|
738 |
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
|
739 llvm::Function* func = DtoDeclareFunction(this); |
9 | 740 |
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
|
741 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
|
742 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
|
743 |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
744 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
|
745 if (!llvmQueued) { |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
746 Logger::println("queueing %s", toChars()); |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
747 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
|
748 llvmQueued = true; |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
749 } |
10 | 750 return; // we wait with the definition as they might invoke a virtual method and the vtable is not yet complete |
1 | 751 } |
752 | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
753 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
|
754 const llvm::FunctionType* functype = llvm::cast<llvm::FunctionType>(llvmValue->getType()->getContainedType(0)); |
1 | 755 |
756 // only members of the current module maybe be defined | |
17
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
757 if (getModule() == gIR->dmodule || parent->isTemplateInstance()) |
1 | 758 { |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
759 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
|
760 |
1 | 761 // handle static constructor / destructor |
762 if (isStaticCtorDeclaration() || isStaticDtorDeclaration()) { | |
763 const llvm::ArrayType* sctor_type = llvm::ArrayType::get(llvm::PointerType::get(functype),1); | |
764 //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
|
765 |
1 | 766 llvm::Constant* sctor_func = llvm::cast<llvm::Constant>(llvmValue); |
767 //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
|
768 |
74 | 769 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
|
770 |
1 | 771 //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
|
772 |
1 | 773 // output the llvm.global_ctors array |
774 const char* varname = isStaticCtorDeclaration() ? "_d_module_ctor_array" : "_d_module_dtor_array"; | |
775 llvm::GlobalVariable* sctor_arr = new llvm::GlobalVariable(sctor_type, false, llvm::GlobalValue::AppendingLinkage, sctor_init, varname, gIR->module); | |
776 } | |
777 | |
778 // function definition | |
74 | 779 if (fbody != 0) |
1 | 780 { |
40 | 781 gIR->functions.push_back(IRFunction(this)); |
782 gIR->func().func = func; | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
783 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
784 // 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
|
785 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
|
786 |
52 | 787 //Logger::cout() << "func type: " << *f->llvmType << '\n'; |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
788 |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
789 // this handling |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
790 if (f->llvmUsesThis) { |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
791 Logger::println("uses this"); |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
792 if (f->llvmRetInPtr) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
793 llvmThisVar = ++func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
794 else |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
795 llvmThisVar = func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
796 assert(llvmThisVar != 0); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
797 } |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
798 |
9 | 799 if (isMain()) |
800 gIR->emitMain = true; | |
801 | |
40 | 802 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func); |
803 llvm::BasicBlock* endbb = new llvm::BasicBlock("endentry",func); | |
1 | 804 |
805 //assert(gIR->scopes.empty()); | |
40 | 806 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
|
807 |
1 | 808 // create alloca point |
809 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); | |
40 | 810 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
|
811 |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
812 llvm::Value* parentNested = NULL; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
813 if (FuncDeclaration* fd = toParent()->isFuncDeclaration()) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
814 parentNested = fd->llvmNested; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
815 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
816 |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
817 // construct nested variables struct |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
818 if (!llvmNestedVars.empty() || parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
819 std::vector<const llvm::Type*> nestTypes; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
820 int j = 0; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
821 if (parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
822 nestTypes.push_back(parentNested->getType()); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
823 j++; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
824 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
825 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
|
826 VarDeclaration* vd = *i; |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
827 vd->llvmNestedIndex = j++; |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
828 if (vd->isParameter()) { |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
829 assert(vd->llvmValue); |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
830 nestTypes.push_back(vd->llvmValue->getType()); |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
831 } |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
832 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
|
833 nestTypes.push_back(DtoType(vd->type)); |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
834 } |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
835 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
836 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
|
837 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
|
838 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
|
839 if (parentNested) { |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
840 assert(llvmThisVar); |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
841 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
|
842 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
|
843 } |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
844 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
|
845 VarDeclaration* vd = *i; |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
846 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
|
847 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
|
848 vd->llvmValue = llvmNested; |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
849 } |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
64
diff
changeset
|
850 } |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
851 } |
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
40
diff
changeset
|
852 |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
853 // copy _argptr to a memory location |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
854 if (f->linkage == LINKd && f->varargs == 1) |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
855 { |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
856 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
|
857 new llvm::StoreInst(llvmArgPtr, argptrmem, gIR->scopebb()); |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
858 llvmArgPtr = argptrmem; |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
859 } |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
860 |
1 | 861 // output function body |
862 fbody->toIR(gIR); | |
863 | |
864 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement | |
865 // in automatically, so we do it here. | |
40 | 866 if (!isMain()) { |
52 | 867 if (!gIR->scopereturned()) { |
40 | 868 // pass the previous block into this block |
869 //new llvm::BranchInst(irs.end, irs.begin); | |
870 if (func->getReturnType() == llvm::Type::VoidTy) { | |
871 new llvm::ReturnInst(gIR->scopebb()); | |
872 } | |
52 | 873 else { |
874 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); | |
875 } | |
40 | 876 } |
1 | 877 } |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
878 |
1 | 879 // erase alloca point |
880 f->llvmAllocaPoint->eraseFromParent(); | |
881 f->llvmAllocaPoint = 0; | |
40 | 882 gIR->func().allocapoint = 0; |
1 | 883 |
884 gIR->scopes.pop_back(); | |
885 | |
886 // get rid of the endentry block, it's never used | |
9 | 887 assert(!func->getBasicBlockList().empty()); |
1 | 888 func->getBasicBlockList().pop_back(); |
889 | |
890 // if the last block is empty now, it must be unreachable or it's a bug somewhere else | |
9 | 891 // would be nice to figure out how to assert that this is correct |
1 | 892 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back(); |
893 if (lastbb->empty()) { | |
52 | 894 if (lastbb->getNumUses() == 0) |
895 lastbb->eraseFromParent(); | |
896 else { | |
897 new llvm::UnreachableInst(lastbb); | |
898 /*if (func->getReturnType() == llvm::Type::VoidTy) { | |
899 new llvm::ReturnInst(lastbb); | |
900 } | |
901 else { | |
902 new llvm::ReturnInst(llvm::UndefValue::get(func->getReturnType()), lastbb); | |
903 }*/ | |
904 } | |
1 | 905 } |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
906 |
40 | 907 gIR->functions.pop_back(); |
1 | 908 } |
17
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
909 |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
910 // template instances should have weak linkage |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
911 if (parent->isTemplateInstance()) { |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
912 func->setLinkage(llvm::GlobalValue::WeakLinkage); |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
913 } |
1 | 914 } |
915 } |