added list-driver option

This commit is contained in:
Sven Vogel 2024-07-18 22:50:37 +02:00
parent 11594bf44c
commit 7cfbeb085d
5 changed files with 32 additions and 2 deletions

View File

@ -268,6 +268,7 @@ void print_help(void) {
" --debug print debug logs (if not disabled at compile time)", " --debug print debug logs (if not disabled at compile time)",
" --version print the version", " --version print the version",
" --list-targets print a list of all available targets supported", " --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", " --help print this help dialog",
" --color-always always colorize output", " --color-always always colorize output",
" --print-gc-stats print statistics of the garbage collector" " --print-gc-stats print statistics of the garbage collector"

View File

@ -356,8 +356,6 @@ static void build_project(ModuleFileStack *unit) {
void run_compiler() { void run_compiler() {
ModuleFileStack files = new_file_stack(); ModuleFileStack files = new_file_stack();
link_init();
if (is_option_set("build")) { if (is_option_set("build")) {
build_project(&files); build_project(&files);
} else if (is_option_set("compile")) { } else if (is_option_set("compile")) {

View File

@ -21,9 +21,17 @@ void link_init() {
for (unsigned long int i = 0; i < sizeof(AVAILABLE_DRIVER)/sizeof(driver_init); i++) { for (unsigned long int i = 0; i < sizeof(AVAILABLE_DRIVER)/sizeof(driver_init); i++) {
BinaryDriver* driver = AVAILABLE_DRIVER[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); g_hash_table_insert(binary_driver, (gpointer) driver->name, driver);
INFO("initialized `%s` driver", driver->name); INFO("initialized `%s` driver", driver->name);
} }
} else {
PANIC("binary driver already initialized");
} }
} }
@ -45,3 +53,16 @@ bool link_run(TargetLinkConfig* config) {
return false; 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);
}
}

View File

@ -13,4 +13,6 @@ void link_init();
bool link_run(TargetLinkConfig*); bool link_run(TargetLinkConfig*);
void link_print_available_driver();
#endif //GEMSTONE_LIB_H #endif //GEMSTONE_LIB_H

View File

@ -7,6 +7,7 @@
#include <compiler.h> #include <compiler.h>
#include <llvm/parser.h> #include <llvm/parser.h>
#include <mem/cache.h> #include <mem/cache.h>
#include <link/lib.h>
/** /**
* @brief Log a debug message to inform about beginning exit procedures * @brief Log a debug message to inform about beginning exit procedures
@ -38,6 +39,8 @@ void setup(int argc, char *argv[]) {
lex_init(); lex_init();
link_init();
DEBUG("finished starting up gemstone..."); DEBUG("finished starting up gemstone...");
} }
@ -64,6 +67,11 @@ int main(int argc, char *argv[]) {
exit(0); exit(0);
} }
if (is_option_set("list-driver")) {
link_print_available_driver();
exit(0);
}
run_compiler(); run_compiler();
if (is_option_set("print-gc-stats")) { if (is_option_set("print-gc-stats")) {