-
Notifications
You must be signed in to change notification settings - Fork 10
/
struct.llcpp
227 lines (191 loc) · 8.06 KB
/
struct.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Generated by llvm2cpp - DO NOT MODIFY!
#include <llvm/Pass.h>
#include <llvm/PassManager.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Assembly/PrintModulePass.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/CallingConv.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/InlineAsm.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/MathExtras.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("struct.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-n8:16:32:64-S128");
mod->setTargetTriple("x86_64-apple-macosx10.7.0");
// Type Definitions
StructType *StructTy_struct_Foo = mod->getTypeByName("struct.Foo");
if (!StructTy_struct_Foo) {
StructTy_struct_Foo = StructType::create(mod->getContext(), "struct.Foo");
}
std::vector<Type*>StructTy_struct_Foo_fields;
StructTy_struct_Foo_fields.push_back(IntegerType::get(mod->getContext(), 32));
StructTy_struct_Foo_fields.push_back(Type::getDoubleTy(mod->getContext()));
ArrayType* ArrayTy_0 = ArrayType::get(Type::getDoubleTy(mod->getContext()), 10);
StructTy_struct_Foo_fields.push_back(ArrayTy_0);
if (StructTy_struct_Foo->isOpaque()) {
StructTy_struct_Foo->setBody(StructTy_struct_Foo_fields, /*isPacked=*/false);
}
PointerType* PointerTy_1 = PointerType::get(StructTy_struct_Foo, 0);
std::vector<Type*>FuncTy_2_args;
FuncTy_2_args.push_back(IntegerType::get(mod->getContext(), 32));
FuncTy_2_args.push_back(Type::getDoubleTy(mod->getContext()));
FunctionType* FuncTy_2 = FunctionType::get(
/*Result=*/IntegerType::get(mod->getContext(), 32),
/*Params=*/FuncTy_2_args,
/*isVarArg=*/false);
PointerType* PointerTy_3 = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
PointerType* PointerTy_4 = PointerType::get(Type::getDoubleTy(mod->getContext()), 0);
PointerType* PointerTy_5 = PointerType::get(ArrayTy_0, 0);
std::vector<Type*>FuncTy_6_args;
FunctionType* FuncTy_6 = FunctionType::get(
/*Result=*/Type::getVoidTy(mod->getContext()),
/*Params=*/FuncTy_6_args,
/*isVarArg=*/false);
// Function Declarations
Function* func_foo = mod->getFunction("foo");
if (!func_foo) {
func_foo = Function::Create(
/*Type=*/FuncTy_2,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"foo", mod);
func_foo->setCallingConv(CallingConv::C);
}
AttributeSet func_foo_PAL;
{
SmallVector<AttributeSet, 4> Attrs;
AttributeSet PAS;
{
AttrBuilder B;
B.addAttribute(Attribute::NoUnwind);
B.addAttribute(Attribute::StackProtect);
B.addAttribute(Attribute::UWTable);
PAS = AttributeSet::get(mod->getContext(), ~0U, B);
}
Attrs.push_back(PAS);
func_foo_PAL = AttributeSet::get(mod->getContext(), Attrs);
}
func_foo->setAttributes(func_foo_PAL);
Function* func_global = mod->getFunction("global");
if (!func_global) {
func_global = Function::Create(
/*Type=*/FuncTy_6,
/*Linkage=*/GlobalValue::ExternalLinkage,
/*Name=*/"global", mod);
func_global->setCallingConv(CallingConv::C);
}
AttributeSet func_global_PAL;
{
SmallVector<AttributeSet, 4> Attrs;
AttributeSet PAS;
{
AttrBuilder B;
B.addAttribute(Attribute::NoUnwind);
B.addAttribute(Attribute::StackProtect);
B.addAttribute(Attribute::UWTable);
PAS = AttributeSet::get(mod->getContext(), ~0U, B);
}
Attrs.push_back(PAS);
func_global_PAL = AttributeSet::get(mod->getContext(), Attrs);
}
func_global->setAttributes(func_global_PAL);
// Global Variable Declarations
GlobalVariable* gvar_struct_f = new GlobalVariable(/*Module=*/*mod,
/*Type=*/StructTy_struct_Foo,
/*isConstant=*/false,
/*Linkage=*/GlobalValue::CommonLinkage,
/*Initializer=*/0, // has initializer, specified below
/*Name=*/"f");
gvar_struct_f->setAlignment(8);
// Constant Definitions
ConstantAggregateZero* const_struct_7 = ConstantAggregateZero::get(StructTy_struct_Foo);
ConstantInt* const_int32_8 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
ConstantInt* const_int32_9 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
ConstantInt* const_int32_10 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("2"), 10));
ConstantInt* const_int64_11 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("0"), 10));
ConstantInt* const_int32_12 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("7"), 10));
std::vector<Constant*> const_ptr_13_indices;
const_ptr_13_indices.push_back(const_int32_9);
const_ptr_13_indices.push_back(const_int32_9);
Constant* const_ptr_13 = ConstantExpr::getGetElementPtr(gvar_struct_f, const_ptr_13_indices);
// Global Variable Definitions
gvar_struct_f->setInitializer(const_struct_7);
// Function Definitions
// Function: foo (func_foo)
{
Function::arg_iterator args = func_foo->arg_begin();
Value* int32_i = args++;
int32_i->setName("i");
Value* double_d = args++;
double_d->setName("d");
BasicBlock* label_entry = BasicBlock::Create(mod->getContext(), "entry",func_foo,0);
// Block entry (label_entry)
AllocaInst* ptr_i_addr = new AllocaInst(IntegerType::get(mod->getContext(), 32), "i.addr", label_entry);
ptr_i_addr->setAlignment(4);
AllocaInst* ptr_d_addr = new AllocaInst(Type::getDoubleTy(mod->getContext()), "d.addr", label_entry);
ptr_d_addr->setAlignment(8);
AllocaInst* ptr_f = new AllocaInst(StructTy_struct_Foo, "f", label_entry);
ptr_f->setAlignment(8);
StoreInst* void_14 = new StoreInst(int32_i, ptr_i_addr, false, label_entry);
void_14->setAlignment(4);
StoreInst* void_15 = new StoreInst(double_d, ptr_d_addr, false, label_entry);
void_15->setAlignment(8);
LoadInst* int32_16 = new LoadInst(ptr_i_addr, "", false, label_entry);
int32_16->setAlignment(4);
std::vector<Value*> ptr_i1_indices;
ptr_i1_indices.push_back(const_int32_9);
ptr_i1_indices.push_back(const_int32_9);
Instruction* ptr_i1 = GetElementPtrInst::Create(ptr_f, ptr_i1_indices, "i1", label_entry);
StoreInst* void_17 = new StoreInst(int32_16, ptr_i1, false, label_entry);
void_17->setAlignment(4);
LoadInst* double_18 = new LoadInst(ptr_d_addr, "", false, label_entry);
double_18->setAlignment(8);
std::vector<Value*> ptr_d2_indices;
ptr_d2_indices.push_back(const_int32_9);
ptr_d2_indices.push_back(const_int32_8);
Instruction* ptr_d2 = GetElementPtrInst::Create(ptr_f, ptr_d2_indices, "d2", label_entry);
StoreInst* void_19 = new StoreInst(double_18, ptr_d2, false, label_entry);
void_19->setAlignment(8);
LoadInst* double_20 = new LoadInst(ptr_d_addr, "", false, label_entry);
double_20->setAlignment(8);
std::vector<Value*> ptr_vals_indices;
ptr_vals_indices.push_back(const_int32_9);
ptr_vals_indices.push_back(const_int32_10);
Instruction* ptr_vals = GetElementPtrInst::Create(ptr_f, ptr_vals_indices, "vals", label_entry);
std::vector<Value*> ptr_arrayidx_indices;
ptr_arrayidx_indices.push_back(const_int32_9);
ptr_arrayidx_indices.push_back(const_int64_11);
Instruction* ptr_arrayidx = GetElementPtrInst::Create(ptr_vals, ptr_arrayidx_indices, "arrayidx", label_entry);
StoreInst* void_21 = new StoreInst(double_20, ptr_arrayidx, false, label_entry);
void_21->setAlignment(8);
ReturnInst::Create(mod->getContext(), const_int32_9, label_entry);
}
// Function: global (func_global)
{
BasicBlock* label_entry_23 = BasicBlock::Create(mod->getContext(), "entry",func_global,0);
// Block entry (label_entry_23)
StoreInst* void_24 = new StoreInst(const_int32_12, const_ptr_13, false, label_entry_23);
void_24->setAlignment(4);
ReturnInst::Create(mod->getContext(), label_entry_23);
}
return mod;
}