comparison gen/toobj.cpp @ 986:a8cb25d478c4

Use LLVM-style command line (instead of DMD-style) Note: For a backward compatible interface, use the new bin/ldmd script. It supports all old options while passing on anything it doesn't recognize. Some changes caused by this: * -debug and -version are now -d-debug and -d-version due to a conflict with standard LLVM options. * All "flag" options now allow an optional =true/=1/=false/=0 suffix. * Some "hidden debug switches" starting with "--" were renamed because LLVM doesn't care about the number of dashes, so they were conflicting with other options (such as -c). The new versions start with "-hidden-debug-" instead of "--" * --help works, but has a non-zero exit code. This breaks some Tango scripts which use it to test for compiler existence. See tango.patch. Some changes not (directly) caused by this; * (-enable/-disable)-FOO options are now available for pre- and postconditions. * -march is used instead of -m (like other LLVM programs), but -m is an alias for it. * -defaultlib, -debuglib, -d-debug and -d-version allow comma-separated values. The effect should be identical to specifying the same option multiple times. I decided against allowing these for some other options because paths might contain commas on some systems. * -fPIC is removed in favor of the standard LLVM option -relocation-model=pic Bug: * If -run is specified as the last argument in DFLAGS, no error is generated. (Not very serious IMHO)
author Frits van Bommel <fvbommel wxs.nl>
date Wed, 25 Feb 2009 17:34:51 +0100
parents e71c61befd6d
children 2667e3a145be
comparison
equal deleted inserted replaced
985:bce024c60adc 986:a8cb25d478c4
22 #include "llvm/PassManager.h" 22 #include "llvm/PassManager.h"
23 #include "llvm/LinkAllPasses.h" 23 #include "llvm/LinkAllPasses.h"
24 #include "llvm/System/Program.h" 24 #include "llvm/System/Program.h"
25 #include "llvm/System/Path.h" 25 #include "llvm/System/Path.h"
26 #include "llvm/Support/raw_ostream.h" 26 #include "llvm/Support/raw_ostream.h"
27 #include "llvm/Support/CommandLine.h"
27 28
28 #include "mars.h" 29 #include "mars.h"
29 #include "module.h" 30 #include "module.h"
30 #include "mtype.h" 31 #include "mtype.h"
31 #include "declaration.h" 32 #include "declaration.h"
53 #include "ir/irvar.h" 54 #include "ir/irvar.h"
54 #include "ir/irmodule.h" 55 #include "ir/irmodule.h"
55 56
56 ////////////////////////////////////////////////////////////////////////////////////////// 57 //////////////////////////////////////////////////////////////////////////////////////////
57 58
59 static llvm::cl::opt<bool> noVerify("noverify",
60 llvm::cl::desc("Do not run the validation pass before writing bitcode"),
61 llvm::cl::ZeroOrMore);
62
63 //////////////////////////////////////////////////////////////////////////////////////////
64
58 // in gen/optimize.cpp 65 // in gen/optimize.cpp
59 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline); 66 void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline);
60 67
61 // fwd decl 68 // fwd decl
62 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out); 69 void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out);
121 llvm::SubtargetFeatures Features; 128 llvm::SubtargetFeatures Features;
122 //TODO: Features? 129 //TODO: Features?
123 // Features.setCPU(MCPU); 130 // Features.setCPU(MCPU);
124 // for (unsigned i = 0; i != MAttrs.size(); ++i) 131 // for (unsigned i = 0; i != MAttrs.size(); ++i)
125 // Features.AddFeature(MAttrs[i]); 132 // Features.AddFeature(MAttrs[i]);
126
127 // only generate PIC code when -fPIC switch is used
128 if (global.params.pic)
129 llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
130 133
131 // allocate the target machine 134 // allocate the target machine
132 std::auto_ptr<llvm::TargetMachine> target(MArch->CtorFn(*ir.module, Features.getString())); 135 std::auto_ptr<llvm::TargetMachine> target(MArch->CtorFn(*ir.module, Features.getString()));
133 assert(target.get() && "Could not allocate target machine!"); 136 assert(target.get() && "Could not allocate target machine!");
134 llvm::TargetMachine &Target = *target.get(); 137 llvm::TargetMachine &Target = *target.get();
180 LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module); 183 LLGlobalVariable* usedArray = new LLGlobalVariable(usedTy, true, LLGlobalValue::AppendingLinkage, usedInit, "llvm.used", ir.module);
181 usedArray->setSection("llvm.metadata"); 184 usedArray->setSection("llvm.metadata");
182 } 185 }
183 186
184 // verify the llvm 187 // verify the llvm
185 if (!global.params.novalidate) { 188 if (!noVerify) {
186 std::string verifyErr; 189 std::string verifyErr;
187 Logger::println("Verifying module..."); 190 Logger::println("Verifying module...");
188 LOG_SCOPE; 191 LOG_SCOPE;
189 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) 192 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
190 { 193 {
198 201
199 // run optimizer 202 // run optimizer
200 ldc_optimize_module(ir.module, global.params.optimizeLevel, global.params.llvmInline); 203 ldc_optimize_module(ir.module, global.params.optimizeLevel, global.params.llvmInline);
201 204
202 // verify the llvm 205 // verify the llvm
203 if (!global.params.novalidate && (global.params.optimizeLevel >= 0 || global.params.llvmInline)) { 206 if (!noVerify && (global.params.optimizeLevel >= 0 || global.params.llvmInline)) {
204 std::string verifyErr; 207 std::string verifyErr;
205 Logger::println("Verifying module... again..."); 208 Logger::println("Verifying module... again...");
206 LOG_SCOPE; 209 LOG_SCOPE;
207 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr)) 210 if (llvm::verifyModule(*ir.module,llvm::ReturnStatusAction,&verifyErr))
208 { 211 {