From 6db6d7da181bd1a3b8d590fd3cbc7fcb5130d2c2 Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Sat, 1 Jun 2013 18:57:41 +0200 Subject: [PATCH] added for statment --- src/AST/CodeGenVisitor.cpp | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/AST/CodeGenVisitor.cpp b/src/AST/CodeGenVisitor.cpp index a9025f1..ea6468a 100644 --- a/src/AST/CodeGenVisitor.cpp +++ b/src/AST/CodeGenVisitor.cpp @@ -65,7 +65,47 @@ void CodeGenVisitor::visit(ConstantExpression* e) { void CodeGenVisitor::visit(ExpressionStatement* e) { } -void CodeGenVisitor::visit(ForStatement* e) { +void CodeGenVisitor::visit(ForStatement* e) +{ + value_ = 0; + e->getInit()->accept(this); + + + e->getCond()->accept(this); + + llvm::Function* f = builder_->GetInsertBlock()->getParent(); + llvm::BasicBlock* loopBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", f); + + builder_->CreateBr(loopBB); + builder_->SetInsertPoint(loopBB); + + + 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 + } + + llvm::BasicBlock* afterBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "afterLoop",f); + + builder_->CreateCondBr(value_, loopBB, afterBB); + + builder_->SetInsertPoint(afterBB); } void CodeGenVisitor::visit(FunctionCallExpression* e) {