implement EXTCODESIZE

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-22 22:56:03 +02:00
parent 06aa289d9b
commit 5138fe3d06
8 changed files with 100 additions and 8 deletions
@@ -1,17 +1,36 @@
//! Translates the external code operations.
use inkwell::values::BasicValue;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::polkavm_const::runtime_api;
/// Translates the `extcodesize` instruction.
pub fn size<'ctx, D>(
_context: &mut Context<'ctx, D>,
_address: inkwell::values::IntValue<'ctx>,
context: &mut Context<'ctx, D>,
address: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
todo!()
let address_pointer = context.build_alloca(context.word_type(), "value");
context.build_store(address_pointer, address)?;
let address_pointer_casted = context.builder().build_ptr_to_int(
address_pointer.value,
context.xlen_type(),
"address_pointer",
)?;
let value = context
.build_runtime_call(runtime_api::CODE_SIZE, &[address_pointer_casted.into()])
.unwrap_or_else(|| panic!("{} should return a value", runtime_api::CODE_SIZE))
.into_int_value();
Ok(context
.builder()
.build_int_z_extend(value, context.word_type(), "extcodesize")?
.as_basic_value_enum())
}
/// Translates the `extcodehash` instruction.