changeset 939:cac9895be400

Automated merge with http://hg.dsource.org/projects/ldc
author Christian Kamm <kamm incasoftware de>
date Wed, 04 Feb 2009 18:39:39 +0100
parents 6c09179ebba0 (diff) a904cc9bc064 (current diff)
children 39519a1ff603
files gen/functions.cpp gen/tocall.cpp
diffstat 13 files changed, 46 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/func.c	Wed Feb 04 18:39:33 2009 +0100
+++ b/dmd/func.c	Wed Feb 04 18:39:39 2009 +0100
@@ -2566,7 +2566,7 @@
 	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);
--- a/dmd2/func.c	Wed Feb 04 18:39:33 2009 +0100
+++ b/dmd2/func.c	Wed Feb 04 18:39:39 2009 +0100
@@ -2722,7 +2722,7 @@
 	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);
--- a/gen/arrays.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/arrays.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -290,7 +290,7 @@
     // 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++)
--- a/gen/asm-x86-64.h	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/asm-x86-64.h	Wed Feb 04 18:39:39 2009 +0100
@@ -1558,6 +1558,10 @@
                             break;
                         }
 
+			// osx needs an extra underscore
+			if (global.params.os == OSMacOSX)
+			  insnTemplate->writestring("_");
+
                         // print out the mangle
                         insnTemplate->writestring(vd->mangle());
                         vd->nakedUse = true;
--- a/gen/functions.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/functions.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -528,7 +528,7 @@
 
     // 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 @@
     }
 
     // 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
--- a/gen/llvmhelpers.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/llvmhelpers.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -109,7 +109,7 @@
 // ASSERT HELPER
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
-void DtoAssert(Loc* loc, DValue* msg)
+void DtoAssert(Module* M, Loc* loc, DValue* msg)
 {
     std::vector<LLValue*> args;
 
@@ -124,7 +124,12 @@
     }
 
     // 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 @@
 //      TEMPLATE HELPERS
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
+// FIXME: when is this the right one to use instead of Dsymbol::inTemplateInstance() ?
 bool DtoIsTemplateInstance(Dsymbol* s)
 {
     if (!s) return false;
--- a/gen/llvmhelpers.h	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/llvmhelpers.h	Wed Feb 04 18:39:39 2009 +0100
@@ -16,7 +16,7 @@
 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 @@
 ////////////////////////////////////////////
 
 /// convert DMD calling conv to LLVM
-unsigned DtoCallingConv(LINK l);
+unsigned DtoCallingConv(Loc loc, LINK l);
 
 ///
 TypeFunction* DtoTypeFunction(DValue* fnval);
--- a/gen/tocall.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/tocall.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -33,7 +33,7 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-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 @@
     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 @@
     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);
--- a/gen/toir.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/toir.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -1632,6 +1632,8 @@
         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 @@
 
         // 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 @@
     // 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),"");
--- a/gen/toobj.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/gen/toobj.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -99,8 +99,9 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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
--- a/ir/irfunction.cpp	Wed Feb 04 18:39:33 2009 +0100
+++ b/ir/irfunction.cpp	Wed Feb 04 18:39:39 2009 +0100
@@ -33,9 +33,6 @@
     
     dwarfSubProg = NULL;
 
-    srcfileArg = NULL;
-    msgArg = NULL;
-
     nextUnique.push(0);
 }
 
--- a/ir/irfunction.h	Wed Feb 04 18:39:33 2009 +0100
+++ b/ir/irfunction.h	Wed Feb 04 18:39:39 2009 +0100
@@ -30,9 +30,6 @@
     
     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
--- a/tests/mini/naked_asm4.d	Wed Feb 04 18:39:33 2009 +0100
+++ b/tests/mini/naked_asm4.d	Wed Feb 04 18:39:39 2009 +0100
@@ -8,7 +8,7 @@
         hlt;
 pass:   ret;
     }
-    version(X86_64)
+    else version(X86_64)
     asm
     {
         naked;