X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=driver%2Ffirm_machine.c;h=7e751040b823b57eae67fb38a90790114aa3c5b3;hb=09964a9e87be1ddf585aef762a0042feff30ce87;hp=23a24833ec4afb7d7318fc3acc2ed79a5376350a;hpb=e8b6008fb191413535961886b0ea73413d0f24d6;p=cparser diff --git a/driver/firm_machine.c b/driver/firm_machine.c index 23a2483..7e75104 100644 --- a/driver/firm_machine.c +++ b/driver/firm_machine.c @@ -2,7 +2,7 @@ #include #include -#include "firm_os.h" +#include "firm_machine.h" #include "adt/strutil.h" #include "adt/xmalloc.h" #include @@ -14,21 +14,52 @@ static void set_be_option(const char *arg) assert(res); } +static ir_entity *underscore_compilerlib_entity_creator(ident *id, ir_type *mt) +{ + ir_entity *entity = new_entity(get_glob_type(), id, mt); + ident *ldname = id_mangle3("_", id, ""); + + set_entity_visibility(entity, ir_visibility_external); + set_entity_ld_ident(entity, ldname); + + return entity; +} + +bool firm_is_unixish_os(const machine_triple_t *machine) +{ + const char *os = machine->operating_system; + return strstr(os, "linux") != NULL || strstr(os, "bsd") != NULL + || strstart(os, "solaris"); +} + +bool firm_is_darwin_os(const machine_triple_t *machine) +{ + const char *os = machine->operating_system; + return strstart(os, "darwin"); +} + +bool firm_is_windows_os(const machine_triple_t *machine) +{ + const char *os = machine->operating_system; + return strstart(os, "mingw") || streq(os, "win32"); +} + /** * Initialize firm codegeneration for a specific operating system. * The argument is the operating system part of a target-triple */ -static bool setup_os_support(const char *os) +static bool setup_os_support(const machine_triple_t *machine) { - if (strstr(os, "linux") != NULL || strstr(os, "bsd") != NULL - || streq(os, "solaris")) { + if (firm_is_unixish_os(machine)) { set_be_option("ia32-gasmode=elf"); - } else if (streq(os, "darwin")) { + } else if (firm_is_darwin_os(machine)) { set_be_option("ia32-gasmode=macho"); set_be_option("ia32-stackalign=4"); set_be_option("pic=true"); - } else if (strstr(os, "mingw") != NULL || streq(os, "win32")) { + set_compilerlib_entity_creator(underscore_compilerlib_entity_creator); + } else if (firm_is_windows_os(machine)) { set_be_option("ia32-gasmode=mingw"); + set_compilerlib_entity_creator(underscore_compilerlib_entity_creator); } else { return false; } @@ -67,7 +98,7 @@ bool setup_firm_for_machine(const machine_triple_t *machine) } /* process operating system */ - if (!setup_os_support(machine->operating_system)) { + if (!setup_os_support(machine)) { fprintf(stderr, "Unknown operating system '%s' in target-triple\n", machine->operating_system); return false; } @@ -119,7 +150,7 @@ machine_triple_t *firm_parse_machine_triple(const char *triple_string) machine_triple_t *triple = XMALLOCZ(machine_triple_t); - size_t cpu_type_len = manufacturer-cpu+1; + size_t cpu_type_len = manufacturer-cpu; triple->cpu_type = XMALLOCN(char, cpu_type_len); memcpy(triple->cpu_type, cpu, cpu_type_len-1); triple->cpu_type[cpu_type_len-1] = '\0'; @@ -130,7 +161,7 @@ machine_triple_t *firm_parse_machine_triple(const char *triple_string) triple->manufacturer = xstrdup("unknown"); os = manufacturer; } else { - size_t manufacturer_len = os-manufacturer+1; + size_t manufacturer_len = os-manufacturer; triple->manufacturer = XMALLOCN(char, manufacturer_len); memcpy(triple->manufacturer, manufacturer, manufacturer_len-1); triple->manufacturer[manufacturer_len-1] = '\0';