changeset 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 3112d269dd95
children a51fed3de34e
files dmd/mars.c dmd/mars.h gen/toobj.cpp
diffstat 3 files changed, 69 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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<filename>  name output file to <filename>\n\
   -o-            do not write object file\n\
   -od<objdir>    write object files to directory <objdir>\n\
   -op            do not strip paths from source file\n\
   -oq            write object files with fully qualified names\n\
+  -of<filename>  name output file to <filename>\n\
+                 extension of <filename> 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<linkerflag> pass <linkerflag> 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;
--- 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;
--- 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;