mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-26 17:43:14 +01:00
Automated merge with http://hg.dsource.org/projects/ldc
This commit is contained in:
@@ -2566,7 +2566,7 @@ void StaticDtorDeclaration::semantic(Scope *sc)
|
||||
Statement *s = new DeclarationStatement(0, v);
|
||||
sa->push(s);
|
||||
Expression *e = new IdentifierExp(0, id);
|
||||
e = new AddAssignExp(0, e, new IntegerExp(-1));
|
||||
e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1));
|
||||
e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0));
|
||||
s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
|
||||
sa->push(s);
|
||||
|
||||
@@ -2722,7 +2722,7 @@ void StaticDtorDeclaration::semantic(Scope *sc)
|
||||
Statement *s = new DeclarationStatement(0, v);
|
||||
sa->push(s);
|
||||
Expression *e = new IdentifierExp(0, id);
|
||||
e = new AddAssignExp(0, e, new IntegerExp(-1));
|
||||
e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1));
|
||||
e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0));
|
||||
s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL);
|
||||
sa->push(s);
|
||||
|
||||
@@ -290,7 +290,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
||||
// fill out any null entries still left with default values
|
||||
|
||||
// element default initializer
|
||||
LLConstant* defelem = elemty->defaultInit(arrinit->loc)->toConstElem(gIR);
|
||||
LLConstant* defelem = DtoConstExpInit(arrinit->loc, elemty, elemty->defaultInit(arrinit->loc));
|
||||
bool mismatch2 = (defelem->getType() != llelemty);
|
||||
|
||||
for (size_t i = 0; i < arrlen; i++)
|
||||
|
||||
@@ -1558,6 +1558,10 @@ struct AsmProcessor
|
||||
break;
|
||||
}
|
||||
|
||||
// osx needs an extra underscore
|
||||
if (global.params.os == OSMacOSX)
|
||||
insnTemplate->writestring("_");
|
||||
|
||||
// print out the mangle
|
||||
insnTemplate->writestring(vd->mangle());
|
||||
vd->nakedUse = true;
|
||||
|
||||
@@ -528,7 +528,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
|
||||
// calling convention
|
||||
if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
|
||||
func->setCallingConv(DtoCallingConv(f->linkage));
|
||||
func->setCallingConv(DtoCallingConv(fdecl->loc, f->linkage));
|
||||
else // fall back to C, it should be the right thing to do
|
||||
func->setCallingConv(llvm::CallingConv::C);
|
||||
|
||||
@@ -546,12 +546,16 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
}
|
||||
|
||||
// static ctor
|
||||
if (fdecl->isStaticCtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
|
||||
gIR->ctors.push_back(fdecl);
|
||||
if (fdecl->isStaticCtorDeclaration()) {
|
||||
if (fdecl->getModule() == gIR->dmodule || fdecl->inTemplateInstance()) {
|
||||
gIR->ctors.push_back(fdecl);
|
||||
}
|
||||
}
|
||||
// static dtor
|
||||
else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) {
|
||||
gIR->dtors.push_back(fdecl);
|
||||
else if (fdecl->isStaticDtorDeclaration()) {
|
||||
if (fdecl->getModule() == gIR->dmodule || fdecl->inTemplateInstance()) {
|
||||
gIR->dtors.push_back(fdecl);
|
||||
}
|
||||
}
|
||||
|
||||
// we never reference parameters of function prototypes
|
||||
|
||||
@@ -109,7 +109,7 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std:
|
||||
// ASSERT HELPER
|
||||
////////////////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
void DtoAssert(Loc* loc, DValue* msg)
|
||||
void DtoAssert(Module* M, Loc* loc, DValue* msg)
|
||||
{
|
||||
std::vector<LLValue*> args;
|
||||
|
||||
@@ -124,7 +124,12 @@ void DtoAssert(Loc* loc, DValue* msg)
|
||||
}
|
||||
|
||||
// file param
|
||||
args.push_back(DtoLoad(gIR->dmodule->ir.irModule->fileName));
|
||||
|
||||
// we might be generating for an imported template function
|
||||
if (!M->ir.irModule)
|
||||
M->ir.irModule = new IrModule(M, M->srcfile->toChars());
|
||||
|
||||
args.push_back(DtoLoad(M->ir.irModule->fileName));
|
||||
|
||||
// line param
|
||||
LLConstant* c = DtoConstUint(loc->linnum);
|
||||
@@ -826,6 +831,7 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to)
|
||||
// TEMPLATE HELPERS
|
||||
////////////////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
// FIXME: when is this the right one to use instead of Dsymbol::inTemplateInstance() ?
|
||||
bool DtoIsTemplateInstance(Dsymbol* s)
|
||||
{
|
||||
if (!s) return false;
|
||||
|
||||
@@ -16,7 +16,7 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name = "");
|
||||
llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name = "");
|
||||
|
||||
// assertion generator
|
||||
void DtoAssert(Loc* loc, DValue* msg);
|
||||
void DtoAssert(Module* M, Loc* loc, DValue* msg);
|
||||
|
||||
// return the LabelStatement from the current function with the given identifier or NULL if not found
|
||||
LabelStatement* DtoLabelStatement(Identifier* ident);
|
||||
@@ -113,7 +113,7 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s
|
||||
////////////////////////////////////////////
|
||||
|
||||
/// convert DMD calling conv to LLVM
|
||||
unsigned DtoCallingConv(LINK l);
|
||||
unsigned DtoCallingConv(Loc loc, LINK l);
|
||||
|
||||
///
|
||||
TypeFunction* DtoTypeFunction(DValue* fnval);
|
||||
|
||||
@@ -33,7 +33,7 @@ TypeFunction* DtoTypeFunction(DValue* fnval)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned DtoCallingConv(LINK l)
|
||||
unsigned DtoCallingConv(Loc loc, LINK l)
|
||||
{
|
||||
if (l == LINKc || l == LINKcpp || l == LINKintrinsic)
|
||||
return llvm::CallingConv::C;
|
||||
@@ -50,7 +50,10 @@ unsigned DtoCallingConv(LINK l)
|
||||
else if (l == LINKwindows)
|
||||
return llvm::CallingConv::X86_StdCall;
|
||||
else
|
||||
assert(0 && "Unsupported calling convention");
|
||||
{
|
||||
error(loc, "unsupported calling convention");
|
||||
fatal();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -235,7 +238,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
||||
bool nestedcall = tf->usesNest;
|
||||
bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1);
|
||||
|
||||
unsigned callconv = DtoCallingConv(tf->linkage);
|
||||
unsigned callconv = DtoCallingConv(loc, tf->linkage);
|
||||
|
||||
// get callee llvm value
|
||||
LLValue* callable = DtoCallableValue(fnval);
|
||||
|
||||
@@ -1632,6 +1632,8 @@ DValue* NewExp::toElem(IRState* p)
|
||||
DVarValue tmpvar(newtype, mem);
|
||||
|
||||
// default initialize
|
||||
// FIXME: should this use DtoConstExpInit instead ?
|
||||
// or is static arrays the only troublemaker?
|
||||
Expression* exp = newtype->defaultInit(loc);
|
||||
DValue* iv = exp->toElem(gIR);
|
||||
DtoAssign(loc, &tmpvar, iv);
|
||||
@@ -1766,7 +1768,7 @@ DValue* AssertExp::toElem(IRState* p)
|
||||
|
||||
// call assert runtime functions
|
||||
p->scope() = IRScope(assertbb,endbb);
|
||||
DtoAssert(&loc, msg ? msg->toElem(p) : NULL);
|
||||
DtoAssert(p->func()->decl->getModule(), &loc, msg ? msg->toElem(p) : NULL);
|
||||
|
||||
// rewrite the scope
|
||||
p->scope() = IRScope(endbb,oldend);
|
||||
@@ -1941,7 +1943,7 @@ DValue* HaltExp::toElem(IRState* p)
|
||||
// FIXME: DMD inserts a trap here... we probably should as well !?!
|
||||
|
||||
#if 1
|
||||
DtoAssert(&loc, NULL);
|
||||
DtoAssert(p->func()->decl->getModule(), &loc, NULL);
|
||||
#else
|
||||
// call the new (?) trap intrinsic
|
||||
p->ir->CreateCall(GET_INTRINSIC_DECL(trap),"");
|
||||
|
||||
@@ -99,8 +99,9 @@ void Module::genobjfile(int multiobj)
|
||||
ir.module = new llvm::Module(mname);
|
||||
|
||||
// module ir state
|
||||
// might already exist via import, just overwrite...
|
||||
//FIXME: is there a good reason for overwriting?
|
||||
// might already exist via import, just overwrite since
|
||||
// the global created for the filename must belong to the right llvm module
|
||||
// FIXME: but shouldn't this always get reset between modules? like other IrSymbols
|
||||
this->ir.irModule = new IrModule(this, srcfile->toChars());
|
||||
|
||||
// set target stuff
|
||||
@@ -417,7 +418,7 @@ llvm::Function* build_module_ctor()
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
fn->setCallingConv(DtoCallingConv(LINKd));
|
||||
fn->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
|
||||
llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
|
||||
IRBuilder<> builder(bb);
|
||||
@@ -432,7 +433,7 @@ llvm::Function* build_module_ctor()
|
||||
for (size_t i=0; i<n; i++) {
|
||||
llvm::Function* f = gIR->ctors[i]->ir.irFunc->func;
|
||||
llvm::CallInst* call = builder.CreateCall(f,"");
|
||||
call->setCallingConv(DtoCallingConv(LINKd));
|
||||
call->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
}
|
||||
|
||||
// debug info end
|
||||
@@ -462,7 +463,7 @@ static llvm::Function* build_module_dtor()
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
fn->setCallingConv(DtoCallingConv(LINKd));
|
||||
fn->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
|
||||
llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
|
||||
IRBuilder<> builder(bb);
|
||||
@@ -477,7 +478,7 @@ static llvm::Function* build_module_dtor()
|
||||
for (size_t i=0; i<n; i++) {
|
||||
llvm::Function* f = gIR->dtors[i]->ir.irFunc->func;
|
||||
llvm::CallInst* call = builder.CreateCall(f,"");
|
||||
call->setCallingConv(DtoCallingConv(LINKd));
|
||||
call->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
}
|
||||
|
||||
// debug info end
|
||||
@@ -507,7 +508,7 @@ static llvm::Function* build_module_unittest()
|
||||
const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false);
|
||||
assert(gIR->module->getFunction(name) == NULL);
|
||||
llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module);
|
||||
fn->setCallingConv(DtoCallingConv(LINKd));
|
||||
fn->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
|
||||
llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn);
|
||||
IRBuilder<> builder(bb);
|
||||
@@ -522,7 +523,7 @@ static llvm::Function* build_module_unittest()
|
||||
for (size_t i=0; i<n; i++) {
|
||||
llvm::Function* f = gIR->unitTests[i]->ir.irFunc->func;
|
||||
llvm::CallInst* call = builder.CreateCall(f,"");
|
||||
call->setCallingConv(DtoCallingConv(LINKd));
|
||||
call->setCallingConv(DtoCallingConv(0, LINKd));
|
||||
}
|
||||
|
||||
// debug info end
|
||||
|
||||
@@ -33,9 +33,6 @@ IrFunction::IrFunction(FuncDeclaration* fd)
|
||||
|
||||
dwarfSubProg = NULL;
|
||||
|
||||
srcfileArg = NULL;
|
||||
msgArg = NULL;
|
||||
|
||||
nextUnique.push(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,6 @@ struct IrFunction : IrBase
|
||||
|
||||
llvm::Constant* dwarfSubProg;
|
||||
|
||||
llvm::AllocaInst* srcfileArg;
|
||||
llvm::AllocaInst* msgArg;
|
||||
|
||||
// pushes a unique label scope of the given name
|
||||
void pushUniqueLabelScope(const char* name);
|
||||
// pops a label scope
|
||||
|
||||
@@ -8,7 +8,7 @@ void foo()
|
||||
hlt;
|
||||
pass: ret;
|
||||
}
|
||||
version(X86_64)
|
||||
else version(X86_64)
|
||||
asm
|
||||
{
|
||||
naked;
|
||||
|
||||
Reference in New Issue
Block a user