X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=examples%2FBrainF%2FBrainF.cpp;h=86f2ea495d31230c8800391836a11a64358c64dc;hb=dc770929cb2f97397970e2942b746839fc387992;hp=a92079364860d27c2f3abb404e2bf683ac9f2a66;hpb=fc001bbfc360ab828e5a4b0cbe4bb7db87361b85;p=oota-llvm.git diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index a9207936486..86f2ea495d3 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -25,8 +25,9 @@ #include "BrainF.h" #include "llvm/Constants.h" +#include "llvm/Intrinsics.h" #include "llvm/ADT/STLExtras.h" - +#include using namespace llvm; //Set the constants for naming @@ -52,11 +53,7 @@ void BrainF::header() { //Function prototypes //declare void @llvm.memset.i32(i8 *, i8, i32, i32) - Function *memset_func = cast(module-> - getOrInsertFunction("llvm.memset.i32", Type::VoidTy, - PointerType::getUnqual(IntegerType::Int8Ty), - IntegerType::Int8Ty, IntegerType::Int32Ty, - IntegerType::Int32Ty, NULL)); + Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset_i32); //declare i32 @getchar() getchar_func = cast(module-> @@ -74,7 +71,7 @@ void BrainF::header() { brainf_func = cast(module-> getOrInsertFunction("brainf", Type::VoidTy, NULL)); - builder = new LLVMBuilder(new BasicBlock(label, brainf_func)); + builder = new IRBuilder<>(BasicBlock::Create(label, brainf_func)); //%arr = malloc i8, i32 %d ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal)); @@ -110,13 +107,13 @@ void BrainF::header() { //Function footer //brainf.end: - endbb = new BasicBlock(label, brainf_func); + endbb = BasicBlock::Create(label, brainf_func); //free i8 *%arr new FreeInst(ptr_arr, endbb); //ret void - new ReturnInst(endbb); + ReturnInst::Create(endbb); @@ -141,7 +138,7 @@ void BrainF::header() { PointerType::getUnqual(IntegerType::Int8Ty), NULL)); //brainf.aberror: - aberrorbb = new BasicBlock(label, brainf_func); + aberrorbb = BasicBlock::Create(label, brainf_func); //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0)) { @@ -161,14 +158,14 @@ void BrainF::header() { }; CallInst *puts_call = - new CallInst(puts_func, - puts_params, array_endof(puts_params), - "", aberrorbb); + CallInst::Create(puts_func, + puts_params, array_endof(puts_params), + "", aberrorbb); puts_call->setTailCall(false); } //br label %brainf.end - new BranchInst(endbb, aberrorbb); + BranchInst::Create(endbb, aberrorbb); } } @@ -196,7 +193,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { Value *tape_0 = getchar_call; //%tape.%d = trunc i32 %tape.%d to i8 - TruncInst *tape_1 = builder-> + Value *tape_1 = builder-> CreateTrunc(tape_0, IntegerType::Int8Ty, tapereg); //store i8 %tape.%d, i8 *%head.%d @@ -210,7 +207,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { LoadInst *tape_0 = builder->CreateLoad(curhead, tapereg); //%tape.%d = sext i8 %tape.%d to i32 - SExtInst *tape_1 = builder-> + Value *tape_1 = builder-> CreateSExt(tape_0, IntegerType::Int32Ty, tapereg); //call i32 @putchar(i32 %tape.%d) @@ -235,19 +232,19 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { if (comflag & flag_arraybounds) { //%test.%d = icmp uge i8 *%head.%d, %arrmax - ICmpInst *test_0 = builder-> + Value *test_0 = builder-> CreateICmpUGE(curhead, ptr_arrmax, testreg); //%test.%d = icmp ult i8 *%head.%d, %arr - ICmpInst *test_1 = builder-> + Value *test_1 = builder-> CreateICmpULT(curhead, ptr_arr, testreg); //%test.%d = or i1 %test.%d, %test.%d - BinaryOperator *test_2 = builder-> + Value *test_2 = builder-> CreateOr(test_0, test_1, testreg); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *nextbb = new BasicBlock(label, brainf_func); + BasicBlock *nextbb = BasicBlock::Create(label, brainf_func); builder->CreateCondBr(test_2, aberrorbb, nextbb); //main.%d: @@ -262,7 +259,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { LoadInst *tape_0 = builder->CreateLoad(curhead, tapereg); //%tape.%d = add i8 %tape.%d, %d - BinaryOperator *tape_1 = builder-> + Value *tape_1 = builder-> CreateAdd(tape_0, ConstantInt::get(APInt(8, curvalue)), tapereg); //store i8 %tape.%d, i8 *%head.%d\n" @@ -273,17 +270,18 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { case SYM_LOOP: { //br label %main.%d - BasicBlock *testbb = new BasicBlock(label, brainf_func); + BasicBlock *testbb = BasicBlock::Create(label, brainf_func); builder->CreateBr(testbb); //main.%d: BasicBlock *bb_0 = builder->GetInsertBlock(); - BasicBlock *bb_1 = new BasicBlock(label, brainf_func); + BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func); builder->SetInsertPoint(bb_1); - //Make part of PHI instruction now, wait until end of loop to finish - PHINode *phi_0 = new PHINode(PointerType::getUnqual(IntegerType::Int8Ty), - headreg, testbb); + // Make part of PHI instruction now, wait until end of loop to finish + PHINode *phi_0 = + PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty), + headreg, testbb); phi_0->reserveOperandSpace(2); phi_0->addIncoming(curhead, bb_0); curhead = phi_0; @@ -293,7 +291,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { break; default: - cerr<<"Error: Unknown symbol.\n"; + std::cerr << "Error: Unknown symbol.\n"; abort(); break; } @@ -406,7 +404,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { if (cursym == SYM_ENDLOOP) { if (!phi) { - cerr<<"Error: Extra ']'\n"; + std::cerr << "Error: Extra ']'\n"; abort(); } @@ -431,8 +429,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { testbb); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *bb_0 = new BasicBlock(label, brainf_func); - new BranchInst(bb_0, oldbb, test_0, testbb); + BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func); + BranchInst::Create(bb_0, oldbb, test_0, testbb); //main.%d: builder->SetInsertPoint(bb_0); @@ -452,7 +450,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { builder->CreateBr(endbb); if (phi) { - cerr<<"Error: Missing ']'\n"; + std::cerr << "Error: Missing ']'\n"; abort(); } }