diff 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
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;