Mercurial > projects > ldc
annotate gen/toobj.c @ 38:27b2f40bdb58 trunk
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
Fiddled a bit the the testing system.
Added a very simple SDL graphics demo.
author | lindquist |
---|---|
date | Wed, 10 Oct 2007 06:16:48 +0200 |
parents | 2841234d2aea |
children | 8b0e809563df |
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 | |
14 #include "llvm/Type.h" | |
15 #include "llvm/Constants.h" | |
16 #include "llvm/DerivedTypes.h" | |
17 #include "llvm/Instructions.h" | |
18 #include "llvm/Analysis/Verifier.h" | |
19 #include "llvm/Bitcode/ReaderWriter.h" | |
20 | |
21 #include "llvm/Target/TargetData.h" | |
22 #include "llvm/Target/TargetMachine.h" | |
23 #include "llvm/Target/TargetMachineRegistry.h" | |
24 | |
25 #include "mars.h" | |
26 #include "module.h" | |
27 #include "mtype.h" | |
28 #include "declaration.h" | |
29 #include "statement.h" | |
30 #include "enum.h" | |
31 #include "aggregate.h" | |
32 #include "init.h" | |
33 #include "attrib.h" | |
34 #include "id.h" | |
35 #include "import.h" | |
36 #include "template.h" | |
18 | 37 #include "scope.h" |
1 | 38 |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
39 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
40 #include "gen/elem.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
41 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
42 #include "gen/tollvm.h" |
1 | 43 |
44 ////////////////////////////////////////////////////////////////////////////////////////// | |
45 | |
46 void | |
47 Module::genobjfile() | |
48 { | |
49 Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n'; | |
50 LOG_SCOPE; | |
51 | |
6 | 52 // start by deleting the old object file |
1 | 53 deleteObjFile(); |
54 | |
18 | 55 // create a new ir state |
1 | 56 IRState ir; |
57 gIR = &ir; | |
58 ir.dmodule = this; | |
59 | |
6 | 60 // name the module |
1 | 61 std::string mname(toChars()); |
62 if (md != 0) | |
63 mname = md->toChars(); | |
64 ir.module = new llvm::Module(mname); | |
65 | |
6 | 66 // set target stuff |
1 | 67 std::string target_triple(global.params.tt_arch); |
68 target_triple.append(global.params.tt_os); | |
69 ir.module->setTargetTriple(target_triple); | |
70 ir.module->setDataLayout(global.params.data_layout); | |
71 | |
72 gTargetData = new llvm::TargetData(ir.module); | |
73 | |
6 | 74 // process module members |
1 | 75 for (int k=0; k < members->dim; k++) { |
76 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
77 assert(dsym); | |
78 dsym->toObjFile(); | |
79 } | |
80 | |
81 delete gTargetData; | |
82 gTargetData = 0; | |
83 | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
84 // 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
|
85 if (ir.emitMain) { |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
86 LLVM_DtoMain(); |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
87 } |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
88 |
6 | 89 // verify the llvm |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
90 if (!global.params.novalidate) { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
91 std::string verifyErr; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
92 Logger::println("Verifying module..."); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
93 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
94 { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
95 error("%s", verifyErr.c_str()); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
96 fatal(); |
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 else { |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
99 Logger::println("Verification passed!"); |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
100 } |
1 | 101 } |
102 | |
103 // run passes | |
104 // TODO | |
105 | |
106 /*if (global.params.llvmLL) { | |
107 //assert(0); | |
108 std::ofstream os(llfile->name->toChars()); | |
109 //llvm::WriteAssemblyToFile(ir.module, os); | |
110 ir.module->print(os); | |
111 }*/ | |
112 | |
6 | 113 // write bytecode |
1 | 114 //if (global.params.llvmBC) { |
115 Logger::println("Writing LLVM bitcode\n"); | |
116 std::ofstream os(bcfile->name->toChars(), std::ios::binary); | |
117 llvm::WriteBitcodeToFile(ir.module, os); | |
118 //} | |
119 | |
120 delete ir.module; | |
121 gIR = NULL; | |
122 } | |
123 | |
124 /* ================================================================== */ | |
125 | |
126 // Put out instance of ModuleInfo for this Module | |
127 | |
128 void Module::genmoduleinfo() | |
129 { | |
130 } | |
131 | |
132 /* ================================================================== */ | |
133 | |
134 void Dsymbol::toObjFile() | |
135 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
136 Logger::println("Ignoring Dsymbol::toObjFile for %s", toChars()); |
1 | 137 } |
138 | |
139 /* ================================================================== */ | |
140 | |
141 void Declaration::toObjFile() | |
142 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
143 Logger::println("Ignoring Declaration::toObjFile for %s", toChars()); |
1 | 144 } |
145 | |
146 /* ================================================================== */ | |
147 | |
6 | 148 /// Returns the LLVM style index from a DMD style offset |
24
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
149 void AggregateDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result) |
1 | 150 { |
24
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
151 Logger::println("checking for offset %u type %s:", os, t->toChars()); |
23 | 152 LOG_SCOPE; |
1 | 153 for (unsigned i=0; i<fields.dim; ++i) { |
154 VarDeclaration* vd = (VarDeclaration*)fields.data[i]; | |
24
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
155 Logger::println("found %u type %s", vd->offset, vd->type->toChars()); |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
156 if (os == vd->offset && vd->type == t) { |
23 | 157 result.push_back(i); |
158 return; | |
159 } | |
24
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
160 else if (vd->type->ty == Tstruct && (vd->offset + vd->type->size()) > os) { |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
161 TypeStruct* ts = (TypeStruct*)vd->type; |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
162 StructDeclaration* sd = ts->sym; |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
163 result.push_back(i); |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
164 sd->offsetToIndex(t, os - vd->offset, result); |
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
165 return; |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
166 } |
1 | 167 } |
168 assert(0 && "Offset not found in any aggregate field"); | |
169 } | |
170 | |
171 /* ================================================================== */ | |
172 | |
173 static unsigned LLVM_ClassOffsetToIndex(ClassDeclaration* cd, unsigned os, unsigned& idx) | |
174 { | |
175 // start at the bottom of the inheritance chain | |
176 if (cd->baseClass != 0) { | |
177 unsigned o = LLVM_ClassOffsetToIndex(cd->baseClass, os, idx); | |
178 if (o != (unsigned)-1) | |
179 return o; | |
180 } | |
181 | |
182 // check this class | |
183 unsigned i; | |
184 for (i=0; i<cd->fields.dim; ++i) { | |
185 VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i]; | |
186 if (os == vd->offset) | |
187 return i+idx; | |
188 } | |
189 idx += i; | |
190 | |
191 return (unsigned)-1; | |
192 } | |
193 | |
6 | 194 /// Returns the LLVM style index from a DMD style offset |
195 /// Handles class inheritance | |
24
25bb577878e8
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents:
23
diff
changeset
|
196 void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result) |
1 | 197 { |
198 unsigned idx = 0; | |
199 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); | |
200 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
6
diff
changeset
|
201 result.push_back(r+1); // vtable is 0 |
1 | 202 } |
203 | |
204 /* ================================================================== */ | |
205 | |
206 void InterfaceDeclaration::toObjFile() | |
207 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
208 Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); |
1 | 209 } |
210 | |
211 /* ================================================================== */ | |
212 | |
213 void StructDeclaration::toObjFile() | |
214 { | |
215 TypeStruct* ts = (TypeStruct*)type; | |
216 if (llvmType != 0) | |
217 return; | |
218 | |
219 static int sdi = 0; | |
220 Logger::print("StructDeclaration::toObjFile(%d): %s\n", sdi++, toChars()); | |
221 LOG_SCOPE; | |
222 | |
223 gIR->structs.push_back(IRStruct(ts)); | |
224 | |
225 for (int k=0; k < members->dim; k++) { | |
226 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
227 dsym->toObjFile(); |
1 | 228 } |
229 | |
23 | 230 if (gIR->topstruct().fields.empty()) |
231 { | |
232 gIR->topstruct().fields.push_back(llvm::Type::Int8Ty); | |
233 gIR->topstruct().inits.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | |
234 } | |
235 | |
1 | 236 llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields); |
237 | |
238 // refine abstract types for stuff like: struct S{S* next;} | |
239 if (gIR->topstruct().recty != 0) | |
240 { | |
241 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
242 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
243 structtype = llvm::cast<llvm::StructType>(pa.get()); | |
244 } | |
245 | |
246 ts->llvmType = structtype; | |
247 llvmType = structtype; | |
248 | |
249 if (parent->isModule()) { | |
250 gIR->module->addTypeName(mangle(),ts->llvmType); | |
251 } | |
252 | |
253 // generate static data | |
254 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
255 llvm::Constant* _init = 0; | |
256 | |
257 // always generate the constant initalizer | |
258 if (!zeroInit) { | |
259 Logger::println("Not zero initialized"); | |
260 //assert(tk == gIR->topstruct().size()); | |
261 #ifndef LLVMD_NO_LOGGER | |
262 Logger::cout() << *structtype << '\n'; | |
263 for (size_t k=0; k<gIR->topstruct().inits.size(); ++k) { | |
264 Logger::cout() << "Type:" << '\n'; | |
265 Logger::cout() << *gIR->topstruct().inits[k]->getType() << '\n'; | |
266 Logger::cout() << "Value:" << '\n'; | |
267 Logger::cout() << *gIR->topstruct().inits[k] << '\n'; | |
268 } | |
269 Logger::cout() << "Initializer printed" << '\n'; | |
270 #endif | |
271 llvmInitZ = llvm::ConstantStruct::get(structtype,gIR->topstruct().inits); | |
272 } | |
273 else { | |
274 Logger::println("Zero initialized"); | |
275 llvmInitZ = llvm::ConstantAggregateZero::get(structtype); | |
276 } | |
277 | |
278 // only provide the constant initializer for the defining module | |
279 if (getModule() == gIR->dmodule) | |
280 { | |
281 _init = llvmInitZ; | |
282 } | |
283 | |
284 std::string initname(mangle()); | |
285 initname.append("__initZ"); | |
286 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, _init, initname, gIR->module); | |
287 ts->llvmInit = initvar; | |
288 | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
289 // generate member function definitions |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
290 gIR->topstruct().queueFuncs = false; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
291 IRState::FuncDeclVec& mfs = gIR->topstruct().funcs; |
1 | 292 size_t n = mfs.size(); |
293 for (size_t i=0; i<n; ++i) { | |
294 mfs[i]->toObjFile(); | |
295 } | |
296 | |
297 llvmDModule = gIR->dmodule; | |
298 | |
299 gIR->structs.pop_back(); | |
300 | |
301 // generate typeinfo | |
302 type->getTypeInfo(NULL); // generate TypeInfo | |
303 } | |
304 | |
305 /* ================================================================== */ | |
306 | |
307 static void LLVM_AddBaseClassData(BaseClasses* bcs) | |
308 { | |
309 // add base class data members first | |
310 for (int j=0; j<bcs->dim; j++) | |
311 { | |
312 BaseClass* bc = (BaseClass*)(bcs->data[j]); | |
313 assert(bc); | |
314 LLVM_AddBaseClassData(&bc->base->baseclasses); | |
315 for (int k=0; k < bc->base->members->dim; k++) { | |
316 Dsymbol* dsym = (Dsymbol*)(bc->base->members->data[k]); | |
317 if (dsym->isVarDeclaration()) | |
318 { | |
319 dsym->toObjFile(); | |
320 } | |
321 } | |
322 } | |
323 } | |
324 | |
325 void ClassDeclaration::toObjFile() | |
326 { | |
327 TypeClass* ts = (TypeClass*)type; | |
328 if (ts->llvmType != 0 || llvmInProgress) | |
329 return; | |
330 | |
331 llvmInProgress = true; | |
332 | |
333 static int fdi = 0; | |
334 Logger::print("ClassDeclaration::toObjFile(%d): %s\n", fdi++, toChars()); | |
335 LOG_SCOPE; | |
336 | |
6 | 337 gIR->structs.push_back(IRStruct(ts)); |
1 | 338 gIR->classes.push_back(this); |
339 | |
340 // add vtable | |
9 | 341 llvm::PATypeHolder pa = llvm::OpaqueType::get(); |
342 const llvm::Type* vtabty = llvm::PointerType::get(pa); | |
1 | 343 gIR->topstruct().fields.push_back(vtabty); |
344 gIR->topstruct().inits.push_back(0); | |
345 | |
346 // base classes first | |
347 LLVM_AddBaseClassData(&baseclasses); | |
348 | |
349 // then add own members | |
350 for (int k=0; k < members->dim; k++) { | |
351 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | |
352 dsym->toObjFile(); | |
353 } | |
354 | |
355 llvm::StructType* structtype = llvm::StructType::get(gIR->topstruct().fields); | |
6 | 356 // refine abstract types for stuff like: class C {C next;} |
357 if (gIR->topstruct().recty != 0) | |
358 { | |
359 llvm::PATypeHolder& pa = gIR->topstruct().recty; | |
360 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(structtype); | |
361 structtype = llvm::cast<llvm::StructType>(pa.get()); | |
362 } | |
363 | |
1 | 364 ts->llvmType = structtype; |
365 llvmType = structtype; | |
366 | |
367 bool define_vtable = false; | |
368 if (parent->isModule()) { | |
369 gIR->module->addTypeName(mangle(),ts->llvmType); | |
370 define_vtable = (getModule() == gIR->dmodule); | |
371 } | |
372 else { | |
373 assert(0 && "class parent is not a module"); | |
374 } | |
375 | |
9 | 376 // generate vtable |
377 llvm::GlobalVariable* svtblVar = 0; | |
378 std::vector<llvm::Constant*> sinits; | |
379 std::vector<const llvm::Type*> sinits_ty; | |
380 sinits.reserve(vtbl.dim); | |
381 sinits_ty.reserve(vtbl.dim); | |
382 | |
383 for (int k=0; k < vtbl.dim; k++) | |
384 { | |
385 Dsymbol* dsym = (Dsymbol*)vtbl.data[k]; | |
386 assert(dsym); | |
387 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; | |
388 | |
389 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
390 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
|
391 assert(fd->llvmValue); |
9 | 392 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue); |
393 sinits.push_back(c); | |
394 sinits_ty.push_back(c->getType()); | |
395 } | |
396 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
397 const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
398 llvm::Constant* c = llvm::Constant::getNullValue(cty); | |
399 sinits.push_back(c); | |
400 sinits_ty.push_back(cty); | |
401 } | |
402 else | |
403 assert(0); | |
404 } | |
405 | |
406 const llvm::StructType* svtbl_ty = 0; | |
407 if (!sinits.empty()) | |
408 { | |
409 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
410 | |
411 std::string varname(mangle()); | |
412 varname.append("__vtblZ"); | |
413 std::string styname(mangle()); | |
414 styname.append("__vtblTy"); | |
415 | |
416 svtbl_ty = llvm::StructType::get(sinits_ty); | |
417 gIR->module->addTypeName(styname, svtbl_ty); | |
418 svtblVar = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); | |
419 | |
420 if (define_vtable) { | |
421 svtblVar->setInitializer(llvm::ConstantStruct::get(svtbl_ty, sinits)); | |
422 } | |
423 llvmVtbl = svtblVar; | |
424 } | |
425 | |
426 //////////////////////////////////////////////////////////////////////////////// | |
427 | |
428 // refine for final vtable type | |
429 llvm::cast<llvm::OpaqueType>(pa.get())->refineAbstractTypeTo(svtbl_ty); | |
430 svtbl_ty = llvm::cast<llvm::StructType>(pa.get()); | |
431 structtype = llvm::cast<llvm::StructType>(gIR->topstruct().recty.get()); | |
432 ts->llvmType = structtype; | |
433 llvmType = structtype; | |
434 | |
435 // generate initializer | |
436 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::ExternalLinkage; | |
437 llvm::Constant* _init = 0; | |
438 | |
439 // first field is always the vtable | |
440 assert(svtblVar != 0); | |
441 gIR->topstruct().inits[0] = svtblVar; | |
442 | |
443 _init = llvm::ConstantStruct::get(structtype,gIR->topstruct().inits); | |
444 assert(_init); | |
445 std::string initname(mangle()); | |
446 initname.append("__initZ"); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
447 //Logger::cout() << *_init << '\n'; |
9 | 448 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType, true, _linkage, 0, initname, gIR->module); |
449 ts->llvmInit = initvar; | |
450 if (define_vtable) { | |
451 initvar->setInitializer(_init); | |
452 } | |
453 | |
454 // generate member function definitions | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
455 gIR->topstruct().queueFuncs = false; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
456 IRState::FuncDeclVec& mfs = gIR->topstruct().funcs; |
1 | 457 size_t n = mfs.size(); |
458 for (size_t i=0; i<n; ++i) { | |
459 mfs[i]->toObjFile(); | |
460 } | |
461 | |
462 gIR->classes.pop_back(); | |
463 gIR->structs.pop_back(); | |
464 | |
465 llvmInProgress = false; | |
466 } | |
467 | |
468 /****************************************** | |
469 * Get offset of base class's vtbl[] initializer from start of csym. | |
470 * Returns ~0 if not this csym. | |
471 */ | |
472 | |
473 unsigned ClassDeclaration::baseVtblOffset(BaseClass *bc) | |
474 { | |
475 return ~0; | |
476 } | |
477 | |
478 /* ================================================================== */ | |
479 | |
480 void VarDeclaration::toObjFile() | |
481 { | |
482 static int vdi = 0; | |
483 Logger::print("VarDeclaration::toObjFile(%d): %s | %s\n", vdi++, toChars(), type->toChars()); | |
484 LOG_SCOPE; | |
485 llvm::Module* M = gIR->module; | |
486 | |
487 // handle bind pragma | |
488 if (llvmInternal == LLVMbind) { | |
489 Logger::println("var is bound: %s", llvmInternal1); | |
490 llvmValue = M->getGlobalVariable(llvmInternal1); | |
491 assert(llvmValue); | |
492 return; | |
493 } | |
494 | |
495 // global variable or magic | |
22
a6360e68134a
[svn r26] * Fixed templates defining a constant value
lindquist
parents:
21
diff
changeset
|
496 if (isDataseg()) |
1 | 497 { |
498 bool _isconst = isConst(); | |
26
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
499 |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
500 llvm::GlobalValue::LinkageTypes _linkage; |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
501 if (parent->isFuncDeclaration()) |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
502 _linkage = llvm::GlobalValue::InternalLinkage; |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
503 else |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
504 _linkage = LLVM_DtoLinkage(protection, storage_class); |
99737f94abfb
[svn r30] * Fixed static function-local variables.
lindquist
parents:
24
diff
changeset
|
505 |
1 | 506 const llvm::Type* _type = LLVM_DtoType(type); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
507 assert(_type); |
1 | 508 |
509 llvm::Constant* _init = 0; | |
510 bool _signed = !type->isunsigned(); | |
511 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
512 Logger::println("Creating global variable"); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
513 std::string _name(mangle()); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
514 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
|
515 llvmValue = gvar; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
516 gIR->lvals.push_back(gvar); |
1 | 517 |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
518 _init = LLVM_DtoInitializer(type, init); |
1 | 519 assert(_init); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
520 |
1 | 521 //Logger::cout() << "initializer: " << *_init << '\n'; |
522 if (_type != _init->getType()) { | |
523 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n"; | |
524 // zero initalizer | |
525 if (_init->isNullValue()) | |
526 _init = llvm::Constant::getNullValue(_type); | |
527 // pointer to global constant (struct.init) | |
528 else if (llvm::isa<llvm::GlobalVariable>(_init)) | |
529 { | |
530 assert(_init->getType()->getContainedType(0) == _type); | |
531 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); | |
532 assert(type->ty == Tstruct); | |
533 TypeStruct* ts = (TypeStruct*)type; | |
534 assert(ts->sym->llvmInitZ); | |
535 _init = ts->sym->llvmInitZ; | |
536 } | |
537 // array single value init | |
538 else if (llvm::isa<llvm::ArrayType>(_type)) | |
539 { | |
540 const llvm::ArrayType* at = llvm::cast<llvm::ArrayType>(_type); | |
541 assert(_type->getContainedType(0) == _init->getType()); | |
542 std::vector<llvm::Constant*> initvals; | |
543 initvals.resize(at->getNumElements(), _init); | |
544 _init = llvm::ConstantArray::get(at, initvals); | |
545 } | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
546 else { |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
547 Logger::cout() << "Unexpected initializer type: " << *_type << '\n'; |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
548 //assert(0); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
549 } |
1 | 550 } |
551 | |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
552 gIR->lvals.pop_back(); |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
553 |
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
554 gvar->setInitializer(_init); |
1 | 555 |
556 //if (storage_class & STCprivate) | |
557 // gvar->setVisibility(llvm::GlobalValue::ProtectedVisibility); | |
558 } | |
559 | |
560 // inside aggregate declaration. declare a field. | |
561 else | |
562 { | |
563 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | |
564 | |
565 const llvm::Type* _type = LLVM_DtoType(type); | |
566 gIR->topstruct().fields.push_back(_type); | |
567 | |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
568 llvm::Constant*_init = LLVM_DtoInitializer(type, init); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
569 assert(_init); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
570 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
571 if (!_init || _type != _init->getType()) |
1 | 572 { |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
573 if (type->ty == Tsarray) |
1 | 574 { |
575 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(_type); | |
576 uint64_t n = arrty->getNumElements(); | |
577 std::vector<llvm::Constant*> vals(n,_init); | |
578 _init = llvm::ConstantArray::get(arrty, vals); | |
579 } | |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
580 else if (type->ty == Tarray) |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
581 { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
582 assert(llvm::isa<llvm::StructType>(_type)); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
583 _init = llvm::ConstantAggregateZero::get(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
584 } |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
585 else if (type->ty == Tstruct) |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
586 { |
6 | 587 const llvm::StructType* structty = llvm::cast<llvm::StructType>(_type); |
588 TypeStruct* ts = (TypeStruct*)type; | |
9 | 589 assert(ts); |
590 assert(ts->sym); | |
6 | 591 assert(ts->sym->llvmInitZ); |
592 _init = ts->sym->llvmInitZ; | |
593 } | |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
594 else if (type->ty == Tclass) |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
595 { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
596 _init = llvm::Constant::getNullValue(_type); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
597 } |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
598 else { |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
599 Logger::println("failed for type %s", type->toChars()); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
600 assert(0); |
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
26
diff
changeset
|
601 } |
1 | 602 } |
603 gIR->topstruct().inits.push_back(_init); | |
604 } | |
605 | |
606 Logger::println("VarDeclaration::toObjFile is done"); | |
607 } | |
608 | |
609 /* ================================================================== */ | |
610 | |
611 void TypedefDeclaration::toObjFile() | |
612 { | |
613 static int tdi = 0; | |
614 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars()); | |
615 LOG_SCOPE; | |
616 | |
617 // TODO | |
618 } | |
619 | |
620 /* ================================================================== */ | |
621 | |
622 void EnumDeclaration::toObjFile() | |
623 { | |
38
27b2f40bdb58
[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents:
31
diff
changeset
|
624 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); |
1 | 625 } |
626 | |
627 /* ================================================================== */ | |
628 | |
629 void FuncDeclaration::toObjFile() | |
630 { | |
18 | 631 if (llvmDModule) { |
9 | 632 assert(llvmValue != 0); |
1 | 633 return; |
634 } | |
635 | |
9 | 636 llvm::Function* func = LLVM_DtoDeclareFunction(this); |
637 | |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
638 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
|
639 if (!llvmQueued) { |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
640 Logger::println("queueing %s", toChars()); |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
641 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
|
642 llvmQueued = true; |
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
643 } |
10 | 644 return; // we wait with the definition as they might invoke a virtual method and the vtable is not yet complete |
1 | 645 } |
646 | |
647 TypeFunction* f = (TypeFunction*)type; | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
648 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
|
649 const llvm::FunctionType* functype = llvm::cast<llvm::FunctionType>(llvmValue->getType()->getContainedType(0)); |
1 | 650 |
651 // only members of the current module maybe be defined | |
17
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
652 if (getModule() == gIR->dmodule || parent->isTemplateInstance()) |
1 | 653 { |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
654 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
|
655 |
1 | 656 bool allow_fbody = true; |
657 // handle static constructor / destructor | |
658 if (isStaticCtorDeclaration() || isStaticDtorDeclaration()) { | |
659 const llvm::ArrayType* sctor_type = llvm::ArrayType::get(llvm::PointerType::get(functype),1); | |
660 //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
|
661 |
1 | 662 llvm::Constant* sctor_func = llvm::cast<llvm::Constant>(llvmValue); |
663 //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
|
664 |
1 | 665 llvm::Constant* sctor_init = 0; |
666 if (llvmInternal == LLVMnull) | |
667 { | |
668 llvm::Constant* sctor_init_null = llvm::Constant::getNullValue(sctor_func->getType()); | |
669 sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_init_null,1); | |
670 allow_fbody = false; | |
671 } | |
672 else | |
673 { | |
674 sctor_init = llvm::ConstantArray::get(sctor_type,&sctor_func,1); | |
675 } | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
676 |
1 | 677 //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
|
678 |
1 | 679 // output the llvm.global_ctors array |
680 const char* varname = isStaticCtorDeclaration() ? "_d_module_ctor_array" : "_d_module_dtor_array"; | |
681 llvm::GlobalVariable* sctor_arr = new llvm::GlobalVariable(sctor_type, false, llvm::GlobalValue::AppendingLinkage, sctor_init, varname, gIR->module); | |
682 } | |
683 | |
684 // function definition | |
685 if (allow_fbody && fbody != 0) | |
686 { | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
687 gIR->funcdecls.push_back(this); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
688 |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
689 // 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
|
690 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
|
691 |
31
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
692 Logger::cout() << "func type: " << *f->llvmType << '\n'; |
2841234d2aea
[svn r35] * Attributes on struct fields/methods now work
lindquist
parents:
28
diff
changeset
|
693 |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
694 // this handling |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
695 if (f->llvmUsesThis) { |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
696 if (f->llvmRetInPtr) |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
697 llvmThisVar = ++func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
698 else |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
699 llvmThisVar = func->arg_begin(); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
700 assert(llvmThisVar != 0); |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
701 } |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
702 |
9 | 703 if (isMain()) |
704 gIR->emitMain = true; | |
705 | |
1 | 706 gIR->funcs.push(func); |
707 gIR->functypes.push(f); | |
708 | |
709 IRScope irs; | |
710 irs.begin = new llvm::BasicBlock("entry",func); | |
711 irs.end = new llvm::BasicBlock("endentry",func); | |
712 | |
713 //assert(gIR->scopes.empty()); | |
714 gIR->scopes.push_back(irs); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
715 |
1 | 716 // create alloca point |
717 f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
718 |
1 | 719 // output function body |
720 fbody->toIR(gIR); | |
721 | |
722 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement | |
723 // in automatically, so we do it here. | |
724 if (!isMain() && (gIR->scopebb()->empty() || !llvm::isa<llvm::TerminatorInst>(gIR->scopebb()->back()))) { | |
725 // pass the previous block into this block | |
726 //new llvm::BranchInst(irs.end, irs.begin); | |
727 new llvm::ReturnInst(gIR->scopebb()); | |
728 } | |
11
d3ee9efe20e2
[svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents:
10
diff
changeset
|
729 |
1 | 730 // erase alloca point |
731 f->llvmAllocaPoint->eraseFromParent(); | |
732 f->llvmAllocaPoint = 0; | |
733 | |
734 gIR->scopes.pop_back(); | |
735 //assert(gIR->scopes.empty()); | |
736 | |
737 gIR->functypes.pop(); | |
738 gIR->funcs.pop(); | |
739 | |
740 // get rid of the endentry block, it's never used | |
9 | 741 assert(!func->getBasicBlockList().empty()); |
1 | 742 func->getBasicBlockList().pop_back(); |
743 | |
744 // if the last block is empty now, it must be unreachable or it's a bug somewhere else | |
9 | 745 // would be nice to figure out how to assert that this is correct |
1 | 746 llvm::BasicBlock* lastbb = &func->getBasicBlockList().back(); |
747 if (lastbb->empty()) { | |
9 | 748 // possibly assert(lastbb->getNumPredecessors() == 0); ??? try it out sometime ... |
1 | 749 new llvm::UnreachableInst(lastbb); |
750 } | |
15
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
751 |
37a4fdab33fc
[svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents:
14
diff
changeset
|
752 gIR->funcdecls.pop_back(); |
1 | 753 } |
17
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
754 |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
755 // template instances should have weak linkage |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
756 if (parent->isTemplateInstance()) { |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
757 func->setLinkage(llvm::GlobalValue::WeakLinkage); |
6c6cd097bcdf
[svn r21] * Fixed local instances of imported templates
lindquist
parents:
15
diff
changeset
|
758 } |
1 | 759 } |
760 } |