# HG changeset patch # User lindquist # Date 1191455273 -7200 # Node ID c05ef76f1c20ee17fcaa7f0de35e47c17977ab5e # Parent 6c6cd097bcdfde8d016ad0587592ed39995674ab [svn r22] * Forgot to add std.stdio diff -r 6c6cd097bcdf -r c05ef76f1c20 gen/toir.c --- a/gen/toir.c Wed Oct 03 06:14:41 2007 +0200 +++ b/gen/toir.c Thu Oct 04 01:47:53 2007 +0200 @@ -760,16 +760,16 @@ 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 @@ } dlink = tf->linkage; } - + // delegates else if (e1->type->ty == Tdelegate) { Logger::println("delegateTy = %s\n", e1->type->toChars()); @@ -790,7 +790,7 @@ dlink = tf->linkage; delegateCall = true; } - + // invalid else { assert(tf); @@ -801,10 +801,11 @@ 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 @@ 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 @@ 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 -r 6c6cd097bcdf -r c05ef76f1c20 gen/tollvm.c --- a/gen/tollvm.c Wed Oct 03 06:14:41 2007 +0200 +++ b/gen/tollvm.c Thu Oct 04 01:47:53 2007 +0200 @@ -891,12 +891,15 @@ 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 -r 6c6cd097bcdf -r c05ef76f1c20 gen/toobj.c --- a/gen/toobj.c Wed Oct 03 06:14:41 2007 +0200 +++ b/gen/toobj.c Thu Oct 04 01:47:53 2007 +0200 @@ -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 @@ // 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 @@ LLVM_DtoMain(); } - /* // verify the llvm std::string verifyErr; Logger::println("Verifying module..."); @@ -96,7 +96,6 @@ } else Logger::println("Verification passed!"); - */ // run passes // TODO @@ -608,7 +607,7 @@ void FuncDeclaration::toObjFile() { - if (llvmDModule == gIR->dmodule) { + if (llvmDModule) { assert(llvmValue != 0); return; } diff -r 6c6cd097bcdf -r c05ef76f1c20 lphobos/std/stdio.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lphobos/std/stdio.d Thu Oct 04 01:47:53 2007 +0200 @@ -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 -r 6c6cd097bcdf -r c05ef76f1c20 test/imports2.d --- a/test/imports2.d Wed Oct 03 06:14:41 2007 +0200 +++ b/test/imports2.d Thu Oct 04 01:47:53 2007 +0200 @@ -3,6 +3,4 @@ void main() { writefln("Hello world!"[]); - print(42); - printf("\n"); }