Mercurial > projects > ldc
comparison gen/main.cpp @ 1543:21d691518d82
Use TargetRegistry instead of TargetMachineRegistry for Target lookups
This fixes the build for LLVM >= r75774 and will probably break older
LLVM revs.
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Wed, 15 Jul 2009 23:01:51 +0200 |
parents | 61f12f4651b5 |
children | 8863cf7236e6 |
comparison
equal
deleted
inserted
replaced
1542:ba2a5d2fe748 | 1543:21d691518d82 |
---|---|
430 mod.setTargetTriple(global.params.targetTriple); | 430 mod.setTargetTriple(global.params.targetTriple); |
431 | 431 |
432 // Allocate target machine. | 432 // Allocate target machine. |
433 | 433 |
434 // first initialize llvm | 434 // first initialize llvm |
435 #define LLVM_TARGET(A) LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); | 435 #define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter(); |
436 // this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ... | 436 // this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ... |
437 LDC_TARGETS | 437 LDC_TARGETS |
438 #undef LLVM_TARGET | 438 #undef LLVM_TARGET |
439 | 439 |
440 const llvm::Target *theTarget; | |
440 // Check whether the user has explicitly specified an architecture to compile for. | 441 // Check whether the user has explicitly specified an architecture to compile for. |
441 if (mArch == 0) | 442 if (mArch == 0) |
442 { | 443 { |
443 std::string Err; | 444 std::string Err; |
444 mArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err); | 445 theTarget = llvm::TargetRegistry::getClosestStaticTargetForModule(mod, Err); |
445 if (mArch == 0) | 446 if (theTarget == 0) |
446 { | 447 { |
447 error("failed to auto-select target: %s, please use the -march option", Err.c_str()); | 448 error("failed to auto-select target: %s, please use the -march option", Err.c_str()); |
448 fatal(); | 449 fatal(); |
449 } | 450 } |
451 } | |
452 else | |
453 { | |
454 theTarget = &mArch->TheTarget; | |
450 } | 455 } |
451 | 456 |
452 // Package up features to be passed to target/subtarget | 457 // Package up features to be passed to target/subtarget |
453 std::string FeaturesStr; | 458 std::string FeaturesStr; |
454 if (mCPU.size() || mAttrs.size()) | 459 if (mCPU.size() || mAttrs.size()) |
458 for (unsigned i = 0; i != mAttrs.size(); ++i) | 463 for (unsigned i = 0; i != mAttrs.size(); ++i) |
459 Features.AddFeature(mAttrs[i]); | 464 Features.AddFeature(mAttrs[i]); |
460 FeaturesStr = Features.getString(); | 465 FeaturesStr = Features.getString(); |
461 } | 466 } |
462 | 467 |
463 std::auto_ptr<llvm::TargetMachine> target(mArch->CtorFn(mod, FeaturesStr)); | 468 std::auto_ptr<llvm::TargetMachine> target(theTarget->createTargetMachine(mod, FeaturesStr)); |
464 assert(target.get() && "Could not allocate target machine!"); | 469 assert(target.get() && "Could not allocate target machine!"); |
465 gTargetMachine = target.get(); | 470 gTargetMachine = target.get(); |
466 gTargetData = gTargetMachine->getTargetData(); | 471 gTargetData = gTargetMachine->getTargetData(); |
467 | 472 |
468 // get final data layout | 473 // get final data layout |
469 std::string datalayout = gTargetData->getStringRepresentation(); | 474 std::string datalayout = gTargetData->getStringRepresentation(); |
470 global.params.dataLayout = datalayout.c_str(); | 475 global.params.dataLayout = datalayout.c_str(); |
471 | 476 |
472 global.params.llvmArch = mArch->Name; | 477 global.params.llvmArch = theTarget->getName(); |
473 | 478 |
474 if (strcmp(global.params.llvmArch,"x86")==0) { | 479 if (strcmp(global.params.llvmArch,"x86")==0) { |
475 VersionCondition::addPredefinedGlobalIdent("X86"); | 480 VersionCondition::addPredefinedGlobalIdent("X86"); |
476 global.params.isLE = true; | 481 global.params.isLE = true; |
477 global.params.is64bit = false; | 482 global.params.is64bit = false; |