diff options
| author | gingerBill <bill@gingerbill.org> | 2020-04-13 12:00:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-04-13 12:00:40 +0100 |
| commit | 65a2125dba5652577588afee31d7333f13eb0c31 (patch) | |
| tree | 2b7da4905dd3ce06c79f50079d20200ba5b4aba9 /src | |
| parent | 9e698b720f4f26341db81b70ea5f70f5bdfd9e3a (diff) | |
Add `-build-mode=obj`
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_settings.cpp | 8 | ||||
| -rw-r--r-- | src/checker.cpp | 2 | ||||
| -rw-r--r-- | src/ir.cpp | 8 | ||||
| -rw-r--r-- | src/ir_print.cpp | 12 | ||||
| -rw-r--r-- | src/llvm_backend.cpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 46 |
6 files changed, 48 insertions, 30 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp index d9d810ea4..065f25484 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -81,6 +81,12 @@ struct QueryDataSetSettings { bool compact; }; +enum BuildModeKind { + BuildMode_Executable, + BuildMode_DynamicLibrary, + BuildMode_Object, +}; + // This stores the information for the specify architecture of this build struct BuildContext { @@ -114,7 +120,7 @@ struct BuildContext { String llc_flags; String target_triplet; String link_flags; - bool is_dll; + BuildModeKind build_mode; bool generate_docs; i32 optimization_level; bool show_timings; diff --git a/src/checker.cpp b/src/checker.cpp index 323adac2a..d58cb1fde 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -4131,7 +4131,7 @@ void check_parsed_files(Checker *c) { TIME_SECTION("check entry point"); - if (!build_context.is_dll) { + if (build_context.build_mode == BuildMode_Executable) { Scope *s = c->info.init_scope; GB_ASSERT(s != nullptr); GB_ASSERT(s->flags&ScopeFlag_Init); diff --git a/src/ir.cpp b/src/ir.cpp index c01876b5d..2cc7270cb 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -12137,7 +12137,7 @@ void ir_gen_tree(irGen *s) { #if defined(GB_SYSTEM_WINDOWS) - if (build_context.is_dll && !has_dll_main) { + if (build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main) { // DllMain :: proc(inst: rawptr, reason: u32, reserved: rawptr) -> i32 String name = str_lit("DllMain"); Type *proc_params = alloc_type_tuple(); @@ -12208,7 +12208,7 @@ void ir_gen_tree(irGen *s) { ir_emit_return(proc, v_one32); } #endif - if (!(build_context.is_dll && !has_dll_main)) { + if (!(build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main)) { // main :: proc(argc: i32, argv: ^^u8) -> i32 String name = str_lit("main"); @@ -12287,7 +12287,7 @@ void ir_gen_tree(irGen *s) { } #if defined(GB_SYSTEM_WINDOWS) - // if (!m->build_context->is_dll && !has_win_main) { + // if (m->build_context->build_mode != BuildMode_DynamicLibrary && !has_win_main) { // // proc WinMain(inst, prev: rawptr, cmd_line: ^byte, cmd_show: i32) -> i32 // String name = str_lit("WinMain"); // Type *proc_params = alloc_type_tuple(); @@ -12331,7 +12331,7 @@ void ir_gen_tree(irGen *s) { // ir_emit_return(proc, v_one32); // ir_end_procedure_body(proc); // } - if (!build_context.is_dll && build_context.no_crt) { + if (build_context.build_mode != BuildMode_DynamicLibrary && build_context.no_crt) { s->print_chkstk = true; { diff --git a/src/ir_print.cpp b/src/ir_print.cpp index ebb729420..6d7148eab 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -2382,10 +2382,8 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) { } else { ir_write_byte(f, '\n'); ir_write_str_lit(f, "define "); - if (build_context.is_dll) { - if (proc->is_export) { - ir_write_str_lit(f, "dllexport "); - } + if (proc->is_export) { + ir_write_str_lit(f, "dllexport "); } // if (!proc->is_export && !proc->is_foreign && !proc->is_entry_point) { // ir_write_string(f, "internal "); @@ -2735,10 +2733,8 @@ void print_llvm_ir(irGen *ir) { if (g->is_foreign) { ir_write_string(f, str_lit("external ")); } - if (build_context.is_dll) { - if (g->is_export) { - ir_write_string(f, str_lit("dllexport ")); - } + if (g->is_export) { + ir_write_string(f, str_lit("dllexport ")); } if (g->is_private) { diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index c308f5746..302f7af91 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -11594,7 +11594,7 @@ void lb_generate_code(lbGenerator *gen) { }*/ } - if (!(build_context.is_dll && !has_dll_main)) { + if (!(build_context.build_mode == BuildMode_DynamicLibrary && !has_dll_main)) { Type *params = alloc_type_tuple(); Type *results = alloc_type_tuple(); diff --git a/src/main.cpp b/src/main.cpp index b1158b08e..c2c3ed2b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -195,7 +195,7 @@ i32 linker_stage(lbGenerator *gen) { - if (build_context.is_dll) { + if (build_context.build_mode == BuildMode_DynamicLibrary) { output_ext = "dll"; link_settings = gb_string_append_fmt(link_settings, " /DLL"); } else { @@ -346,7 +346,7 @@ i32 linker_stage(lbGenerator *gen) { String output_ext = {}; char const *link_settings = ""; char const *linker; - if (build_context.is_dll) { + if (build_context.build_mode == BuildMode_DynamicLibrary) { // Shared libraries are .dylib on MacOS and .so on Linux. #if defined(GB_SYSTEM_OSX) output_ext = STR_LIT(".dylib"); @@ -969,9 +969,11 @@ bool parse_build_flags(Array<String> args) { } if (str == "dll" || str == "shared") { - build_context.is_dll = true; + build_context.build_mode = BuildMode_DynamicLibrary; + } else if (str == "obj" || str == "object") { + build_context.build_mode = BuildMode_Object; } else if (str == "exe") { - build_context.is_dll = false; + build_context.build_mode = BuildMode_Executable; } else { gb_printf_err("Unknown build mode '%.*s'\n", LIT(str)); bad_flags = true; @@ -1208,12 +1210,14 @@ void remove_temp_files(String output_base) { } while (0) EXT_REMOVE(".ll"); EXT_REMOVE(".bc"); -#if defined(GB_SYSTEM_WINDOWS) - EXT_REMOVE(".obj"); - EXT_REMOVE(".res"); -#else - EXT_REMOVE(".o"); -#endif + if (build_context.build_mode != BuildMode_Object) { + #if defined(GB_SYSTEM_WINDOWS) + EXT_REMOVE(".obj"); + EXT_REMOVE(".res"); + #else + EXT_REMOVE(".o"); + #endif + } #undef EXT_REMOVE } @@ -1602,9 +1606,11 @@ int main(int arg_count, char const **arg_ptr) { } lb_generate_code(&gen); - i32 linker_stage_exit_count = linker_stage(&gen); - if (linker_stage_exit_count != 0) { - return linker_stage_exit_count; + if (build_context.build_mode != BuildMode_Object) { + i32 linker_stage_exit_count = linker_stage(&gen); + if (linker_stage_exit_count != 0) { + return linker_stage_exit_count; + } } if (build_context.show_timings) { @@ -1697,6 +1703,16 @@ int main(int arg_count, char const **arg_ptr) { return exit_code; } + if (build_context.build_mode == BuildMode_Object) { + // Ignore the linker + if (build_context.show_timings) { + show_timings(&checker, timings); + } + + remove_temp_files(output_base); + return exit_code; + } + if (build_context.cross_compiling && selected_target_metrics->metrics == &target_essence_amd64) { #ifdef GB_SYSTEM_UNIX system_exec_command_line_app("linker", "x86_64-essence-gcc \"%.*s.o\" -o \"%.*s\" %.*s", @@ -1752,7 +1768,7 @@ int main(int arg_count, char const **arg_ptr) { - if (build_context.is_dll) { + if (build_context.build_mode == BuildMode_DynamicLibrary) { output_ext = "dll"; link_settings = gb_string_append_fmt(link_settings, "/DLL"); } else { @@ -1904,7 +1920,7 @@ int main(int arg_count, char const **arg_ptr) { String output_ext = {}; char const *link_settings = ""; char const *linker; - if (build_context.is_dll) { + if (build_context.build_mode == BuildMode_DynamicLibrary) { // Shared libraries are .dylib on MacOS and .so on Linux. #if defined(GB_SYSTEM_OSX) output_ext = STR_LIT(".dylib"); |