diff options
Diffstat (limited to 'llvm.cpp')
-rw-r--r-- | llvm.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -173,7 +173,7 @@ compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ATu if (!argNames.empty()) for (size_t i = 0; i != protT.size(); ++a, ++i) a->setName(argNames.at(i)); - + BasicBlock* bb = BasicBlock::Create("entry", f); llengine(cenv)->builder.SetInsertPoint(bb); @@ -232,7 +232,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT) return; ATuple* protT = thisType->at(1)->as<ATuple*>(); - + // Write function declaration string name = this->name == "" ? cenv.gensym("_fn") : this->name; Function* f = compileFunction(cenv, name, @@ -286,9 +286,9 @@ ACall::lift(CEnv& cenv) at(i)->lift(cenv); argsT.push_back(cenv.type(at(i))); } - + if (!c) return; // Primitive - + if (c->prot()->size() < size() - 1) throw Error((format("too many arguments to function `%1%'") % at(0)->str()).str(), loc); if (c->prot()->size() > size() - 1) @@ -301,7 +301,7 @@ CValue ACall::compile(CEnv& cenv) { AClosure* c = cenv.tenv.resolve(at(0))->to<AClosure*>(); - + if (!c) return NULL; // Primitive AType* protT = new AType(loc, NULL); @@ -425,7 +425,7 @@ APrimitive::compile(CEnv& cenv) else return llengine(cenv)->builder.CreateICmp(pred, a, b); } - + throw Error("unknown primitive", loc); } @@ -444,9 +444,9 @@ AConsCall::lift(CEnv& cenv) AType* funcType = functionType(cenv); if (funcs.find(functionType(cenv))) return; - + ACall::lift(cenv); - + ATuple* protT = new ATuple(loc, cenv.type(at(1)), cenv.type(at(2)), 0); vector<const Type*> types; @@ -457,12 +457,12 @@ AConsCall::lift(CEnv& cenv) sz += t->getPrimitiveSizeInBits(); } sz = (sz % 8 == 0) ? sz / 8 : sz / 8 + 1; - + llvm::IRBuilder<>& builder = llengine(cenv)->builder; StructType* sT = StructType::get(types, false); Type* pT = PointerType::get(sT, 0); - + // Write function declaration vector<string> argNames; argNames.push_back("car"); @@ -474,14 +474,14 @@ AConsCall::lift(CEnv& cenv) Value* s = builder.CreateGEP(cell, ConstantInt::get(Type::Int32Ty, 0), "pair"); Value* carP = builder.CreateStructGEP(s, 0, "car"); Value* cdrP = builder.CreateStructGEP(s, 1, "cdr"); - + Function::arg_iterator ai = func->arg_begin(); Value& carArg = *ai++; Value& cdrArg = *ai++; builder.CreateStore(&carArg, carP); builder.CreateStore(&cdrArg, cdrP); builder.CreateRet(cell); - + cenv.optimise(func); funcs.push_back(make_pair(funcType, func)); } @@ -599,7 +599,7 @@ repl(CEnv& cenv) AST* body = cenv.penv.parse(exp); // Parse input Constraints c; body->constrain(cenv.tenv, c); // Constrain types - + Subst oldSubst = cenv.tsubst; cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints @@ -607,7 +607,7 @@ repl(CEnv& cenv) if (!bodyT) throw Error("call to untyped body", cursor); body->lift(cenv); - + if (lltype(bodyT)) { // Create anonymous function to insert code into Function* f = compileFunction(cenv, cenv.gensym("_repl"), lltype(bodyT), ATuple(cursor)); @@ -637,7 +637,7 @@ newCenv(PEnv& penv, TEnv& tenv) { LLVMEngine* engine = new LLVMEngine(); CEnv* cenv = new CEnv(penv, tenv, engine); - + // Host provided allocation primitive prototypes std::vector<const Type*> argsT(1, Type::Int32Ty); FunctionType* funcT = FunctionType::get(PointerType::get(Type::Int8Ty, 0), argsT, false); |