Mercurial > projects > ldc
comparison gen/main.cpp @ 1570:ab03cfb3a212
Remove dummy module hack.
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Thu, 06 Aug 2009 16:02:14 +0200 |
parents | 755abafbf25d |
children | 4551475bc6b6 |
comparison
equal
deleted
inserted
replaced
1569:755abafbf25d | 1570:ab03cfb3a212 |
---|---|
400 else if ((m32bits || m64bits) && (!mArch.empty() || !mTargetTriple.empty())) | 400 else if ((m32bits || m64bits) && (!mArch.empty() || !mTargetTriple.empty())) |
401 error("-m32 and -m64 switches cannot be used together with -march and -mtriple switches"); | 401 error("-m32 and -m64 switches cannot be used together with -march and -mtriple switches"); |
402 if (global.errors) | 402 if (global.errors) |
403 fatal(); | 403 fatal(); |
404 | 404 |
405 llvm::LLVMContext& context = llvm::getGlobalContext(); | |
406 llvm::Module mod("dummy", context); | |
407 | |
408 // override triple if needed | 405 // override triple if needed |
409 const char* defaultTriple = DEFAULT_TARGET_TRIPLE; | 406 const char* defaultTriple = DEFAULT_TARGET_TRIPLE; |
410 if ((sizeof(void*) == 4 && m64bits) || (sizeof(void*) == 8 && m32bits)) | 407 if ((sizeof(void*) == 4 && m64bits) || (sizeof(void*) == 8 && m32bits)) |
411 { | 408 { |
412 defaultTriple = DEFAULT_ALT_TARGET_TRIPLE; | 409 defaultTriple = DEFAULT_ALT_TARGET_TRIPLE; |
425 else | 422 else |
426 { | 423 { |
427 global.params.targetTriple = mTargetTriple.c_str(); | 424 global.params.targetTriple = mTargetTriple.c_str(); |
428 } | 425 } |
429 | 426 |
430 mod.setTargetTriple(global.params.targetTriple); | 427 std::string triple = global.params.targetTriple; |
431 | 428 |
432 // Allocate target machine. | 429 // Allocate target machine. |
433 | 430 |
434 // first initialize llvm | 431 // first initialize llvm |
435 #define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); | 432 #define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); |
440 const llvm::Target *theTarget = NULL; | 437 const llvm::Target *theTarget = NULL; |
441 // Check whether the user has explicitly specified an architecture to compile for. | 438 // Check whether the user has explicitly specified an architecture to compile for. |
442 if (mArch.empty()) | 439 if (mArch.empty()) |
443 { | 440 { |
444 std::string Err; | 441 std::string Err; |
445 #if LLVM_REV < 77950 | 442 theTarget = llvm::TargetRegistry::lookupTarget(triple, Err); |
446 theTarget = llvm::TargetRegistry::lookupTarget(mod.getTargetTriple(), false, false, Err); | |
447 #else | |
448 theTarget = llvm::TargetRegistry::lookupTarget(mod.getTargetTriple(), Err); | |
449 #endif | |
450 if (theTarget == 0) | 443 if (theTarget == 0) |
451 { | 444 { |
452 error("failed to auto-select target: %s, please use the -march option", Err.c_str()); | 445 error("failed to auto-select target: %s, please use the -march option", Err.c_str()); |
453 fatal(); | 446 fatal(); |
454 } | 447 } |
481 for (unsigned i = 0; i != mAttrs.size(); ++i) | 474 for (unsigned i = 0; i != mAttrs.size(); ++i) |
482 Features.AddFeature(mAttrs[i]); | 475 Features.AddFeature(mAttrs[i]); |
483 FeaturesStr = Features.getString(); | 476 FeaturesStr = Features.getString(); |
484 } | 477 } |
485 | 478 |
486 std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(mod.getTargetTriple(), FeaturesStr)); | 479 std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(triple, FeaturesStr)); |
487 assert(target.get() && "Could not allocate target machine!"); | 480 assert(target.get() && "Could not allocate target machine!"); |
488 gTargetMachine = target.get(); | 481 gTargetMachine = target.get(); |
489 gTargetData = gTargetMachine->getTargetData(); | 482 gTargetData = gTargetMachine->getTargetData(); |
490 | 483 |
491 // get final data layout | 484 // get final data layout |
557 } | 550 } |
558 | 551 |
559 // parse the OS out of the target triple | 552 // parse the OS out of the target triple |
560 // see http://gcc.gnu.org/install/specific.html for details | 553 // see http://gcc.gnu.org/install/specific.html for details |
561 // also llvm's different SubTargets have useful information | 554 // also llvm's different SubTargets have useful information |
562 std::string triple = global.params.targetTriple; | |
563 size_t npos = std::string::npos; | 555 size_t npos = std::string::npos; |
564 | 556 |
565 // windows | 557 // windows |
566 // FIXME: win64 | 558 // FIXME: win64 |
567 if (triple.find("windows") != npos || triple.find("win32") != npos || triple.find("mingw") != npos) | 559 if (triple.find("windows") != npos || triple.find("win32") != npos || triple.find("mingw") != npos) |
902 deps.write(); | 894 deps.write(); |
903 } | 895 } |
904 | 896 |
905 // collects llvm modules to be linked if singleobj is passed | 897 // collects llvm modules to be linked if singleobj is passed |
906 std::vector<llvm::Module*> llvmModules; | 898 std::vector<llvm::Module*> llvmModules; |
899 llvm::LLVMContext& context = llvm::getGlobalContext(); | |
907 | 900 |
908 // Generate output files | 901 // Generate output files |
909 for (int i = 0; i < modules.dim; i++) | 902 for (int i = 0; i < modules.dim; i++) |
910 { | 903 { |
911 m = (Module *)modules.data[i]; | 904 m = (Module *)modules.data[i]; |