From f6529341a2413a3eb72920418d19ea7d2aca089b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 27 Nov 2015 22:13:39 -0700 Subject: [PATCH] ability to export .o file --- README.md | 1 - src/codegen.cpp | 16 +++++++++++++++- src/zig_llvm.cpp | 2 +- src/zig_llvm.hpp | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0de6d8d5d..2684b7605 100644 --- a/README.md +++ b/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 diff --git a/src/codegen.cpp b/src/codegen.cpp index 3f0860a70..c79796c0f 100644 --- a/src/codegen.cpp +++ b/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 args = {0}; if (g->is_static) { args.append("-static"); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 89d0563b9..cde28c13b 100644 --- a/src/zig_llvm.cpp +++ b/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); diff --git a/src/zig_llvm.hpp b/src/zig_llvm.hpp index fda8e371e..be1bf64d9 100644 --- a/src/zig_llvm.hpp +++ b/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);