Add no-obj and no-stdlib-codegen options.

This commit is contained in:
Christoffer Lerno
2023-06-06 15:22:28 +02:00
parent 8eaad81800
commit 379a5f670f
6 changed files with 43 additions and 5 deletions

View File

@@ -114,6 +114,8 @@ static void usage(void)
OUTPUT(" --emit-llvm - Emit LLVM IR as a .ll file per module.");
OUTPUT(" --asm-out <dir> - 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 <target> - Compile for a particular architecture + OS target.");
OUTPUT(" --threads <number> - 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,

View File

@@ -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;

View File

@@ -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]);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.523"
#define COMPILER_VERSION "0.4.524"