mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-20 06:43:14 +01:00
Take advantage of Triple and TargetData.
A lot of system specific knowledge is already present in LLVM. This is used to populate several fields in global.params instead of hard coded values in main(). Ensures that the frontend and LLVM have always the same values.
This commit is contained in:
36
dmd/mars.h
36
dmd/mars.h
@@ -71,6 +71,10 @@ the target object file format:
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if IN_LLVM
|
||||||
|
#include "llvm/ADT/Triple.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __DMC__
|
#ifdef __DMC__
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#undef assert
|
#undef assert
|
||||||
@@ -140,14 +144,15 @@ struct OutBuffer;
|
|||||||
// LDC
|
// LDC
|
||||||
enum ARCH
|
enum ARCH
|
||||||
{
|
{
|
||||||
ARCHinvalid,
|
ARCHinvalid = llvm::Triple::UnknownArch,
|
||||||
ARCHx86,
|
ARCHx86 = llvm::Triple::x86,
|
||||||
ARCHx86_64,
|
ARCHx86_64 = llvm::Triple::x86_64,
|
||||||
ARCHppc,
|
ARCHppc = llvm::Triple::ppc,
|
||||||
ARCHppc_64,
|
ARCHppc_64 = llvm::Triple::ppc64,
|
||||||
ARCHarm,
|
ARCHarm = llvm::Triple::arm,
|
||||||
ARCHthumb
|
ARCHthumb = llvm::Triple::thumb,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OUTPUTFLAG
|
enum OUTPUTFLAG
|
||||||
{
|
{
|
||||||
OUTPUTFLAGno,
|
OUTPUTFLAGno,
|
||||||
@@ -157,13 +162,13 @@ enum OUTPUTFLAG
|
|||||||
|
|
||||||
enum OS
|
enum OS
|
||||||
{
|
{
|
||||||
OSinvalid,
|
OSinvalid = llvm::Triple::UnknownOS,
|
||||||
OSLinux,
|
OSLinux = llvm::Triple::Linux,
|
||||||
OSHaiku,
|
OSHaiku = llvm::Triple::Haiku,
|
||||||
OSWindows,
|
OSWindows = llvm::Triple::Win32,
|
||||||
OSMacOSX,
|
OSMacOSX = llvm::Triple::MacOSX,
|
||||||
OSFreeBSD,
|
OSFreeBSD = llvm::Triple::FreeBSD,
|
||||||
OSSolaris,
|
OSSolaris = llvm::Triple::Solaris,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned char ubyte;
|
typedef unsigned char ubyte;
|
||||||
@@ -303,8 +308,7 @@ struct Param
|
|||||||
bool useAvailableExternally;
|
bool useAvailableExternally;
|
||||||
|
|
||||||
// target stuff
|
// target stuff
|
||||||
const char* llvmArch;
|
llvm::Triple *targetTriple;
|
||||||
const char *targetTriple;
|
|
||||||
|
|
||||||
// Codegen cl options
|
// Codegen cl options
|
||||||
bool singleObj;
|
bool singleObj;
|
||||||
|
|||||||
36
dmd2/mars.h
36
dmd2/mars.h
@@ -71,6 +71,10 @@ the target object file format:
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if IN_LLVM
|
||||||
|
#include "llvm/ADT/Triple.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __DMC__
|
#ifdef __DMC__
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#undef assert
|
#undef assert
|
||||||
@@ -145,14 +149,15 @@ typedef ArrayBase<char> Strings;
|
|||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
enum ARCH
|
enum ARCH
|
||||||
{
|
{
|
||||||
ARCHinvalid,
|
ARCHinvalid = llvm::Triple::UnknownArch,
|
||||||
ARCHx86,
|
ARCHx86 = llvm::Triple::x86,
|
||||||
ARCHx86_64,
|
ARCHx86_64 = llvm::Triple::x86_64,
|
||||||
ARCHppc,
|
ARCHppc = llvm::Triple::ppc,
|
||||||
ARCHppc_64,
|
ARCHppc_64 = llvm::Triple::ppc64,
|
||||||
ARCHarm,
|
ARCHarm = llvm::Triple::arm,
|
||||||
ARCHthumb
|
ARCHthumb = llvm::Triple::thumb,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OUTPUTFLAG
|
enum OUTPUTFLAG
|
||||||
{
|
{
|
||||||
OUTPUTFLAGno,
|
OUTPUTFLAGno,
|
||||||
@@ -162,13 +167,13 @@ enum OUTPUTFLAG
|
|||||||
|
|
||||||
enum OS
|
enum OS
|
||||||
{
|
{
|
||||||
OSinvalid,
|
OSinvalid = llvm::Triple::UnknownOS,
|
||||||
OSLinux,
|
OSLinux = llvm::Triple::Linux,
|
||||||
OSHaiku,
|
OSHaiku = llvm::Triple::Haiku,
|
||||||
OSWindows,
|
OSWindows = llvm::Triple::Win32,
|
||||||
OSMacOSX,
|
OSMacOSX = llvm::Triple::MacOSX,
|
||||||
OSFreeBSD,
|
OSFreeBSD = llvm::Triple::FreeBSD,
|
||||||
OSSolaris,
|
OSSolaris = llvm::Triple::Solaris,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned char ubyte;
|
typedef unsigned char ubyte;
|
||||||
@@ -271,8 +276,7 @@ struct Param
|
|||||||
bool useAvailableExternally;
|
bool useAvailableExternally;
|
||||||
|
|
||||||
// target stuff
|
// target stuff
|
||||||
const char* llvmArch;
|
llvm::Triple targetTriple;
|
||||||
const char *targetTriple;
|
|
||||||
|
|
||||||
// Codegen cl options
|
// Codegen cl options
|
||||||
bool singleObj;
|
bool singleObj;
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ int linkObjToBinaryWin(bool sharedLib)
|
|||||||
int linkObjToBinary(bool sharedLib)
|
int linkObjToBinary(bool sharedLib)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
if (llvm::Triple(global.params.targetTriple).isOSWindows())
|
if (global.params.targetTriple.getOS() == llvm::Triple::Win32)
|
||||||
status = linkObjToBinaryWin(sharedLib);
|
status = linkObjToBinaryWin(sharedLib);
|
||||||
else
|
else
|
||||||
status = linkObjToBinaryGcc(sharedLib);
|
status = linkObjToBinaryGcc(sharedLib);
|
||||||
@@ -395,7 +395,7 @@ void createStaticLibrary()
|
|||||||
{
|
{
|
||||||
Logger::println("*** Creating static library ***");
|
Logger::println("*** Creating static library ***");
|
||||||
|
|
||||||
const bool isTargetWindows = llvm::Triple(global.params.targetTriple).isOSWindows();
|
const bool isTargetWindows = global.params.targetTriple.getOS() == llvm::Triple::Win32;
|
||||||
|
|
||||||
// find archiver
|
// find archiver
|
||||||
llvm::sys::Path tool = isTargetWindows ? getLib() : getArchiver();
|
llvm::sys::Path tool = isTargetWindows ? getLib() : getArchiver();
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ int main(int argc, char** argv)
|
|||||||
triple = llvm::Triple::normalize(mTargetTriple);
|
triple = llvm::Triple::normalize(mTargetTriple);
|
||||||
}
|
}
|
||||||
|
|
||||||
global.params.targetTriple = triple.c_str();
|
global.params.targetTriple = llvm::Triple(triple);
|
||||||
|
|
||||||
// Allocate target machine.
|
// Allocate target machine.
|
||||||
const llvm::Target *theTarget = NULL;
|
const llvm::Target *theTarget = NULL;
|
||||||
@@ -566,54 +566,41 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
gTargetData = target->getTargetData();
|
gTargetData = target->getTargetData();
|
||||||
|
|
||||||
global.params.llvmArch = theTarget->getName();
|
global.params.isLE = gTargetData->isLittleEndian();
|
||||||
|
// Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit();
|
||||||
|
global.params.is64bit = gTargetData->getPointerSizeInBits() == 64;
|
||||||
|
global.params.cpu = static_cast<ARCH>(global.params.targetTriple.getArch());
|
||||||
|
global.params.os = static_cast<OS>(global.params.targetTriple.getOS());
|
||||||
|
|
||||||
if (strcmp(global.params.llvmArch,"x86")==0) {
|
switch (global.params.targetTriple.getArch())
|
||||||
VersionCondition::addPredefinedGlobalIdent("X86");
|
{
|
||||||
global.params.isLE = true;
|
case llvm::Triple::x86:
|
||||||
global.params.is64bit = false;
|
VersionCondition::addPredefinedGlobalIdent("X86");
|
||||||
global.params.cpu = ARCHx86;
|
if (global.params.useInlineAsm) {
|
||||||
if (global.params.useInlineAsm) {
|
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
|
||||||
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
|
}
|
||||||
}
|
break;
|
||||||
}
|
case llvm::Triple::x86_64:
|
||||||
else if (strcmp(global.params.llvmArch,"x86-64")==0) {
|
VersionCondition::addPredefinedGlobalIdent("X86_64");
|
||||||
VersionCondition::addPredefinedGlobalIdent("X86_64");
|
if (global.params.useInlineAsm) {
|
||||||
global.params.isLE = true;
|
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86_64");
|
||||||
global.params.is64bit = true;
|
}
|
||||||
global.params.cpu = ARCHx86_64;
|
break;
|
||||||
if (global.params.useInlineAsm) {
|
case llvm::Triple::ppc:
|
||||||
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86_64");
|
VersionCondition::addPredefinedGlobalIdent("PPC");
|
||||||
}
|
break;
|
||||||
}
|
case llvm::Triple::ppc64:
|
||||||
else if (strcmp(global.params.llvmArch,"ppc32")==0) {
|
VersionCondition::addPredefinedGlobalIdent("PPC64");
|
||||||
VersionCondition::addPredefinedGlobalIdent("PPC");
|
break;
|
||||||
global.params.isLE = false;
|
case llvm::Triple::arm:
|
||||||
global.params.is64bit = false;
|
VersionCondition::addPredefinedGlobalIdent("ARM");
|
||||||
global.params.cpu = ARCHppc;
|
case llvm::Triple::thumb:
|
||||||
}
|
VersionCondition::addPredefinedGlobalIdent("ARM");
|
||||||
else if (strcmp(global.params.llvmArch,"ppc64")==0) {
|
VersionCondition::addPredefinedGlobalIdent("Thumb");
|
||||||
VersionCondition::addPredefinedGlobalIdent("PPC64");
|
break;
|
||||||
global.params.isLE = false;
|
default:
|
||||||
global.params.is64bit = true;
|
error("invalid cpu architecture specified: %s", global.params.targetTriple.getArchName().str().c_str());
|
||||||
global.params.cpu = ARCHppc_64;
|
fatal();
|
||||||
}
|
|
||||||
else if (strcmp(global.params.llvmArch,"arm")==0) {
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("ARM");
|
|
||||||
global.params.isLE = true;
|
|
||||||
global.params.is64bit = false;
|
|
||||||
global.params.cpu = ARCHarm;
|
|
||||||
}
|
|
||||||
else if (strcmp(global.params.llvmArch,"thumb")==0) {
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("ARM");
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("Thumb");
|
|
||||||
global.params.isLE = true;
|
|
||||||
global.params.is64bit = false;
|
|
||||||
global.params.cpu = ARCHthumb;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
error("invalid cpu architecture specified: %s", global.params.llvmArch);
|
|
||||||
fatal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// endianness
|
// endianness
|
||||||
@@ -638,10 +625,9 @@ int main(int argc, char** argv)
|
|||||||
// parse the OS out of the target triple
|
// parse the OS out of the target triple
|
||||||
// see http://gcc.gnu.org/install/specific.html for details
|
// see http://gcc.gnu.org/install/specific.html for details
|
||||||
// also llvm's different SubTargets have useful information
|
// also llvm's different SubTargets have useful information
|
||||||
switch (llvm::Triple(triple).getOS())
|
switch (global.params.targetTriple.getOS())
|
||||||
{
|
{
|
||||||
case llvm::Triple::Win32:
|
case llvm::Triple::Win32:
|
||||||
global.params.os = OSWindows;
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("Windows");
|
VersionCondition::addPredefinedGlobalIdent("Windows");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Win32");
|
VersionCondition::addPredefinedGlobalIdent("Win32");
|
||||||
if (global.params.is64bit) {
|
if (global.params.is64bit) {
|
||||||
@@ -649,7 +635,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::MinGW32:
|
case llvm::Triple::MinGW32:
|
||||||
global.params.os = OSWindows;
|
global.params.os = OSWindows; // FIXME: Check source for uses of MinGW32
|
||||||
VersionCondition::addPredefinedGlobalIdent("Windows");
|
VersionCondition::addPredefinedGlobalIdent("Windows");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Win32");
|
VersionCondition::addPredefinedGlobalIdent("Win32");
|
||||||
VersionCondition::addPredefinedGlobalIdent("mingw32");
|
VersionCondition::addPredefinedGlobalIdent("mingw32");
|
||||||
@@ -663,35 +649,31 @@ int main(int argc, char** argv)
|
|||||||
fatal();
|
fatal();
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::Linux:
|
case llvm::Triple::Linux:
|
||||||
global.params.os = OSLinux;
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("linux");
|
VersionCondition::addPredefinedGlobalIdent("linux");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::Haiku:
|
case llvm::Triple::Haiku:
|
||||||
global.params.os = OSHaiku;
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("Haiku");
|
VersionCondition::addPredefinedGlobalIdent("Haiku");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::Darwin:
|
case llvm::Triple::Darwin:
|
||||||
global.params.os = OSMacOSX;
|
global.params.os = OSMacOSX; // FIXME: Do we need to distinguish between Darwin and MacOSX?
|
||||||
VersionCondition::addPredefinedGlobalIdent("OSX");
|
VersionCondition::addPredefinedGlobalIdent("OSX");
|
||||||
VersionCondition::addPredefinedGlobalIdent("darwin");
|
VersionCondition::addPredefinedGlobalIdent("darwin");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::FreeBSD:
|
case llvm::Triple::FreeBSD:
|
||||||
global.params.os = OSFreeBSD;
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("freebsd");
|
VersionCondition::addPredefinedGlobalIdent("freebsd");
|
||||||
VersionCondition::addPredefinedGlobalIdent("FreeBSD");
|
VersionCondition::addPredefinedGlobalIdent("FreeBSD");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::Solaris:
|
case llvm::Triple::Solaris:
|
||||||
global.params.os = OSSolaris;
|
|
||||||
VersionCondition::addPredefinedGlobalIdent("solaris");
|
VersionCondition::addPredefinedGlobalIdent("solaris");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Solaris");
|
VersionCondition::addPredefinedGlobalIdent("Solaris");
|
||||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("target '%s' is not yet supported", global.params.targetTriple);
|
error("target '%s' is not yet supported", global.params.targetTriple.str().c_str());
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ Statement *AsmStatement::semantic(Scope *sc)
|
|||||||
bool err = false;
|
bool err = false;
|
||||||
if ((global.params.cpu != ARCHx86) && (global.params.cpu != ARCHx86_64))
|
if ((global.params.cpu != ARCHx86) && (global.params.cpu != ARCHx86_64))
|
||||||
{
|
{
|
||||||
error("inline asm is not supported for the \"%s\" architecture", global.params.llvmArch);
|
error("inline asm is not supported for the \"%s\" architecture", global.params.targetTriple.getArchName().str().c_str());
|
||||||
err = true;
|
err = true;
|
||||||
}
|
}
|
||||||
if (!global.params.useInlineAsm)
|
if (!global.params.useInlineAsm)
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
|
|||||||
sir->setState(&ir);
|
sir->setState(&ir);
|
||||||
|
|
||||||
// set target triple
|
// set target triple
|
||||||
ir.module->setTargetTriple(global.params.targetTriple);
|
ir.module->setTargetTriple(global.params.targetTriple.str());
|
||||||
|
|
||||||
// set final data layout
|
// set final data layout
|
||||||
ir.module->setDataLayout(gTargetData->getStringRepresentation());
|
ir.module->setDataLayout(gTargetData->getStringRepresentation());
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
|
|||||||
// unsupported
|
// unsupported
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple);
|
error(loc, "this target (%s) does not implement inline asm falling off the end of the function", global.params.targetTriple.str().c_str());
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user