-
Notifications
You must be signed in to change notification settings - Fork 10
/
not.llcpp
111 lines (89 loc) · 3.87 KB
/
not.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
// 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("not.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));
// Global Variable Definitions
// Function Definitions
// Function: foo (func_foo)
{
Function::arg_iterator args = func_foo->arg_begin();
Value* int32_z = args++;
int32_z->setName("z");
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func_foo,0);
BasicBlock* label_return = BasicBlock::Create(mod->getContext(), "return",func_foo,0);
// Block entry (label_entry)
AllocaInst* ptr_z_addr = new AllocaInst(IntegerType::get(mod->getContext(), 32), "z_addr", label_entry);
AllocaInst* ptr_retval = new AllocaInst(IntegerType::get(mod->getContext(), 32), "retval", label_entry);
AllocaInst* ptr_4 = 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_z, ptr_z_addr, false, label_entry);
LoadInst* int32_6 = new LoadInst(ptr_z_addr, "", false, label_entry);
ICmpInst* int1_7 = new ICmpInst(*label_entry, ICmpInst::ICMP_EQ, int32_6, const_int32_3, "");
CastInst* int32_8 = new ZExtInst(int1_7, IntegerType::get(mod->getContext(), 32), "", label_entry);
new StoreInst(int32_8, ptr_4, false, label_entry);
LoadInst* int32_10 = new LoadInst(ptr_4, "", false, label_entry);
new StoreInst(int32_10, ptr_retval, false, label_entry);
BranchInst::Create(label_return, label_entry);
// Block return (label_return)
LoadInst* int32_retval1 = new LoadInst(ptr_retval, "retval1", false, label_return);
ReturnInst::Create(mod->getContext(), int32_retval1, label_return);
}
return mod;
}