tidy up the runtime API crate (#85)

- remove unused runtime API imports and constants
- move runtime api symbols into the revive-runtime-api crate

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2024-10-17 10:55:27 +02:00
committed by GitHub
parent 20e3560398
commit 82ae22c163
18 changed files with 162 additions and 242 deletions
+1 -2
View File
@@ -5,7 +5,6 @@ use inkwell::values::BasicValue;
use crate::polkavm::context::argument::Argument;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
const STATIC_CALL_FLAG: u32 = 0b0001_0000;
const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
@@ -77,7 +76,7 @@ where
arguments,
)?;
let name = runtime_api::imports::CALL;
let name = revive_runtime_api::polkavm_imports::CALL;
let argument_pointer = context.builder().build_ptr_to_int(
argument_pointer.value,
context.xlen_type(),
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `gas_limit` instruction.
pub fn gas_limit<'ctx, D>(
@@ -43,7 +42,7 @@ pub fn chain_id<'ctx, D>(
where
D: Dependency + Clone,
{
context.build_runtime_call_to_getter(runtime_api::imports::CHAIN_ID)
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::CHAIN_ID)
}
/// Translates the `block_number` instruction.
@@ -53,7 +52,7 @@ pub fn block_number<'ctx, D>(
where
D: Dependency + Clone,
{
context.build_runtime_call_to_getter(runtime_api::imports::BLOCK_NUMBER)
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::BLOCK_NUMBER)
}
/// Translates the `block_timestamp` instruction.
@@ -63,7 +62,7 @@ pub fn block_timestamp<'ctx, D>(
where
D: Dependency + Clone,
{
context.build_runtime_call_to_getter(runtime_api::imports::NOW)
context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::NOW)
}
/// Translates the `block_hash` instruction.
@@ -119,7 +118,7 @@ where
"address_output",
);
context.build_runtime_call(
runtime_api::imports::ADDRESS,
revive_runtime_api::polkavm_imports::ADDRESS,
&[pointer.to_int(context).into()],
);
context.build_load_address(pointer)
@@ -137,7 +136,7 @@ where
"address_output",
);
context.build_runtime_call(
runtime_api::imports::CALLER,
revive_runtime_api::polkavm_imports::CALLER,
&[pointer.to_int(context).into()],
);
context.build_load_address(pointer)
@@ -7,7 +7,6 @@ use crate::polkavm::context::argument::Argument;
use crate::polkavm::context::code_type::CodeType;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the contract `create` and `create2` instruction.
///
@@ -82,7 +81,7 @@ where
"instantiate_argument_pointer",
)?;
context.build_runtime_call(
runtime_api::imports::INSTANTIATE,
revive_runtime_api::polkavm_imports::INSTANTIATE,
&[argument_pointer.into()],
);
@@ -2,7 +2,6 @@
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `sha3` instruction.
pub fn sha3<'ctx, D>(
@@ -19,7 +18,7 @@ where
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
context.build_runtime_call(
runtime_api::imports::HASH_KECCAK_256,
revive_runtime_api::polkavm_imports::HASH_KECCAK_256,
&[
input_pointer.to_int(context).into(),
length_casted.into(),
@@ -4,7 +4,6 @@ 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>(
@@ -26,7 +25,7 @@ where
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
context.build_store(output_pointer, context.word_const(0))?;
context.build_runtime_call(
runtime_api::imports::VALUE_TRANSFERRED,
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
&[output_pointer.to_int(context).into()],
);
context.build_load(output_pointer, "value_transferred")
@@ -50,7 +49,7 @@ where
)?;
context.build_runtime_call(
runtime_api::imports::BALANCE_OF,
revive_runtime_api::polkavm_imports::BALANCE_OF,
&[address_pointer.to_int(context).into(), balance.into()],
);
@@ -71,7 +70,10 @@ where
"balance",
)?;
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
context.build_runtime_call(
revive_runtime_api::polkavm_imports::BALANCE,
&[balance.into()],
);
context.build_load(balance_pointer, "balance")
}
+4 -2
View File
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates a log or event call.
///
@@ -77,7 +76,10 @@ where
]
};
let _ = context.build_runtime_call(runtime_api::imports::DEPOSIT_EVENT, &arguments);
let _ = context.build_runtime_call(
revive_runtime_api::polkavm_imports::DEPOSIT_EVENT,
&arguments,
);
Ok(())
}
@@ -4,7 +4,6 @@ use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `extcodesize` instruction if `address` is `Some`.
/// Otherwise, translates the `codesize` instruction.
@@ -31,10 +30,15 @@ where
)?;
let value = context
.build_runtime_call(
runtime_api::imports::CODE_SIZE,
revive_runtime_api::polkavm_imports::CODE_SIZE,
&[address_pointer_casted.into()],
)
.unwrap_or_else(|| panic!("{} should return a value", runtime_api::imports::CODE_SIZE))
.unwrap_or_else(|| {
panic!(
"{} should return a value",
revive_runtime_api::polkavm_imports::CODE_SIZE
)
})
.into_int_value();
Ok(context
@@ -4,7 +4,7 @@ use crate::polkavm::context::address_space::AddressSpace;
use crate::polkavm::context::code_type::CodeType;
use crate::polkavm::context::pointer::Pointer;
use crate::polkavm::context::Context;
use crate::polkavm::{runtime_api, Dependency};
use crate::polkavm::Dependency;
/// Translates the `return` instruction.
pub fn r#return<'ctx, D>(
@@ -51,7 +51,7 @@ where
.value
.as_pointer_value();
context.build_runtime_call(
runtime_api::imports::SET_IMMUTABLE_DATA,
revive_runtime_api::polkavm_imports::SET_IMMUTABLE_DATA,
&[
context
.builder()
@@ -2,7 +2,6 @@
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the return data size.
pub fn size<'ctx, D>(
@@ -18,7 +17,7 @@ where
"return_data_copy_output_pointer",
)?;
context.build_runtime_call(
runtime_api::imports::RETURNDATASIZE,
revive_runtime_api::polkavm_imports::RETURNDATASIZE,
&[output_pointer_parameter.into()],
);
context.build_load(output_pointer, "return_data_size_load")
@@ -59,7 +58,7 @@ where
)?;
context.build_runtime_call(
runtime_api::imports::RETURNDATACOPY,
revive_runtime_api::polkavm_imports::RETURNDATACOPY,
&[
output_pointer.into(),
output_length_pointer_int.into(),