Mercurial > projects > ldc
comparison gen/toobj.cpp @ 583:12bda38ea366
Fixed choosing default target machine without needing to link in targets.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 07 Sep 2008 17:44:25 -0700 |
parents | 7824c21a58e3 |
children | e235b80c92bc |
comparison
equal
deleted
inserted
replaced
582:723806dc48d8 | 583:12bda38ea366 |
---|---|
93 std::string target_triple(global.params.tt_arch); | 93 std::string target_triple(global.params.tt_arch); |
94 target_triple.append(global.params.tt_os); | 94 target_triple.append(global.params.tt_os); |
95 ir.module->setTargetTriple(target_triple); | 95 ir.module->setTargetTriple(target_triple); |
96 ir.module->setDataLayout(global.params.data_layout); | 96 ir.module->setDataLayout(global.params.data_layout); |
97 | 97 |
98 // heavily inspired by tools/llc/llc.cpp:200-230 | 98 gTargetData = new llvm::TargetData(global.params.data_layout); |
99 const llvm::TargetMachineRegistry::entry* targetEntry; | |
100 std::string targetError; | |
101 targetEntry = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, targetError); | |
102 assert(targetEntry && "Failed to find a static target for module"); | |
103 std::auto_ptr<llvm::TargetMachine> targetPtr(targetEntry->CtorFn(*ir.module, "")); // TODO: replace "" with features | |
104 assert(targetPtr.get() && "Could not allocate target machine!"); | |
105 llvm::TargetMachine &targetMachine = *targetPtr.get(); | |
106 gTargetData = targetMachine.getTargetData(); | |
107 | 99 |
108 // debug info | 100 // debug info |
109 if (global.params.symdebug) { | 101 if (global.params.symdebug) { |
110 RegisterDwarfSymbols(ir.module); | 102 RegisterDwarfSymbols(ir.module); |
111 DtoDwarfCompileUnit(this); | 103 DtoDwarfCompileUnit(this); |