changeset 675:bfe5229f9d8e

Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s. Call to gcc to convert assembly to object file still required.
author Christian Kamm <kamm incasoftware de>
date Sat, 11 Oct 2008 13:07:59 +0200
parents db6a7e574cbd
children 1f0a78174598
files dmd/mars.c dmd/mars.h dmd/module.c gen/toobj.cpp
diffstat 4 files changed, 56 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mars.c	Sat Oct 11 11:41:56 2008 +0200
+++ b/dmd/mars.c	Sat Oct 11 13:07:59 2008 +0200
@@ -52,13 +52,13 @@
     ddoc_ext = "ddoc";
 
 // LDC
-    obj_ext  = "bc";
     ll_ext  = "ll";
     bc_ext  = "bc";
+    s_ext   = "s";
 #if _WIN32
-    nativeobj_ext = "obj";
+    obj_ext = "obj";
 #elif POSIX
-    nativeobj_ext = "o";
+    obj_ext = "o";
 #else
 #error "fix this"
 #endif
@@ -168,6 +168,10 @@
   -op            do not strip paths from source file\n\
   -oq            write object files with fully qualified names\n\
 \n\
+  -output-ll     write LLVM IR\n\
+  -output-bc     write LLVM bitcode\n\
+  -output-s      write native assembly\n\
+\n\
   -c             do not link\n\
   -L<linkerflag> pass <linkerflag> to llvm-ld\n\
 \n\
@@ -216,7 +220,6 @@
   -d             allow deprecated features\n\
 \n\
   -annotate      annotate the bitcode with human readable source code\n\
-  -dis           disassemble module after compiling\n\
   -ignore        ignore unsupported pragmas\n\
 \n\
 Path options:\n\
@@ -404,8 +407,6 @@
             global.params.noruntime = 1;
         else if (strcmp(p + 1, "noverify") == 0)
             global.params.novalidate = 1;
-        else if (strcmp(p + 1, "dis") == 0)
-            global.params.disassemble = 1;
         else if (strcmp(p + 1, "annotate") == 0)
             global.params.llvmAnnotate = 1;
         else if (strncmp(p + 1, "enable-", 7) == 0 ||
@@ -463,6 +464,19 @@
 			global.params.fqnNames = 1;
 			break;
 
+		    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;
+			else
+			    goto Lerror;
+			break;
+
 		    case 0:
 			error("-o no longer supported, use -of or -od");
 			break;
@@ -918,13 +932,12 @@
 	ext = FileName::ext(p);
 	if (ext)
 	{
-#if IN_LLVM
-        if (strcmp(ext, global.nativeobj_ext) == 0 ||
-            strcmp(ext, global.obj_ext) == 0)
-#elif TARGET_LINUX
-	    if (strcmp(ext, global.obj_ext) == 0)
+#if TARGET_LINUX
+	    if (strcmp(ext, global.obj_ext) == 0 ||
+		strcmp(ext, global.bc_ext) == 0)
 #else
-	    if (stricmp(ext, global.obj_ext) == 0)
+	    if (stricmp(ext, global.obj_ext) == 0 ||
+		stricmp(ext, global.bc_ext) == 0)
 #endif
 	    {
 		global.params.objfiles->push(files.data[i]);
--- a/dmd/mars.h	Sat Oct 11 11:41:56 2008 +0200
+++ b/dmd/mars.h	Sat Oct 11 13:07:59 2008 +0200
@@ -145,7 +145,9 @@
     char *tt_arch;
     char *tt_os;
     char *data_layout;
-    char disassemble;
+    char output_ll;
+    char output_bc;
+    char output_s;
     char llvmInline;
     char llvmAnnotate;
     char useInlineAsm;
@@ -160,7 +162,7 @@
     char *obj_ext;
     char *ll_ext;
     char *bc_ext;
-    char *nativeobj_ext;
+    char *s_ext;
     char *doc_ext;	// for Ddoc generated files
     char *ddoc_ext;	// for Ddoc macro include files
     char *hdr_ext;	// for D 'header' import files
--- a/dmd/module.c	Sat Oct 11 11:41:56 2008 +0200
+++ b/dmd/module.c	Sat Oct 11 13:07:59 2008 +0200
@@ -180,7 +180,7 @@
 	return;
 
     if(!objfile)
-	objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
+	objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.obj_ext);
     if(doDocComment && !docfile)
 	docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
     if(doHdrGen && !hdrfile)
--- a/gen/toobj.cpp	Sat Oct 11 11:41:56 2008 +0200
+++ b/gen/toobj.cpp	Sat Oct 11 13:07:59 2008 +0200
@@ -179,33 +179,43 @@
 
     // eventually do our own path stuff, dmd's is a bit strange.
     typedef llvm::sys::Path LLPath;
-    LLPath bcpath = LLPath(objfile->name->toChars());
-    LLPath llpath = bcpath;
-    llpath.eraseSuffix();
-    llpath.appendSuffix(std::string(global.ll_ext));
 
-    // write bytecode
-    {
+    // write LLVM bitcode
+    if (global.params.output_bc) {
+        LLPath bcpath = LLPath(objfile->name->toChars());
+        bcpath.eraseSuffix();
+        bcpath.appendSuffix(std::string(global.bc_ext));
         Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
         std::ofstream bos(bcpath.c_str(), std::ios::binary);
         llvm::WriteBitcodeToFile(ir.module, bos);
     }
 
-    // disassemble ?
-    if (global.params.disassemble) {
+    // write LLVM IR
+    if (global.params.output_ll) {
+        LLPath llpath = LLPath(objfile->name->toChars());
+        llpath.eraseSuffix();
+        llpath.appendSuffix(std::string(global.ll_ext));
         Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
         std::ofstream aos(llpath.c_str());
         ir.module->print(aos, NULL);
     }
 
-    //TODO: command line switch
-    if(false)
-    {
-        //FIXME: Proper out file name.
-        Logger::println("Writing native asm to: %s\n", "");
-        std::string err;
-        llvm::raw_fd_ostream out("test.s", err);
-        write_asm_to_file(*ir.module, out);
+    // 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);
+
+    //TODO: call gcc to convert assembly to object file
+
+    if (!global.params.output_s) {
+        spath.eraseFromDisk();
     }
 
     delete ir.module;