diff --git a/src/cfg/opt.c b/src/cfg/opt.c index b29475d..f5f47aa 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -268,6 +268,7 @@ void print_help(void) { " --debug print debug logs (if not disabled at compile time)", " --version print the version", " --list-targets print a list of all available targets supported", + " --list-driver print a list of all available binary driver", " --help print this help dialog", " --color-always always colorize output", " --print-gc-stats print statistics of the garbage collector" diff --git a/src/compiler.c b/src/compiler.c index 0ca4c9d..103f07d 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -356,8 +356,6 @@ static void build_project(ModuleFileStack *unit) { void run_compiler() { ModuleFileStack files = new_file_stack(); - link_init(); - if (is_option_set("build")) { build_project(&files); } else if (is_option_set("compile")) { diff --git a/src/link/lib.c b/src/link/lib.c index 81ccdb8..15cd7fa 100644 --- a/src/link/lib.c +++ b/src/link/lib.c @@ -21,9 +21,17 @@ void link_init() { for (unsigned long int i = 0; i < sizeof(AVAILABLE_DRIVER)/sizeof(driver_init); i++) { BinaryDriver* driver = AVAILABLE_DRIVER[i](); + + if (driver == NULL) { + ERROR("failed to init driver by index: %d", i); + continue; + } + g_hash_table_insert(binary_driver, (gpointer) driver->name, driver); INFO("initialized `%s` driver", driver->name); } + } else { + PANIC("binary driver already initialized"); } } @@ -45,3 +53,16 @@ bool link_run(TargetLinkConfig* config) { return false; } } + +void link_print_available_driver() { + printf("Available binary driver:\n"); + + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init(&iter, binary_driver); + + while (g_hash_table_iter_next(&iter, &key, &value)) { + + printf(" - %s\n", (char*) key); + } +} diff --git a/src/link/lib.h b/src/link/lib.h index 44dcbde..cf592a1 100644 --- a/src/link/lib.h +++ b/src/link/lib.h @@ -13,4 +13,6 @@ void link_init(); bool link_run(TargetLinkConfig*); +void link_print_available_driver(); + #endif //GEMSTONE_LIB_H diff --git a/src/main.c b/src/main.c index 5b222a4..ea6aef9 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,7 @@ #include #include #include +#include /** * @brief Log a debug message to inform about beginning exit procedures @@ -38,6 +39,8 @@ void setup(int argc, char *argv[]) { lex_init(); + link_init(); + DEBUG("finished starting up gemstone..."); } @@ -64,6 +67,11 @@ int main(int argc, char *argv[]) { exit(0); } + if (is_option_set("list-driver")) { + link_print_available_driver(); + exit(0); + } + run_compiler(); if (is_option_set("print-gc-stats")) {