Removed redundant global.params.os field.

I hope I have untangled the checks for "native" Windows (Triple::Win32)
vs. Windows/MinGW/Cygwin (Triple::isOSWindows) correctly.

MinGW needs some default libraries as well, has to be fixed later.
This commit is contained in:
David Nadlinger 2013-02-07 17:13:24 +01:00
parent 4e02f41f31
commit d4b391249d
15 changed files with 71 additions and 59 deletions

View file

@ -181,7 +181,6 @@ struct Param
#endif #endif
char vtls; // identify thread local variables char vtls; // identify thread local variables
// KN Start merge conflict // KN Start merge conflict
OS os; // target OS
bool is64bit; // generate 64 bit code bool is64bit; // generate 64 bit code
bool useDeprecated; // allow use of deprecated features bool useDeprecated; // allow use of deprecated features
bool useAssert; // generate runtime code for assert()'s bool useAssert; // generate runtime code for assert()'s

View file

@ -168,6 +168,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
#endif #endif
} }
#if IN_LLVM
File* Module::buildFilePath(const char* forcename, const char* path, const char* ext) File* Module::buildFilePath(const char* forcename, const char* path, const char* ext)
{ {
const char *argobj; const char *argobj;
@ -219,7 +220,6 @@ File* Module::buildFilePath(const char* forcename, const char* path, const char*
return new File(FileName::forceExt(argobj, ext)); return new File(FileName::forceExt(argobj, ext));
} }
// LDC
static void check_and_add_output_file(Module* NewMod, const std::string& str) static void check_and_add_output_file(Module* NewMod, const std::string& str)
{ {
typedef std::map<std::string, Module*> map_t; typedef std::map<std::string, Module*> map_t;
@ -252,7 +252,8 @@ void Module::buildTargetFiles(bool singleObj)
else if (global.params.output_s) else if (global.params.output_s)
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext); objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext);
else else
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.params.os == OSWindows ? global.obj_ext_alt : global.obj_ext); objfile = Module::buildFilePath(global.params.objname, global.params.objdir,
global.params.targetTriple.isOSWindows() ? global.obj_ext_alt : global.obj_ext);
} }
if(doDocComment && !docfile) if(doDocComment && !docfile)
docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext); docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
@ -285,6 +286,7 @@ void Module::buildTargetFiles(bool singleObj)
if (hdrfile) if (hdrfile)
check_and_add_output_file(this, hdrfile->name->str); check_and_add_output_file(this, hdrfile->name->str);
} }
#endif
void Module::deleteObjFile() void Module::deleteObjFile()
{ {

View file

@ -671,11 +671,18 @@ enum LINK Parser::parseLinkage()
} }
else if (id == Id::System) else if (id == Id::System)
{ {
// LDC we configure target at runtime #if IN_LLVM
if (global.params.os == OSWindows) if (global.params.targetTriple.isOSWindows())
link = LINKwindows; link = LINKwindows;
else else
link = LINKc; link = LINKc;
#else
#if _WIN32
link = LINKwindows;
#else
link = LINKc;
#endif
#endif
} }
else else
{ {

View file

@ -47,9 +47,9 @@ int os_critsecsize()
// Return sizeof(RTL_CRITICAL_SECTION) // Return sizeof(RTL_CRITICAL_SECTION)
return global.params.is64bit ? 40 : 24; return global.params.is64bit ? 40 : 24;
#else #else
if (global.params.os == OSWindows) if (global.params.targetTriple.isOSWindows())
return global.params.is64bit ? 40 : 24; return global.params.is64bit ? 40 : 24;
else if (global.params.os == OSFreeBSD) else if (global.params.targetTriple.getOS() == llvm::Triple::FreeBSD)
return sizeof(size_t); return sizeof(size_t);
else else
return sizeof(pthread_mutex_t); return sizeof(pthread_mutex_t);

View file

@ -154,17 +154,6 @@ enum OUTPUTFLAG
OUTPUTFLAGset // for -output OUTPUTFLAGset // for -output
}; };
enum OS
{
OSinvalid = llvm::Triple::UnknownOS,
OSLinux = llvm::Triple::Linux,
OSHaiku = llvm::Triple::Haiku,
OSWindows = llvm::Triple::Win32,
OSMacOSX = llvm::Triple::MacOSX,
OSFreeBSD = llvm::Triple::FreeBSD,
OSSolaris = llvm::Triple::Solaris,
};
typedef unsigned char ubyte; typedef unsigned char ubyte;
#endif #endif
@ -190,9 +179,7 @@ struct Param
#endif #endif
char map; // generate linker .map file char map; // generate linker .map file
bool is64bit; // generate 64 bit code bool is64bit; // generate 64 bit code
#if IN_LLVM #if !IN_LLVM
OS os;
#else
char isLinux; // generate code for linux char isLinux; // generate code for linux
char isOSX; // generate code for Mac OSX char isOSX; // generate code for Mac OSX
char isWindows; // generate code for Windows char isWindows; // generate code for Windows

