added gcc driver

This commit is contained in:
Sven Vogel 2024-07-18 23:00:38 +02:00
parent 7cfbeb085d
commit 9786abc212
4 changed files with 62 additions and 2 deletions

42
src/link/gcc/driver.c Normal file
View File

@ -0,0 +1,42 @@
//
// Created by servostar on 18.07.24.
//
#include <link/clang/driver.h>
#include <io/files.h>
#include <mem/cache.h>
bool gcc_link(TargetLinkConfig* config) {
GString* commandString = g_string_new("");
g_string_append(commandString, "gcc");
for (guint i = 0; i < config->object_file_names->len; i++) {
g_string_append(commandString, " ");
g_string_append(commandString, g_array_index(config->object_file_names, char*, i));
}
g_string_append(commandString, " -o ");
g_string_append(commandString, config->output_file);
print_message(Info, "invoking binary link with: %s", commandString->str);
if (system(commandString->str)) {
return false;
}
g_string_free(commandString, true);
return true;
}
BinaryDriver* gcc_get_driver() {
BinaryDriver* driver = mem_alloc(MemoryNamespaceLld, sizeof (BinaryDriver));
driver->name = "gcc";
driver->link_func = &gcc_link;
return driver;
}

14
src/link/gcc/driver.h Normal file
View File

@ -0,0 +1,14 @@
//
// Created by servostar on 18.07.24.
//
#ifndef GEMSTONE_GCC_DRIVER_H
#define GEMSTONE_GCC_DRIVER_H
#include <link/driver.h>
bool gcc_link(TargetLinkConfig* config);
BinaryDriver* gcc_get_driver();
#endif // GEMSTONE_GCC_DRIVER_H

View File

@ -7,8 +7,12 @@
#include <sys/log.h> #include <sys/log.h>
#include <io/files.h> #include <io/files.h>
#include <link/clang/driver.h>
#include <link/gcc/driver.h>
static driver_init AVAILABLE_DRIVER[] = { static driver_init AVAILABLE_DRIVER[] = {
clang_get_driver clang_get_driver,
gcc_get_driver
}; };
static GHashTable* binary_driver = NULL; static GHashTable* binary_driver = NULL;

View File

@ -5,7 +5,7 @@
#ifndef GEMSTONE_LIB_H #ifndef GEMSTONE_LIB_H
#define GEMSTONE_LIB_H #define GEMSTONE_LIB_H
#include <link/clang/driver.h> #include <link/driver.h>
typedef BinaryDriver* (*driver_init)(); typedef BinaryDriver* (*driver_init)();