Mercurial > projects > ldc
comparison gen/toobj.cpp @ 133:44a95ac7368a trunk
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
In particular, assertions has been fixed to include file/line info, and much more!
author | lindquist |
---|---|
date | Mon, 14 Jan 2008 05:11:54 +0100 |
parents | 1700239cab2e |
children | 0e28624814e8 |
comparison
equal
deleted
inserted
replaced
132:1700239cab2e | 133:44a95ac7368a |
---|---|
72 target_triple.append(global.params.tt_os); | 72 target_triple.append(global.params.tt_os); |
73 ir.module->setTargetTriple(target_triple); | 73 ir.module->setTargetTriple(target_triple); |
74 ir.module->setDataLayout(global.params.data_layout); | 74 ir.module->setDataLayout(global.params.data_layout); |
75 | 75 |
76 // heavily inspired by tools/llc/llc.cpp:200-230 | 76 // heavily inspired by tools/llc/llc.cpp:200-230 |
77 const llvm::TargetMachineRegistry::Entry* targetEntry; | 77 const llvm::TargetMachineRegistry::entry* targetEntry; |
78 std::string targetError; | 78 std::string targetError; |
79 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError); | 79 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError); |
80 assert(targetEntry && "Failed to find a static target for module"); | 80 assert(targetEntry && "Failed to find a static target for module"); |
81 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features | 81 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features |
82 assert(targetPtr.get() && "Could not allocate target machine!"); | 82 assert(targetPtr.get() && "Could not allocate target machine!"); |
116 // do this again as moduleinfo might have pulled something in! | 116 // do this again as moduleinfo might have pulled something in! |
117 DtoEmptyAllLists(); | 117 DtoEmptyAllLists(); |
118 | 118 |
119 // emit the llvm main function if necessary | 119 // emit the llvm main function if necessary |
120 if (ir.emitMain) { | 120 if (ir.emitMain) { |
121 DtoMain(); | 121 //DtoMain(); |
122 } | 122 } |
123 | 123 |
124 // verify the llvm | 124 // verify the llvm |
125 if (!global.params.novalidate) { | 125 if (!global.params.novalidate) { |
126 std::string verifyErr; | 126 std::string verifyErr; |
293 // vtable | 293 // vtable |
294 c = moduleinfo->llvmVtbl; | 294 c = moduleinfo->llvmVtbl; |
295 initVec.push_back(c); | 295 initVec.push_back(c); |
296 | 296 |
297 // monitor | 297 // monitor |
298 c = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); | 298 c = getNullPtr(getPtrToType(llvm::Type::Int8Ty)); |
299 initVec.push_back(c); | 299 initVec.push_back(c); |
300 | 300 |
301 // name | 301 // name |
302 char *name = toPrettyChars(); | 302 char *name = toPrettyChars(); |
303 c = DtoConstString(name); | 303 c = DtoConstString(name); |
319 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); | 319 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, NULL, m_name, gIR->module); |
320 importInits.push_back(m_gvar); | 320 importInits.push_back(m_gvar); |
321 } | 321 } |
322 } | 322 } |
323 // has import array? | 323 // has import array? |
324 if (!importInits.empty()) { | 324 if (!importInits.empty()) |
325 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(llvm::PointerType::get(moduleinfoTy), importInits.size()); | 325 { |
326 const llvm::ArrayType* importArrTy = llvm::ArrayType::get(getPtrToType(moduleinfoTy), importInits.size()); | |
326 c = llvm::ConstantArray::get(importArrTy, importInits); | 327 c = llvm::ConstantArray::get(importArrTy, importInits); |
327 std::string m_name("_D"); | 328 std::string m_name("_D"); |
328 m_name.append(mangle()); | 329 m_name.append(mangle()); |
329 m_name.append("9__importsZ"); | 330 m_name.append("9__importsZ"); |
330 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); | 331 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(importArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); |
331 c = llvm::ConstantExpr::getBitCast(m_gvar, llvm::PointerType::get(importArrTy->getElementType())); | 332 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importArrTy->getElementType())); |
332 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); | 333 c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); |
333 } | 334 } |
334 else | 335 else |
335 c = moduleinfo->llvmConstInit->getOperand(3); | 336 c = moduleinfo->llvmConstInit->getOperand(3); |
336 initVec.push_back(c); | 337 initVec.push_back(c); |
349 // fill inits | 350 // fill inits |
350 std::vector<llvm::Constant*> classInits; | 351 std::vector<llvm::Constant*> classInits; |
351 for (size_t i = 0; i < aclasses.dim; i++) | 352 for (size_t i = 0; i < aclasses.dim; i++) |
352 { | 353 { |
353 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; | 354 ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; |
355 if (cd->isInterfaceDeclaration()) | |
356 { | |
357 Logger::println("skipping interface '%s'", cd->toPrettyChars()); | |
358 continue; | |
359 } | |
354 Logger::println("class: %s", cd->toPrettyChars()); | 360 Logger::println("class: %s", cd->toPrettyChars()); |
355 assert(cd->llvmClass); | 361 assert(cd->llvmClass); |
356 classInits.push_back(cd->llvmClass); | 362 classInits.push_back(cd->llvmClass); |
357 } | 363 } |
358 // has class array? | 364 // has class array? |
359 if (!classInits.empty()) { | 365 if (!classInits.empty()) |
360 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(llvm::PointerType::get(classinfoTy), classInits.size()); | 366 { |
367 const llvm::ArrayType* classArrTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size()); | |
361 c = llvm::ConstantArray::get(classArrTy, classInits); | 368 c = llvm::ConstantArray::get(classArrTy, classInits); |
362 std::string m_name("_D"); | 369 std::string m_name("_D"); |
363 m_name.append(mangle()); | 370 m_name.append(mangle()); |
364 m_name.append("9__classesZ"); | 371 m_name.append("9__classesZ"); |
365 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); | 372 llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(classArrTy, true, llvm::GlobalValue::InternalLinkage, c, m_name, gIR->module); |
366 c = llvm::ConstantExpr::getBitCast(m_gvar, llvm::PointerType::get(classArrTy->getElementType())); | 373 c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(classArrTy->getElementType())); |
367 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); | 374 c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); |
368 } | 375 } |
369 else | 376 else |
370 c = moduleinfo->llvmConstInit->getOperand(4); | 377 c = moduleinfo->llvmConstInit->getOperand(4); |
371 initVec.push_back(c); | 378 initVec.push_back(c); |
418 // declare | 425 // declare |
419 // flags will be modified at runtime so can't make it constant | 426 // flags will be modified at runtime so can't make it constant |
420 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module); | 427 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(moduleinfoTy, false, llvm::GlobalValue::ExternalLinkage, constMI, MIname, gIR->module); |
421 | 428 |
422 // declare the appending array | 429 // declare the appending array |
423 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(llvm::PointerType::get(llvm::Type::Int8Ty), 1); | 430 const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(getPtrToType(llvm::Type::Int8Ty), 1); |
424 std::vector<llvm::Constant*> appendInits; | 431 std::vector<llvm::Constant*> appendInits; |
425 appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, llvm::PointerType::get(llvm::Type::Int8Ty))); | 432 appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llvm::Type::Int8Ty))); |
426 llvm::Constant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); | 433 llvm::Constant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); |
427 std::string appendName("_d_moduleinfo_array"); | 434 std::string appendName("_d_moduleinfo_array"); |
428 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); | 435 llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); |
429 } | 436 } |
430 | 437 |
444 | 451 |
445 /* ================================================================== */ | 452 /* ================================================================== */ |
446 | 453 |
447 void InterfaceDeclaration::toObjFile() | 454 void InterfaceDeclaration::toObjFile() |
448 { | 455 { |
449 Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); | 456 //Logger::println("Ignoring InterfaceDeclaration::toObjFile for %s", toChars()); |
457 gIR->resolveList.push_back(this); | |
450 } | 458 } |
451 | 459 |
452 /* ================================================================== */ | 460 /* ================================================================== */ |
453 | 461 |
454 void StructDeclaration::toObjFile() | 462 void StructDeclaration::toObjFile() |
489 | 497 |
490 // global variable or magic | 498 // global variable or magic |
491 if (isDataseg()) | 499 if (isDataseg()) |
492 { | 500 { |
493 // we don't want to touch private static members at all !!! | 501 // we don't want to touch private static members at all !!! |
494 if ((prot() & PROTprivate) && getModule() != gIR->dmodule) | 502 if ((prot() == PROTprivate) && getModule() != gIR->dmodule) |
495 return; | 503 return; |
496 | 504 |
497 // don't duplicate work | 505 // don't duplicate work |
498 if (llvmResolved) return; | 506 if (llvmResolved) return; |
499 llvmResolved = true; | 507 llvmResolved = true; |