# HG changeset patch # User Christian Kamm # Date 1223888280 -7200 # Node ID 931333ea35c62e996e29a78e6fe3a04a7564a970 # Parent 3112d269dd959903b250d11b83be383e25fb0265 Allow output of only bc, ll, or s by making -of set the output type depending on the extension. diff -r 3112d269dd95 -r 931333ea35c6 dmd/mars.c --- a/dmd/mars.c Sun Oct 12 20:22:51 2008 +0200 +++ b/dmd/mars.c Mon Oct 13 10:58:00 2008 +0200 @@ -162,15 +162,19 @@ ldc files.d ... { -switch }\n\ \n\ files.d D source files\n%s\ - -of name output file to \n\ -o- do not write object file\n\ -od write object files to directory \n\ -op do not strip paths from source file\n\ -oq write object files with fully qualified names\n\ + -of name output file to \n\ + extension of determines output type\n\ + no extension means native object or executable\n\ + if the extension is ll, bc, s, or o/obj, linking is disabled\n\ \n\ -output-ll write LLVM IR\n\ -output-bc write LLVM bitcode\n\ -output-s write native assembly\n\ + -output-o write native object\n\ \n\ -c do not link\n\ -L pass to llvm-ld\n\ @@ -248,7 +252,7 @@ { int i; Array files; - char *p; + char *p, *ext; Module *m; int status = EXIT_SUCCESS; int argcstart = argc; @@ -295,6 +299,8 @@ global.params.Dversion = 2; global.params.quiet = 1; + global.params.output_o = 1; + global.params.linkswitches = new Array(); global.params.libfiles = new Array(); global.params.objfiles = new Array(); @@ -450,6 +456,35 @@ if (!p[3]) goto Lnoarg; global.params.objname = p + 3; + + // remove default output + if (global.params.output_ll == 1) + global.params.output_ll = 0; + if (global.params.output_bc == 1) + global.params.output_bc = 0; + if (global.params.output_s == 1) + global.params.output_s = 0; + if (global.params.output_o == 1) + global.params.output_o = 0; + + // determine output based on ext + ext = FileName::ext(global.params.objname); + if (strcmp(ext, global.ll_ext) == 0) { + global.params.output_ll = 1; + global.params.link = 0; + } else if (strcmp(ext, global.bc_ext) == 0) { + global.params.output_bc = 1; + global.params.link = 0; + } else if (strcmp(ext, global.s_ext) == 0) { + global.params.output_s = 1; + global.params.link = 0; + } else if (strcmp(ext, global.obj_ext) == 0) { + global.params.output_o = 1; + global.params.link = 0; + } else { + global.params.output_o = 1; + } + break; case 'p': @@ -467,12 +502,14 @@ case 'u': if (strncmp(p+1, "output-", 7) != 0) goto Lerror; - if (strcmp(p+8, "ll") == 0) - global.params.output_ll = 1; - else if (strcmp(p+8, "bc") == 0) - global.params.output_bc = 1; - else if (strcmp(p+8, "s") == 0) - global.params.output_s = 1; + if (strcmp(p+8, global.ll_ext) == 0) + global.params.output_ll = 2; + else if (strcmp(p+8, global.bc_ext) == 0) + global.params.output_bc = 2; + else if (strcmp(p+8, global.s_ext) == 0) + global.params.output_s = 2; + else if (strcmp(p+8, global.obj_ext) == 0) + global.params.output_o = 2; else goto Lerror; break; diff -r 3112d269dd95 -r 931333ea35c6 dmd/mars.h --- a/dmd/mars.h Sun Oct 12 20:22:51 2008 +0200 +++ b/dmd/mars.h Mon Oct 13 10:58:00 2008 +0200 @@ -148,6 +148,7 @@ char output_ll; char output_bc; char output_s; + char output_o; char llvmInline; char llvmAnnotate; char useInlineAsm; diff -r 3112d269dd95 -r 931333ea35c6 gen/toobj.cpp --- a/gen/toobj.cpp Sun Oct 12 20:22:51 2008 +0200 +++ b/gen/toobj.cpp Mon Oct 13 10:58:00 2008 +0200 @@ -211,25 +211,31 @@ } // write native assembly - LLPath spath = LLPath(objfile->name->toChars()); - spath.eraseSuffix(); - spath.appendSuffix(std::string(global.s_ext)); - if (!global.params.output_s) { - spath.createTemporaryFileOnDisk(); - } - Logger::println("Writing native asm to: %s\n", spath.c_str()); - std::string err; - { - llvm::raw_fd_ostream out(spath.c_str(), err); - write_asm_to_file(*ir.module, out); - } + if (global.params.output_s || global.params.output_o) { + LLPath spath = LLPath(objfile->name->toChars()); + spath.eraseSuffix(); + spath.appendSuffix(std::string(global.s_ext)); + if (!global.params.output_s) { + spath.createTemporaryFileOnDisk(); + } + Logger::println("Writing native asm to: %s\n", spath.c_str()); + std::string err; + { + llvm::raw_fd_ostream out(spath.c_str(), err); + write_asm_to_file(*ir.module, out); + } - // call gcc to convert assembly to object file - LLPath objpath = LLPath(objfile->name->toChars()); - assemble(spath, objpath, envp); + // call gcc to convert assembly to object file + if (global.params.output_o) { + LLPath objpath = LLPath(objfile->name->toChars()); + objpath.eraseSuffix(); + objpath.appendSuffix(std::string(global.obj_ext)); + assemble(spath, objpath, envp); + } - if (!global.params.output_s) { - spath.eraseFromDisk(); + if (!global.params.output_s) { + spath.eraseFromDisk(); + } } delete ir.module;