Commit f6529341a2

Andrew Kelley <superjoe30@gmail.com>
2015-11-28 06:13:39
ability to export .o file
1 parent 03f9922
src/codegen.cpp
@@ -994,7 +994,10 @@ void code_gen_link(CodeGen *g, const char *out_file) {
 
     Buf out_file_o = BUF_INIT;
     buf_init_from_str(&out_file_o, out_file);
-    buf_append_str(&out_file_o, ".o");
+
+    if (g->out_type != OutTypeObj) {
+        buf_append_str(&out_file_o, ".o");
+    }
 
     char *err_msg = nullptr;
     if (LLVMZigTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&out_file_o),
@@ -1003,6 +1006,17 @@ void code_gen_link(CodeGen *g, const char *out_file) {
         zig_panic("unable to write object file: %s", err_msg);
     }
 
+    if (g->out_type == OutTypeObj) {
+        return;
+    }
+
+    if (g->out_type == OutTypeLib && g->is_static) {
+        // invoke `ar`
+        zig_panic("TODO invoke ar");
+        return;
+    }
+
+    // invoke `ld`
     ZigList<const char *> args = {0};
     if (g->is_static) {
         args.append("-static");
src/zig_llvm.cpp
@@ -156,7 +156,7 @@ static LLVMBool LLVMZigTargetMachineEmit(LLVMTargetMachineRef targ_machine_ref,
 }
 
 LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
-        char* filename, LLVMCodeGenFileType codegen, char** err_msg)
+        const char* filename, LLVMCodeGenFileType codegen, char** err_msg)
 {
     std::error_code error_code;
     raw_fd_ostream dest(filename, error_code, sys::fs::F_None);
src/zig_llvm.hpp
@@ -22,7 +22,7 @@ char *LLVMZigGetHostCPUName(void);
 char *LLVMZigGetNativeFeatures(void);
 
 LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef target_machine, LLVMModuleRef module,
-        char* filename, LLVMCodeGenFileType codegen, char** error_msg);
+        const char* filename, LLVMCodeGenFileType codegen, char** error_msg);
 
 void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref);
 
README.md
@@ -34,7 +34,6 @@ readable, safe, optimal, and concise code to solve any computing problem.
 
  * Math expression
  * Export .so library
- * Export .o file
  * Multiple files
  * inline assembly and syscalls
  * running code at compile time