comparison gen/linker.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 893d72ab95d0
children 18ad5601dff7
comparison
equal deleted inserted replaced
985:bce024c60adc 986:a8cb25d478c4
1 #include "gen/linker.h"
1 #include "gen/llvm.h" 2 #include "gen/llvm.h"
2 #include "llvm/Linker.h" 3 #include "llvm/Linker.h"
3 #include "llvm/System/Program.h" 4 #include "llvm/System/Program.h"
4 #if _WIN32 5 #if _WIN32
5 #include "llvm/Support/SystemUtils.h" 6 #include "llvm/Support/SystemUtils.h"
9 #include "mars.h" 10 #include "mars.h"
10 #include "module.h" 11 #include "module.h"
11 12
12 #define NO_COUT_LOGGER 13 #define NO_COUT_LOGGER
13 #include "gen/logger.h" 14 #include "gen/logger.h"
15 #include "gen/cl_options.h"
16
17 //////////////////////////////////////////////////////////////////////////////
18
19 // Is this useful?
20 llvm::cl::opt<bool> quiet("quiet",
21 llvm::cl::desc("Suppress output of link command (unless -v is also passed)"),
22 llvm::cl::Hidden,
23 llvm::cl::ZeroOrMore,
24 llvm::cl::init(true));
14 25
15 ////////////////////////////////////////////////////////////////////////////// 26 //////////////////////////////////////////////////////////////////////////////
16 27
17 typedef std::vector<llvm::Module*> Module_vector; 28 typedef std::vector<llvm::Module*> Module_vector;
18 29
171 char *p = (char *)global.params.objfiles->data[i]; 182 char *p = (char *)global.params.objfiles->data[i];
172 args.push_back(p); 183 args.push_back(p);
173 } 184 }
174 185
175 // print link command? 186 // print link command?
176 if (!global.params.quiet || global.params.verbose) 187 if (!quiet || global.params.verbose)
177 { 188 {
178 // Print it 189 // Print it
179 for (int i = 0; i < args.size(); i++) 190 for (int i = 0; i < args.size(); i++)
180 printf("%s ", args[i]); 191 printf("%s ", args[i]);
181 printf("\n"); 192 printf("\n");
309 //FIXME: enforce 64 bit 320 //FIXME: enforce 64 bit
310 if (global.params.is64bit) 321 if (global.params.is64bit)
311 args.push_back("-m64"); 322 args.push_back("-m64");
312 323
313 // print link command? 324 // print link command?
314 if (!global.params.quiet || global.params.verbose) 325 if (!quiet || global.params.verbose)
315 { 326 {
316 // Print it 327 // Print it
317 for (int i = 0; i < args.size(); i++) 328 for (int i = 0; i < args.size(); i++)
318 printf("%s ", args[i]); 329 printf("%s ", args[i]);
319 printf("\n"); 330 printf("\n");
361 assert(!gExePath.isEmpty()); 372 assert(!gExePath.isEmpty());
362 assert(gExePath.isValid()); 373 assert(gExePath.isValid());
363 374
364 // build arguments 375 // build arguments
365 std::vector<const char*> args; 376 std::vector<const char*> args;
366 for (size_t i = 0; i < global.params.runargs_length; i++) 377 // args[0] should be the name of the executable
367 { 378 args.push_back(gExePath.toString().c_str());
368 char *a = global.params.runargs[i]; 379 // Skip first argument to -run; it's a D source file.
369 args.push_back(a); 380 for (size_t i = 1, length = opts::runargs.size(); i < length; i++)
381 {
382 args.push_back(opts::runargs[i].c_str());
370 } 383 }
371 // terminate args list 384 // terminate args list
372 args.push_back(NULL); 385 args.push_back(NULL);
373 386
374 // try to call linker!!! 387 // try to call linker!!!