diff --git a/include/vm_lifters.hpp b/include/vm_lifters.hpp index e69de29..94c7808 100644 --- a/include/vm_lifters.hpp +++ b/include/vm_lifters.hpp @@ -0,0 +1,22 @@ +#pragma once +#include +#include + +#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" + +namespace vmp2::lifters +{ + bool lift( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr, + llvm::IRBuilder<> *ir_builder ); +} \ No newline at end of file diff --git a/include/vmp_rtn.hpp b/include/vmp_rtn.hpp index fa46aef..4a08eb5 100644 --- a/include/vmp_rtn.hpp +++ b/include/vmp_rtn.hpp @@ -23,6 +23,7 @@ namespace vm 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 ); + ~vmp_rtn_t(); llvm::Function *lift( void ); private: @@ -30,9 +31,10 @@ namespace vm llvm::Module *llvm_module; std::uintptr_t rtn_begin; - std::shared_ptr< llvm::Function > llvm_fptr; + llvm::Function* llvm_fptr; std::shared_ptr< llvm::IRBuilder<> > ir_builder; - std::vector< std::shared_ptr< llvm::BasicBlock > > llvm_code_blocks; + llvm::AllocaInst *virutal_registers; + std::vector< llvm::BasicBlock * > llvm_code_blocks; std::vector< vm::instrs::code_block_t > vmp2_code_blocks; }; } // namespace vm \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index dcb2e34..7fde48e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,20 +4,6 @@ #include #include -#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" - using namespace llvm; int main( int argc, const char *argv[] ) diff --git a/src/vmp_rtn.cpp b/src/vmp_rtn.cpp index 5f49f6b..fa8938d 100644 --- a/src/vmp_rtn.cpp +++ b/src/vmp_rtn.cpp @@ -1,3 +1,4 @@ +#include #include namespace vm @@ -13,12 +14,31 @@ namespace vm // 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 ) ); + llvm_fptr = llvm::Function::Create( func_ty, llvm::GlobalValue::LinkageTypes::ExternalLinkage, + rtn_name.str().c_str(), *llvm_module ); + for ( const auto &vmp2_code_block : vmp2_code_blocks ) + { + // create basic block name... block_xxxxxxxx format... + std::stringstream blk_name; + blk_name << "blk_" << std::hex << vmp2_code_block.vip_begin; + llvm_code_blocks.push_back( llvm::BasicBlock::Create( *llvm_ctx, blk_name.str().c_str(), llvm_fptr ) ); + } + + // set the insert point to the first code block... ir_builder = std::make_shared< llvm::IRBuilder<> >( *llvm_ctx ); + ir_builder->SetInsertPoint( llvm_code_blocks[ 0 ] ); + + // allocate virtual register space... + virutal_registers = ir_builder->CreateAlloca( + llvm::ArrayType::get( llvm::IntegerType::get( *llvm_ctx, 64 ), 24 ), nullptr, "vregs" ); + + llvm_fptr->print( llvm::outs() ); + } + + vmp_rtn_t::~vmp_rtn_t() + { } llvm::Function *vmp_rtn_t::lift( void )