You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
#pragma once
|
|
#include <functional>
|
|
#include <vmp_rtn.hpp>
|
|
#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"
|
|
|
|
namespace vmp2::lifters
|
|
{
|
|
using lifter_callback_t =
|
|
std::function< void( 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 ) >;
|
|
|
|
extern lifter_callback_t lconstq;
|
|
extern lifter_callback_t lconstdwsxq;
|
|
|
|
extern lifter_callback_t pushvsp;
|
|
extern lifter_callback_t addq;
|
|
extern lifter_callback_t sregq;
|
|
extern lifter_callback_t lregq;
|
|
|
|
inline std::map< vm::handler::mnemonic_t, lifter_callback_t * > lifters = {
|
|
{ vm::handler::LCONSTQ, &lconstq }, { vm::handler::LCONSTDWSXQ, &lconstdwsxq },
|
|
{ vm::handler::ADDQ, &addq },
|
|
{ vm::handler::PUSHVSP, &pushvsp }, {vm::handler::PUSHVSPDW, &pushvspdw},
|
|
{ vm::handler::SREGQ, &sregq }, { vm::handler::LREGQ, &lregq } };
|
|
|
|
inline 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 )
|
|
{
|
|
if ( vinstr.mnemonic_t == vm::handler::INVALID || lifters.find( vinstr.mnemonic_t ) == lifters.end() )
|
|
return false;
|
|
|
|
( *( lifters[ vinstr.mnemonic_t ] ) )( rtn, vm_code_block, vinstr, ir_builder );
|
|
return true;
|
|
}
|
|
} // namespace vmp2::lifters
|