From d65cd73a8bfe39349be09a5f76f8477f3e3210b9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Apr 2017 07:46:50 -0400 Subject: add support to use zig as a linker driver closes #243 I also added --grep to ./run_tests if you want to single out some specific tests --- src/codegen.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 28a8243aca..50eba6e2c8 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3743,6 +3743,18 @@ static void do_code_gen(CodeGen *g) { char *error = nullptr; LLVMVerifyModule(g->module, LLVMAbortProcessAction, &error); #endif + + char *err_msg = nullptr; + Buf *out_file_o = buf_create_from_buf(g->root_out_name); + const char *o_ext = target_o_file_ext(&g->zig_target); + buf_append_str(out_file_o, o_ext); + if (LLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(out_file_o), + LLVMObjectFile, &err_msg)) + { + zig_panic("unable to write object file: %s", err_msg); + } + + g->link_objects.append(out_file_o); } static const size_t int_sizes_in_bits[] = { @@ -4550,6 +4562,10 @@ void codegen_add_root_assembly(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf do_code_gen(g); } +void codegen_add_object(CodeGen *g, Buf *object_path) { + g->link_objects.append(object_path); +} + static const char *c_int_type_names[] = { [CIntTypeShort] = "short", -- cgit v1.2.3