Advertisement
Guest User

LLVM BC to C++

a guest
Jul 31st, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.45 KB | None | 0 0
  1. // Generated by llvm2cpp - DO NOT MODIFY!
  2.  
  3. #include <llvm/Pass.h>
  4. #include <llvm/PassManager.h>
  5. #include <llvm/ADT/SmallVector.h>
  6. #include <llvm/Analysis/Verifier.h>
  7. #include <llvm/Assembly/PrintModulePass.h>
  8. #include <llvm/IR/BasicBlock.h>
  9. #include <llvm/IR/CallingConv.h>
  10. #include <llvm/IR/Constants.h>
  11. #include <llvm/IR/DerivedTypes.h>
  12. #include <llvm/IR/Function.h>
  13. #include <llvm/IR/GlobalVariable.h>
  14. #include <llvm/IR/InlineAsm.h>
  15. #include <llvm/IR/Instructions.h>
  16. #include <llvm/IR/LLVMContext.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("examplergbatogray.bc", getGlobalContext());
  38.  mod->setDataLayout("e-p:32:32-i64:64-v128:64:128-n32-S64");
  39.  mod->setTargetTriple("armv7-none-linux-gnueabi");
  40.  
  41.  // Type Definitions
  42.  StructType *StructTy_struct_rs_allocation = mod->getTypeByName("struct.rs_allocation");
  43.  if (!StructTy_struct_rs_allocation) {
  44.  StructTy_struct_rs_allocation = StructType::create(mod->getContext(), "struct.rs_allocation");
  45.  }
  46.  std::vector<Type*>StructTy_struct_rs_allocation_fields;
  47.  PointerType* PointerTy_0 = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
  48.  
  49.  StructTy_struct_rs_allocation_fields.push_back(PointerTy_0);
  50.  if (StructTy_struct_rs_allocation->isOpaque()) {
  51.  StructTy_struct_rs_allocation->setBody(StructTy_struct_rs_allocation_fields, /*isPacked=*/false);
  52.  }
  53.  
  54.  PointerType* PointerTy_1 = PointerType::get(StructTy_struct_rs_allocation, 0);
  55.  
  56.  VectorType* VectorTy_2 = VectorType::get(IntegerType::get(mod->getContext(), 8), 4);
  57.  
  58.  std::vector<Type*>FuncTy_3_args;
  59.  FuncTy_3_args.push_back(IntegerType::get(mod->getContext(), 32));
  60.  FuncTy_3_args.push_back(IntegerType::get(mod->getContext(), 32));
  61.  FunctionType* FuncTy_3 = FunctionType::get(
  62.   /*Result=*/VectorTy_2,
  63.   /*Params=*/FuncTy_3_args,
  64.   /*isVarArg=*/false);
  65.  
  66.  ArrayType* ArrayTy_4 = ArrayType::get(IntegerType::get(mod->getContext(), 32), 1);
  67.  
  68.  PointerType* PointerTy_5 = PointerType::get(ArrayTy_4, 0);
  69.  
  70.  std::vector<Type*>FuncTy_7_args;
  71.  FuncTy_7_args.push_back(ArrayTy_4);
  72.  FuncTy_7_args.push_back(IntegerType::get(mod->getContext(), 32));
  73.  FuncTy_7_args.push_back(IntegerType::get(mod->getContext(), 32));
  74.  FunctionType* FuncTy_7 = FunctionType::get(
  75.   /*Result=*/VectorTy_2,
  76.   /*Params=*/FuncTy_7_args,
  77.   /*isVarArg=*/false);
  78.  
  79.  PointerType* PointerTy_6 = PointerType::get(FuncTy_7, 0);
  80.  
  81.  VectorType* VectorTy_8 = VectorType::get(IntegerType::get(mod->getContext(), 32), 4);
  82.  
  83.  std::vector<Type*>FuncTy_9_args;
  84.  FunctionType* FuncTy_9 = FunctionType::get(
  85.   /*Result=*/Type::getVoidTy(mod->getContext()),
  86.   /*Params=*/FuncTy_9_args,
  87.   /*isVarArg=*/false);
  88.  
  89.  std::vector<Type*>FuncTy_11_args;
  90.  FuncTy_11_args.push_back(PointerTy_1);
  91.  FunctionType* FuncTy_11 = FunctionType::get(
  92.   /*Result=*/Type::getVoidTy(mod->getContext()),
  93.   /*Params=*/FuncTy_11_args,
  94.   /*isVarArg=*/false);
  95.  
  96.  PointerType* PointerTy_10 = PointerType::get(FuncTy_11, 0);
  97.  
  98.  
  99.  // Function Declarations
  100.  
  101.  Function* func_convertRGBAToGray = mod->getFunction("convertRGBAToGray");
  102.  if (!func_convertRGBAToGray) {
  103.  func_convertRGBAToGray = Function::Create(
  104.   /*Type=*/FuncTy_3,
  105.   /*Linkage=*/GlobalValue::ExternalLinkage,
  106.   /*Name=*/"convertRGBAToGray", mod);
  107.  func_convertRGBAToGray->setCallingConv(CallingConv::C);
  108.  }
  109.  AttributeSet func_convertRGBAToGray_PAL;
  110.  {
  111.   SmallVector<AttributeSet, 4> Attrs;
  112.   AttributeSet PAS;
  113.    {
  114.     AttrBuilder B;
  115.     B.addAttribute(Attribute::NoUnwind);
  116.     PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  117.    }
  118.  
  119.   Attrs.push_back(PAS);
  120.   func_convertRGBAToGray_PAL = AttributeSet::get(mod->getContext(), Attrs);
  121.  
  122.  }
  123.  func_convertRGBAToGray->setAttributes(func_convertRGBAToGray_PAL);
  124.  
  125.  Function* func__Z21rsGetElementAt_uchar413rs_allocationjj = mod->getFunction("_Z21rsGetElementAt_uchar413rs_allocationjj");
  126.  if (!func__Z21rsGetElementAt_uchar413rs_allocationjj) {
  127.  func__Z21rsGetElementAt_uchar413rs_allocationjj = Function::Create(
  128.   /*Type=*/FuncTy_7,
  129.   /*Linkage=*/GlobalValue::ExternalLinkage,
  130.   /*Name=*/"_Z21rsGetElementAt_uchar413rs_allocationjj", mod); // (external, no body)
  131.  func__Z21rsGetElementAt_uchar413rs_allocationjj->setCallingConv(CallingConv::C);
  132.  }
  133.  AttributeSet func__Z21rsGetElementAt_uchar413rs_allocationjj_PAL;
  134.  func__Z21rsGetElementAt_uchar413rs_allocationjj->setAttributes(func__Z21rsGetElementAt_uchar413rs_allocationjj_PAL);
  135.  
  136.  Function* func__rs_dtor = mod->getFunction(".rs.dtor");
  137.  if (!func__rs_dtor) {
  138.  func__rs_dtor = Function::Create(
  139.   /*Type=*/FuncTy_9,
  140.   /*Linkage=*/GlobalValue::ExternalLinkage,
  141.   /*Name=*/".rs.dtor", mod);
  142.  func__rs_dtor->setCallingConv(CallingConv::C);
  143.  }
  144.  AttributeSet func__rs_dtor_PAL;
  145.  {
  146.   SmallVector<AttributeSet, 4> Attrs;
  147.   AttributeSet PAS;
  148.    {
  149.     AttrBuilder B;
  150.     B.addAttribute(Attribute::NoUnwind);
  151.     PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  152.    }
  153.  
  154.   Attrs.push_back(PAS);
  155.   func__rs_dtor_PAL = AttributeSet::get(mod->getContext(), Attrs);
  156.  
  157.  }
  158.  func__rs_dtor->setAttributes(func__rs_dtor_PAL);
  159.  
  160.  Function* func__Z13rsClearObjectP13rs_allocation = mod->getFunction("_Z13rsClearObjectP13rs_allocation");
  161.  if (!func__Z13rsClearObjectP13rs_allocation) {
  162.  func__Z13rsClearObjectP13rs_allocation = Function::Create(
  163.   /*Type=*/FuncTy_11,
  164.   /*Linkage=*/GlobalValue::ExternalLinkage,
  165.   /*Name=*/"_Z13rsClearObjectP13rs_allocation", mod); // (external, no body)
  166.  func__Z13rsClearObjectP13rs_allocation->setCallingConv(CallingConv::C);
  167.  }
  168.  AttributeSet func__Z13rsClearObjectP13rs_allocation_PAL;
  169.  func__Z13rsClearObjectP13rs_allocation->setAttributes(func__Z13rsClearObjectP13rs_allocation_PAL);
  170.  
  171.  // Global Variable Declarations
  172.  
  173.  
  174.  GlobalVariable* gvar_struct_inAllocation = new GlobalVariable(/*Module=*/*mod,
  175.  /*Type=*/StructTy_struct_rs_allocation,
  176.  /*isConstant=*/false,
  177.  /*Linkage=*/GlobalValue::CommonLinkage,
  178.  /*Initializer=*/0, // has initializer, specified below
  179.  /*Name=*/"inAllocation");
  180.  gvar_struct_inAllocation->setAlignment(4);
  181.  
  182.  // Constant Definitions
  183.  ConstantAggregateZero* const_struct_12 = ConstantAggregateZero::get(StructTy_struct_rs_allocation);
  184.  Constant* const_ptr_13 = ConstantExpr::getCast(Instruction::BitCast, gvar_struct_inAllocation, PointerTy_5);
  185.  ConstantInt* const_int32_14 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
  186.  ConstantFP* const_float_15 = ConstantFP::get(mod->getContext(), APFloat(2.990000e-01f));
  187.  ConstantInt* const_int32_16 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
  188.  ConstantFP* const_float_17 = ConstantFP::get(mod->getContext(), APFloat(5.870000e-01f));
  189.  ConstantInt* const_int32_18 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("2"), 10));
  190.  ConstantFP* const_float_19 = ConstantFP::get(mod->getContext(), APFloat(1.140000e-01f));
  191.  UndefValue* const_packed_20 = UndefValue::get(VectorTy_2);
  192.  std::vector<Constant*> const_packed_21_elems;
  193.  const_packed_21_elems.push_back(const_int32_14);
  194.  const_packed_21_elems.push_back(const_int32_16);
  195.  const_packed_21_elems.push_back(const_int32_18);
  196.  ConstantInt* const_int32_22 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("7"), 10));
  197.  const_packed_21_elems.push_back(const_int32_22);
  198.  Constant* const_packed_21 = ConstantVector::get(VectorTy_8, const_packed_21_elems);
  199.  
  200.  // Global Variable Definitions
  201.  gvar_struct_inAllocation->setInitializer(const_struct_12);
  202.  
  203.  // Function Definitions
  204.  
  205.  // Function: convertRGBAToGray (func_convertRGBAToGray)
  206.  {
  207.   Function::arg_iterator args = func_convertRGBAToGray->arg_begin();
  208.   Value* int32_x = args++;
  209.   int32_x->setName("x");
  210.   Value* int32_y = args++;
  211.   int32_y->setName("y");
  212.  
  213.   BasicBlock* label_23 = BasicBlock::Create(mod->getContext(), "",func_convertRGBAToGray,0);
  214.  
  215.   // Block  (label_23)
  216.   LoadInst* array_24 = new LoadInst(const_ptr_13, "", false, label_23);
  217.   array_24->setAlignment(4);
  218.   std::vector<Value*> packed_25_params;
  219.   packed_25_params.push_back(array_24);
  220.   packed_25_params.push_back(int32_x);
  221.   packed_25_params.push_back(int32_y);
  222.   CallInst* packed_25 = CallInst::Create(func__Z21rsGetElementAt_uchar413rs_allocationjj, packed_25_params, "", label_23);
  223.   packed_25->setCallingConv(CallingConv::C);
  224.   packed_25->setTailCall(true);
  225.   AttributeSet packed_25_PAL;
  226.   {
  227.    SmallVector<AttributeSet, 4> Attrs;
  228.    AttributeSet PAS;
  229.     {
  230.      AttrBuilder B;
  231.      B.addAttribute(Attribute::NoUnwind);
  232.      PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  233.     }
  234.    
  235.    Attrs.push_back(PAS);
  236.    packed_25_PAL = AttributeSet::get(mod->getContext(), Attrs);
  237.    
  238.   }
  239.   packed_25->setAttributes(packed_25_PAL);
  240.  
  241.   ExtractElementInst* int8_26 = new ExtractElementInst(packed_25, const_int32_14, "", label_23);
  242.   CastInst* float_27 = new UIToFPInst(int8_26, Type::getFloatTy(mod->getContext()), "", label_23);
  243.   BinaryOperator* float_28 = BinaryOperator::Create(Instruction::FMul, float_27, const_float_15, "", label_23);
  244.   ExtractElementInst* int8_29 = new ExtractElementInst(packed_25, const_int32_16, "", label_23);
  245.   CastInst* float_30 = new UIToFPInst(int8_29, Type::getFloatTy(mod->getContext()), "", label_23);
  246.   BinaryOperator* float_31 = BinaryOperator::Create(Instruction::FMul, float_30, const_float_17, "", label_23);
  247.   BinaryOperator* float_32 = BinaryOperator::Create(Instruction::FAdd, float_28, float_31, "", label_23);
  248.   ExtractElementInst* int8_33 = new ExtractElementInst(packed_25, const_int32_18, "", label_23);
  249.   CastInst* float_34 = new UIToFPInst(int8_33, Type::getFloatTy(mod->getContext()), "", label_23);
  250.   BinaryOperator* float_35 = BinaryOperator::Create(Instruction::FMul, float_34, const_float_19, "", label_23);
  251.   BinaryOperator* float_36 = BinaryOperator::Create(Instruction::FAdd, float_35, float_32, "", label_23);
  252.   CastInst* int8_37 = new FPToUIInst(float_36, IntegerType::get(mod->getContext(), 8), "", label_23);
  253.   InsertElementInst* packed_38 = InsertElementInst::Create(const_packed_20, int8_37, const_int32_14, "", label_23);
  254.   InsertElementInst* packed_39 = InsertElementInst::Create(packed_38, int8_37, const_int32_16, "", label_23);
  255.   InsertElementInst* packed_40 = InsertElementInst::Create(packed_39, int8_37, const_int32_18, "", label_23);
  256.   ShuffleVectorInst* packed_41 = new ShuffleVectorInst(packed_40, packed_25, const_packed_21, "", label_23);
  257.   ReturnInst::Create(mod->getContext(), packed_41, label_23);
  258.  
  259.  }
  260.  
  261.  // Function: .rs.dtor (func__rs_dtor)
  262.  {
  263.  
  264.   BasicBlock* label_43 = BasicBlock::Create(mod->getContext(), "",func__rs_dtor,0);
  265.  
  266.   // Block  (label_43)
  267.   CallInst* void_44 = CallInst::Create(func__Z13rsClearObjectP13rs_allocation, gvar_struct_inAllocation, "", label_43);
  268.   void_44->setCallingConv(CallingConv::C);
  269.   void_44->setTailCall(true);
  270.   AttributeSet void_44_PAL;
  271.   {
  272.    SmallVector<AttributeSet, 4> Attrs;
  273.    AttributeSet PAS;
  274.     {
  275.      AttrBuilder B;
  276.      B.addAttribute(Attribute::NoUnwind);
  277.      PAS = AttributeSet::get(mod->getContext(), ~0U, B);
  278.     }
  279.    
  280.    Attrs.push_back(PAS);
  281.    void_44_PAL = AttributeSet::get(mod->getContext(), Attrs);
  282.    
  283.   }
  284.   void_44->setAttributes(void_44_PAL);
  285.  
  286.   ReturnInst::Create(mod->getContext(), label_43);
  287.  
  288.  }
  289.  
  290.  return mod;
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement