chore: run clang format
This commit is contained in:
parent
fb055a5225
commit
d2d70edb06
|
@ -5,12 +5,15 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/log.h>
|
||||
|
||||
bool AST_annotation_array_contains_flag(AST_Annotation* haystack, const char* needle) {
|
||||
bool AST_annotation_array_contains_flag(AST_Annotation* haystack,
|
||||
const char* needle) {
|
||||
if (haystack->kind == AnnotationKindArray) {
|
||||
for (guint i = 0; i < haystack->impl.array->len; i++) {
|
||||
AST_Annotation child = g_array_index(haystack->impl.array, AST_Annotation, i);
|
||||
AST_Annotation child =
|
||||
g_array_index(haystack->impl.array, AST_Annotation, i);
|
||||
|
||||
if (child.kind == AnnotationKindFlag && strcmp(child.impl.flag, needle) == 0) {
|
||||
if (child.kind == AnnotationKindFlag
|
||||
&& strcmp(child.impl.flag, needle) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -232,8 +235,8 @@ void AST_delete_node(struct AST_Node_t* node) {
|
|||
DEBUG("Deleting AST node: %p", node);
|
||||
|
||||
if (node->parent != NULL) {
|
||||
[[maybe_unused]] const struct AST_Node_t* child =
|
||||
AST_detach_child(node->parent, node);
|
||||
[[maybe_unused]]
|
||||
const struct AST_Node_t* child = AST_detach_child(node->parent, node);
|
||||
assert(child == node);
|
||||
}
|
||||
|
||||
|
@ -284,8 +287,8 @@ static void AST_fprint_graphviz_node_definition(FILE* stream,
|
|||
assert(node != NULL);
|
||||
|
||||
char* module_path = module_ref_to_str(node->location.module_ref);
|
||||
fprintf(stream, "\tnode%p [label=\"@%s\\n%s\"]\n", (void*) node, module_path,
|
||||
AST_node_to_string(node));
|
||||
fprintf(stream, "\tnode%p [label=\"@%s\\n%s\"]\n", (void*) node,
|
||||
module_path, AST_node_to_string(node));
|
||||
|
||||
if (node->children == NULL) {
|
||||
return;
|
||||
|
@ -367,7 +370,8 @@ void AST_import_module(AST_NODE_PTR dst, size_t k, AST_NODE_PTR src) {
|
|||
switch (node->kind) {
|
||||
case AST_FunDef:
|
||||
{
|
||||
AST_NODE_PTR decl = AST_new_node(node->location, AST_FunDecl, NULL);
|
||||
AST_NODE_PTR decl =
|
||||
AST_new_node(node->location, AST_FunDecl, NULL);
|
||||
|
||||
for (int u = 0; u < node->children->len - 1; u++) {
|
||||
AST_push_node(decl, AST_get_node(node, u));
|
||||
|
@ -378,7 +382,8 @@ void AST_import_module(AST_NODE_PTR dst, size_t k, AST_NODE_PTR src) {
|
|||
}
|
||||
case AST_ProcDef:
|
||||
{
|
||||
AST_NODE_PTR decl = AST_new_node(node->location, AST_ProcDecl, NULL);
|
||||
AST_NODE_PTR decl =
|
||||
AST_new_node(node->location, AST_ProcDecl, NULL);
|
||||
|
||||
for (int u = 0; u < node->children->len - 1; u++) {
|
||||
AST_push_node(decl, AST_get_node(node, u));
|
||||
|
|
103
src/cfg/opt.c
103
src/cfg/opt.c
|
@ -44,43 +44,36 @@ const char* ENV_ANDROID = "android";
|
|||
const char* ENV_MACHO = "macho";
|
||||
const char* ENV_ELF = "elf";
|
||||
|
||||
bool target_has_shared_dependency(TargetLinkConfig* config)
|
||||
{
|
||||
bool target_has_shared_dependency(TargetLinkConfig* config) {
|
||||
bool has_shared = false;
|
||||
|
||||
const char* shared_files[] = {
|
||||
".so",
|
||||
".dll"
|
||||
};
|
||||
const char* shared_files[] = {".so", ".dll"};
|
||||
|
||||
for (guint i = 0; i < config->object_file_names->len; i++)
|
||||
{
|
||||
for (guint i = 0; i < config->object_file_names->len; i++) {
|
||||
char* object_file = g_array_index(config->object_file_names, char*, i);
|
||||
|
||||
for (int k = 0; k < sizeof(shared_files)/sizeof(char*); k++)
|
||||
{
|
||||
for (int k = 0; k < sizeof(shared_files) / sizeof(char*); k++) {
|
||||
has_shared = g_str_has_suffix(object_file, shared_files[k]);
|
||||
if (has_shared)
|
||||
if (has_shared) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (has_shared)
|
||||
if (has_shared) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return has_shared;
|
||||
}
|
||||
|
||||
const char* find_string(const char* haystack, const char** options, size_t size)
|
||||
{
|
||||
const char* find_string(const char* haystack, const char** options,
|
||||
size_t size) {
|
||||
const static char* found = NULL;
|
||||
|
||||
if (haystack != NULL)
|
||||
{
|
||||
for (size_t i = 0; i < size/sizeof(const char*); i++)
|
||||
{
|
||||
if (strstr(haystack, options[i]))
|
||||
{
|
||||
if (haystack != NULL) {
|
||||
for (size_t i = 0; i < size / sizeof(const char*); i++) {
|
||||
if (strstr(haystack, options[i])) {
|
||||
found = options[i];
|
||||
break;
|
||||
}
|
||||
|
@ -90,65 +83,36 @@ const char* find_string(const char* haystack, const char** options, size_t size)
|
|||
return found;
|
||||
}
|
||||
|
||||
const char* extract_arch_from_triple(const char* triple)
|
||||
{
|
||||
const char* known_archs[] = {
|
||||
ARCH_X86_64,
|
||||
ARCH_I386,
|
||||
ARCH_ARM,
|
||||
ARCH_THUMB,
|
||||
ARCH_MIPS
|
||||
};
|
||||
const char* extract_arch_from_triple(const char* triple) {
|
||||
const char* known_archs[] = {ARCH_X86_64, ARCH_I386, ARCH_ARM, ARCH_THUMB,
|
||||
ARCH_MIPS};
|
||||
|
||||
return find_string(triple, known_archs, sizeof(known_archs));
|
||||
}
|
||||
|
||||
const char* extract_sub_from_triple(const char* triple)
|
||||
{
|
||||
const char* known_subs[] = {
|
||||
SUB_V5,
|
||||
SUB_V6M,
|
||||
SUB_V7A,
|
||||
SUB_V7M
|
||||
};
|
||||
const char* extract_sub_from_triple(const char* triple) {
|
||||
const char* known_subs[] = {SUB_V5, SUB_V6M, SUB_V7A, SUB_V7M};
|
||||
|
||||
return find_string(triple, known_subs, sizeof(known_subs));
|
||||
}
|
||||
|
||||
const char* extract_vendor_from_triple(const char* triple)
|
||||
{
|
||||
const char* known_subs[] = {
|
||||
VENDOR_PC,
|
||||
VENDOR_APPLE,
|
||||
VENDOR_NVIDIA,
|
||||
VENDOR_IBM
|
||||
};
|
||||
const char* extract_vendor_from_triple(const char* triple) {
|
||||
const char* known_subs[] = {VENDOR_PC, VENDOR_APPLE, VENDOR_NVIDIA,
|
||||
VENDOR_IBM};
|
||||
|
||||
return find_string(triple, known_subs, sizeof(known_subs));
|
||||
}
|
||||
|
||||
const char* extract_sys_from_triple(const char* triple)
|
||||
{
|
||||
const char* known_sys[] = {
|
||||
SYS_NONE,
|
||||
SYS_LINUX,
|
||||
SYS_WIN32,
|
||||
SYS_DARWIN,
|
||||
SYS_CUDA
|
||||
};
|
||||
const char* extract_sys_from_triple(const char* triple) {
|
||||
const char* known_sys[] = {SYS_NONE, SYS_LINUX, SYS_WIN32, SYS_DARWIN,
|
||||
SYS_CUDA};
|
||||
|
||||
return find_string(triple, known_sys, sizeof(known_sys));
|
||||
}
|
||||
|
||||
const char* extract_env_from_triple(const char* triple)
|
||||
{
|
||||
const char* known_envs[] = {
|
||||
ENV_EABI,
|
||||
ENV_GNU,
|
||||
ENV_ANDROID,
|
||||
ENV_MACHO,
|
||||
ENV_ELF
|
||||
};
|
||||
const char* extract_env_from_triple(const char* triple) {
|
||||
const char* known_envs[] = {ENV_EABI, ENV_GNU, ENV_ANDROID, ENV_MACHO,
|
||||
ENV_ELF};
|
||||
|
||||
return find_string(triple, known_envs, sizeof(known_envs));
|
||||
}
|
||||
|
@ -603,7 +567,8 @@ static int get_mode_from_str(TargetCompilationMode* mode, const char* name) {
|
|||
return PROJECT_SEMANTIC_ERR;
|
||||
}
|
||||
|
||||
static int parse_dependency(Dependency* dependency, toml_table_t* table, char* name) {
|
||||
static int parse_dependency(Dependency* dependency, toml_table_t* table,
|
||||
char* name) {
|
||||
dependency->name = mem_strdup(MemoryNamespaceOpt, name);
|
||||
|
||||
bool is_project = false;
|
||||
|
@ -676,7 +641,8 @@ static int parse_target(const ProjectConfig* config,
|
|||
|
||||
toml_table_t* dependencies = toml_table_in(target_table, "dependencies");
|
||||
if (dependencies) {
|
||||
target_config->dependencies = mem_new_g_hash_table(MemoryNamespaceOpt, g_str_hash, g_str_equal);
|
||||
target_config->dependencies =
|
||||
mem_new_g_hash_table(MemoryNamespaceOpt, g_str_hash, g_str_equal);
|
||||
for (int i = 0; i < toml_table_ntab(dependencies); i++) {
|
||||
char* key = (char*) toml_key_in(dependencies, i);
|
||||
|
||||
|
@ -686,11 +652,14 @@ static int parse_target(const ProjectConfig* config,
|
|||
|
||||
toml_table_t* dependency_table = toml_table_in(dependencies, key);
|
||||
Dependency* dependency = new_dependency();
|
||||
if (parse_dependency(dependency, dependency_table, key) == PROJECT_SEMANTIC_ERR) {
|
||||
if (parse_dependency(dependency, dependency_table, key)
|
||||
== PROJECT_SEMANTIC_ERR) {
|
||||
return PROJECT_SEMANTIC_ERR;
|
||||
}
|
||||
|
||||
g_hash_table_insert(target_config->dependencies, mem_strdup(MemoryNamespaceOpt, key), dependency);
|
||||
g_hash_table_insert(target_config->dependencies,
|
||||
mem_strdup(MemoryNamespaceOpt, key),
|
||||
dependency);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,7 @@ typedef enum TargetCompilationMode_t {
|
|||
Library
|
||||
} TargetCompilationMode;
|
||||
|
||||
typedef enum DependencyKind_t {
|
||||
GemstoneProject,
|
||||
NativeLibrary
|
||||
} DependencyKind;
|
||||
typedef enum DependencyKind_t { GemstoneProject, NativeLibrary } DependencyKind;
|
||||
|
||||
// Possible configuration modes:
|
||||
// - build project (local/git)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <glib.h>
|
||||
#include <io/files.h>
|
||||
#include <lex/util.h>
|
||||
#include <link/lib.h>
|
||||
#include <llvm/backend.h>
|
||||
#include <mem/cache.h>
|
||||
#include <set/set.h>
|
||||
|
@ -17,7 +18,6 @@
|
|||
#include <sys/log.h>
|
||||
#include <unistd.h>
|
||||
#include <yacc/parser.tab.h>
|
||||
#include <link/lib.h>
|
||||
|
||||
#define GRAPHVIZ_FILE_EXTENSION "gv"
|
||||
|
||||
|
@ -239,7 +239,8 @@ static int compile_module_with_dependencies(ModuleFileStack* unit,
|
|||
|
||||
if (NULL == module_ref) {
|
||||
module_ref = mem_alloc(MemoryNamespaceOpt, sizeof(ModuleRef));
|
||||
module_ref->module_path = mem_new_g_array(MemoryNamespaceOpt, sizeof(char*));
|
||||
module_ref->module_path =
|
||||
mem_new_g_array(MemoryNamespaceOpt, sizeof(char*));
|
||||
} else {
|
||||
module_ref_push(module_ref, module_from_basename(file->path));
|
||||
}
|
||||
|
@ -262,37 +263,51 @@ static int compile_module_with_dependencies(ModuleFileStack* unit,
|
|||
gchar* cwd = g_get_current_dir();
|
||||
chdir(dependency->mode.project.path);
|
||||
|
||||
ProjectConfig* new_config = default_project_config();
|
||||
ProjectConfig* new_config =
|
||||
default_project_config();
|
||||
if (load_project_config(new_config)) {
|
||||
print_message(Error, "Failed to load project config: `%s`",
|
||||
print_message(
|
||||
Error, "Failed to load project config: `%s`",
|
||||
child->value);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
TargetConfig* dep_target = g_hash_table_lookup(new_config->targets, dependency->mode.project.target);
|
||||
TargetConfig* dep_target = g_hash_table_lookup(
|
||||
new_config->targets,
|
||||
dependency->mode.project.target);
|
||||
if (build_target(unit, dep_target)) {
|
||||
print_message(Error, "Failed to build project config: `%s`",
|
||||
print_message(
|
||||
Error, "Failed to build project config: `%s`",
|
||||
child->value);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
GPathBuf* buf = g_path_buf_new_from_path(dependency->mode.project.path);
|
||||
TargetConfig* dep_conf = g_hash_table_lookup(new_config->targets, dependency->mode.project.target);
|
||||
GPathBuf* buf = g_path_buf_new_from_path(
|
||||
dependency->mode.project.path);
|
||||
TargetConfig* dep_conf = g_hash_table_lookup(
|
||||
new_config->targets,
|
||||
dependency->mode.project.target);
|
||||
char* root_mod = dep_conf->root_module;
|
||||
g_path_buf_push(buf, root_mod);
|
||||
char* rel_path = g_path_buf_to_path(buf);
|
||||
|
||||
GPathBuf* dep_bin = g_path_buf_new();
|
||||
g_path_buf_push(dep_bin, dependency->mode.project.path);
|
||||
g_path_buf_push(dep_bin, dep_conf->archive_directory);
|
||||
char* dep_obj_file = g_strjoin(".", dep_conf->name, "o", NULL);
|
||||
g_path_buf_push(dep_bin,
|
||||
dependency->mode.project.path);
|
||||
g_path_buf_push(dep_bin,
|
||||
dep_conf->archive_directory);
|
||||
char* dep_obj_file =
|
||||
g_strjoin(".", dep_conf->name, "o", NULL);
|
||||
g_path_buf_push(dep_bin, dep_obj_file);
|
||||
char* dep_bin_path = g_path_buf_free_to_path(dep_bin);
|
||||
char* dep_bin_path =
|
||||
g_path_buf_free_to_path(dep_bin);
|
||||
g_free(dep_obj_file);
|
||||
char* cached_dep_bin_path = mem_strdup(MemoryNamespaceLld, dep_bin_path);
|
||||
char* cached_dep_bin_path =
|
||||
mem_strdup(MemoryNamespaceLld, dep_bin_path);
|
||||
g_free(dep_bin_path);
|
||||
|
||||
g_array_append_val(dependency->libraries, cached_dep_bin_path);
|
||||
g_array_append_val(dependency->libraries,
|
||||
cached_dep_bin_path);
|
||||
|
||||
const char* path =
|
||||
get_absolute_import_path(target, rel_path);
|
||||
|
@ -303,12 +318,16 @@ static int compile_module_with_dependencies(ModuleFileStack* unit,
|
|||
}
|
||||
|
||||
ModuleFile* imported_file = push_file(unit, path);
|
||||
AST_NODE_PTR imported_module =
|
||||
AST_new_node(empty_location(imported_file, module_ref), AST_Module, NULL);
|
||||
AST_NODE_PTR imported_module = AST_new_node(
|
||||
empty_location(imported_file, module_ref),
|
||||
AST_Module, NULL);
|
||||
|
||||
if (compile_module_with_dependencies(unit, imported_file, dep_conf, imported_module)
|
||||
if (compile_module_with_dependencies(
|
||||
unit, imported_file, dep_conf,
|
||||
imported_module)
|
||||
== EXIT_SUCCESS) {
|
||||
AST_import_module(root_module, i + 1, imported_module);
|
||||
AST_import_module(root_module, i + 1,
|
||||
imported_module);
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -320,41 +339,52 @@ static int compile_module_with_dependencies(ModuleFileStack* unit,
|
|||
gchar* cached_directory =
|
||||
mem_strdup(MemoryNamespaceLld, directory);
|
||||
g_free(directory);
|
||||
g_array_append_val(target->import_paths, cached_directory);
|
||||
g_array_append_val(target->import_paths,
|
||||
cached_directory);
|
||||
|
||||
chdir(cwd);
|
||||
g_free(cwd);
|
||||
|
||||
GHashTableIter iter;
|
||||
|
||||
g_hash_table_iter_init(&iter, dep_target->dependencies);
|
||||
g_hash_table_iter_init(&iter,
|
||||
dep_target->dependencies);
|
||||
char* key;
|
||||
Dependency* dep;
|
||||
while (g_hash_table_iter_next(&iter, (gpointer) &key, (gpointer) &dep)) {
|
||||
while (g_hash_table_iter_next(
|
||||
&iter, (gpointer) &key, (gpointer) &dep)) {
|
||||
if (dep->kind == GemstoneProject) {
|
||||
for (guint i = 0; i < dep->libraries->len; i++) {
|
||||
char* dep_lib = g_array_index(dep->libraries, char*, i);
|
||||
g_array_append_val(dependency->libraries, dep_lib);
|
||||
for (guint i = 0; i < dep->libraries->len;
|
||||
i++) {
|
||||
char* dep_lib = g_array_index(
|
||||
dep->libraries, char*, i);
|
||||
g_array_append_val(
|
||||
dependency->libraries, dep_lib);
|
||||
}
|
||||
} else if (dep->kind == NativeLibrary) {
|
||||
char* library_name = build_platform_library_name(dep->mode.library.name, dep->mode.library.shared);
|
||||
g_array_append_val(dependency->libraries, library_name);
|
||||
char* library_name =
|
||||
build_platform_library_name(
|
||||
dep->mode.library.name,
|
||||
dep->mode.library.shared);
|
||||
g_array_append_val(dependency->libraries,
|
||||
library_name);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case NativeLibrary:
|
||||
|
||||
char* library_name = build_platform_library_name(dependency->mode.library.name, dependency->mode.library.shared);
|
||||
g_array_append_val(dependency->libraries, library_name);
|
||||
char* library_name = build_platform_library_name(
|
||||
dependency->mode.library.name,
|
||||
dependency->mode.library.shared);
|
||||
g_array_append_val(dependency->libraries,
|
||||
library_name);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
print_message(Error, "Cannot resolve path for import: `%s`",
|
||||
child->value);
|
||||
|
@ -379,8 +409,8 @@ static int compile_module_with_dependencies(ModuleFileStack* unit,
|
|||
module_ref_push(module_ref, module_from_basename(path));
|
||||
|
||||
ModuleFile* imported_file = push_file(unit, path);
|
||||
AST_NODE_PTR imported_module =
|
||||
AST_new_node(empty_location(imported_file, module_ref), AST_Module, NULL);
|
||||
AST_NODE_PTR imported_module = AST_new_node(
|
||||
empty_location(imported_file, module_ref), AST_Module, NULL);
|
||||
|
||||
if (compile_file_to_ast(imported_module, imported_file)
|
||||
== EXIT_SUCCESS) {
|
||||
|
|
|
@ -228,8 +228,8 @@ void print_diagnostic(TokenLocation* location, Message kind,
|
|||
TokenLocation new_location(unsigned long int line_start,
|
||||
unsigned long int col_start,
|
||||
unsigned long int line_end,
|
||||
unsigned long int col_end,
|
||||
ModuleFile* file, ModuleRef* ref) {
|
||||
unsigned long int col_end, ModuleFile* file,
|
||||
ModuleRef* ref) {
|
||||
TokenLocation location;
|
||||
|
||||
location.line_start = line_start;
|
||||
|
|
|
@ -78,8 +78,8 @@ void delete_files(ModuleFileStack* stack);
|
|||
TokenLocation new_location(unsigned long int line_start,
|
||||
unsigned long int col_start,
|
||||
unsigned long int line_end,
|
||||
unsigned long int col_end,
|
||||
ModuleFile* file, ModuleRef* ref);
|
||||
unsigned long int col_end, ModuleFile* file,
|
||||
ModuleRef* ref);
|
||||
|
||||
/**
|
||||
* @brief Create a new empty location with all of its contents set to zero
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
#include <mem/cache.h>
|
||||
#include <sys/log.h>
|
||||
|
||||
static driver_init AVAILABLE_DRIVER[] = {clang_get_driver, gcc_get_driver, lldc_get_driver};
|
||||
static driver_init AVAILABLE_DRIVER[] = {clang_get_driver, gcc_get_driver,
|
||||
lldc_get_driver};
|
||||
|
||||
static GHashTable* binary_driver = NULL;
|
||||
|
||||
|
@ -82,7 +83,8 @@ static const char* get_library_file_extension(bool shared) {
|
|||
}
|
||||
|
||||
char* build_platform_library_name(char* basename, bool shared) {
|
||||
char* library_name = g_strjoin("", "lib", basename, ".", get_library_file_extension(shared), NULL);
|
||||
char* library_name = g_strjoin("", "lib", basename, ".",
|
||||
get_library_file_extension(shared), NULL);
|
||||
char* cached_library_name = mem_strdup(MemoryNamespaceLld, library_name);
|
||||
g_free(library_name);
|
||||
return cached_library_name;
|
||||
|
|
|
@ -10,13 +10,9 @@
|
|||
|
||||
extern int lld_main(int Argc, const char** Argv, const char** outstr);
|
||||
|
||||
const char* FLAGS[] = {
|
||||
"--fatal-warnings",
|
||||
"--nostdlib"
|
||||
};
|
||||
const char* FLAGS[] = {"--fatal-warnings", "--nostdlib"};
|
||||
|
||||
const char* get_optimization_level_string(TargetConfig* config)
|
||||
{
|
||||
const char* get_optimization_level_string(TargetConfig* config) {
|
||||
char* buffer = mem_alloc(MemoryNamespaceLld, 6);
|
||||
|
||||
sprintf(buffer, "-O%d", config->optimization_level);
|
||||
|
@ -37,17 +33,17 @@ bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) {
|
|||
}
|
||||
|
||||
if (link_config->entry != NULL) {
|
||||
char* colored_diagnostics = mem_asprintf(MemoryNamespaceLld, "--entry=%s", link_config->entry);
|
||||
char* colored_diagnostics =
|
||||
mem_asprintf(MemoryNamespaceLld, "--entry=%s", link_config->entry);
|
||||
g_array_append_val(arguments, colored_diagnostics);
|
||||
}
|
||||
|
||||
const char* optimization_level = get_optimization_level_string(target_config);
|
||||
const char* optimization_level =
|
||||
get_optimization_level_string(target_config);
|
||||
g_array_append_val(arguments, optimization_level);
|
||||
|
||||
if (extract_sys_from_triple(target_config->triple) == SYS_LINUX)
|
||||
{
|
||||
if (target_has_shared_dependency(link_config))
|
||||
{
|
||||
if (extract_sys_from_triple(target_config->triple) == SYS_LINUX) {
|
||||
if (target_has_shared_dependency(link_config)) {
|
||||
// add dynamic linker
|
||||
print_message(Info, "Enabling dynamic linker for build");
|
||||
|
||||
|
@ -57,8 +53,11 @@ bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) {
|
|||
const char* default_dynamic_linker_path = "/usr/bin/ld.so";
|
||||
const char* dynamic_linker_option = "--dynamic-linker=";
|
||||
|
||||
char* buffer = mem_alloc(MemoryNamespaceLld, strlen(dynamic_linker_option) + strlen(default_dynamic_linker_path) + 1);
|
||||
sprintf(buffer, "%s%s", dynamic_linker_option, default_dynamic_linker_path);
|
||||
char* buffer = mem_alloc(
|
||||
MemoryNamespaceLld, strlen(dynamic_linker_option)
|
||||
+ strlen(default_dynamic_linker_path) + 1);
|
||||
sprintf(buffer, "%s%s", dynamic_linker_option,
|
||||
default_dynamic_linker_path);
|
||||
g_array_append_val(arguments, buffer);
|
||||
}
|
||||
}
|
||||
|
@ -86,12 +85,14 @@ bool lldc_link(TargetConfig* target_config, TargetLinkConfig* link_config) {
|
|||
char* buffer = mem_alloc(MemoryNamespaceLld, chars + 1);
|
||||
size_t offset = 0;
|
||||
for (guint i = 0; i < arguments->len; i++) {
|
||||
offset += sprintf(buffer + offset, "%s ", g_array_index(arguments, char*, i));
|
||||
offset +=
|
||||
sprintf(buffer + offset, "%s ", g_array_index(arguments, char*, i));
|
||||
}
|
||||
print_message(Info, buffer);
|
||||
|
||||
const char* message = NULL;
|
||||
const bool code = lld_main(arguments->len, (const char**) arguments->data, &message);
|
||||
const bool code =
|
||||
lld_main(arguments->len, (const char**) arguments->data, &message);
|
||||
|
||||
if (!code) {
|
||||
print_message(Error, message);
|
||||
|
@ -113,4 +114,3 @@ BinaryDriver* lldc_get_driver() {
|
|||
|
||||
return driver;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,7 @@ static char* create_target_output_name(const TargetConfig* config) {
|
|||
return cached_name;
|
||||
}
|
||||
|
||||
Target create_target_from_triple(char* triple)
|
||||
{
|
||||
Target create_target_from_triple(char* triple) {
|
||||
Target target;
|
||||
|
||||
target.triple = mem_strdup(MemoryNamespaceLld, triple);
|
||||
|
@ -79,11 +78,9 @@ Target create_target_from_config(TargetConfig* config) {
|
|||
DEBUG("Building target from configuration");
|
||||
|
||||
Target target = create_native_target();
|
||||
if (config->triple != NULL)
|
||||
{
|
||||
if (config->triple != NULL) {
|
||||
target = create_target_from_triple(config->triple);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
config->triple = target.triple;
|
||||
}
|
||||
|
||||
|
@ -91,8 +88,8 @@ Target create_target_from_config(TargetConfig* config) {
|
|||
|
||||
target.opt = llvm_opt_from_int(config->optimization_level);
|
||||
|
||||
INFO("Configured target: %s/%d: (%s) on %s { %s }", target.name,
|
||||
target.opt, target.triple, target.cpu, target.features);
|
||||
INFO("Configured target: %s/%d: (%s) on %s { %s }", target.name, target.opt,
|
||||
target.triple, target.cpu, target.features);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
|
|
@ -99,8 +99,9 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused))
|
|||
|
||||
for (guint k = 0; k < dep->libraries->len; k++) {
|
||||
char* lib = g_array_index(dep->libraries, char*, k);
|
||||
if (lib == NULL)
|
||||
if (lib == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// resolve path to object file
|
||||
if (g_file_test(lib, G_FILE_TEST_EXISTS)) {
|
||||
|
@ -122,7 +123,8 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused))
|
|||
return config;
|
||||
}
|
||||
|
||||
BackendError lld_link_target(TargetConfig* target_config, TargetLinkConfig* config) {
|
||||
BackendError lld_link_target(TargetConfig* target_config,
|
||||
TargetLinkConfig* config) {
|
||||
|
||||
if (link_run(target_config, config)) {
|
||||
return SUCCESS;
|
||||
|
|
|
@ -13,7 +13,8 @@ TargetLinkConfig* lld_create_link_config(__attribute__((unused))
|
|||
const TargetConfig* target_config,
|
||||
const Module* module);
|
||||
|
||||
BackendError lld_link_target(TargetConfig* target_config, TargetLinkConfig* config);
|
||||
BackendError lld_link_target(TargetConfig* target_config,
|
||||
TargetLinkConfig* config);
|
||||
|
||||
void lld_delete_link_config(TargetLinkConfig* config);
|
||||
|
||||
|
|
|
@ -124,8 +124,7 @@ BackendError export_object(LLVMBackendCompileUnit* unit, const Target* target,
|
|||
LLVMInitializeAllAsmPrinters();
|
||||
|
||||
DEBUG("creating target...");
|
||||
if (LLVMGetTargetFromTriple(target->triple, &llvm_target, &error)
|
||||
!= 0) {
|
||||
if (LLVMGetTargetFromTriple(target->triple, &llvm_target, &error) != 0) {
|
||||
ERROR("failed to create target machine: %s", error);
|
||||
err = new_backend_impl_error(Implementation, NULL,
|
||||
"unable to create target machine");
|
||||
|
@ -135,8 +134,8 @@ BackendError export_object(LLVMBackendCompileUnit* unit, const Target* target,
|
|||
|
||||
DEBUG("Creating target machine...");
|
||||
LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(
|
||||
llvm_target, target->triple, target->cpu, target->features,
|
||||
target->opt, target->reloc, target->model);
|
||||
llvm_target, target->triple, target->cpu, target->features, target->opt,
|
||||
target->reloc, target->model);
|
||||
|
||||
print_message(Info, "Generating code for: %s", target->triple);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "cfg/opt.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ast/ast.h>
|
||||
#include <glib.h>
|
||||
|
@ -2649,12 +2650,15 @@ int createFunction(Function* function, AST_NODE_PTR currentNode) {
|
|||
}
|
||||
|
||||
if (!(currentNode->annotation.kind == AnnotationKindArray
|
||||
&& AST_annotation_array_contains_flag(¤tNode->annotation, "nomangle"))) {
|
||||
&& AST_annotation_array_contains_flag(¤tNode->annotation,
|
||||
"nomangle"))) {
|
||||
|
||||
// compose function name by appending parent modules
|
||||
char* modules = module_ref_to_str(currentNode->location.module_ref);
|
||||
char* composed_name = g_strjoin("", modules, "::", function->name, NULL);
|
||||
char* cached_composed_name = mem_strdup(MemoryNamespaceSet, composed_name);
|
||||
char* composed_name =
|
||||
g_strjoin("", modules, "::", function->name, NULL);
|
||||
char* cached_composed_name =
|
||||
mem_strdup(MemoryNamespaceSet, composed_name);
|
||||
|
||||
g_free(composed_name);
|
||||
function->name = cached_composed_name;
|
||||
|
@ -2930,10 +2934,13 @@ Module* create_set(AST_NODE_PTR currentNode) {
|
|||
}
|
||||
|
||||
if (function_node->annotation.kind == AnnotationKindArray) {
|
||||
if (AST_annotation_array_contains_flag(&function_node->annotation, "entry")) {
|
||||
if (AST_annotation_array_contains_flag(
|
||||
&function_node->annotation, "entry")) {
|
||||
|
||||
if (rootModule->entry != NULL) {
|
||||
print_diagnostic(&function_node->location, Error, "Multiple functions marked as entry points");
|
||||
print_diagnostic(
|
||||
&function_node->location, Error,
|
||||
"Multiple functions marked as entry points");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -2941,7 +2948,8 @@ Module* create_set(AST_NODE_PTR currentNode) {
|
|||
}
|
||||
}
|
||||
|
||||
g_hash_table_insert(rootModule->functions, function->name, function);
|
||||
g_hash_table_insert(rootModule->functions, function->name,
|
||||
function);
|
||||
|
||||
DEBUG("created function successfully");
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue