From 936f996c4091266e9404f346e2939e613121f74c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 18 Jun 2009 20:45:40 +0000 Subject: Make source location mandatory parameter for Error. git-svn-id: http://svn.drobilla.net/resp/tuplr@121 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- llvm.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'llvm.cpp') diff --git a/llvm.cpp b/llvm.cpp index dcf8365..d04bd1b 100644 --- a/llvm.cpp +++ b/llvm.cpp @@ -56,7 +56,7 @@ lltype(const AType* t) if (t->at(0)->str() == "Bool") return Type::Int1Ty; if (t->at(0)->str() == "Int") return Type::Int32Ty; if (t->at(0)->str() == "Float") return Type::FloatTy; - throw Error(string("Unknown primitive type `") + t->str() + "'"); + throw Error(string("Unknown primitive type `") + t->str() + "'", t->loc); case AType::EXPR: if (t->at(0)->str() == "Pair") { vector types; @@ -148,24 +148,24 @@ LITERAL(bool, "Bool", ConstantInt::get(Type::Int1Ty, val, false)) static Function* compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ATuple& protT, - const vector argNames=vector()) + Cursor loc, const vector argNames=vector()) { Function::LinkageTypes linkage = Function::ExternalLinkage; vector cprot; for (size_t i = 0; i < protT.size(); ++i) { AType* at = protT.at(i)->as(); - THROW_IF(!lltype(at), "function parameter is untyped") + THROW_IF(!lltype(at), "function parameter is untyped", protT.at(i)->loc) cprot.push_back(lltype(at)); } - THROW_IF(!retT, "function return is untyped") + THROW_IF(!retT, "function return is untyped", loc); FunctionType* fT = FunctionType::get(static_cast(retT), cprot, false); Function* f = Function::Create(fT, linkage, name, llengine(cenv)->module); if (f->getName() != name) { f->eraseFromParent(); - throw Error("function redefined"); + throw Error("function redefined", loc); } // Set argument names in generated code @@ -237,7 +237,7 @@ AClosure::liftCall(CEnv& cenv, const vector& argsT) string name = this->name == "" ? cenv.gensym("_fn") : this->name; Function* f = compileFunction(cenv, name, lltype(thisType->at(thisType->size()-1)->to()), - *protT); + *protT, loc); cenv.push(); Subst oldSubst = cenv.tsubst; @@ -467,7 +467,7 @@ AConsCall::lift(CEnv& cenv) vector argNames; argNames.push_back("car"); argNames.push_back("cdr"); - Function* func = compileFunction(cenv, cenv.gensym("cons"), pT, *protT, argNames); + Function* func = compileFunction(cenv, cenv.gensym("cons"), pT, *protT, loc, argNames); Value* mem = builder.CreateCall(LLVal(cenv.alloc), ConstantInt::get(Type::Int32Ty, sz), "mem"); Value* cell = builder.CreateBitCast(mem, pT, "cell"); @@ -563,7 +563,7 @@ eval(CEnv& cenv, const string& name, istream& is) THROW_IF(!ctype, "body has non-compilable type", cursor) // Create function for top-level of program - Function* f = compileFunction(cenv, "main", ctype, ATuple(cursor)); + Function* f = compileFunction(cenv, "main", ctype, ATuple(cursor), cursor); // Compile all expressions into it Value* val = NULL; @@ -610,7 +610,7 @@ repl(CEnv& cenv) if (lltype(bodyT)) { // Create anonymous function to insert code into - Function* f = compileFunction(cenv, cenv.gensym("_repl"), lltype(bodyT), ATuple(cursor)); + Function* f = compileFunction(cenv, cenv.gensym("_repl"), lltype(bodyT), ATuple(cursor), cursor); try { Value* retVal = LLVal(cenv.compile(body)); llengine(cenv)->builder.CreateRet(retVal); // Finish function -- cgit v1.2.1