parent
8841661c3b
commit
1bb5d7e399
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <vmprofiler.hpp>
|
||||
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace vm
|
||||
{
|
||||
class vmp_rtn_t
|
||||
{
|
||||
public:
|
||||
explicit vmp_rtn_t( llvm::LLVMContext *llvm_ctx, llvm::Module *llvm_module, std::uintptr_t rtn_begin,
|
||||
std::vector< vm::instrs::code_block_t > vmp2_code_blocks );
|
||||
|
||||
llvm::Function *lift( void );
|
||||
|
||||
private:
|
||||
llvm::LLVMContext *llvm_ctx;
|
||||
llvm::Module *llvm_module;
|
||||
|
||||
std::uintptr_t rtn_begin;
|
||||
std::shared_ptr< llvm::Function > llvm_fptr;
|
||||
std::shared_ptr< llvm::IRBuilder<> > ir_builder;
|
||||
std::vector< std::shared_ptr< llvm::BasicBlock > > llvm_code_blocks;
|
||||
std::vector< vm::instrs::code_block_t > vmp2_code_blocks;
|
||||
};
|
||||
} // namespace vm
|
@ -0,0 +1,28 @@
|
||||
#include <vmp_rtn.hpp>
|
||||
|
||||
namespace vm
|
||||
{
|
||||
vmp_rtn_t::vmp_rtn_t( llvm::LLVMContext *llvm_ctx, llvm::Module *llvm_module, std::uintptr_t rtn_begin,
|
||||
std::vector< vm::instrs::code_block_t > vmp2_code_blocks )
|
||||
: llvm_ctx( llvm_ctx ), llvm_module( llvm_module ), rtn_begin( rtn_begin ), vmp2_code_blocks( vmp2_code_blocks )
|
||||
{
|
||||
// function has no arguments and returns void... maybe change this in the future as i learn
|
||||
// more and more LLVM...
|
||||
auto func_ty = llvm::FunctionType::get( llvm::Type::getVoidTy( *llvm_ctx ), false );
|
||||
|
||||
// convert the rtn_begin address to a hex string and prepend "rtn_" to it...
|
||||
std::stringstream rtn_name;
|
||||
rtn_name << "rtn_" << std::hex << rtn_begin;
|
||||
const llvm::Twine rtn_twine( rtn_name.str() );
|
||||
|
||||
llvm_fptr = std::shared_ptr< llvm::Function >( llvm::Function::Create(
|
||||
func_ty, llvm::GlobalValue::LinkageTypes::ExternalLinkage, rtn_twine, *llvm_module ) );
|
||||
|
||||
ir_builder = std::make_shared< llvm::IRBuilder<> >( *llvm_ctx );
|
||||
}
|
||||
|
||||
llvm::Function *vmp_rtn_t::lift( void )
|
||||
{
|
||||
return {};
|
||||
}
|
||||
} // namespace vm
|
Loading…
Reference in new issue