mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 18:01:05 +00:00
431b5a2ce5
- Lazily load function arguments so that they can be passed as pointers. - Lazily call the immutable store function to avoid storing zero sized immutable data. --------- Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
81 lines
2.8 KiB
Rust
81 lines
2.8 KiB
Rust
//! Translates the storage operations.
|
|
|
|
use crate::polkavm::context::runtime::RuntimeFunction;
|
|
use crate::polkavm::context::Context;
|
|
use crate::polkavm::Dependency;
|
|
use crate::PolkaVMArgument;
|
|
use crate::PolkaVMLoadStorageWordFunction;
|
|
use crate::PolkaVMLoadTransientStorageWordFunction;
|
|
use crate::PolkaVMStoreStorageWordFunction;
|
|
use crate::PolkaVMStoreTransientStorageWordFunction;
|
|
|
|
/// Translates the storage load.
|
|
pub fn load<'ctx, D>(
|
|
context: &mut Context<'ctx, D>,
|
|
position: &PolkaVMArgument<'ctx>,
|
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
|
where
|
|
D: Dependency + Clone,
|
|
{
|
|
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")))
|
|
}
|
|
|
|
/// Translates the storage store.
|
|
pub fn store<'ctx, D>(
|
|
context: &mut Context<'ctx, D>,
|
|
position: &PolkaVMArgument<'ctx>,
|
|
value: &PolkaVMArgument<'ctx>,
|
|
) -> anyhow::Result<()>
|
|
where
|
|
D: Dependency + Clone,
|
|
{
|
|
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
|
let arguments = [
|
|
position.as_pointer(context)?.value.into(),
|
|
value.as_pointer(context)?.value.into(),
|
|
];
|
|
context.build_call(declaration, &arguments, "storage_store");
|
|
Ok(())
|
|
}
|
|
|
|
/// Translates the transient storage load.
|
|
pub fn transient_load<'ctx, D>(
|
|
context: &mut Context<'ctx, D>,
|
|
position: &PolkaVMArgument<'ctx>,
|
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
|
where
|
|
D: Dependency + Clone,
|
|
{
|
|
let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME;
|
|
let arguments = [position.as_pointer(context)?.value.into()];
|
|
let declaration =
|
|
<PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
|
Ok(context
|
|
.build_call(declaration, &arguments, "transient_storage_load")
|
|
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
|
|
}
|
|
|
|
/// Translates the transient storage store.
|
|
pub fn transient_store<'ctx, D>(
|
|
context: &mut Context<'ctx, D>,
|
|
position: &PolkaVMArgument<'ctx>,
|
|
value: &PolkaVMArgument<'ctx>,
|
|
) -> anyhow::Result<()>
|
|
where
|
|
D: Dependency + Clone,
|
|
{
|
|
let declaration =
|
|
<PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
|
|
let arguments = [
|
|
position.as_pointer(context)?.value.into(),
|
|
value.as_pointer(context)?.value.into(),
|
|
];
|
|
context.build_call(declaration, &arguments, "transient_storage_store");
|
|
Ok(())
|
|
}
|