comparison dmd/mars.c @ 694:931333ea35c6

Allow output of only bc, ll, or s by making -of set the output type depending on the extension.
author Christian Kamm <kamm incasoftware de>
date Mon, 13 Oct 2008 10:58:00 +0200
parents 8526cf626110
children a51fed3de34e
comparison
equal deleted inserted replaced
693:3112d269dd95 694:931333ea35c6
160 LDC Homepage: http://www.dsource.org/projects/ldc\n\ 160 LDC Homepage: http://www.dsource.org/projects/ldc\n\
161 Usage:\n\ 161 Usage:\n\
162 ldc files.d ... { -switch }\n\ 162 ldc files.d ... { -switch }\n\
163 \n\ 163 \n\
164 files.d D source files\n%s\ 164 files.d D source files\n%s\
165 -of<filename> name output file to <filename>\n\
166 -o- do not write object file\n\ 165 -o- do not write object file\n\
167 -od<objdir> write object files to directory <objdir>\n\ 166 -od<objdir> write object files to directory <objdir>\n\
168 -op do not strip paths from source file\n\ 167 -op do not strip paths from source file\n\
169 -oq write object files with fully qualified names\n\ 168 -oq write object files with fully qualified names\n\
169 -of<filename> name output file to <filename>\n\
170 extension of <filename> determines output type\n\
171 no extension means native object or executable\n\
172 if the extension is ll, bc, s, or o/obj, linking is disabled\n\
170 \n\ 173 \n\
171 -output-ll write LLVM IR\n\ 174 -output-ll write LLVM IR\n\
172 -output-bc write LLVM bitcode\n\ 175 -output-bc write LLVM bitcode\n\
173 -output-s write native assembly\n\ 176 -output-s write native assembly\n\
177 -output-o write native object\n\
174 \n\ 178 \n\
175 -c do not link\n\ 179 -c do not link\n\
176 -L<linkerflag> pass <linkerflag> to llvm-ld\n\ 180 -L<linkerflag> pass <linkerflag> to llvm-ld\n\
177 \n\ 181 \n\
178 -g add symbolic debug info\n\ 182 -g add symbolic debug info\n\
246 250
247 int main(int argc, char *argv[], char** envp) 251 int main(int argc, char *argv[], char** envp)
248 { 252 {
249 int i; 253 int i;
250 Array files; 254 Array files;
251 char *p; 255 char *p, *ext;
252 Module *m; 256 Module *m;
253 int status = EXIT_SUCCESS; 257 int status = EXIT_SUCCESS;
254 int argcstart = argc; 258 int argcstart = argc;
255 bool very_verbose = false; 259 bool very_verbose = false;
256 260
292 global.params.useInline = 0; // this one messes things up to a point where codegen breaks 296 global.params.useInline = 0; // this one messes things up to a point where codegen breaks
293 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run 297 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run
294 global.params.obj = 1; 298 global.params.obj = 1;
295 global.params.Dversion = 2; 299 global.params.Dversion = 2;
296 global.params.quiet = 1; 300 global.params.quiet = 1;
301
302 global.params.output_o = 1;
297 303
298 global.params.linkswitches = new Array(); 304 global.params.linkswitches = new Array();
299 global.params.libfiles = new Array(); 305 global.params.libfiles = new Array();
300 global.params.objfiles = new Array(); 306 global.params.objfiles = new Array();
301 global.params.ddocfiles = new Array(); 307 global.params.ddocfiles = new Array();
448 454
449 case 'f': 455 case 'f':
450 if (!p[3]) 456 if (!p[3])
451 goto Lnoarg; 457 goto Lnoarg;
452 global.params.objname = p + 3; 458 global.params.objname = p + 3;
459
460 // remove default output
461 if (global.params.output_ll == 1)
462 global.params.output_ll = 0;
463 if (global.params.output_bc == 1)
464 global.params.output_bc = 0;
465 if (global.params.output_s == 1)
466 global.params.output_s = 0;
467 if (global.params.output_o == 1)
468 global.params.output_o = 0;
469
470 // determine output based on ext
471 ext = FileName::ext(global.params.objname);
472 if (strcmp(ext, global.ll_ext) == 0) {
473 global.params.output_ll = 1;
474 global.params.link = 0;
475 } else if (strcmp(ext, global.bc_ext) == 0) {
476 global.params.output_bc = 1;
477 global.params.link = 0;
478 } else if (strcmp(ext, global.s_ext) == 0) {
479 global.params.output_s = 1;
480 global.params.link = 0;
481 } else if (strcmp(ext, global.obj_ext) == 0) {
482 global.params.output_o = 1;
483 global.params.link = 0;
484 } else {
485 global.params.output_o = 1;
486 }
487
453 break; 488 break;
454 489
455 case 'p': 490 case 'p':
456 if (p[3]) 491 if (p[3])
457 goto Lerror; 492 goto Lerror;
465 break; 500 break;
466 501
467 case 'u': 502 case 'u':
468 if (strncmp(p+1, "output-", 7) != 0) 503 if (strncmp(p+1, "output-", 7) != 0)
469 goto Lerror; 504 goto Lerror;
470 if (strcmp(p+8, "ll") == 0) 505 if (strcmp(p+8, global.ll_ext) == 0)
471 global.params.output_ll = 1; 506 global.params.output_ll = 2;
472 else if (strcmp(p+8, "bc") == 0) 507 else if (strcmp(p+8, global.bc_ext) == 0)
473 global.params.output_bc = 1; 508 global.params.output_bc = 2;
474 else if (strcmp(p+8, "s") == 0) 509 else if (strcmp(p+8, global.s_ext) == 0)
475 global.params.output_s = 1; 510 global.params.output_s = 2;
511 else if (strcmp(p+8, global.obj_ext) == 0)
512 global.params.output_o = 2;
476 else 513 else
477 goto Lerror; 514 goto Lerror;
478 break; 515 break;
479 516
480 case 0: 517 case 0: