mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Started changing target triple stuff, part of fixing #97
This commit is contained in:
1447
config.guess
vendored
Executable file
1447
config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
19
dmd/mars.c
19
dmd/mars.c
@@ -829,8 +829,7 @@ int main(int argc, char *argv[], char** envp)
|
||||
global.params.isLE = true;
|
||||
global.params.is64bit = false;
|
||||
global.params.cpu = ARCHx86;
|
||||
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";
|
||||
//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("LLVM_InlineAsm_X86");
|
||||
}
|
||||
@@ -840,24 +839,21 @@ int main(int argc, char *argv[], char** envp)
|
||||
global.params.isLE = true;
|
||||
global.params.is64bit = true;
|
||||
global.params.cpu = ARCHx86_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";
|
||||
//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;
|
||||
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";
|
||||
//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;
|
||||
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";
|
||||
//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");
|
||||
@@ -888,19 +884,16 @@ int main(int argc, char *argv[], char** envp)
|
||||
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;
|
||||
|
||||
case OSMacOSX:
|
||||
VersionCondition::addPredefinedGlobalIdent("darwin");
|
||||
VersionCondition::addPredefinedGlobalIdent("Posix");
|
||||
global.params.tt_os = "-pc-darwin-gnu";
|
||||
break;
|
||||
|
||||
case OSFreeBSD:
|
||||
@@ -912,6 +905,10 @@ int main(int argc, char *argv[], char** envp)
|
||||
assert(false && "Target OS not supported");
|
||||
}
|
||||
|
||||
if (!global.params.targetTriple)
|
||||
global.params.targetTriple = DEFAULT_TARGET_TRIPLE;
|
||||
|
||||
Logger::println("Target triple: %s", global.params.targetTriple);
|
||||
|
||||
// Initialization
|
||||
Type::init();
|
||||
|
||||
@@ -142,9 +142,6 @@ struct Param
|
||||
// LDC stuff
|
||||
char *llvmArch;
|
||||
char forceBE;
|
||||
char *tt_arch;
|
||||
char *tt_os;
|
||||
char *data_layout;
|
||||
char output_ll;
|
||||
char output_bc;
|
||||
char output_s;
|
||||
@@ -154,6 +151,9 @@ struct Param
|
||||
char useInlineAsm;
|
||||
char fqnNames; // use fully qualified object names
|
||||
char noDefaultLib;
|
||||
|
||||
// target stuff
|
||||
char *targetTriple;
|
||||
};
|
||||
|
||||
struct Global
|
||||
|
||||
21
gen/toir.cpp
21
gen/toir.cpp
@@ -471,6 +471,15 @@ DValue* AssignExp::toElem(IRState* p)
|
||||
DtoAssign(loc, &arrval, slice);
|
||||
return newlen;
|
||||
}
|
||||
else if (e1->op == TOKslice && !ismemset &&
|
||||
(e2->op == TOKadd || e2->op == TOKmin ||
|
||||
e2->op == TOKmul || e2->op == TOKdiv ||
|
||||
e2->op == TOKmod || e2->op == TOKxor ||
|
||||
e2->op == TOKand || e2->op == TOKor ||
|
||||
e2->op == TOKtilde || e2->op == TOKneg))
|
||||
{
|
||||
assert(0 && "array op assignment is TODO");
|
||||
}
|
||||
|
||||
Logger::println("performing normal assignment");
|
||||
|
||||
@@ -481,19 +490,7 @@ DValue* AssignExp::toElem(IRState* p)
|
||||
if (l->isSlice())
|
||||
return l;
|
||||
|
||||
#if 0
|
||||
if (type->toBasetype()->ty == Tstruct && e2->type->isintegral())
|
||||
{
|
||||
// handle struct = 0;
|
||||
return l;
|
||||
}
|
||||
else
|
||||
{
|
||||
return r;
|
||||
}
|
||||
#else
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
void ldc_optimize_module(llvm::Module* m, char lvl, bool doinline);
|
||||
|
||||
// fwd decl
|
||||
void write_asm_to_file(llvm::Module& m, llvm::raw_fd_ostream& Out);
|
||||
void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& Out);
|
||||
void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath, char** envp);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -102,12 +102,36 @@ void Module::genobjfile(int multiobj, char** envp)
|
||||
this->ir.irModule = new IrModule(this, srcfile->toChars());
|
||||
|
||||
// set target stuff
|
||||
std::string target_triple(global.params.tt_arch);
|
||||
target_triple.append(global.params.tt_os);
|
||||
ir.module->setTargetTriple(target_triple);
|
||||
ir.module->setDataLayout(global.params.data_layout);
|
||||
|
||||
gTargetData = new llvm::TargetData(global.params.data_layout);
|
||||
ir.module->setTargetTriple(global.params.targetTriple);
|
||||
|
||||
// get the target machine
|
||||
const llvm::TargetMachineRegistry::entry* MArch;
|
||||
|
||||
std::string Err;
|
||||
MArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*ir.module, Err);
|
||||
if (MArch == 0) {
|
||||
error("error auto-selecting target for module '%s'", Err.c_str());
|
||||
fatal();
|
||||
}
|
||||
|
||||
llvm::SubtargetFeatures Features;
|
||||
//TODO: Features?
|
||||
// Features.setCPU(MCPU);
|
||||
// for (unsigned i = 0; i != MAttrs.size(); ++i)
|
||||
// Features.AddFeature(MAttrs[i]);
|
||||
|
||||
// only generate PIC code when -fPIC switch is used
|
||||
if (global.params.pic)
|
||||
llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_);
|
||||
|
||||
// allocate the target machine
|
||||
std::auto_ptr<llvm::TargetMachine> target(MArch->CtorFn(*ir.module, Features.getString()));
|
||||
assert(target.get() && "Could not allocate target machine!");
|
||||
llvm::TargetMachine &Target = *target.get();
|
||||
|
||||
gTargetData = Target.getTargetData();
|
||||
ir.module->setDataLayout(gTargetData->getStringRepresentation());
|
||||
|
||||
// debug info
|
||||
if (global.params.symdebug) {
|
||||
@@ -222,7 +246,7 @@ void Module::genobjfile(int multiobj, char** envp)
|
||||
std::string err;
|
||||
{
|
||||
llvm::raw_fd_ostream out(spath.c_str(), err);
|
||||
write_asm_to_file(*ir.module, out);
|
||||
write_asm_to_file(Target, *ir.module, out);
|
||||
}
|
||||
|
||||
// call gcc to convert assembly to object file
|
||||
@@ -251,37 +275,14 @@ void Module::genobjfile(int multiobj, char** envp)
|
||||
/* ================================================================== */
|
||||
|
||||
// based on llc code, University of Illinois Open Source License
|
||||
void write_asm_to_file(llvm::Module& m, llvm::raw_fd_ostream& out)
|
||||
void write_asm_to_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& out)
|
||||
{
|
||||
using namespace llvm;
|
||||
|
||||
std::string Err;
|
||||
|
||||
const TargetMachineRegistry::entry* MArch;
|
||||
MArch = TargetMachineRegistry::getClosestStaticTargetForModule(m, Err);
|
||||
if (MArch == 0) {
|
||||
error("error auto-selecting target for module '%s'", Err.c_str());
|
||||
fatal();
|
||||
}
|
||||
|
||||
SubtargetFeatures Features;
|
||||
//TODO: Features?
|
||||
// Features.setCPU(MCPU);
|
||||
// for (unsigned i = 0; i != MAttrs.size(); ++i)
|
||||
// Features.AddFeature(MAttrs[i]);
|
||||
|
||||
//FIXME: Only set this if required?
|
||||
TargetMachine::setRelocationModel(Reloc::PIC_);
|
||||
|
||||
std::auto_ptr<TargetMachine> target(MArch->CtorFn(m, Features.getString()));
|
||||
assert(target.get() && "Could not allocate target machine!");
|
||||
TargetMachine &Target = *target.get();
|
||||
|
||||
// Build up all of the passes that we want to do to the module.
|
||||
ExistingModuleProvider Provider(&m);
|
||||
FunctionPassManager Passes(&Provider);
|
||||
//FIXME: Will gTargetData always be Target.getTargetData anyway?
|
||||
assert(gTargetData->getStringRepresentation() == Target.getTargetData()->getStringRepresentation());
|
||||
|
||||
Passes.add(new TargetData(*Target.getTargetData()));
|
||||
|
||||
// Ask the target to add backend passes as necessary.
|
||||
@@ -305,6 +306,7 @@ void write_asm_to_file(llvm::Module& m, llvm::raw_fd_ostream& out)
|
||||
Passes.doFinalization();
|
||||
|
||||
// release module from module provider so we can delete it ourselves
|
||||
std::string Err;
|
||||
llvm::Module* rmod = Provider.releaseModule(&Err);
|
||||
assert(rmod);
|
||||
}
|
||||
|
||||
15
premake.lua
15
premake.lua
@@ -21,6 +21,20 @@ if OS == "windows" then
|
||||
POSIX = 0
|
||||
end
|
||||
|
||||
|
||||
-- guess the host machine description
|
||||
-- also allow overriding it
|
||||
|
||||
addoption("target-override", "Override the default target machine");
|
||||
|
||||
TRIPLE = "";
|
||||
if options["target-override"] then
|
||||
TRIPLE = options["target-override"]
|
||||
else
|
||||
local p = io.popen("./config.guess")
|
||||
TRIPLE = p:read()
|
||||
end
|
||||
|
||||
-- D version - don't change these !!!
|
||||
DMDV1 = "1"
|
||||
|
||||
@@ -65,6 +79,7 @@ package.defines = {
|
||||
"USE_BOEHM_GC="..USE_BOEHM_GC,
|
||||
"DMDV1="..DMDV1,
|
||||
"POSIX="..POSIX,
|
||||
"DEFAULT_TARGET_TRIPLE=\\\""..TRIPLE.."\\\"",
|
||||
}
|
||||
package.config.Release.defines = { "LLVMD_NO_LOGGER" }
|
||||
package.config.Debug.buildoptions = { "-g -O0" }
|
||||
|
||||
Reference in New Issue
Block a user