View file

@ -357,7 +357,8 @@ void Module::buildTargetFiles(bool singleObj)
if(!objfile) if(!objfile)
{ {
if (global.params.output_o) if (global.params.output_o)
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.params.os == OSWindows ? global.obj_ext_alt : global.obj_ext); objfile = Module::buildFilePath(global.params.objname, global.params.objdir,
global.params.targetTriple.isOSWindows() ? global.obj_ext_alt : global.obj_ext);
else if (global.params.output_bc) else if (global.params.output_bc)
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext); objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
else if (global.params.output_ll) else if (global.params.output_ll)

View file

@ -980,11 +980,18 @@ enum LINK Parser::parseLinkage()
} }
else if (id == Id::System) else if (id == Id::System)
{ {
// LDC we configure target at runtime #if IN_LLVM
if (global.params.os == OSWindows) if (global.params.targetTriple.isOSWindows())
link = LINKwindows; link = LINKwindows;
else else
link = LINKc; link = LINKc;
#else
#if _WIN32
link = LINKwindows;
#else
link = LINKc;
#endif
#endif
} }
else else
{ {

View file

@ -44,9 +44,9 @@ int os_critsecsize()
// Return sizeof(RTL_CRITICAL_SECTION) // Return sizeof(RTL_CRITICAL_SECTION)
return global.params.is64bit ? 40 : 24; return global.params.is64bit ? 40 : 24;
#else #else
if (global.params.os == OSWindows) if (global.params.targetTriple.isOSWindows())
return global.params.is64bit ? 40 : 24; return global.params.is64bit ? 40 : 24;
else if (global.params.os == OSFreeBSD) else if (global.params.targetTriple.getOS() == llvm::Triple::FreeBSD)
return sizeof(size_t); return sizeof(size_t);
else else
return sizeof(pthread_mutex_t); return sizeof(pthread_mutex_t);

View file

@ -220,32 +220,30 @@ int linkObjToBinaryGcc(bool sharedLib)
// default libs // default libs
bool addSoname = false; bool addSoname = false;
switch(global.params.os) { switch (global.params.targetTriple.getOS()) {
case OSLinux: case llvm::Triple::Linux:
addSoname = true; addSoname = true;
args.push_back("-lrt"); args.push_back("-lrt");
// fallthrough // fallthrough
case OSMacOSX: case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
args.push_back("-ldl"); args.push_back("-ldl");
// fallthrough // fallthrough
case OSFreeBSD: case llvm::Triple::FreeBSD:
addSoname = true; addSoname = true;
args.push_back("-lpthread"); args.push_back("-lpthread");
args.push_back("-lm"); args.push_back("-lm");
break; break;
case OSSolaris: case llvm::Triple::Solaris:
args.push_back("-lm"); args.push_back("-lm");
args.push_back("-lumem"); args.push_back("-lumem");
// solaris TODO // solaris TODO
break; break;
case OSWindows:
// FIXME: I'd assume kernel32 etc
break;
default: default:
// OS not yet handled, will probably lead to linker errors. // OS not yet handled, will probably lead to linker errors.
// FIXME: Win32, MinGW.
break; break;
} }

View file

@ -590,7 +590,6 @@ int main(int argc, char** argv)
// Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit(); // Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit();
global.params.is64bit = gDataLayout->getPointerSizeInBits(ADDRESS_SPACE) == 64; global.params.is64bit = gDataLayout->getPointerSizeInBits(ADDRESS_SPACE) == 64;
global.params.os = static_cast<OS>(global.params.targetTriple.getOS());
switch (global.params.targetTriple.getArch()) switch (global.params.targetTriple.getArch())
{ {
@ -681,7 +680,6 @@ int main(int argc, char** argv)
VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32"); VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32");
break; break;
case llvm::Triple::MinGW32: case llvm::Triple::MinGW32:
global.params.os = OSWindows; // FIXME: Check source for uses of MinGW32
VersionCondition::addPredefinedGlobalIdent("Windows"); VersionCondition::addPredefinedGlobalIdent("Windows");
VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32"); VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32");
VersionCondition::addPredefinedGlobalIdent("mingw32"); // For backwards compatibility. VersionCondition::addPredefinedGlobalIdent("mingw32"); // For backwards compatibility.
@ -701,7 +699,6 @@ int main(int argc, char** argv)
VersionCondition::addPredefinedGlobalIdent("Posix"); VersionCondition::addPredefinedGlobalIdent("Posix");
break; break;
case llvm::Triple::Darwin: case llvm::Triple::Darwin:
global.params.os = OSMacOSX;
VersionCondition::addPredefinedGlobalIdent("OSX"); VersionCondition::addPredefinedGlobalIdent("OSX");
VersionCondition::addPredefinedGlobalIdent("darwin"); // For backwards compatibility. VersionCondition::addPredefinedGlobalIdent("darwin"); // For backwards compatibility.
VersionCondition::addPredefinedGlobalIdent("Posix"); VersionCondition::addPredefinedGlobalIdent("Posix");
@ -746,7 +743,7 @@ int main(int argc, char** argv)
#undef XSTR #undef XSTR
#undef STR #undef STR
if (global.params.os == OSWindows) { if (global.params.targetTriple.isOSWindows()) {
global.dll_ext = "dll"; global.dll_ext = "dll";
global.lib_ext = "lib"; global.lib_ext = "lib";
} else { } else {

View file

@ -1838,8 +1838,12 @@ namespace AsmParserx8664
} }
// osx needs an extra underscore // osx needs an extra underscore
if ( global.params.os == OSMacOSX || global.params.os == OSWindows ) if ( global.params.targetTriple.getOS() == llvm::Triple::MacOSX ||
global.params.targetTriple.getOS() == llvm::Triple::Darwin ||
global.params.targetTriple.isOSWindows() )
{
insnTemplate << "_"; insnTemplate << "_";
}
// print out the mangle // print out the mangle
insnTemplate << vd->mangle(); insnTemplate << vd->mangle();
@ -2512,8 +2516,12 @@ namespace AsmParserx8664
use_star = false; use_star = false;
// simply write out the mangle // simply write out the mangle
// on osx and windows, prepend extra _ // on osx and windows, prepend extra _
if ( global.params.os == OSMacOSX || global.params.os == OSWindows ) if ( global.params.targetTriple.getOS() == llvm::Triple::MacOSX ||
global.params.targetTriple.getOS() == llvm::Triple::Darwin ||
global.params.targetTriple.isOSWindows() )
{
insnTemplate << "_"; insnTemplate << "_";
}
insnTemplate << decl->mangle(); insnTemplate << decl->mangle();
// addOperand2("${", ":c}", Arg_Pointer, e, asmcode); // addOperand2("${", ":c}", Arg_Pointer, e, asmcode);
} }

