zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit f6529341a2413a3eb72920418d19ea7d2aca089b (tree)
parent 03f992273493ef1e635a7a3bb3de9c5cd5182789
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Fri, 27 Nov 2015 22:13:39 -0700

ability to export .o file

Diffstat:
MREADME.md | 1-
Msrc/codegen.cpp | 16+++++++++++++++-
Msrc/zig_llvm.cpp | 2+-
Msrc/zig_llvm.hpp | 2+-
4 files changed, 17 insertions(+), 4 deletions(-)

diff --git 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 @@ -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"); diff --git 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 @@ -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);