mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-26 00:37:58 +00:00
pass assignment ptr
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
use inkwell::values::BasicValueEnum;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::runtime::RuntimeFunction;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
@@ -17,20 +19,27 @@ where
|
||||
const NAME: &'static str = "__revive_load_storage_word";
|
||||
|
||||
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
|
||||
context
|
||||
.word_type()
|
||||
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
|
||||
context.void_type().fn_type(
|
||||
&[
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
context.llvm().ptr_type(Default::default()).into(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn emit_body<'ctx>(
|
||||
&self,
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
|
||||
Ok(Some(emit_load(
|
||||
context,
|
||||
Self::paramater(context, 0),
|
||||
false,
|
||||
)?))
|
||||
let key = Self::paramater(context, 0);
|
||||
let assignment_pointer = Self::paramater(context, 1).into_pointer_value();
|
||||
let value = emit_load(context, key, false)?;
|
||||
context.build_store(
|
||||
Pointer::new(context.word_type(), AddressSpace::Stack, assignment_pointer),
|
||||
value,
|
||||
)?;
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,16 +13,32 @@ use crate::PolkaVMStoreTransientStorageWordFunction;
|
||||
pub fn load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
position: &PolkaVMArgument<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
assignment_pointer: Option<inkwell::values::PointerValue<'ctx>>,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let _name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
|
||||
let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
||||
let arguments = [position.as_pointer(context)?.value.into()];
|
||||
Ok(context
|
||||
.build_call(declaration, &arguments, "storage_load")
|
||||
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
|
||||
match assignment_pointer {
|
||||
Some(assignment_pointer) => {
|
||||
let arguments = [
|
||||
position.as_pointer(context)?.value.into(),
|
||||
assignment_pointer.into(),
|
||||
];
|
||||
context.build_call(declaration, &arguments, "storage_load");
|
||||
Ok(None)
|
||||
}
|
||||
None => {
|
||||
let pointer = context.build_alloca_at_entry(context.word_type(), "pointer");
|
||||
let arguments = [
|
||||
position.as_pointer(context)?.value.into(),
|
||||
pointer.value.into(),
|
||||
];
|
||||
context.build_call(declaration, &arguments, "storage_load");
|
||||
Ok(Some(context.build_load(pointer, "storage_value")?))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates the storage store.
|
||||
|
||||
Reference in New Issue
Block a user