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) {
|
||||
value_ = 0;
|
||||
e->getExpr()->accept(this);
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
}
|
||||
|
||||
void CodeGenVisitor::visit(ForStatement* e)
|
||||
@@ -91,7 +95,11 @@ void CodeGenVisitor::visit(ForStatement* e)
|
||||
value_ = 0;
|
||||
e->getInit()->accept(this);
|
||||
|
||||
value_ = 0;
|
||||
e->getCond()->accept(this);
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
||||
llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
||||
@@ -101,20 +109,14 @@ void CodeGenVisitor::visit(ForStatement* e)
|
||||
|
||||
value_ = 0;
|
||||
e->getStmt()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
}
|
||||
|
||||
value_ = 0;
|
||||
e->getStep()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
}
|
||||
|
||||
value_ = 0;
|
||||
e->getCond()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
||||
@@ -218,6 +220,9 @@ void CodeGenVisitor::visit(FunctionDefinition* e) {
|
||||
void CodeGenVisitor::visit(IfStatement* e) {
|
||||
value_ = 0;
|
||||
e->getCond()->accept(this);
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
llvm::Function* f = builder_->GetInsertBlock()->getParent();
|
||||
llvm::BasicBlock* thenBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "then", f);
|
||||
@@ -242,18 +247,22 @@ void CodeGenVisitor::visit(IfStatement* e) {
|
||||
}
|
||||
|
||||
void CodeGenVisitor::visit(ParameterList* e) {
|
||||
// NOT USED
|
||||
}
|
||||
|
||||
void CodeGenVisitor::visit(RandomForStatement* e) {
|
||||
|
||||
value_ = 0;
|
||||
e->getInit()->accept(this);
|
||||
|
||||
value_ = 0;
|
||||
e->getProb()->accept(this);
|
||||
if (!value_) {
|
||||
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::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f);
|
||||
|
||||
@@ -262,20 +271,14 @@ void CodeGenVisitor::visit(RandomForStatement* e) {
|
||||
|
||||
value_ = 0;
|
||||
e->getStmt()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
}
|
||||
|
||||
value_ = 0;
|
||||
e->getStep()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
}
|
||||
|
||||
value_ = 0;
|
||||
e->getProb()->accept(this);
|
||||
if (value_ == 0) {
|
||||
// throw err
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f);
|
||||
@@ -289,6 +292,10 @@ void CodeGenVisitor::visit(RandomForStatement* e) {
|
||||
void CodeGenVisitor::visit(RandomIfStatement* e) {
|
||||
value_ = 0;
|
||||
e->getProb()->accept(this);
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
llvm::Function* cf = module_->getFunction("random_if");
|
||||
llvm::Value* cond = builder_->CreateCall(cf,value_,"callTmp");
|
||||
|
||||
@@ -316,6 +323,11 @@ void CodeGenVisitor::visit(RandomIfStatement* e) {
|
||||
|
||||
void CodeGenVisitor::visit(ReturnStatement* e) {
|
||||
e->getExpr()->accept(this);
|
||||
|
||||
if (!value_) {
|
||||
throw "error evaluating expression";
|
||||
}
|
||||
|
||||
builder_->CreateRet(value_);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
int main() {
|
||||
srand(42);
|
||||
|
||||
bool debugParser = false;
|
||||
bool debugCodeGen = false;
|
||||
bool debugParser = true;
|
||||
bool debugCodeGen = true;
|
||||
|
||||
lexertl::rules rules;
|
||||
lexertl::state_machine state_machine;
|
||||
|
||||
Reference in New Issue
Block a user