internalize runtime API function symbols

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-06 13:45:58 +02:00
parent a75fc55133
commit 518c03d045
9 changed files with 160 additions and 110 deletions
@@ -2,6 +2,7 @@
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `sha3` instruction.
pub fn sha3<'ctx, D>(
@@ -28,20 +29,14 @@ where
"output_pointer_casted",
)?;
let function = context
.module()
.get_function("hash_keccak_256")
.expect("is declared");
context.builder().build_call(
function,
context.build_runtime_call(
runtime_api::HASH_KECCAK_256,
&[
input_pointer_casted.into(),
length_casted.into(),
output_pointer_casted.into(),
],
"call_seal_hash_keccak_256",
)?;
);
Ok(context.build_byte_swap(context.build_load(output_pointer, "sha3_output")?))
}
@@ -4,6 +4,7 @@ use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `gas` instruction.
pub fn gas<'ctx, D>(
@@ -43,17 +44,13 @@ where
),
)?;
context.builder().build_call(
context
.module()
.get_function("value_transferred")
.expect("is declared"),
context.build_runtime_call(
runtime_api::VALUE_TRANSFERRED,
&[
output_pointer_casted.into(),
output_length_pointer_casted.into(),
],
"call_seal_value_transferred",
)?;
);
let value = context.build_load(output_pointer, "transferred_value")?;
let value_extended = context.builder().build_int_z_extend(