View file

@ -38,13 +38,12 @@ LLType* DtoComplexBaseType(Type* t)
case Tcomplex32: return LLType::getFloatTy(gIR->context()); case Tcomplex32: return LLType::getFloatTy(gIR->context());
case Tcomplex64: return LLType::getDoubleTy(gIR->context()); case Tcomplex64: return LLType::getDoubleTy(gIR->context());
case Tcomplex80: case Tcomplex80:
if ((global.params.targetTriple.getArch() == llvm::Triple::x86) || llvm::Triple::ArchType const a = global.params.targetTriple.getArch();
global.params.targetTriple.getArch() == llvm::Triple::x86_64) if (a == llvm::Triple::x86 || a == llvm::Triple::x86_64)
{ {
return LLType::getX86_FP80Ty(gIR->context()); return LLType::getX86_FP80Ty(gIR->context());
} }
else if (global.params.targetTriple.getArch() == llvm::Triple::ppc || else if (a == llvm::Triple::ppc || a == llvm::Triple::ppc64)
global.params.targetTriple.getArch() == llvm::Triple::ppc64)
{ {
return LLType::getPPC_FP128Ty(gIR->context()); return LLType::getPPC_FP128Ty(gIR->context());
} }

View file

@ -127,9 +127,13 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
const char* mangle = fd->mangle(); const char* mangle = fd->mangle();
std::ostringstream tmpstr; std::ostringstream tmpstr;
bool const isWin = global.params.targetTriple.isOSWindows();
bool const isOSX = (global.params.targetTriple.getOS() == llvm::Triple::Darwin ||
global.params.targetTriple.getOS() == llvm::Triple::MacOSX);
// osx is different // osx is different
// also mangling has an extra underscore prefixed // also mangling has an extra underscore prefixed
if (global.params.os == OSMacOSX) if (isOSX)
{ {
std::string section = "text"; std::string section = "text";
bool weak = false; bool weak = false;
@ -159,10 +163,11 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
{ {
linkage = "weak"; linkage = "weak";
tmpstr << "section\t.gnu.linkonce.t."; tmpstr << "section\t.gnu.linkonce.t.";
if (global.params.os != OSWindows) if (!isWin)
{ {
tmpstr << mangle << ",\"ax\",@progbits"; tmpstr << mangle << ",\"ax\",@progbits";
} else }
else
{ {
tmpstr << "_" << mangle << ",\"ax\""; tmpstr << "_" << mangle << ",\"ax\"";
} }
@ -171,7 +176,7 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
asmstr << "\t." << section << std::endl; asmstr << "\t." << section << std::endl;
asmstr << "\t.align\t16" << std::endl; asmstr << "\t.align\t16" << std::endl;
if (global.params.os == OSWindows) if (isWin)
{ {
std::string def = "def"; std::string def = "def";
std::string endef = "endef"; std::string endef = "endef";
@ -179,7 +184,8 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
// hard code these two numbers for now since gas ignores .scl and llvm // hard code these two numbers for now since gas ignores .scl and llvm
// is defaulting to .type 32 for everything I have seen // is defaulting to .type 32 for everything I have seen
asmstr << "\t.scl 2; .type 32;\t" << "." << endef << std::endl; asmstr << "\t.scl 2; .type 32;\t" << "." << endef << std::endl;
} else }
else
{ {
asmstr << "\t." << linkage << "\t" << mangle << std::endl; asmstr << "\t." << linkage << "\t" << mangle << std::endl;
asmstr << "\t.type\t" << mangle << ",@function" << std::endl; asmstr << "\t.type\t" << mangle << ",@function" << std::endl;
@ -199,7 +205,7 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
// emit size after body // emit size after body
// llvm does this on linux, but not on osx or Win // llvm does this on linux, but not on osx or Win
if (global.params.os != OSMacOSX && global.params.os != OSWindows) if (!(isWin || isOSX))
{ {
asmstr << "\t.size\t" << mangle << ", .-" << mangle << std::endl << std::endl; asmstr << "\t.size\t" << mangle << ", .-" << mangle << std::endl << std::endl;
} }

View file

@ -59,17 +59,18 @@ TypeFunction* DtoTypeFunction(DValue* fnval)
llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l) llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l)
{ {
llvm::Triple::ArchType const arch = global.params.targetTriple.getArch();
if (l == LINKc || l == LINKcpp || l == LINKintrinsic) if (l == LINKc || l == LINKcpp || l == LINKintrinsic)
return llvm::CallingConv::C; return llvm::CallingConv::C;
else if (l == LINKd || l == LINKdefault) else if (l == LINKd || l == LINKdefault)
{ {
//TODO: StdCall is not a good base on Windows due to extra name mangling //TODO: StdCall is not a good base on Windows due to extra name mangling
// applied there // applied there
if (global.params.targetTriple.getArch() == llvm::Triple::x86 || if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
global.params.targetTriple.getArch() == llvm::Triple::x86_64)
{ {
return (global.params.os != OSWindows) ? return global.params.targetTriple.isOSWindows() ?
llvm::CallingConv::X86_StdCall : llvm::CallingConv::C; llvm::CallingConv::C : llvm::CallingConv::X86_StdCall;
} }
else else
return llvm::CallingConv::Fast; return llvm::CallingConv::Fast;
@ -78,7 +79,7 @@ llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l)
// On Windows 64bit, there is only one calling convention! // On Windows 64bit, there is only one calling convention!
else if (l == LINKwindows) else if (l == LINKwindows)
{ {
return (global.params.targetTriple.getArch() == llvm::Triple::x86_64) ? return (arch == llvm::Triple::x86_64) ?
llvm::CallingConv::C : llvm::CallingConv::X86_StdCall; llvm::CallingConv::C : llvm::CallingConv::X86_StdCall;
} }
else if (l == LINKpascal) else if (l == LINKpascal)

View file

@ -965,7 +965,7 @@ LLStructType* DtoMutexType()
// The structures defined here must be the same as in druntime/src/rt/critical.c // The structures defined here must be the same as in druntime/src/rt/critical.c
// Windows // Windows
if (global.params.os == OSWindows) if (global.params.targetTriple.isOSWindows())
{ {
llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context()); llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context());
llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context()); llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context());
@ -993,7 +993,7 @@ LLStructType* DtoMutexType()
} }
// FreeBSD // FreeBSD
else if (global.params.os == OSFreeBSD) { else if (global.params.targetTriple.getOS() == llvm::Triple::FreeBSD) {
// Just a pointer // Just a pointer
return LLStructType::get(gIR->context(), DtoSize_t()); return LLStructType::get(gIR->context(), DtoSize_t());
} }