Mercurial > projects > ldc
comparison gen/toobj.cpp @ 136:0e28624814e8 trunk
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
author | lindquist |
---|---|
date | Thu, 17 Jan 2008 03:15:12 +0100 |
parents | 44a95ac7368a |
children | ce7b81fb957f |
comparison
equal
deleted
inserted
replaced
135:176bd52b3cf5 | 136:0e28624814e8 |
---|---|
39 #include "gen/classes.h" | 39 #include "gen/classes.h" |
40 #include "gen/functions.h" | 40 #include "gen/functions.h" |
41 #include "gen/todebug.h" | 41 #include "gen/todebug.h" |
42 #include "gen/runtime.h" | 42 #include "gen/runtime.h" |
43 | 43 |
44 #include "ir/irvar.h" | |
45 | |
44 ////////////////////////////////////////////////////////////////////////////////////////// | 46 ////////////////////////////////////////////////////////////////////////////////////////// |
45 | 47 |
46 // in gen/optimize.cpp | 48 // in gen/optimize.cpp |
47 void llvmdc_optimize_module(llvm::Module* m, char lvl, bool doinline); | 49 void llvmdc_optimize_module(llvm::Module* m, char lvl, bool doinline); |
48 | 50 |
167 if (gIR->ctors.empty()) | 169 if (gIR->ctors.empty()) |
168 return NULL; | 170 return NULL; |
169 | 171 |
170 size_t n = gIR->ctors.size(); | 172 size_t n = gIR->ctors.size(); |
171 if (n == 1) | 173 if (n == 1) |
172 return llvm::cast<llvm::Function>(gIR->ctors[0]->llvmValue); | 174 return gIR->ctors[0]->irFunc->func; |
173 | 175 |
174 std::string name("_D"); | 176 std::string name("_D"); |
175 name.append(gIR->dmodule->mangle()); | 177 name.append(gIR->dmodule->mangle()); |
176 name.append("6__ctorZ"); | 178 name.append("6__ctorZ"); |
177 | 179 |
182 | 184 |
183 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); | 185 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); |
184 LLVMBuilder builder(bb); | 186 LLVMBuilder builder(bb); |
185 | 187 |
186 for (size_t i=0; i<n; i++) { | 188 for (size_t i=0; i<n; i++) { |
187 llvm::Function* f = llvm::cast<llvm::Function>(gIR->ctors[i]->llvmValue); | 189 llvm::Function* f = gIR->ctors[i]->irFunc->func; |
188 llvm::CallInst* call = builder.CreateCall(f,""); | 190 llvm::CallInst* call = builder.CreateCall(f,""); |
189 call->setCallingConv(llvm::CallingConv::Fast); | 191 call->setCallingConv(llvm::CallingConv::Fast); |
190 } | 192 } |
191 | 193 |
192 builder.CreateRetVoid(); | 194 builder.CreateRetVoid(); |
200 if (gIR->dtors.empty()) | 202 if (gIR->dtors.empty()) |
201 return NULL; | 203 return NULL; |
202 | 204 |
203 size_t n = gIR->dtors.size(); | 205 size_t n = gIR->dtors.size(); |
204 if (n == 1) | 206 if (n == 1) |
205 return llvm::cast<llvm::Function>(gIR->dtors[0]->llvmValue); | 207 return gIR->dtors[0]->irFunc->func; |
206 | 208 |
207 std::string name("_D"); | 209 std::string name("_D"); |
208 name.append(gIR->dmodule->mangle()); | 210 name.append(gIR->dmodule->mangle()); |
209 name.append("6__dtorZ"); | 211 name.append("6__dtorZ"); |
210 | 212 |
215 | 217 |
216 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); | 218 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); |
217 LLVMBuilder builder(bb); | 219 LLVMBuilder builder(bb); |
218 | 220 |
219 for (size_t i=0; i<n; i++) { | 221 for (size_t i=0; i<n; i++) { |
220 llvm::Function* f = llvm::cast<llvm::Function>(gIR->dtors[i]->llvmValue); | 222 llvm::Function* f = gIR->dtors[i]->irFunc->func; |
221 llvm::CallInst* call = builder.CreateCall(f,""); | 223 llvm::CallInst* call = builder.CreateCall(f,""); |
222 call->setCallingConv(llvm::CallingConv::Fast); | 224 call->setCallingConv(llvm::CallingConv::Fast); |
223 } | 225 } |
224 | 226 |
225 builder.CreateRetVoid(); | 227 builder.CreateRetVoid(); |
233 if (gIR->unitTests.empty()) | 235 if (gIR->unitTests.empty()) |
234 return NULL; | 236 return NULL; |
235 | 237 |
236 size_t n = gIR->unitTests.size(); | 238 size_t n = gIR->unitTests.size(); |
237 if (n == 1) | 239 if (n == 1) |
238 return llvm::cast<llvm::Function>(gIR->unitTests[0]->llvmValue); | 240 return gIR->unitTests[0]->irFunc->func; |
239 | 241 |
240 std::string name("_D"); | 242 std::string name("_D"); |
241 name.append(gIR->dmodule->mangle()); | 243 name.append(gIR->dmodule->mangle()); |
242 name.append("10__unittestZ"); | 244 name.append("10__unittestZ"); |
243 | 245 |
248 | 250 |
249 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); | 251 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", fn); |
250 LLVMBuilder builder(bb); | 252 LLVMBuilder builder(bb); |
251 | 253 |
252 for (size_t i=0; i<n; i++) { | 254 for (size_t i=0; i<n; i++) { |
253 llvm::Function* f = llvm::cast<llvm::Function>(gIR->unitTests[i]->llvmValue); | 255 llvm::Function* f = gIR->unitTests[i]->irFunc->func; |
254 llvm::CallInst* call = builder.CreateCall(f,""); | 256 llvm::CallInst* call = builder.CreateCall(f,""); |
255 call->setCallingConv(llvm::CallingConv::Fast); | 257 call->setCallingConv(llvm::CallingConv::Fast); |
256 } | 258 } |
257 | 259 |
258 builder.CreateRetVoid(); | 260 builder.CreateRetVoid(); |
352 for (size_t i = 0; i < aclasses.dim; i++) | 354 for (size_t i = 0; i < aclasses.dim; i++) |
353 { | 355 { |
354 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; | 356 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; |
355 if (cd->isInterfaceDeclaration()) | 357 if (cd->isInterfaceDeclaration()) |
356 { | 358 { |
357 Logger::println("skipping interface '%s'", cd->toPrettyChars()); | 359 Logger::println("skipping interface '%s' in moduleinfo", cd->toPrettyChars()); |
358 continue; | 360 continue; |
359 } | 361 } |
360 Logger::println("class: %s", cd->toPrettyChars()); | 362 Logger::println("class: %s", cd->toPrettyChars()); |
361 assert(cd->llvmClass); | 363 assert(cd->llvmClass); |
362 classInits.push_back(cd->llvmClass); | 364 classInits.push_back(cd->llvmClass); |
505 // don't duplicate work | 507 // don't duplicate work |
506 if (llvmResolved) return; | 508 if (llvmResolved) return; |
507 llvmResolved = true; | 509 llvmResolved = true; |
508 llvmDeclared = true; | 510 llvmDeclared = true; |
509 | 511 |
510 llvmIRGlobal = new IRGlobal(this); | 512 irGlobal = new IrGlobal(this); |
511 | 513 |
512 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind()); | 514 Logger::println("parent: %s (%s)", parent->toChars(), parent->kind()); |
513 | 515 |
514 bool _isconst = isConst(); | 516 bool _isconst = isConst(); |
515 if (parent && parent->isFuncDeclaration() && init && init->isExpInitializer()) | 517 if (parent && parent->isFuncDeclaration() && init && init->isExpInitializer()) |
527 static_local = true; | 529 static_local = true; |
528 } | 530 } |
529 else | 531 else |
530 _linkage = DtoLinkage(protection, storage_class); | 532 _linkage = DtoLinkage(protection, storage_class); |
531 | 533 |
532 const llvm::Type* _type = llvmIRGlobal->type.get(); | 534 const llvm::Type* _type = irGlobal->type.get(); |
533 | 535 |
534 Logger::println("Creating global variable"); | 536 Logger::println("Creating global variable"); |
535 std::string _name(mangle()); | 537 std::string _name(mangle()); |
536 | 538 |
537 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module); | 539 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module); |
538 llvmValue = gvar; | 540 irGlobal->value = gvar; |
539 | 541 |
540 if (static_local) | 542 if (static_local) |
541 DtoConstInitGlobal(this); | 543 DtoConstInitGlobal(this); |
542 else | 544 else |
543 gIR->constInitList.push_back(this); | 545 gIR->constInitList.push_back(this); |
547 else | 549 else |
548 { | 550 { |
549 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | 551 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); |
550 | 552 |
551 const llvm::Type* _type = DtoType(type); | 553 const llvm::Type* _type = DtoType(type); |
554 irField = new IrField(this); | |
552 | 555 |
553 // add the field in the IRStruct | 556 // add the field in the IRStruct |
554 gIR->topstruct()->offsets.insert(std::make_pair(offset, IRStruct::Offset(this, _type))); | 557 gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type))); |
555 } | 558 } |
556 | 559 |
557 Logger::println("VarDeclaration::toObjFile is done"); | 560 Logger::println("VarDeclaration::toObjFile is done"); |
558 } | 561 } |
559 | 562 |