aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-06 20:12:35 +0000
committerDavid Robillard <d@drobilla.net>2009-03-06 20:12:35 +0000
commit8ee76375d7f19cd0723334e33050584ec83cfe12 (patch)
tree951a59d05bfd4529fb837b49082c40e083048769
parent64c901f7261dcd78840f728ed2206318a23fab95 (diff)
downloadresp-8ee76375d7f19cd0723334e33050584ec83cfe12.tar.gz
resp-8ee76375d7f19cd0723334e33050584ec83cfe12.tar.bz2
resp-8ee76375d7f19cd0723334e33050584ec83cfe12.zip
Tidy.
git-svn-id: http://svn.drobilla.net/resp/tuplr@61 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--Makefile2
-rw-r--r--llvm.cpp (renamed from tuplr_llvm.cpp)21
-rw-r--r--tuplr.hpp8
-rw-r--r--typing.cpp22
4 files changed, 31 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 22c7a29..001c37d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ LLVM_LDFLAGS=`llvm-config --ldflags --libs core jit native`
CXXFLAGS=-O0 -g -Wall -Wextra -Wno-unused-parameter $(LLVM_CXXFLAGS)
LDFLAGS=$(LLVM_LDFLAGS) -lm
-tuplr: tuplr.o typing.o tuplr_llvm.o
+tuplr: tuplr.o typing.o llvm.o
g++ -o $@ $^ $(LDFLAGS)
%.o: %.cpp tuplr.hpp
diff --git a/tuplr_llvm.cpp b/llvm.cpp
index 5ff570e..0b32656 100644
--- a/tuplr_llvm.cpp
+++ b/llvm.cpp
@@ -212,6 +212,11 @@ compileFunction(CEnv& cenv, const std::string& name, CType retT, const ASTTuple&
return f;
}
+
+/***************************************************************************
+ * AST Code Generation *
+ ***************************************************************************/
+
CValue
ASTSymbol::compile(CEnv& cenv)
{
@@ -332,22 +337,18 @@ ASTIf::compile(CEnv& cenv)
BasicBlock* mergeBB = BasicBlock::Create("endif");
BasicBlock* nextBB = NULL;
Branches branches;
- ostringstream ss;
for (size_t i = 1; i < size() - 1; i += 2) {
- Value* condV = LLVal(cenv.compile(at(i)));
-
- ss.str(""); ss << "then" << ((i + 1) / 2);
- BasicBlock* thenBB = BasicBlock::Create(ss.str());
+ Value* condV = LLVal(cenv.compile(at(i)));
+ BasicBlock* thenBB = BasicBlock::Create((format("then%1%") % ((i+1)/2)).str());
- ss.str(""); ss << "else" << ((i + 1) / 2);
- nextBB = BasicBlock::Create(ss.str());
+ nextBB = BasicBlock::Create((format("else%1%") % ((i+1)/2)).str());
cenv.engine.builder.CreateCondBr(condV, thenBB, nextBB);
// Emit then block for this condition
parent->getBasicBlockList().push_back(thenBB);
cenv.engine.builder.SetInsertPoint(thenBB);
- Value* thenV = LLVal(cenv.compile(at(i + 1)));
+ Value* thenV = LLVal(cenv.compile(at(i+1)));
cenv.engine.builder.CreateBr(mergeBB);
branches.push_back(make_pair(thenV, cenv.engine.builder.GetInsertBlock()));
@@ -355,7 +356,7 @@ ASTIf::compile(CEnv& cenv)
cenv.engine.builder.SetInsertPoint(nextBB);
}
- // Emit else block
+ // Emit final else block
cenv.engine.builder.SetInsertPoint(nextBB);
Value* elseV = LLVal(cenv.compile(at(size() - 1)));
cenv.engine.builder.CreateBr(mergeBB);
@@ -366,7 +367,7 @@ ASTIf::compile(CEnv& cenv)
cenv.engine.builder.SetInsertPoint(mergeBB);
PHINode* pn = cenv.engine.builder.CreatePHI(LLType(cenv.tenv.type(this)->type()), "ifval");
- for (Branches::iterator i = branches.begin(); i != branches.end(); ++i)
+ FOREACH(Branches::iterator, i, branches)
pn->addIncoming(i->first, i->second);
return pn;
diff --git a/tuplr.hpp b/tuplr.hpp
index 093f95c..a1bae51 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -151,7 +151,13 @@ struct ASTTuple : public AST, public vector<AST*> {
FOREACH(iterator, t, *this)
(*t)->lift(cenv);
}
- bool contains(AST* child) const;
+ bool contains(AST* child) const {
+ if (*this == *child) return true;
+ FOREACH(const_iterator, p, *this)
+ if (**p == *child || (*p)->contains(child))
+ return true;
+ return false;
+ }
void constrain(TEnv& tenv) const;
CValue compile(CEnv& cenv) { throw Error("tuple compiled"); }
};
diff --git a/typing.cpp b/typing.cpp
index eeba8dc..9dc94f6 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -16,6 +16,12 @@
*/
#include "tuplr.hpp"
+
+
+/***************************************************************************
+ * AST Type Contraints *
+ ***************************************************************************/
+
void
ASTTuple::constrain(TEnv& tenv) const
{
@@ -107,6 +113,11 @@ ASTCdrCall::constrain(TEnv& tenv) const
tenv.constrain(this, ct);
}
+
+/***************************************************************************
+ * Type Inferencing/Substitution *
+ ***************************************************************************/
+
static void
substitute(ASTTuple* tup, AST* from, AST* to)
{
@@ -118,16 +129,6 @@ substitute(ASTTuple* tup, AST* from, AST* to)
substitute(dynamic_cast<ASTTuple*>(tup->at(i)), from, to);
}
-bool
-ASTTuple::contains(AST* child) const
-{
- if (*this == *child) return true;
- FOREACH(const_iterator, p, *this)
- if (**p == *child || (*p)->contains(child))
- return true;
- return false;
-}
-
TSubst
compose(const TSubst& delta, const TSubst& gamma) // TAPL 22.1.1
{
@@ -196,3 +197,4 @@ TEnv::apply(const TSubst& substs)
else
substitute(t->second, s->first, s->second);
}
+