diff options
Diffstat (limited to 'llvm.cpp')
-rw-r--r-- | llvm.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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<const Type*> 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<string> argNames=vector<string>()) + Cursor loc, const vector<string> argNames=vector<string>()) { Function::LinkageTypes linkage = Function::ExternalLinkage; vector<const Type*> cprot; for (size_t i = 0; i < protT.size(); ++i) { AType* at = protT.at(i)->as<AType*>(); - 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<const Type*>(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<AType*>& argsT) string name = this->name == "" ? cenv.gensym("_fn") : this->name; Function* f = compileFunction(cenv, name, lltype(thisType->at(thisType->size()-1)->to<AType*>()), - *protT); + *protT, loc); cenv.push(); Subst oldSubst = cenv.tsubst; @@ -467,7 +467,7 @@ AConsCall::lift(CEnv& cenv) vector<string> 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 |