#pragma once #include #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.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/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" #include "llvm/Transforms/InstCombine/InstCombine.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "X86TargetMachine.h" #include "llvm/Pass.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" namespace llvm { extern "C" void LLVMInitializeX86TargetInfo(); extern "C" void LLVMInitializeX86Target(); extern "C" void LLVMInitializeX86TargetMC(); extern "C" void LLVMInitializeX86AsmParser(); extern "C" void LLVMInitializeX86AsmPrinter(); } // namespace llvm namespace vm { class vmp_rtn_t { friend class lifters_t; public: explicit vmp_rtn_t( llvm::LLVMContext *llvm_ctx, llvm::Module *llvm_module, vm::ctx_t *vm_ctx, 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; llvm::Function *llvm_fptr; llvm::AllocaInst *flags, *stack; vm::ctx_t *vm_ctx; std::uintptr_t rtn_begin; std::shared_ptr< llvm::IRBuilder<> > ir_builder; std::vector< llvm::AllocaInst * > virtual_registers; std::vector< std::pair< std::uintptr_t, llvm::BasicBlock * > > llvm_code_blocks; std::vector< vm::instrs::code_block_t > vmp2_code_blocks; void push( std::uint8_t byte_size, llvm::Value *input_val ); llvm::Value *pop( std::uint8_t byte_size ); llvm::Value *load_value( std::uint8_t byte_size, llvm::GlobalValue *global ); llvm::Value *load_value( std::uint8_t byte_size, llvm::AllocaInst *var ); llvm::Value *compute_sf( std::uint8_t byte_size, llvm::Value *val ); llvm::Value *compute_zf( std::uint8_t byte_size, llvm::Value *val ); llvm::Value *compute_pf( std::uint8_t byte_size, llvm::Value *val ); llvm::Value *combine_flags( llvm::Value *cf, llvm::Value *pf, llvm::Value *af, llvm::Value *zf, llvm::Value *sf, llvm::Value *of ); void create_virtual_registers( void ); void create_routine( void ); }; } // namespace vm