diff --git a/src/build/build_options.c b/src/build/build_options.c index cdd8a4794..668371b1c 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -114,6 +114,8 @@ static void usage(void) OUTPUT(" --emit-llvm - Emit LLVM IR as a .ll file per module."); OUTPUT(" --asm-out - Override asm output directory for '--emit-asm'."); OUTPUT(" --emit-asm - Emit asm as a .s file per module."); + OUTPUT(" --no-obj - Do not output object files, this is only valid for `compile-only`."); + OUTPUT(" --no-stdlib-codegen - Do not output object files (nor asm or ir) for the standard library."); OUTPUT(" --target - Compile for a particular architecture + OS target."); OUTPUT(" --threads - Set the number of threads to use for compilation."); OUTPUT(" --safe - Set mode to 'safe', generating runtime traps on overflows and contract violations."); @@ -585,6 +587,16 @@ static void parse_option(BuildOptions *options) OUTPUT("C3 is low level programming language based on C."); exit_compiler(COMPILER_SUCCESS_EXIT); } + if (match_longopt("no-obj")) + { + options->no_obj = true; + return; + } + if (match_longopt("no-stdlib-codegen")) + { + options->no_stdlib_gen = true; + return; + } if (match_longopt("debug-log")) { debug_log = true; @@ -871,7 +883,6 @@ BuildOptions parse_arguments(int argc, const char *argv[]) BuildOptions build_options = { .path = ".", .emit_llvm = false, - .emit_bitcode = true, .optimization_setting_override = OPT_SETTING_NOT_SET, .debug_info_override = DEBUG_INFO_NOT_SET, .safe_mode = -1, diff --git a/src/build/build_options.h b/src/build/build_options.h index 80812c16d..edb929816 100644 --- a/src/build/build_options.h +++ b/src/build/build_options.h @@ -321,11 +321,12 @@ typedef struct BuildOptions_ int safe_mode; bool emit_llvm; bool emit_asm; - bool emit_bitcode; bool test_mode; bool no_stdlib; bool no_entry; bool no_libc; + bool no_obj; + bool no_stdlib_gen; bool force_linker; bool read_stdin; bool print_output; @@ -422,6 +423,7 @@ typedef struct bool read_stdin; bool print_output; bool no_entry; + bool no_stdlibgen; int build_threads; OptimizationLevel optimization_level; MemoryEnvironment memory_environment; diff --git a/src/build/builder.c b/src/build/builder.c index 7d2ce7836..a71751f2e 100644 --- a/src/build/builder.c +++ b/src/build/builder.c @@ -302,6 +302,11 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions * target->emit_asm = false; target->emit_object_files = false; } + if (options->no_obj) + { + target->emit_object_files = false; + } + target->no_stdlibgen = options->no_stdlib_gen; for (int i = 0; i < options->lib_dir_count; i++) { vec_add(target->libdirs, options->lib_dir[i]); diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index e8caec440..426b58237 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -484,21 +484,29 @@ void compiler_compile(void) printf("Program finished with exit code %d.\n", ret); } } - if (output_static) + else if (output_static) { if (!static_lib_linker(output_static, obj_files, output_file_count)) { error_exit("Failed to produce static library '%s'.", output_static); } + compiler_link_time = bench_mark(); + compiler_print_bench(); printf("Static library '%s' created.", output_static); } - if (output_dynamic) + else if (output_dynamic) { if (!dynamic_lib_linker(output_dynamic, obj_files, output_file_count)) { error_exit("Failed to produce static library '%s'.", output_dynamic); } printf("Dynamic library '%s' created.", output_dynamic); + compiler_link_time = bench_mark(); + compiler_print_bench(); + } + else + { + compiler_print_bench(); } free(obj_files); } diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index e23e6a497..b7ec7358a 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -1265,9 +1265,21 @@ LLVMMetadataRef llvm_get_debug_file(GenContext *c, FileId file_id) return file; } +static bool module_is_stdlib(Module *module) +{ + if (module->name->len < 3) return false; + if (module->name->len == 3 && strcmp(module->name->module, "std") == 0) return true; + if (module->name->len > 5 && memcmp(module->name->module, "std::", 5) == 0) return true; + if (module->name->len == 4 && strcmp(module->name->module, "libc") == 0) return true; + if (module->name->len > 6 && memcmp(module->name->module, "libc::", 6) == 0) return true; + return false; +} + static GenContext *llvm_gen_module(Module *module, LLVMContextRef shared_context) { if (!vec_size(module->units)) return NULL; + if (active_target.no_stdlibgen && module_is_stdlib(module)) return NULL; + assert(intrinsics_setup); bool has_elements = false; diff --git a/src/version.h b/src/version.h index 4346e2e67..78d716cb7 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.523" \ No newline at end of file +#define COMPILER_VERSION "0.4.524" \ No newline at end of file