From 130a36e4e56a9f2804ac746a8556146ce212f8a3 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 2 Apr 2008 23:22:55 +0000 Subject: [PATCH] - fixed ld_name for Win32 and Mach-O - add options -f mac, -f linux - set the default mode depending on the host OS [r19082] --- ast2firm.c | 55 ++++++++++++++++++++++++++++++++++--------- driver/firm_cmdline.c | 18 +++++++------- driver/firm_cmdline.h | 3 ++- main.c | 5 +++- 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/ast2firm.c b/ast2firm.c index 9232a52..7db20e2 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -43,6 +43,10 @@ #define MAGIC_DEFAULT_PN_NUMBER (long) -314159265 +/* some idents needed for name mangling */ +static ident *id_underscore; +static ident *id_imp; + static ir_type *ir_type_const_char; static ir_type *ir_type_wchar_t; static ir_type *ir_type_void; @@ -931,8 +935,8 @@ static const struct { /** * Mangles an entity linker (ld) name for win32 usage. * - * @param ent the entity to be mangled - * @param decl_modifiers the set of modifiers for this entity + * @param ent the entity to be mangled + * @param declaration the declaration */ static ident *create_ld_ident_win32(ir_entity *ent, declaration_t *declaration) { @@ -942,34 +946,46 @@ static ident *create_ld_ident_win32(ir_entity *ent, declaration_t *declaration) id = decorate_win32_c_fkt(ent, get_entity_ident(ent)); else { /* always add an underscore in win32 */ - id = mangle(new_id_from_chars("_", 1), get_entity_ident(ent)); + id = mangle(id_underscore, get_entity_ident(ent)); } decl_modifiers_t decl_modifiers = declaration->decl_modifiers; if (decl_modifiers & DM_DLLIMPORT) { /* add prefix for imported symbols */ - id = mangle(new_id_from_chars("__imp_", 6), id); + id = mangle(id_imp, id); } return id; } -static ident *create_ld_ident_linux(ir_entity *entity, - declaration_t *declaration) +/** + * Mangles an entity linker (ld) name for Linux ELF usage. + * + * @param ent the entity to be mangled + * @param declaration the declaration + */ +static ident *create_ld_ident_linux_elf(ir_entity *entity, + declaration_t *declaration) { (void) declaration; return get_entity_ident(entity); } +/** + * Mangles an entity linker (ld) name for Mach-O usage. + * + * @param ent the entity to be mangled + * @param declaration the declaration + */ static ident *create_ld_ident_macho(ir_entity *ent, declaration_t *declaration) { (void) declaration; - ident *id = mangle(new_id_from_chars("_", 1), get_entity_ident(ent)); + ident *id = mangle(id_underscore, get_entity_ident(ent)); return id; } typedef ident* (*create_ld_ident_func)(ir_entity *entity, declaration_t *declaration); -create_ld_ident_func create_ld_ident = create_ld_ident_linux; +create_ld_ident_func create_ld_ident = create_ld_ident_linux_elf; static ir_entity* get_function_entity(declaration_t *declaration) { @@ -4821,9 +4837,26 @@ void init_ast2firm(void) obstack_init(&asm_obst); init_atomic_modes(); - (void) create_ld_ident_win32; - (void) create_ld_ident_linux; - (void) create_ld_ident_macho; + id_underscore = new_id_from_chars("_", 1); + id_imp = new_id_from_chars("__imp_", 6); + + /* OS option must be set to the backend */ + const char *s = "ia32-gasmode=linux"; + switch (firm_opt.os_support) { + case OS_SUPPORT_WIN32: + create_ld_ident = create_ld_ident_win32; + s = "ia32-gasmode=mingw"; + break; + case OS_SUPPORT_LINUX: + create_ld_ident = create_ld_ident_linux_elf; + s = "ia32-gasmode=linux"; break; + break; + case OS_SUPPORT_MACHO: + create_ld_ident = create_ld_ident_macho; + s = "ia32-gasmode=macho"; break; + break; + } + firm_be_option(s); /* create idents for all known runtime functions */ for (size_t i = 0; i < sizeof(rts_data) / sizeof(rts_data[0]); ++i) { diff --git a/driver/firm_cmdline.c b/driver/firm_cmdline.c index 955813d..c7f563b 100644 --- a/driver/firm_cmdline.c +++ b/driver/firm_cmdline.c @@ -12,6 +12,12 @@ #include #include +#ifdef _WIN32 +#define DEFAULT_OS OS_SUPPORT_WIN32 +#else +#define DEFAULT_OS OS_SUPPORT_LINUX +#endif + /* optimization settings */ struct a_firm_opt firm_opt = { /* enabled = */ TRUE, @@ -56,7 +62,7 @@ struct a_firm_opt firm_opt = { /* vrfy = */ FIRM_VERIFICATION_ON, /* check_all = */ FALSE, /* lower = */ TRUE, - /* os_support = */ OS_SUPPORT_LINUX, + /* os_support = */ DEFAULT_OS, /* honor_restrict = */ TRUE, /* lower_bitfields = */ TRUE, /* pic = */ FALSE, @@ -239,7 +245,9 @@ static const struct params { { X("stat-pattern"), &firm_dump.stat_pattern, 1, "misc: Firm statistic calculates most used pattern" }, { X("stat-dag"), &firm_dump.stat_dag, 1, "misc: Firm calculates DAG statistics" }, { X("firm-asm"), &firm_dump.gen_firm_asm, 1, "misc: output Firm assembler" }, - { X("win32"), &firm_opt.os_support, OS_SUPPORT_MINGW, "misc: generate MinGW code" }, + { X("win32"), &firm_opt.os_support, OS_SUPPORT_WIN32, "misc: generate Win32 code" }, + { X("mac"), &firm_opt.os_support, OS_SUPPORT_MACHO, "misc: generate MacOS code" }, + { X("linux"), &firm_opt.os_support, OS_SUPPORT_LINUX, "misc: generate Linux-ELF code" }, { X("ycomp"), &firm_opt.ycomp_dbg, 1, "misc: enable yComp debugger extension" }, { X("ycomp-host="), NULL, 0, "misc: yComp host" }, { X("ycomp-port="), NULL, 0, "misc: yComp port" }, @@ -371,12 +379,6 @@ int firm_option(const char *opt) #endif /* FIRM_BACKEND */ return res; } -#ifdef FIRM_BACKEND - /* OS option must be set to the backend */ - else if (firm_options[i].flag == &firm_opt.os_support) - firm_be_option(firm_opt.os_support == OS_SUPPORT_MINGW ? - "ia32-gasmode=mingw" : "ia32-gasmode=linux"); -#endif /* FIRM_BACKEND */ break; } } diff --git a/driver/firm_cmdline.h b/driver/firm_cmdline.h index 79e54a4..12ea3a5 100644 --- a/driver/firm_cmdline.h +++ b/driver/firm_cmdline.h @@ -14,7 +14,8 @@ enum an_os_support { OS_SUPPORT_LINUX, /**< create code for Linux OS */ - OS_SUPPORT_MINGW /**< create code for MinGW WIN32 */ + OS_SUPPORT_WIN32, /**< create code for MinGW WIN32 */ + OS_SUPPORT_MACHO } an_os_support; enum a_debug_mode { diff --git a/main.c b/main.c index 25564fb..b2e48dd 100644 --- a/main.c +++ b/main.c @@ -656,7 +656,10 @@ int main(int argc, char **argv) break; case CompileAssembleLink: #ifdef _WIN32 - outname = "a.exe"; + /* Windows compiler typically derive the output name from + the first source file */ + get_output_name(outnamebuf, sizeof(outnamebuf), input, ".exe"); + outname = outnamebuf; #else outname = "a.out"; #endif -- 2.20.1