diff gen/toobj.cpp @ 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 06c05906b054
children ed9a9e6dd1cc
line wrap: on
line diff
--- 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;