diff --git a/gen/toir.c b/gen/toir.c index 88d617bf..4cfc31d4 100644 --- a/gen/toir.c +++ b/gen/toir.c @@ -760,16 +760,16 @@ elem* CallExp::toElem(IRState* p) elem* e = new elem; elem* fn = e1->toElem(p); LINK dlink = LINKdefault; - + bool delegateCall = false; llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); // hidden struct return parameter handling bool retinptr = false; - + TypeFunction* tf = 0; - + // regular functions if (e1->type->ty == Tfunction) { tf = (TypeFunction*)e1->type; @@ -778,7 +778,7 @@ elem* CallExp::toElem(IRState* p) } dlink = tf->linkage; } - + // delegates else if (e1->type->ty == Tdelegate) { Logger::println("delegateTy = %s\n", e1->type->toChars()); @@ -790,7 +790,7 @@ elem* CallExp::toElem(IRState* p) dlink = tf->linkage; delegateCall = true; } - + // invalid else { assert(tf); @@ -801,10 +801,11 @@ elem* CallExp::toElem(IRState* p) if (retinptr) n++; llvm::Value* funcval = fn->getValue(); + assert(funcval != 0); std::vector llargs(n, 0); const llvm::FunctionType* llfnty = 0; - + // normal function call if (llvm::isa(funcval->getType())) { llfnty = llvm::cast(funcval->getType()); @@ -816,7 +817,6 @@ elem* CallExp::toElem(IRState* p) if (llvm::isa(funcval->getType()->getContainedType(0))) { funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); } - // function pointer if (llvm::isa(funcval->getType()->getContainedType(0))) { //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; @@ -956,7 +956,7 @@ elem* CallExp::toElem(IRState* p) Logger::cout() << *llargs[i] << '\n'; } - Logger::cout() << "Calling: " << *funcval->getType() << '\n'; + //Logger::cout() << "Calling: " << *funcval->getType() << '\n'; // call the function llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); diff --git a/gen/tollvm.c b/gen/tollvm.c index 308ddca3..db493819 100644 --- a/gen/tollvm.c +++ b/gen/tollvm.c @@ -891,12 +891,15 @@ llvm::Function* LLVM_DtoDeclareFunction(FuncDeclaration* fdecl) assert(f != 0); if (fdecl->llvmValue != 0) { - assert(llvm::isa(fdecl->llvmValue)); + if (!llvm::isa(fdecl->llvmValue)) + { + Logger::cout() << *fdecl->llvmValue << '\n'; + assert(0); + } return llvm::cast(fdecl->llvmValue); } - static int fdi = 0; - Logger::print("FuncDeclaration::toObjFile(%d,%s): %s\n", fdi++, fdecl->needThis()?"this":"static",fdecl->toChars()); + Logger::print("FuncDeclaration::toObjFile(%s): %s\n", fdecl->needThis()?"this":"static",fdecl->toChars()); LOG_SCOPE; if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) { diff --git a/gen/toobj.c b/gen/toobj.c index b4661feb..f903c71b 100644 --- a/gen/toobj.c +++ b/gen/toobj.c @@ -34,6 +34,7 @@ #include "id.h" #include "import.h" #include "template.h" +#include "scope.h" #include "gen/irstate.h" #include "gen/elem.h" @@ -51,7 +52,7 @@ Module::genobjfile() // start by deleting the old object file deleteObjFile(); - // creaet a new ir state + // create a new ir state IRState ir; gIR = &ir; ir.dmodule = this; @@ -85,7 +86,6 @@ Module::genobjfile() LLVM_DtoMain(); } - /* // verify the llvm std::string verifyErr; Logger::println("Verifying module..."); @@ -96,7 +96,6 @@ Module::genobjfile() } else Logger::println("Verification passed!"); - */ // run passes // TODO @@ -608,7 +607,7 @@ void EnumDeclaration::toObjFile() void FuncDeclaration::toObjFile() { - if (llvmDModule == gIR->dmodule) { + if (llvmDModule) { assert(llvmValue != 0); return; } diff --git a/lphobos/std/stdio.d b/lphobos/std/stdio.d new file mode 100644 index 00000000..153dfca2 --- /dev/null +++ b/lphobos/std/stdio.d @@ -0,0 +1,15 @@ +module std.stdio; + +void _writef(T)(T t) { + //static if(is(T: Object)) _writef(t.toString()); else + static if(is(T: char[])) printf("%.*s", t.length, t.ptr); else + static if(is(T==int)) printf("%i", t); else + static assert(false, "Cannot print "~T.stringof); +} + +void writef(T...)(T t) { + foreach (v; t) _writef(v); +} +void writefln(T...)(T t) { + writef(t, "\n"[]); +} diff --git a/test/imports2.d b/test/imports2.d index ee271d21..7f8bff58 100644 --- a/test/imports2.d +++ b/test/imports2.d @@ -3,6 +3,4 @@ import std.stdio; void main() { writefln("Hello world!"[]); - print(42); - printf("\n"); }