parent
e9c0f6846c
commit
2c85ccae65
@ -1,65 +1,34 @@
|
|||||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
#include <Windows.h>
|
||||||
#include "llvm/IR/CallingConv.h"
|
|
||||||
|
#include "llvm/IR/BasicBlock.h"
|
||||||
|
#include "llvm/IR/Constants.h"
|
||||||
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/IRBuilder.h"
|
#include "llvm/IR/IRBuilder.h"
|
||||||
#include "llvm/IR/IRPrintingPasses.h"
|
#include "llvm/IR/IRPrintingPasses.h"
|
||||||
#include "llvm/IR/LegacyPassManager.h"
|
#include "llvm/IR/LLVMContext.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/IR/PassManager.h"
|
#include "llvm/IR/PassManager.h"
|
||||||
|
#include "llvm/IR/Type.h"
|
||||||
#include "llvm/IR/Verifier.h"
|
#include "llvm/IR/Verifier.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
Module *makeLLVMModule( LLVMContext &Context );
|
|
||||||
|
|
||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
LLVMContext Context;
|
// test for now...
|
||||||
Module *Mod = makeLLVMModule( Context );
|
LLVMContext llvm_ctx;
|
||||||
|
Module llvm_module( "VMProtect 2 Static Devirtualizer", llvm_ctx );
|
||||||
raw_fd_ostream r( fileno( stdout ), false );
|
IRBuilder<> ir_builder( llvm_ctx );
|
||||||
verifyModule( *Mod, &r );
|
|
||||||
|
FunctionType *FT = FunctionType::get( Type::getVoidTy( llvm_ctx ), false );
|
||||||
// Prints the module IR
|
Function *F = Function::Create( FT, Function::ExternalLinkage, "test_func", llvm_module );
|
||||||
ModulePass *m = createPrintModulePass( outs(), "Module IR printer" );
|
F->setCallingConv( CallingConv::C );
|
||||||
legacy::PassManager PM;
|
|
||||||
PM.add( m );
|
auto basic_block = BasicBlock::Create( llvm_ctx, "test", F );
|
||||||
PM.run( *Mod );
|
ir_builder.SetInsertPoint( basic_block );
|
||||||
|
ir_builder.CreateRetVoid();
|
||||||
// Write IR to a bitcode file
|
basic_block->print( outs() );
|
||||||
FILE *mul_add_file = fopen( "mul_add.bc", "w+" );
|
|
||||||
raw_fd_ostream bitcodeWriter( fileno( mul_add_file ), true );
|
|
||||||
WriteBitcodeToFile( *Mod, bitcodeWriter );
|
|
||||||
|
|
||||||
delete Mod;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Module *makeLLVMModule( LLVMContext &Context )
|
|
||||||
{
|
|
||||||
Module *mod = new Module( "mul_add", Context );
|
|
||||||
|
|
||||||
FunctionCallee mul_add_fun =
|
|
||||||
mod->getOrInsertFunction( "mul_add", Type::getInt32Ty( Context ), Type::getInt32Ty( Context ),
|
|
||||||
Type::getInt32Ty( Context ), Type::getInt32Ty( Context ) );
|
|
||||||
Function *mul_add = cast< Function >( mul_add_fun.getCallee() );
|
|
||||||
|
|
||||||
mul_add->setCallingConv( CallingConv::C );
|
|
||||||
Function::arg_iterator args = mul_add->arg_begin();
|
|
||||||
Value *x = args++;
|
|
||||||
x->setName( "x" );
|
|
||||||
Value *y = args++;
|
|
||||||
y->setName( "y" );
|
|
||||||
Value *z = args++;
|
|
||||||
z->setName( "z" );
|
|
||||||
|
|
||||||
BasicBlock *block = BasicBlock::Create( Context, "entry", mul_add );
|
|
||||||
IRBuilder<> builder( block );
|
|
||||||
Value *tmp = builder.CreateBinOp( Instruction::Mul, x, y, "tmp" );
|
|
||||||
Value *tmp2 = builder.CreateBinOp( Instruction::Add, tmp, z, "tmp2" );
|
|
||||||
builder.CreateRet( tmp2 );
|
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
}
|
Loading…
Reference in new issue