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
char vtls; // identify thread local variables
// KN Start merge conflict
OS os; // target OS
bool is64bit; // generate 64 bit code
bool useDeprecated; // allow use of deprecated features
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
}
#if IN_LLVM
File* Module::buildFilePath(const char* forcename, const char* path, const char* ext)
{
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));
}
// LDC
static void check_and_add_output_file(Module* NewMod, const std::string& str)
{
typedef std::map<std::string, Module*> map_t;
@ -252,7 +252,8 @@ void Module::buildTargetFiles(bool singleObj)
else if (global.params.output_s)
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.s_ext);
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)
docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
@ -285,6 +286,7 @@ void Module::buildTargetFiles(bool singleObj)
if (hdrfile)
check_and_add_output_file(this, hdrfile->name->str);
}
#endif
void Module::deleteObjFile()
{

View file

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

View file

@ -47,9 +47,9 @@ int os_critsecsize()
// Return sizeof(RTL_CRITICAL_SECTION)
return global.params.is64bit ? 40 : 24;
#else
if (global.params.os == OSWindows)
if (global.params.targetTriple.isOSWindows())
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);
else
return sizeof(pthread_mutex_t);

View file

@ -154,17 +154,6 @@ enum OUTPUTFLAG
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;
#endif
@ -190,9 +179,7 @@ struct Param
#endif
char map; // generate linker .map file
bool is64bit; // generate 64 bit code
#if IN_LLVM
OS os;
#else
#if !IN_LLVM
char isLinux; // generate code for linux
char isOSX; // generate code for Mac OSX
char isWindows; // generate code for Windows

View file

@ -357,7 +357,8 @@ void Module::buildTargetFiles(bool singleObj)
if(!objfile)
{
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)
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
else if (global.params.output_ll)

View file

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

View file

@ -44,9 +44,9 @@ int os_critsecsize()
// Return sizeof(RTL_CRITICAL_SECTION)
return global.params.is64bit ? 40 : 24;
#else
if (global.params.os == OSWindows)
if (global.params.targetTriple.isOSWindows())
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);
else
return sizeof(pthread_mutex_t);

View file

@ -220,32 +220,30 @@ int linkObjToBinaryGcc(bool sharedLib)
// default libs
bool addSoname = false;
switch(global.params.os) {
case OSLinux:
switch (global.params.targetTriple.getOS()) {
case llvm::Triple::Linux:
addSoname = true;
args.push_back("-lrt");
// fallthrough
case OSMacOSX:
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
args.push_back("-ldl");
// fallthrough
case OSFreeBSD:
case llvm::Triple::FreeBSD:
addSoname = true;
args.push_back("-lpthread");
args.push_back("-lm");
break;
case OSSolaris:
case llvm::Triple::Solaris:
args.push_back("-lm");
args.push_back("-lumem");
// solaris TODO
break;
case OSWindows:
// FIXME: I'd assume kernel32 etc
break;
default:
// OS not yet handled, will probably lead to linker errors.
// FIXME: Win32, MinGW.
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();
global.params.is64bit = gDataLayout->getPointerSizeInBits(ADDRESS_SPACE) == 64;
global.params.os = static_cast<OS>(global.params.targetTriple.getOS());
switch (global.params.targetTriple.getArch())
{
@ -681,7 +680,6 @@ int main(int argc, char** argv)
VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32");
break;
case llvm::Triple::MinGW32:
global.params.os = OSWindows; // FIXME: Check source for uses of MinGW32
VersionCondition::addPredefinedGlobalIdent("Windows");
VersionCondition::addPredefinedGlobalIdent(global.params.is64bit ? "Win64" : "Win32");
VersionCondition::addPredefinedGlobalIdent("mingw32"); // For backwards compatibility.
@ -701,7 +699,6 @@ int main(int argc, char** argv)
VersionCondition::addPredefinedGlobalIdent("Posix");
break;
case llvm::Triple::Darwin:
global.params.os = OSMacOSX;
VersionCondition::addPredefinedGlobalIdent("OSX");
VersionCondition::addPredefinedGlobalIdent("darwin"); // For backwards compatibility.
VersionCondition::addPredefinedGlobalIdent("Posix");
@ -746,7 +743,7 @@ int main(int argc, char** argv)
#undef XSTR
#undef STR
if (global.params.os == OSWindows) {
if (global.params.targetTriple.isOSWindows()) {
global.dll_ext = "dll";
global.lib_ext = "lib";
} else {

View file

@ -1838,8 +1838,12 @@ namespace AsmParserx8664
}
// 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 << "_";
}
// print out the mangle
insnTemplate << vd->mangle();
@ -2512,8 +2516,12 @@ namespace AsmParserx8664
use_star = false;
// simply write out the mangle
// 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 << decl->mangle();
// addOperand2("${", ":c}", Arg_Pointer, e, asmcode);
}

View file

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

View file

@ -127,9 +127,13 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
const char* mangle = fd->mangle();
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
// also mangling has an extra underscore prefixed
if (global.params.os == OSMacOSX)
if (isOSX)
{
std::string section = "text";
bool weak = false;
@ -159,10 +163,11 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
{
linkage = "weak";
tmpstr << "section\t.gnu.linkonce.t.";
if (global.params.os != OSWindows)
if (!isWin)
{
tmpstr << mangle << ",\"ax\",@progbits";
} else
}
else
{
tmpstr << "_" << mangle << ",\"ax\"";
}
@ -171,7 +176,7 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
asmstr << "\t." << section << std::endl;
asmstr << "\t.align\t16" << std::endl;
if (global.params.os == OSWindows)
if (isWin)
{
std::string def = "def";
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
// is defaulting to .type 32 for everything I have seen
asmstr << "\t.scl 2; .type 32;\t" << "." << endef << std::endl;
} else
}
else
{
asmstr << "\t." << linkage << "\t" << mangle << std::endl;
asmstr << "\t.type\t" << mangle << ",@function" << std::endl;
@ -199,7 +205,7 @@ void DtoDefineNakedFunction(FuncDeclaration* fd)
// emit size after body
// 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;
}

View file

@ -59,17 +59,18 @@ TypeFunction* DtoTypeFunction(DValue* fnval)
llvm::CallingConv::ID DtoCallingConv(Loc loc, LINK l)
{
llvm::Triple::ArchType const arch = global.params.targetTriple.getArch();
if (l == LINKc || l == LINKcpp || l == LINKintrinsic)
return llvm::CallingConv::C;
else if (l == LINKd || l == LINKdefault)
{
//TODO: StdCall is not a good base on Windows due to extra name mangling
// applied there
if (global.params.targetTriple.getArch() == llvm::Triple::x86 ||
global.params.targetTriple.getArch() == llvm::Triple::x86_64)
if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
{
return (global.params.os != OSWindows) ?
llvm::CallingConv::X86_StdCall : llvm::CallingConv::C;
return global.params.targetTriple.isOSWindows() ?
llvm::CallingConv::C : llvm::CallingConv::X86_StdCall;
}
else
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!
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;
}
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
// Windows
if (global.params.os == OSWindows)
if (global.params.targetTriple.isOSWindows())
{
llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context());
llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context());
@ -993,7 +993,7 @@ LLStructType* DtoMutexType()
}
// FreeBSD
else if (global.params.os == OSFreeBSD) {
else if (global.params.targetTriple.getOS() == llvm::Triple::FreeBSD) {
// Just a pointer
return LLStructType::get(gIR->context(), DtoSize_t());
}