Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. // Generated by llvm2cpp - DO NOT MODIFY!
  2.  
  3. #include <llvm/Pass.h>
  4. #include <llvm/ADT/SmallVector.h>
  5. #include <llvm/Analysis/Verifier.h>
  6. #include <llvm/IR/BasicBlock.h>
  7. #include <llvm/IR/CallingConv.h>
  8. #include <llvm/IR/Constants.h>
  9. #include <llvm/IR/DerivedTypes.h>
  10. #include <llvm/IR/Function.h>
  11. #include <llvm/IR/GlobalVariable.h>
  12. #include <llvm/IR/IRPrintingPasses.h>
  13. #include <llvm/IR/InlineAsm.h>
  14. #include <llvm/IR/Instructions.h>
  15. #include <llvm/IR/LLVMContext.h>
  16. #include <llvm/IR/LegacyPassManager.h>
  17. #include <llvm/IR/Module.h>
  18. #include <llvm/Support/FormattedStream.h>
  19. #include <llvm/Support/MathExtras.h>
  20. #include <algorithm>
  21. using namespace llvm;
  22.  
  23. Module* makeLLVMModule();
  24.  
  25. int main(int argc, char**argv) {
  26. Module* Mod = makeLLVMModule();
  27. verifyModule(*Mod, PrintMessageAction);
  28. PassManager PM;
  29. PM.add(createPrintModulePass(&outs()));
  30. PM.run(*Mod);
  31. return 0;
  32. }
  33.  
  34.  
  35. Module* makeLLVMModule() {
  36. // Module Construction
  37. Module* mod = new Module("hello.ll", getGlobalContext());
  38. mod->setDataLayout("");
  39. mod->setTargetTriple("x86_64-unknown-linux-gnu");
  40.  
  41. // Type Definitions
  42. std::vector<Type*>StructTy_0_fields;
  43. StructTy_0_fields.push_back(IntegerType::get(mod->getContext(), 64));
  44. StructType *StructTy_struct_func = mod->getTypeByName("struct.func");
  45. if (!StructTy_struct_func) {
  46. StructTy_struct_func = StructType::create(mod->getContext(), "struct.func");
  47. }
  48. std::vector<Type*>StructTy_struct_func_fields;
  49. StructTy_struct_func_fields.push_back(IntegerType::get(mod->getContext(), 64));
  50. PointerType* PointerTy_2 = PointerType::get(StructTy_struct_func, 0);
  51.  
  52. ArrayType* ArrayTy_3 = ArrayType::get(PointerTy_2, 0);
  53.  
  54. StructTy_struct_func_fields.push_back(ArrayTy_3);
  55. if (StructTy_struct_func->isOpaque()) {
  56. StructTy_struct_func->setBody(StructTy_struct_func_fields, /*isPacked=*/false);
  57. }
  58.  
  59.  
  60. ArrayType* ArrayTy_1 = ArrayType::get(PointerTy_2, 2);
  61.  
  62. StructTy_0_fields.push_back(ArrayTy_1);
  63. StructType *StructTy_0 = StructType::get(mod->getContext(), StructTy_0_fields, /*isPacked=*/false);
  64.  
  65. PointerType* PointerTy_4 = PointerType::get(StructTy_0, 0);
  66.  
  67. std::vector<Type*>StructTy_5_fields;
  68. StructTy_5_fields.push_back(IntegerType::get(mod->getContext(), 64));
  69. ArrayType* ArrayTy_6 = ArrayType::get(PointerTy_2, 1);
  70.  
  71. StructTy_5_fields.push_back(ArrayTy_6);
  72. StructType *StructTy_5 = StructType::get(mod->getContext(), StructTy_5_fields, /*isPacked=*/false);
  73.  
  74. PointerType* PointerTy_7 = PointerType::get(StructTy_5, 0);
  75.  
  76. ArrayType* ArrayTy_8 = ArrayType::get(IntegerType::get(mod->getContext(), 8), 13);
  77.  
  78. PointerType* PointerTy_9 = PointerType::get(ArrayTy_8, 0);
  79.  
  80. std::vector<Type*>FuncTy_10_args;
  81. FunctionType* FuncTy_10 = FunctionType::get(
  82. /*Result=*/IntegerType::get(mod->getContext(), 32),
  83. /*Params=*/FuncTy_10_args,
  84. /*isVarArg=*/false);
  85.  
  86. PointerType* PointerTy_11 = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
  87.  
  88. PointerType* PointerTy_12 = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
  89.  
  90. std::vector<Type*>FuncTy_14_args;
  91. FuncTy_14_args.push_back(PointerTy_12);
  92. FunctionType* FuncTy_14 = FunctionType::get(
  93. /*Result=*/IntegerType::get(mod->getContext(), 32),
  94. /*Params=*/FuncTy_14_args,
  95. /*isVarArg=*/true);
  96.  
  97. PointerType* PointerTy_13 = PointerType::get(FuncTy_14, 0);
  98.  
  99.  
  100. // Function Declarations
  101.  
  102. Function* func_main = mod->getFunction("main");
  103. if (!func_main) {
  104. func_main = Function::Create(
  105. /*Type=*/FuncTy_10,
  106. /*Linkage=*/GlobalValue::ExternalLinkage,
  107. /*Name=*/"main", mod);
  108. func_main->setCallingConv(CallingConv::C);
  109. }
  110. AttributeSet func_main_PAL;
  111. {
  112. SmallVector<AttributeSet, 4> Attrs;
  113. AttributeSet PAS;
  114. {
  115. AttrBuilder B;
  116. B.addAttribute(Attribute::NoUnwind);
  117. B.addAttribute(Attribute::UWTable);
  118. PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  119. }
  120.  
  121. Attrs.push_back(PAS);
  122. func_main_PAL = AttributeSet::get(mod->getContext(), Attrs);
  123.  
  124. }
  125. func_main->setAttributes(func_main_PAL);
  126.  
  127. Function* func_printf = mod->getFunction("printf");
  128. if (!func_printf) {
  129. func_printf = Function::Create(
  130. /*Type=*/FuncTy_14,
  131. /*Linkage=*/GlobalValue::ExternalLinkage,
  132. /*Name=*/"printf", mod); // (external, no body)
  133. func_printf->setCallingConv(CallingConv::C);
  134. }
  135. AttributeSet func_printf_PAL;
  136. {
  137. SmallVector<AttributeSet, 4> Attrs;
  138. AttributeSet PAS;
  139. {
  140. AttrBuilder B;
  141. PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  142. }
  143.  
  144. Attrs.push_back(PAS);
  145. func_printf_PAL = AttributeSet::get(mod->getContext(), Attrs);
  146.  
  147. }
  148. func_printf->setAttributes(func_printf_PAL);
  149.  
  150. // Global Variable Declarations
  151.  
  152.  
  153. GlobalVariable* gvar_struct___fstack_main = new GlobalVariable(/*Module=*/*mod,
  154. /*Type=*/StructTy_0,
  155. /*isConstant=*/false,
  156. /*Linkage=*/GlobalValue::ExternalLinkage,
  157. /*Initializer=*/0, // has initializer, specified below
  158. /*Name=*/"__fstack_main");
  159. gvar_struct___fstack_main->setAlignment(8);
  160.  
  161. GlobalVariable* gvar_struct___fstack_foo = new GlobalVariable(/*Module=*/*mod,
  162. /*Type=*/StructTy_5,
  163. /*isConstant=*/false,
  164. /*Linkage=*/GlobalValue::ExternalLinkage,
  165. /*Initializer=*/0, // has initializer, specified below
  166. /*Name=*/"__fstack_foo");
  167. gvar_struct___fstack_foo->setAlignment(8);
  168.  
  169. GlobalVariable* gvar_struct___fstack_bar = new GlobalVariable(/*Module=*/*mod,
  170. /*Type=*/StructTy_5,
  171. /*isConstant=*/false,
  172. /*Linkage=*/GlobalValue::ExternalLinkage,
  173. /*Initializer=*/0, // has initializer, specified below
  174. /*Name=*/"__fstack_bar");
  175. gvar_struct___fstack_bar->setAlignment(8);
  176.  
  177. GlobalVariable* gvar_array__str = new GlobalVariable(/*Module=*/*mod,
  178. /*Type=*/ArrayTy_8,
  179. /*isConstant=*/true,
  180. /*Linkage=*/GlobalValue::PrivateLinkage,
  181. /*Initializer=*/0, // has initializer, specified below
  182. /*Name=*/".str");
  183. gvar_array__str->setAlignment(1);
  184.  
  185. // Constant Definitions
  186. std::vector<Constant*> const_struct_15_fields;
  187. ConstantInt* const_int64_16 = ConstantInt::get(mod->getContext(), APInt(64, StringRef("2"), 10));
  188. const_struct_15_fields.push_back(const_int64_16);
  189. std::vector<Constant*> const_array_17_elems;
  190. Constant* const_ptr_18 = ConstantExpr::getCast(Instruction::BitCast, gvar_struct___fstack_foo, PointerTy_2);
  191. const_array_17_elems.push_back(const_ptr_18);
  192. Constant* const_ptr_19 = ConstantExpr::getCast(Instruction::BitCast, gvar_struct___fstack_bar, PointerTy_2);
  193. const_array_17_elems.push_back(const_ptr_19);
  194. Constant* const_array_17 = ConstantArray::get(ArrayTy_1, const_array_17_elems);
  195. const_struct_15_fields.push_back(const_array_17);
  196. Constant* const_struct_15 = ConstantStruct::get(StructTy_0, const_struct_15_fields);
  197. ConstantAggregateZero* const_struct_20 = ConstantAggregateZero::get(StructTy_5);
  198. Constant *const_array_21 = ConstantDataArray::getString(mod->getContext(), "hello world\x0A", true);
  199. ConstantInt* const_int32_22 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
  200. ConstantInt* const_int32_23 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
  201. std::vector<Constant*> const_ptr_24_indices;
  202. const_ptr_24_indices.push_back(const_int32_23);
  203. const_ptr_24_indices.push_back(const_int32_23);
  204. Constant* const_ptr_24 = ConstantExpr::getGetElementPtr(gvar_array__str, const_ptr_24_indices);
  205.  
  206. // Global Variable Definitions
  207. gvar_struct___fstack_main->setInitializer(const_struct_15);
  208. gvar_struct___fstack_foo->setInitializer(const_struct_20);
  209. gvar_struct___fstack_bar->setInitializer(const_struct_20);
  210. gvar_array__str->setInitializer(const_array_21);
  211.  
  212. // Function Definitions
  213.  
  214. // Function: main (func_main)
  215. {
  216.  
  217. BasicBlock* label_25 = BasicBlock::Create(mod->getContext(), "",func_main,0);
  218.  
  219. // Block (label_25)
  220. AllocaInst* ptr_26 = new AllocaInst(IntegerType::get(mod->getContext(), 32), "", label_25);
  221. ptr_26->setAlignment(4);
  222. StoreInst* void_27 = new StoreInst(const_int32_23, ptr_26, false, label_25);
  223. CallInst* int32_28 = CallInst::Create(func_printf, const_ptr_24, "", label_25);
  224. int32_28->setCallingConv(CallingConv::C);
  225. int32_28->setTailCall(false);
  226. AttributeSet int32_28_PAL;
  227. int32_28->setAttributes(int32_28_PAL);
  228.  
  229. ReturnInst::Create(mod->getContext(), const_int32_23, label_25);
  230.  
  231. }
  232.  
  233. return mod;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement