More error handling

This commit is contained in:
Markus Hauschild
2013-06-02 00:01:38 +02:00
parent 3e62dfb277
commit c485352850

View File

@@ -214,6 +214,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);
@@ -238,17 +241,21 @@ 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);
llvm::Function* cf = module_->getFunction("random_if");
llvm::Value* prob = builder_->CreateCall(cf,value_,"callTmp");
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);
@@ -258,20 +265,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);
@@ -285,6 +286,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");
@@ -312,6 +317,11 @@ void CodeGenVisitor::visit(RandomIfStatement* e) {
void CodeGenVisitor::visit(ReturnStatement* e) {
e->getExpr()->accept(this);
if (!value_) {
throw "error evaluating expression";
}
builder_->CreateRet(value_);
}