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