mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-27 23:18:02 +00:00
implement the code size opcodes (#107)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
//! Translates the external code operations.
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
|
||||
@@ -14,37 +12,23 @@ pub fn size<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let address_pointer = match address {
|
||||
Some(address) => {
|
||||
let address_pointer = context.build_alloca(context.word_type(), "value");
|
||||
context.build_store(address_pointer, address)?;
|
||||
address_pointer
|
||||
}
|
||||
None => context.sentinel_pointer(),
|
||||
let address = match address {
|
||||
Some(address) => address,
|
||||
None => super::context::address(context)?.into_int_value(),
|
||||
};
|
||||
|
||||
let address_pointer_casted = context.builder().build_ptr_to_int(
|
||||
address_pointer.value,
|
||||
context.xlen_type(),
|
||||
"address_pointer",
|
||||
)?;
|
||||
let value = context
|
||||
.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
||||
&[address_pointer_casted.into()],
|
||||
)
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"{} should return a value",
|
||||
revive_runtime_api::polkavm_imports::CODE_SIZE
|
||||
)
|
||||
})
|
||||
.into_int_value();
|
||||
let address_pointer = context.build_address_argument_store(address)?;
|
||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "output_pointer");
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(value, context.word_type(), "extcodesize")?
|
||||
.as_basic_value_enum())
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
||||
&[
|
||||
address_pointer.to_int(context).into(),
|
||||
output_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
|
||||
context.build_load(output_pointer, "code_size")
|
||||
}
|
||||
|
||||
/// Translates the `extcodehash` instruction.
|
||||
|
||||
Reference in New Issue
Block a user