Merge branch 'master' of git.tuxzone.org:woc2013
This commit is contained in:
2
doc/example3.x
Normal file
2
doc/example3.x
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
int rofl dana fox mulder int x; x = 5; if dana x == 5 fox x = 2; return x; scully
|
||||||
|
rofl dana fox
|
||||||
5
doc/example4.x
Normal file
5
doc/example4.x
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
int foobar dana fox mulder return 9001; scully
|
||||||
|
int barfoo dana fox mulder return 8999; scully
|
||||||
|
int foo dana int x fox mulder int y; if dana 2 < x fox y = foobar dana fox; if dana x < 2 fox y = barfoo dana fox; return y; scully
|
||||||
|
foo dana 3 fox
|
||||||
|
foo dana 1 fox
|
||||||
@@ -83,7 +83,11 @@ void CodeGenVisitor::visit(ConstantExpression* e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenVisitor::visit(ExpressionStatement* e) {
|
void CodeGenVisitor::visit(ExpressionStatement* e) {
|
||||||
|
value_ = 0;
|
||||||
e->getExpr()->accept(this);
|
e->getExpr()->accept(this);
|
||||||
|
if (!value_) {
|
||||||
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenVisitor::visit(ForStatement* e)
|
void CodeGenVisitor::visit(ForStatement* e)
|
||||||
@@ -91,7 +95,11 @@ void CodeGenVisitor::visit(ForStatement* e)
|
|||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getInit()->accept(this);
|
e->getInit()->accept(this);
|
||||||
|
|
||||||
|
value_ = 0;
|
||||||
e->getCond()->accept(this);
|
e->getCond()->accept(this);
|
||||||
|
if (!value_) {
|
||||||
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
||||||
llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
||||||
@@ -101,20 +109,14 @@ void CodeGenVisitor::visit(ForStatement* e)
|
|||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getStmt()->accept(this);
|
e->getStmt()->accept(this);
|
||||||
if (value_ == 0) {
|
|
||||||
// throw err
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getStep()->accept(this);
|
e->getStep()->accept(this);
|
||||||
if (value_ == 0) {
|
|
||||||
// throw err
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getCond()->accept(this);
|
e->getCond()->accept(this);
|
||||||
if (value_ == 0) {
|
if (!value_) {
|
||||||
// throw err
|
throw "error evaluating expression";
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
||||||
@@ -218,6 +220,9 @@ void CodeGenVisitor::visit(FunctionDefinition* e) {
|
|||||||
void CodeGenVisitor::visit(IfStatement* e) {
|
void CodeGenVisitor::visit(IfStatement* e) {
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getCond()->accept(this);
|
e->getCond()->accept(this);
|
||||||
|
if (!value_) {
|
||||||
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
||||||
llvm::BasicBlock* thenBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "then", f);
|
llvm::BasicBlock* thenBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "then", f);
|
||||||
@@ -242,17 +247,21 @@ void CodeGenVisitor::visit(IfStatement* e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenVisitor::visit(ParameterList* e) {
|
void CodeGenVisitor::visit(ParameterList* e) {
|
||||||
|
// NOT USED
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeGenVisitor::visit(RandomForStatement* e) {
|
void CodeGenVisitor::visit(RandomForStatement* e) {
|
||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getInit()->accept(this);
|
e->getInit()->accept(this);
|
||||||
|
|
||||||
|
value_ = 0;
|
||||||
e->getProb()->accept(this);
|
e->getProb()->accept(this);
|
||||||
llvm::Function* cf = module_->getFunction("random_if");
|
if (!value_) {
|
||||||
llvm::Value* prob = builder_->CreateCall(cf,value_,"callTmp");
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::Function* cf = module_->getFunction("random_if");
|
||||||
|
llvm::Value* prob = builder_->CreateCall(cf, value_, "callTmp");
|
||||||
|
|
||||||
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
||||||
llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
||||||
@@ -262,20 +271,14 @@ void CodeGenVisitor::visit(RandomForStatement* e) {
|
|||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getStmt()->accept(this);
|
e->getStmt()->accept(this);
|
||||||
if (value_ == 0) {
|
|
||||||
// throw err
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getStep()->accept(this);
|
e->getStep()->accept(this);
|
||||||
if (value_ == 0) {
|
|
||||||
// throw err
|
|
||||||
}
|
|
||||||
|
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getProb()->accept(this);
|
e->getProb()->accept(this);
|
||||||
if (value_ == 0) {
|
if (value_ == 0) {
|
||||||
// throw err
|
throw "error evaluating expression";
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
||||||
@@ -289,6 +292,10 @@ void CodeGenVisitor::visit(RandomForStatement* e) {
|
|||||||
void CodeGenVisitor::visit(RandomIfStatement* e) {
|
void CodeGenVisitor::visit(RandomIfStatement* e) {
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
e->getProb()->accept(this);
|
e->getProb()->accept(this);
|
||||||
|
if (!value_) {
|
||||||
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
|
|
||||||
llvm::Function* cf = module_->getFunction("random_if");
|
llvm::Function* cf = module_->getFunction("random_if");
|
||||||
llvm::Value* cond = builder_->CreateCall(cf,value_,"callTmp");
|
llvm::Value* cond = builder_->CreateCall(cf,value_,"callTmp");
|
||||||
|
|
||||||
@@ -316,6 +323,11 @@ void CodeGenVisitor::visit(RandomIfStatement* e) {
|
|||||||
|
|
||||||
void CodeGenVisitor::visit(ReturnStatement* e) {
|
void CodeGenVisitor::visit(ReturnStatement* e) {
|
||||||
e->getExpr()->accept(this);
|
e->getExpr()->accept(this);
|
||||||
|
|
||||||
|
if (!value_) {
|
||||||
|
throw "error evaluating expression";
|
||||||
|
}
|
||||||
|
|
||||||
builder_->CreateRet(value_);
|
builder_->CreateRet(value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
int main() {
|
int main() {
|
||||||
srand(42);
|
srand(42);
|
||||||
|
|
||||||
bool debugParser = false;
|
bool debugParser = true;
|
||||||
bool debugCodeGen = false;
|
bool debugCodeGen = true;
|
||||||
|
|
||||||
lexertl::rules rules;
|
lexertl::rules rules;
|
||||||
lexertl::state_machine state_machine;
|
lexertl::state_machine state_machine;
|
||||||
|
|||||||
Reference in New Issue
Block a user