From 09b3b8618035fdc6ffb2e11bfa0efd1fcce2cb48 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 18 Jul 2024 23:05:41 +0200 Subject: [PATCH] added configuration options for driver --- src/cfg/opt.c | 12 ++++++++++++ src/cfg/opt.h | 2 ++ src/link/driver.h | 2 ++ src/llvm/link/lld.c | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cfg/opt.c b/src/cfg/opt.c index f5f47aa..eb0ab8e 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -9,6 +9,7 @@ #include #include #include +#include static GHashTable* args = NULL; @@ -98,6 +99,7 @@ TargetConfig* default_target_config() { config->print_ast = false; config->print_asm = false; config->print_ir = false; + config->driver = DEFAULT_DRIVER; config->mode = Application; config->archive_directory = mem_strdup(MemoryNamespaceOpt, "archive"); config->output_directory = mem_strdup(MemoryNamespaceOpt, "bin"); @@ -160,6 +162,14 @@ TargetConfig* default_target_config_from_args() { } } + if (is_option_set("driver")) { + const Option* opt = get_option("driver"); + + if (opt->value != NULL) { + config->driver = mem_strdup(MemoryNamespaceOpt, (char*) opt->value); + } + } + // TODO: free vvvvvvvvvvvvv char* cwd = g_get_current_dir(); g_array_append_val(config->link_search_paths, cwd); @@ -259,6 +269,7 @@ void print_help(void) { " --print-ir print resulting LLVM-IR to a file", " --mode=[app|lib] set the compilation mode to either application or library", " --output=name name of output files without extension", + " --driver set binary driver to use", " --link-paths=[paths,] set a list of directories to for libraries in", " --all-fatal-warnings treat all warnings as errors", " --lld-fatal-warnings treat linker warnings as errors", @@ -389,6 +400,7 @@ static int parse_target(const ProjectConfig *config, const toml_table_t *target_ get_bool(&target_config->print_asm, target_table, "print_asm"); get_bool(&target_config->print_ir, target_table, "print_ir"); + get_str(&target_config->driver, target_table, "driver"); get_str(&target_config->root_module, target_table, "root"); get_str(&target_config->output_directory, target_table, "output"); get_str(&target_config->archive_directory, target_table, "archive"); diff --git a/src/cfg/opt.h b/src/cfg/opt.h index e80f91f..5699145 100644 --- a/src/cfg/opt.h +++ b/src/cfg/opt.h @@ -51,6 +51,8 @@ typedef struct TargetConfig_t { char* output_directory; // output directory for intermediate representations (LLVM-IR, Assembly, ...) char* archive_directory; + // binary driver for executable generation + char* driver; // mode of compilation TargetCompilationMode mode; // number between 1 and 3 diff --git a/src/link/driver.h b/src/link/driver.h index f797778..9eba996 100644 --- a/src/link/driver.h +++ b/src/link/driver.h @@ -7,6 +7,8 @@ #include +#define DEFAULT_DRIVER "clang" + //! @brief Function a binary driver used to link files typedef bool (*driver_link)(TargetLinkConfig*); diff --git a/src/llvm/link/lld.c b/src/llvm/link/lld.c index 012c924..5d596c2 100644 --- a/src/llvm/link/lld.c +++ b/src/llvm/link/lld.c @@ -46,7 +46,7 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused)) const Target* t config->fatal_warnings = target_config->lld_fatal_warnings; config->object_file_names = g_array_new(FALSE, FALSE, sizeof(char*)); config->colorize = stdout_supports_ansi_esc(); - config->driver = mem_strdup(MemoryNamespaceLld, "clang"); + config->driver = target_config->driver; // append build object file char* basename = g_strjoin(".", target_config->name, "o", NULL);