diff --git a/dmd/mars.c b/dmd/mars.c index dc49a9dd..491211ba 100644 --- a/dmd/mars.c +++ b/dmd/mars.c @@ -231,9 +231,6 @@ int main(int argc, char *argv[]) Module *m; int status = EXIT_SUCCESS; int argcstart = argc; - char* tt_arch = 0; - char* tt_os = 0; - char* data_layout = 0; bool very_verbose = false; // Check for malformed input @@ -312,24 +309,15 @@ int main(int argc, char *argv[]) VersionCondition::addPredefinedGlobalIdent("LLVMDC"); #endif + // setup default target os to be build os #if _WIN32 - VersionCondition::addPredefinedGlobalIdent("Windows"); - VersionCondition::addPredefinedGlobalIdent("Win32"); - VersionCondition::addPredefinedGlobalIdent("mingw32"); - global.params.isWindows = 1; - tt_os = "-pc-mingw32"; + global.params.os = OSWindows; #elif linux - VersionCondition::addPredefinedGlobalIdent("linux"); - global.params.isLinux = 1; - tt_os = "-pc-linux-gnu"; + global.params.os = OSLinux; #else #error #endif /* linux */ - // !win32 == posix for now - if (!global.params.isWindows) - VersionCondition::addPredefinedGlobalIdent("Posix"); - //VersionCondition::addPredefinedGlobalIdent("D_Bits"); VersionCondition::addPredefinedGlobalIdent("all"); @@ -700,8 +688,8 @@ int main(int argc, char *argv[]) global.params.isLE = true; global.params.is64bit = false; global.params.cpu = ARCHx86; - tt_arch = "i686"; - data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64"; + global.params.tt_arch = "i686"; + global.params.data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64"; if (global.params.useInlineAsm) { VersionCondition::addPredefinedGlobalIdent("D_InlineAsm"); VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86"); @@ -712,24 +700,24 @@ int main(int argc, char *argv[]) global.params.isLE = true; global.params.is64bit = true; global.params.cpu = ARCHx86_64; - tt_arch = "x86_64"; - data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; + global.params.tt_arch = "x86_64"; + global.params.data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; } else if (strcmp(global.params.llvmArch,"ppc32")==0) { VersionCondition::addPredefinedGlobalIdent("PPC"); global.params.isLE = false; global.params.is64bit = false; global.params.cpu = ARCHppc; - tt_arch = "powerpc"; - data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"; + global.params.tt_arch = "powerpc"; + global.params.data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"; } else if (strcmp(global.params.llvmArch,"ppc64")==0) { VersionCondition::addPredefinedGlobalIdent("PPC64"); global.params.isLE = false; global.params.is64bit = true; global.params.cpu = ARCHppc_64; - tt_arch = "powerpc64"; - data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; + global.params.tt_arch = "powerpc64"; + global.params.data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; } else { assert(0 && "Invalid arch"); @@ -750,12 +738,27 @@ int main(int argc, char *argv[]) VersionCondition::addPredefinedGlobalIdent("LLVM64"); } - assert(tt_arch != 0); - assert(tt_os != 0); - assert(data_layout != 0); - global.params.tt_arch = tt_arch; - global.params.tt_os = tt_os; - global.params.data_layout = data_layout; + + // setup version idents and tt_os for chosen target os + switch(global.params.os) + { + case OSWindows: + VersionCondition::addPredefinedGlobalIdent("Windows"); + VersionCondition::addPredefinedGlobalIdent("Win32"); + VersionCondition::addPredefinedGlobalIdent("mingw32"); + global.params.tt_os = "-pc-mingw32"; + break; + + case OSLinux: + VersionCondition::addPredefinedGlobalIdent("linux"); + VersionCondition::addPredefinedGlobalIdent("Posix"); + global.params.tt_os = "-pc-linux-gnu"; + break; + + default: + assert(false && "Target OS not supported"); + } + // Initialization Type::init(); diff --git a/dmd/mars.h b/dmd/mars.h index 1c22a997..bd8ff6ec 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -37,6 +37,22 @@ struct Array; +// LLVMDC +enum ARCH +{ + ARCHx86, + ARCHx86_64, + ARCHppc, + ARCHppc_64 +}; + +enum OS +{ + OSLinux, + OSWindows, + OSMacOSX +}; + // Put command line switches in here struct Param { @@ -48,11 +64,10 @@ struct Param char symdebug; // insert debug symbolic information char optimize; // run optimizer char optimizeLevel; // optimization level - char cpu; // target CPU + ARCH cpu; // target CPU + OS os; // target OS char is64bit; // generate 64 bit code char isLE; // generate little endian code - char isLinux; // generate code for linux - char isWindows; // generate code for Windows char scheduler; // which scheduler to use char useDeprecated; // allow use of deprecated features char useAssert; // generate runtime code for assert()'s @@ -305,15 +320,6 @@ enum MATCH MATCHexact // exact match }; -// LLVMDC -enum ARCH -{ - ARCHx86, - ARCHx86_64, - ARCHppc, - ARCHppc_64 -}; - void error(Loc loc, const char *format, ...); void verror(Loc loc, const char *format, va_list); void fatal(); diff --git a/gen/linker.cpp b/gen/linker.cpp index 2654b586..399c0a39 100644 --- a/gen/linker.cpp +++ b/gen/linker.cpp @@ -72,7 +72,7 @@ int linkExecutable(const char* argv0) else exestr = "a.out"; } - if (global.params.isWindows) + if (global.params.os == OSWindows) exestr.append(".exe"); std::string outopt = "-o=" + exestr; @@ -151,13 +151,13 @@ int linkExecutable(const char* argv0) } // default libs - if(global.params.isLinux) + if(global.params.os == OSLinux) { args.push_back("-lpthread"); args.push_back("-ldl"); args.push_back("-lm"); } - else if (global.params.isWindows) + else if (global.params.os == OSWindows) { // FIXME: I'd assume kernel32 etc } @@ -174,12 +174,11 @@ int linkExecutable(const char* argv0) std::string runtime_path(global.params.runtimePath); // path seperator can be \ on windows, but we check for / - if (global.params.isWindows) - { - int i=0; - while ((i = runtime_path.find("\\", i)) > 0) - runtime_path.replace(i, 1, "/"); - } +#if _WIN32 + int i=0; + while ((i = runtime_path.find("\\", i)) > 0) + runtime_path.replace(i, 1, "/"); +#endif if (*runtime_path.rbegin() != '/') runtime_path.append("/"); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index c4fded43..de4f0a7c 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -705,7 +705,7 @@ const LLStructType* DtoMutexType() return gIR->mutexType; // win32 - if (global.params.isWindows) + if (global.params.os == OSWindows) { // CRITICAL_SECTION.sizeof == 68 std::vector types(17, LLType::Int32Ty);