Mercurial > projects > ldc
comparison gen/toobj.cpp @ 213:7816aafeea3c trunk
[svn r229] Updated the object.d implementation to the latest Tango.
Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array.
Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 .
Cleaned up some type code.
Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant.
Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/
author | lindquist |
---|---|
date | Fri, 30 May 2008 19:32:04 +0200 |
parents | 9d44ec83acd1 |
children | 0806379a5eca |
comparison
equal
deleted
inserted
replaced
212:4c2689d57ba4 | 213:7816aafeea3c |
---|---|
185 | 185 |
186 std::string name("_D"); | 186 std::string name("_D"); |
187 name.append(gIR->dmodule->mangle()); | 187 name.append(gIR->dmodule->mangle()); |
188 name.append("6__ctorZ"); | 188 name.append("6__ctorZ"); |
189 | 189 |
190 std::vector<const llvm::Type*> argsTy; | 190 std::vector<const LLType*> argsTy; |
191 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); | 191 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); |
192 assert(gIR->module->getFunction(name) == NULL); | 192 assert(gIR->module->getFunction(name) == NULL); |
193 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 193 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
194 fn->setCallingConv(llvm::CallingConv::Fast); | 194 fn->setCallingConv(llvm::CallingConv::Fast); |
195 | 195 |
219 | 219 |
220 std::string name("_D"); | 220 std::string name("_D"); |
221 name.append(gIR->dmodule->mangle()); | 221 name.append(gIR->dmodule->mangle()); |
222 name.append("6__dtorZ"); | 222 name.append("6__dtorZ"); |
223 | 223 |
224 std::vector<const llvm::Type*> argsTy; | 224 std::vector<const LLType*> argsTy; |
225 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); | 225 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); |
226 assert(gIR->module->getFunction(name) == NULL); | 226 assert(gIR->module->getFunction(name) == NULL); |
227 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 227 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
228 fn->setCallingConv(llvm::CallingConv::Fast); | 228 fn->setCallingConv(llvm::CallingConv::Fast); |
229 | 229 |
253 | 253 |
254 std::string name("_D"); | 254 std::string name("_D"); |
255 name.append(gIR->dmodule->mangle()); | 255 name.append(gIR->dmodule->mangle()); |
256 name.append("10__unittestZ"); | 256 name.append("10__unittestZ"); |
257 | 257 |
258 std::vector<const llvm::Type*> argsTy; | 258 std::vector<const LLType*> argsTy; |
259 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); | 259 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); |
260 assert(gIR->module->getFunction(name) == NULL); | 260 assert(gIR->module->getFunction(name) == NULL); |
261 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); | 261 llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); |
262 fn->setCallingConv(llvm::CallingConv::Fast); | 262 fn->setCallingConv(llvm::CallingConv::Fast); |
263 | 263 |
300 | 300 |
301 // classinfo llvm struct type | 301 // classinfo llvm struct type |
302 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); | 302 const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); |
303 | 303 |
304 // initializer vector | 304 // initializer vector |
305 std::vector<llvm::Constant*> initVec; | 305 std::vector<LLConstant*> initVec; |
306 llvm::Constant* c = 0; | 306 LLConstant* c = 0; |
307 | 307 |
308 // vtable | 308 // vtable |
309 c = moduleinfo->ir.irStruct->vtbl; | 309 c = moduleinfo->ir.irStruct->vtbl; |
310 initVec.push_back(c); | 310 initVec.push_back(c); |
311 | 311 |
318 c = DtoConstString(name); | 318 c = DtoConstString(name); |
319 initVec.push_back(c); | 319 initVec.push_back(c); |
320 | 320 |
321 // importedModules[] | 321 // importedModules[] |
322 int aimports_dim = aimports.dim; | 322 int aimports_dim = aimports.dim; |
323 std::vector<llvm::Constant*> importInits; | 323 std::vector<LLConstant*> importInits; |
324 for (size_t i = 0; i < aimports.dim; i++) | 324 for (size_t i = 0; i < aimports.dim; i++) |
325 { | 325 { |
326 Module *m = (Module *)aimports.data[i]; | 326 Module *m = (Module *)aimports.data[i]; |
327 if (!m->needModuleInfo()) | 327 if (!m->needModuleInfo()) |
328 aimports_dim--; | 328 aimports_dim--; |
363 member = (Dsymbol *)members->data[i]; | 363 member = (Dsymbol *)members->data[i]; |
364 //printf("\tmember '%s'\n", member->toChars()); | 364 //printf("\tmember '%s'\n", member->toChars()); |
365 member->addLocalClass(&aclasses); | 365 member->addLocalClass(&aclasses); |
366 } | 366 } |
367 // fill inits | 367 // fill inits |
368 std::vector<llvm::Constant*> classInits; | 368 std::vector<LLConstant*> classInits; |
369 for (size_t i = 0; i < aclasses.dim; i++) | 369 for (size_t i = 0; i < aclasses.dim; i++) |
370 { | 370 { |
371 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; | 371 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; |
372 if (cd->isInterfaceDeclaration()) | 372 if (cd->isInterfaceDeclaration()) |
373 { | 373 { |
431 if (initVec[i]->getType() != moduleinfoTy->getElementType(i)) | 431 if (initVec[i]->getType() != moduleinfoTy->getElementType(i)) |
432 assert(0); | 432 assert(0); |
433 }*/ | 433 }*/ |
434 | 434 |
435 // create initializer | 435 // create initializer |
436 llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); | 436 LLConstant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); |
437 | 437 |
438 // create name | 438 // create name |
439 std::string MIname("_D"); | 439 std::string MIname("_D"); |
440 MIname.append(mangle()); | 440 MIname.append(mangle()); |
441 MIname.append("8__ModuleZ"); | 441 MIname.append("8__ModuleZ"); |
447 if (!gvar) gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module); | 447 if (!gvar) gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, MIname, gIR->module); |
448 gvar->setInitializer(constMI); | 448 gvar->setInitializer(constMI); |
449 | 449 |
450 // declare the appending array | 450 // declare the appending array |
451 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(getPtrToType(llvm::Type::Int8Ty), 1); | 451 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(getPtrToType(llvm::Type::Int8Ty), 1); |
452 std::vector<llvm::Constant*> appendInits; | 452 std::vector<LLConstant*> appendInits; |
453 appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llvm::Type::Int8Ty))); | 453 appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llvm::Type::Int8Ty))); |
454 llvm::Constant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); | 454 LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); |
455 std::string appendName("_d_moduleinfo_array"); | 455 std::string appendName("_d_moduleinfo_array"); |
456 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); | 456 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); |
457 } | 457 } |
458 | 458 |
459 /* ================================================================== */ | 459 /* ================================================================== */ |
543 } | 543 } |
544 } | 544 } |
545 | 545 |
546 Logger::println("Creating global variable"); | 546 Logger::println("Creating global variable"); |
547 | 547 |
548 const llvm::Type* _type = this->ir.irGlobal->type.get(); | 548 const LLType* _type = this->ir.irGlobal->type.get(); |
549 llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this); | 549 llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this); |
550 std::string _name(mangle()); | 550 std::string _name(mangle()); |
551 | 551 |
552 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module); | 552 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module); |
553 this->ir.irGlobal->value = gvar; | 553 this->ir.irGlobal->value = gvar; |
563 // inside aggregate declaration. declare a field. | 563 // inside aggregate declaration. declare a field. |
564 else | 564 else |
565 { | 565 { |
566 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); | 566 Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); |
567 | 567 |
568 const llvm::Type* _type = DtoType(type); | 568 const LLType* _type = DtoType(type); |
569 this->ir.irField = new IrField(this); | 569 this->ir.irField = new IrField(this); |
570 | 570 |
571 // add the field in the IRStruct | 571 // add the field in the IRStruct |
572 gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type))); | 572 gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type))); |
573 } | 573 } |