fixed RandomIf

This commit is contained in:
Florian Sattler
2013-06-01 18:18:48 +02:00
parent aecc17c164
commit 5b794bb09d
2 changed files with 5 additions and 3 deletions

View File

@@ -189,17 +189,18 @@ void CodeGenVisitor::visit(RandomForStatement* e) {
void CodeGenVisitor::visit(RandomIfStatement* e) {
value_ = 0;
e->getProb()->accept(this);
llvm::Function* cf = module_->getFunction("random_if");
llvm::Value* cond = builder_->CreateCall(cf,value_,"callTmp");
llvm::Function* f = builder_->GetInsertBlock()->getParent();
llvm::BasicBlock* thenBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "then", f);
llvm::BasicBlock* elseBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "else");
llvm::BasicBlock* mergeBB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "merge");
builder_->CreateCondBr(value_, thenBB, elseBB);
builder_->CreateCondBr(cond, thenBB, elseBB);
// then
builder_->SetInsertPoint(thenBB);#
builder_->SetInsertPoint(thenBB);
e->getStmt()->accept(this);
builder_->CreateBr(mergeBB);

View File

@@ -1,5 +1,6 @@
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
bool random_if(int p) {
srand(time(NULL));