aboutsummaryrefslogtreecommitdiffstats
path: root/src/llvm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/llvm.cpp')
-rw-r--r--src/llvm.cpp50
1 files changed, 17 insertions, 33 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp
index e7c8524..c7d03a8 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -213,21 +213,21 @@ struct LLVMEngine : public Engine {
typedef pair<Value*, BasicBlock*> IfBranch;
typedef vector<IfBranch> IfBranches;
- struct IfState {
- IfState(BasicBlock* m, Function* p) : mergeBB(m), parent(p) {}
+ struct LLVMIfState {
+ LLVMIfState(BasicBlock* m, Function* p) : mergeBB(m), parent(p) {}
BasicBlock* mergeBB;
Function* parent;
IfBranches branches;
};
- IfState*
+ IfState
compileIfStart(CEnv& cenv);
void
- compileIfBranch(CEnv& cenv, IfState* state, CVal condV, const AST* then);
+ compileIfBranch(CEnv& cenv, IfState state, CVal condV, const AST* then);
CVal
- compileIfEnd(CEnv& cenv, IfState* state, CVal elseV, const AType* type);
+ compileIfEnd(CEnv& cenv, IfState state, CVal elseV, const AType* type);
void writeModule(CEnv& cenv, std::ostream& os) {
AssemblyAnnotationWriter writer;
@@ -371,20 +371,21 @@ LLVMEngine::pushFunctionArgs(CEnv& cenv, const ATuple* prot, const AType* type,
}
}
-LLVMEngine::IfState*
+IfState
LLVMEngine::compileIfStart(CEnv& cenv)
{
LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
- return new IfState(BasicBlock::Create(context, "endif"),
- engine->builder.GetInsertBlock()->getParent());
+ return new LLVMIfState(BasicBlock::Create(context, "endif"),
+ engine->builder.GetInsertBlock()->getParent());
}
void
-LLVMEngine::compileIfBranch(CEnv& cenv, IfState* state, CVal condV, const AST* then)
+LLVMEngine::compileIfBranch(CEnv& cenv, IfState s, CVal condV, const AST* then)
{
- LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
- BasicBlock* thenBB = BasicBlock::Create(context, (format("then%1%") % labelIndex).str());
- BasicBlock* nextBB = BasicBlock::Create(context, (format("else%1%") % labelIndex).str());
+ LLVMIfState* state = (LLVMIfState*)s;
+ LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
+ BasicBlock* thenBB = BasicBlock::Create(context, (format("then%1%") % labelIndex).str());
+ BasicBlock* nextBB = BasicBlock::Create(context, (format("else%1%") % labelIndex).str());
++labelIndex;
@@ -400,9 +401,10 @@ LLVMEngine::compileIfBranch(CEnv& cenv, IfState* state, CVal condV, const AST* t
}
CVal
-LLVMEngine::compileIfEnd(CEnv& cenv, IfState* state, CVal elseV, const AType* type)
+LLVMEngine::compileIfEnd(CEnv& cenv, IfState s, CVal elseV, const AType* type)
{
- LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
+ LLVMIfState* state = (LLVMIfState*)s;
+ LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
// Emit end of final else block
engine->builder.CreateBr(state->mergeBB);
@@ -418,28 +420,10 @@ LLVMEngine::compileIfEnd(CEnv& cenv, IfState* state, CVal elseV, const AType* ty
}
CVal
-LLVMEngine::compileIf(CEnv& cenv, const ATuple* aif)
-{
- IfState* state = compileIfStart(cenv);
- for (ATuple::const_iterator i = aif->iter_at(1); ; ++i) {
- ATuple::const_iterator next = i;
- if (++next == aif->end())
- break;
-
- compileIfBranch(cenv, state, resp_compile(cenv, *i), *next);
-
- i = next; // jump 2 each iteration (to the next predicate)
- }
-
- CVal elseV = resp_compile(cenv, aif->list_last());
- return compileIfEnd(cenv, state, elseV, cenv.type(aif));
-}
-
-CVal
LLVMEngine::compileMatch(CEnv& cenv, const ATuple* match)
{
LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
- IfState* state = compileIfStart(cenv);
+ IfState state = compileIfStart(cenv);
Value* matchee = llVal(resp_compile(cenv, match->list_ref(1)));
Value* rttiPtr = builder.CreateStructGEP(matchee, 0, "matchRTTIPtr");
Value* rtti = builder.CreateLoad(rttiPtr, 0, "matchRTTI");