authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-27 22:13:39-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-27 22:13:39-07:00
logf6529341a2413a3eb72920418d19ea7d2aca089b
treea861b3c8e2397029c8a6d3039e98c4caa4af6f3b
parent03f992273493ef1e635a7a3bb3de9c5cd5182789

ability to export .o file


4 files changed, 17 insertions(+), 4 deletions(-)

README.md-1
......@@ -34,7 +34,6 @@ readable, safe, optimal, and concise code to solve any computing problem.
3434
3535 * Math expression
3636 * Export .so library
37 * Export .o file
3837 * Multiple files
3938 * inline assembly and syscalls
4039 * running code at compile time
src/codegen.cpp+15-1
......@@ -994,7 +994,10 @@ void code_gen_link(CodeGen *g, const char *out_file) {
994994
995995 Buf out_file_o = BUF_INIT;
996996 buf_init_from_str(&out_file_o, out_file);
997 buf_append_str(&out_file_o, ".o");
997
998 if (g->out_type != OutTypeObj) {
999 buf_append_str(&out_file_o, ".o");
1000 }
9981001
9991002 char *err_msg = nullptr;
10001003 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) {
10031006 zig_panic("unable to write object file: %s", err_msg);
10041007 }
10051008
1009 if (g->out_type == OutTypeObj) {
1010 return;
1011 }
1012
1013 if (g->out_type == OutTypeLib && g->is_static) {
1014 // invoke `ar`
1015 zig_panic("TODO invoke ar");
1016 return;
1017 }
1018
1019 // invoke `ld`
10061020 ZigList<const char *> args = {0};
10071021 if (g->is_static) {
10081022 args.append("-static");
src/zig_llvm.cpp+1-1
......@@ -156,7 +156,7 @@ static LLVMBool LLVMZigTargetMachineEmit(LLVMTargetMachineRef targ_machine_ref,
156156}
157157
158158LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
159 char* filename, LLVMCodeGenFileType codegen, char** err_msg)
159 const char* filename, LLVMCodeGenFileType codegen, char** err_msg)
160160{
161161 std::error_code error_code;
162162 raw_fd_ostream dest(filename, error_code, sys::fs::F_None);
src/zig_llvm.hpp+1-1
......@@ -22,7 +22,7 @@ char *LLVMZigGetHostCPUName(void);
2222char *LLVMZigGetNativeFeatures(void);
2323
2424LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef target_machine, LLVMModuleRef module,
25 char* filename, LLVMCodeGenFileType codegen, char** error_msg);
25 const char* filename, LLVMCodeGenFileType codegen, char** error_msg);
2626
2727void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref);
2828