|
|
@ -54,34 +54,28 @@ namespace vm
|
|
|
|
void vmp_rtn_t::push( std::uint8_t num_bytes, llvm::Value *val )
|
|
|
|
void vmp_rtn_t::push( std::uint8_t num_bytes, llvm::Value *val )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// sub rsp, num_bytes
|
|
|
|
// sub rsp, num_bytes
|
|
|
|
auto rsp_addr = ir_builder->CreateLoad( stack );
|
|
|
|
auto rsp_addr = ir_builder->CreateLoad( stack, "rsp_addr" );
|
|
|
|
auto rsp_i64 = ir_builder->CreatePtrToInt( rsp_addr, ir_builder->getInt64Ty() );
|
|
|
|
auto sub_rsp_val = ir_builder->CreateGEP( ir_builder->getInt8Ty(), rsp_addr,
|
|
|
|
auto sub_rsp_val = ir_builder->CreateSub( rsp_i64, ir_builder->getInt64( num_bytes ) );
|
|
|
|
ir_builder->getInt8( 0 - num_bytes ), "sub_rsp_val" );
|
|
|
|
ir_builder->CreateStore(
|
|
|
|
ir_builder->CreateStore( sub_rsp_val, stack );
|
|
|
|
ir_builder->CreateIntToPtr( sub_rsp_val, llvm::PointerType::get( ir_builder->getInt8Ty(), 0ull ) ), stack );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// mov [rsp], val
|
|
|
|
// mov [rsp], val
|
|
|
|
rsp_addr = ir_builder->CreateLoad( stack );
|
|
|
|
auto resized_new_rsp_addr = ir_builder->CreateBitCast(
|
|
|
|
auto rsp_cast_ptr = ir_builder->CreatePointerCast(
|
|
|
|
sub_rsp_val, llvm::PointerType::get( llvm::IntegerType::get( *llvm_ctx, num_bytes * 8 ), 0ull ) );
|
|
|
|
rsp_addr, llvm::PointerType::get( llvm::IntegerType::get( *llvm_ctx, num_bytes * 8 ), false ) );
|
|
|
|
ir_builder->CreateStore( val, resized_new_rsp_addr );
|
|
|
|
ir_builder->CreateStore( val, rsp_cast_ptr );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
llvm::Value *vmp_rtn_t::pop( std::uint8_t num_bytes )
|
|
|
|
llvm::Value *vmp_rtn_t::pop( std::uint8_t num_bytes )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// mov rax, [rsp]
|
|
|
|
// mov rax, [rsp]
|
|
|
|
auto rsp_addr = ir_builder->CreateLoad( stack );
|
|
|
|
auto rsp_addr = ir_builder->CreateLoad( stack, "rsp_addr" );
|
|
|
|
auto rsp_cast_ptr = ir_builder->CreatePointerCast(
|
|
|
|
auto new_rsp_addr = ir_builder->CreateGEP( ir_builder->getInt8Ty(), rsp_addr, ir_builder->getInt8( num_bytes ),
|
|
|
|
rsp_addr, llvm::PointerType::get( llvm::IntegerType::get( *llvm_ctx, num_bytes * 8 ), false ) );
|
|
|
|
"new_rsp_addr" );
|
|
|
|
auto pop_val = ir_builder->CreateLoad( rsp_cast_ptr );
|
|
|
|
auto resized_new_rsp_addr = ir_builder->CreateBitCast(
|
|
|
|
|
|
|
|
rsp_addr, llvm::PointerType::get( llvm::IntegerType::get( *llvm_ctx, num_bytes * 8 ), 0ull ) );
|
|
|
|
// add rsp, num_bytes
|
|
|
|
auto pop_val = ir_builder->CreateLoad( resized_new_rsp_addr );
|
|
|
|
auto rsp_i64 = ir_builder->CreatePtrToInt( rsp_addr, ir_builder->getInt64Ty() );
|
|
|
|
ir_builder->CreateStore( new_rsp_addr, stack );
|
|
|
|
auto sub_rsp_val = ir_builder->CreateAdd( rsp_i64, ir_builder->getInt64( num_bytes ) );
|
|
|
|
ir_builder->CreateStore( llvm::UndefValue::get( ir_builder->getInt8Ty() ), rsp_addr );
|
|
|
|
auto sub_rsp_val_ptr =
|
|
|
|
|
|
|
|
ir_builder->CreateIntToPtr( sub_rsp_val, llvm::PointerType::get( ir_builder->getInt8Ty(), 0ull ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ir_builder->CreateStore( sub_rsp_val_ptr, stack );
|
|
|
|
|
|
|
|
return pop_val;
|
|
|
|
return pop_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|