mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 07:57:57 +00:00
Emerge Yul recompiler (#1)
Provide a modified (and incomplete) version of ZKSync zksolc that can compile the most basic contracts
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
//!
|
||||
//! Translates the heap memory operations.
|
||||
//!
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::eravm::context::address_space::AddressSpace;
|
||||
use crate::eravm::context::pointer::Pointer;
|
||||
use crate::eravm::context::Context;
|
||||
use crate::eravm::Dependency;
|
||||
|
||||
///
|
||||
/// Translates the `mload` instruction.
|
||||
///
|
||||
/// Uses the main heap.
|
||||
///
|
||||
pub fn load<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
offset: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
offset,
|
||||
"memory_load_pointer",
|
||||
);
|
||||
context.build_load(pointer, "memory_load_result")
|
||||
}
|
||||
|
||||
///
|
||||
/// Translates the `mstore` instruction.
|
||||
///
|
||||
/// Uses the main heap.
|
||||
///
|
||||
pub fn store<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
offset: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
offset,
|
||||
"memory_store_pointer",
|
||||
);
|
||||
context.build_store(pointer, value)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Translates the `mstore8` instruction.
|
||||
///
|
||||
/// Uses the main heap.
|
||||
///
|
||||
pub fn store_byte<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
offset: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.byte_type(),
|
||||
offset,
|
||||
"mstore8_offset_pointer",
|
||||
);
|
||||
context.build_call(
|
||||
context.llvm_runtime().mstore8,
|
||||
&[
|
||||
offset_pointer.value.as_basic_value_enum(),
|
||||
value.as_basic_value_enum(),
|
||||
],
|
||||
"mstore8_call",
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user