Mercurial > projects > ldc
diff gen/toobj.cpp @ 1650:40bd4a0d4870
Update to work with LLVM 2.7.
Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).
Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.
Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.
author | Tomas Lindquist Olsen |
---|---|
date | Wed, 19 May 2010 12:42:32 +0200 |
parents | 299a6b634178 |
children |
line wrap: on
line diff
--- a/gen/toobj.cpp Fri Mar 19 09:31:25 2010 +0100 +++ b/gen/toobj.cpp Wed May 19 12:42:32 2010 +0200 @@ -14,7 +14,6 @@ #include "llvm/Analysis/Verifier.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" #include "llvm/PassManager.h" #include "llvm/LinkAllPasses.h" #include "llvm/System/Program.h" @@ -22,6 +21,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/CodeGen/MachineCodeEmitter.h" #include "mars.h" #include "module.h" @@ -114,11 +114,13 @@ // allocate the target abi gABI = TargetABI::getTarget(); + #ifndef DISABLE_DEBUG_INFO // debug info if (global.params.symdebug) { RegisterDwarfSymbols(ir.module); DtoDwarfCompileUnit(this); } + #endif // handle invalid 'objectø module if (!ClassDeclaration::object) { @@ -129,7 +131,7 @@ error("is missing 'class ClassInfo'"); fatal(); } - + LLVM_D_InitRuntime(); // process module members @@ -225,10 +227,11 @@ bcpath.eraseSuffix(); bcpath.appendSuffix(std::string(global.bc_ext)); Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); - std::ofstream bos(bcpath.c_str(), std::ios::binary); - if (bos.fail()) + std::string errinfo; + llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::raw_fd_ostream::F_Binary); + if (bos.has_error()) { - error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str()); + error("cannot write LLVM bitcode file '%s': %s", bcpath.c_str(), errinfo.c_str()); fatal(); } llvm::WriteBitcodeToFile(m, bos); @@ -240,10 +243,11 @@ llpath.eraseSuffix(); llpath.appendSuffix(std::string(global.ll_ext)); Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); - std::ofstream aos(llpath.c_str()); - if (aos.fail()) + std::string errinfo; + llvm::raw_fd_ostream aos(llpath.c_str(), errinfo); + if (aos.has_error()) { - error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str()); + error("cannot write LLVM asm file '%s': %s", llpath.c_str(), errinfo.c_str()); fatal(); } m->print(aos, NULL); @@ -260,7 +264,7 @@ Logger::println("Writing native asm to: %s\n", spath.c_str()); std::string err; { - llvm::raw_fd_ostream out(spath.c_str(), false, true, err); + llvm::raw_fd_ostream out(spath.c_str(), err); if (err.empty()) { write_asm_to_file(*gTargetMachine, *m, out); @@ -292,17 +296,13 @@ using namespace llvm; // Build up all of the passes that we want to do to the module. - ExistingModuleProvider Provider(&m); - FunctionPassManager Passes(&Provider); + FunctionPassManager Passes(&m); if (const TargetData *TD = Target.getTargetData()) Passes.add(new TargetData(*TD)); else Passes.add(new TargetData(&m)); - // Ask the target to add backend passes as necessary. - MachineCodeEmitter *MCE = 0; - // Last argument is enum CodeGenOpt::Level OptLevel // debug info doesn't work properly with OptLevel != None! CodeGenOpt::Level LastArg = CodeGenOpt::Default; @@ -312,11 +312,8 @@ LastArg = CodeGenOpt::Aggressive; llvm::formatted_raw_ostream fout(out); - FileModel::Model mod = Target.addPassesToEmitFile(Passes, fout, TargetMachine::AssemblyFile, LastArg); - assert(mod == FileModel::AsmFile); - - bool err = Target.addPassesToEmitFileFinish(Passes, MCE, LastArg); - assert(!err); + if (Target.addPassesToEmitFile(Passes, fout, TargetMachine::CGFT_AssemblyFile, LastArg)) + assert(0 && "no support for asm output"); Passes.doInitialization(); @@ -328,9 +325,9 @@ Passes.doFinalization(); // release module from module provider so we can delete it ourselves - std::string Err; - llvm::Module* rmod = Provider.releaseModule(&Err); - assert(rmod); + //std::string Err; + //llvm::Module* rmod = Provider.releaseModule(&Err); + //assert(rmod); } /* ================================================================== */ @@ -350,14 +347,14 @@ // and linker because we don't know where to put the _start symbol. // GCC mysteriously knows how to do it. std::vector<std::string> args; - args.push_back(gcc.toString()); + args.push_back(gcc.str()); args.push_back("-fno-strict-aliasing"); args.push_back("-O3"); args.push_back("-c"); args.push_back("-xassembler"); - args.push_back(asmpath.toString()); + args.push_back(asmpath.str()); args.push_back("-o"); - args.push_back(objpath.toString()); + args.push_back(objpath.str()); //FIXME: only use this if needed? args.push_back("-fpic"); @@ -431,11 +428,13 @@ IRBuilder<> builder(bb); // debug info + #ifndef DISABLE_DEBUG_INFO LLGlobalVariable* subprog; if(global.params.symdebug) { subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); } + #endif for (size_t i=0; i<n; i++) { llvm::Function* f = gIR->ctors[i]->ir.irFunc->func; @@ -444,8 +443,10 @@ } // debug info end + #ifndef DISABLE_DEBUG_INFO if(global.params.symdebug) builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); + #endif builder.CreateRetVoid(); return fn; @@ -475,12 +476,14 @@ llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "entry", fn); IRBuilder<> builder(bb); + #ifndef DISABLE_DEBUG_INFO // debug info LLGlobalVariable* subprog; if(global.params.symdebug) { subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); } + #endif for (size_t i=0; i<n; i++) { llvm::Function* f = gIR->dtors[i]->ir.irFunc->func; @@ -488,9 +491,11 @@ call->setCallingConv(DtoCallingConv(0, LINKd)); } + #ifndef DISABLE_DEBUG_INFO // debug info end if(global.params.symdebug) builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); + #endif builder.CreateRetVoid(); return fn; @@ -520,12 +525,14 @@ llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "entry", fn); IRBuilder<> builder(bb); + #ifndef DISABLE_DEBUG_INFO // debug info LLGlobalVariable* subprog; if(global.params.symdebug) { subprog = DtoDwarfSubProgramInternal(name.c_str(), name.c_str()).getGV(); builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); } + #endif for (size_t i=0; i<n; i++) { llvm::Function* f = gIR->unitTests[i]->ir.irFunc->func; @@ -533,9 +540,11 @@ call->setCallingConv(DtoCallingConv(0, LINKd)); } + #ifndef DISABLE_DEBUG_INFO // debug info end if(global.params.symdebug) builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); + #endif builder.CreateRetVoid(); return fn; @@ -578,11 +587,13 @@ IRBuilder<> builder(bb); // debug info + #ifndef DISABLE_DEBUG_INFO LLGlobalVariable* subprog; if(global.params.symdebug) { subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()).getGV(); builder.CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), DBG_CAST(subprog)); } + #endif // get current beginning LLValue* curbeg = builder.CreateLoad(mref, "current"); @@ -594,9 +605,11 @@ // replace beginning builder.CreateStore(thismref, mref); + #ifndef DISABLE_DEBUG_INFO // debug info end if(global.params.symdebug) builder.CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), DBG_CAST(subprog)); + #endif // return builder.CreateRetVoid(); @@ -614,11 +627,11 @@ // ModuleInfo[] importedModules; // ClassInfo[] localClasses; // uint flags; -// +// // void function() ctor; // void function() dtor; // void function() unitTest; -// +// // void* xgetMembers; // void function() ictor; //