-
Notifications
You must be signed in to change notification settings - Fork 10
/
whileReturn.llcpp
140 lines (113 loc) · 5.37 KB
/
whileReturn.llcpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Generated by llvm2cpp - DO NOT MODIFY!
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Constants.h>
#include <llvm/GlobalVariable.h>
#include <llvm/Function.h>
#include <llvm/CallingConv.h>
#include <llvm/BasicBlock.h>
#include <llvm/Instructions.h>
#include <llvm/InlineAsm.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/MathExtras.h>
#include <llvm/Pass.h>
#include <llvm/PassManager.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Assembly/PrintModulePass.h>
#include <algorithm>
using namespace llvm;
Module* makeLLVMModule();
int main(int argc, char**argv) {
Module* Mod = makeLLVMModule();
verifyModule(*Mod, PrintMessageAction);
PassManager PM;
PM.add(createPrintModulePass(&outs()));
PM.run(*Mod);
return 0;
}
Module* makeLLVMModule() {
// Module Construction
Module* mod = new Module("whileReturn.bc", getGlobalContext());
mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128");
mod->setTargetTriple("x86_64-apple-darwin10.4");
// Type Definitions
std::vector<const Type*>FuncTy_0_args;
FuncTy_0_args.push_back(IntegerType::get(mod->getContext(), 32));
FunctionType* FuncTy_0 = FunctionType::get(
/*Result=*/IntegerType::get(mod->getContext(), 32),
/*Params=*/FuncTy_0_args,
/*isVarArg=*/false);
PointerType* PointerTy_1 = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
// Function Declarations
Function* func_foo = Function::Create(
/*Type=*/FuncTy_0,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"foo", mod);
func_foo->setCallingConv(CallingConv::C);
AttrListPtr func_foo_PAL;
{
SmallVector<AttributeWithIndex, 4> Attrs;
AttributeWithIndex PAWI;
PAWI.Index = 4294967295U; PAWI.Attrs = 0 | Attribute::NoUnwind | Attribute::StackProtect;
Attrs.push_back(PAWI);
func_foo_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
}
func_foo->setAttributes(func_foo_PAL);
// Global Variable Declarations
// Constant Definitions
ConstantInt* const_int32_2 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
ConstantInt* const_int32_3 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int32_4 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("5"), 10));
ConstantInt* const_int32_5 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("9"), 10));
// Global Variable Definitions
// Function Definitions
// Function: foo (func_foo)
{
Function::arg_iterator args = func_foo->arg_begin();
Value* int32_len = args++;
int32_len->setName("len");
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func_foo,0);
BasicBlock* label_bb = BasicBlock::Create(mod->getContext(), "bb",func_foo,0);
BasicBlock* label_bb1 = BasicBlock::Create(mod->getContext(), "bb1",func_foo,0);
BasicBlock* label_bb2 = BasicBlock::Create(mod->getContext(), "bb2",func_foo,0);
BasicBlock* label_bb3 = BasicBlock::Create(mod->getContext(), "bb3",func_foo,0);
BasicBlock* label_bb4 = BasicBlock::Create(mod->getContext(), "bb4",func_foo,0);
BasicBlock* label_return = BasicBlock::Create(mod->getContext(), "return",func_foo,0);
// Block entry (label_entry)
AllocaInst* ptr_len_addr = new AllocaInst(IntegerType::get(mod->getContext(), 32), "len_addr", label_entry);
AllocaInst* ptr_retval = new AllocaInst(IntegerType::get(mod->getContext(), 32), "retval", label_entry);
AllocaInst* ptr_a = new AllocaInst(IntegerType::get(mod->getContext(), 32), "a", label_entry);
AllocaInst* ptr_6 = new AllocaInst(IntegerType::get(mod->getContext(), 32), "", label_entry);
CastInst* int32_alloca_point = new BitCastInst(const_int32_3, IntegerType::get(mod->getContext(), 32), "alloca point", label_entry);
new StoreInst(int32_len, ptr_len_addr, false, label_entry);
BranchInst::Create(label_bb2, label_entry);
// Block bb (label_bb)
LoadInst* int32_9 = new LoadInst(ptr_a, "", false, label_bb);
BinaryOperator* int32_10 = BinaryOperator::Create(Instruction::Add, int32_9, const_int32_2, "", label_bb);
new StoreInst(int32_10, ptr_a, false, label_bb);
LoadInst* int32_12 = new LoadInst(ptr_a, "", false, label_bb);
ICmpInst* int1_13 = new ICmpInst(*label_bb, ICmpInst::ICMP_SGT, int32_12, const_int32_4, "");
BranchInst::Create(label_bb1, label_bb2, int1_13, label_bb);
// Block bb1 (label_bb1)
LoadInst* int32_15 = new LoadInst(ptr_a, "", false, label_bb1);
new StoreInst(int32_15, ptr_6, false, label_bb1);
BranchInst::Create(label_bb4, label_bb1);
// Block bb2 (label_bb2)
LoadInst* int32_18 = new LoadInst(ptr_len_addr, "", false, label_bb2);
ICmpInst* int1_19 = new ICmpInst(*label_bb2, ICmpInst::ICMP_SLE, int32_18, const_int32_5, "");
BranchInst::Create(label_bb, label_bb3, int1_19, label_bb2);
// Block bb3 (label_bb3)
new StoreInst(const_int32_3, ptr_6, false, label_bb3);
BranchInst::Create(label_bb4, label_bb3);
// Block bb4 (label_bb4)
LoadInst* int32_23 = new LoadInst(ptr_6, "", false, label_bb4);
new StoreInst(int32_23, ptr_retval, false, label_bb4);
BranchInst::Create(label_return, label_bb4);
// Block return (label_return)
LoadInst* int32_retval5 = new LoadInst(ptr_retval, "retval5", false, label_return);
ReturnInst::Create(mod->getContext(), int32_retval5, label_return);
}
return mod;
}