mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 13:51:12 +00:00
@@ -2,12 +2,12 @@
|
||||
|
||||
/// Translates the contract hash copying.
|
||||
pub fn contract_hash<'ctx, D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||
offset: inkwell::values::IntValue<'ctx>,
|
||||
value: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let offset = context.builder().build_int_add(
|
||||
offset,
|
||||
@@ -17,21 +17,21 @@ where
|
||||
"datacopy_contract_hash_offset",
|
||||
)?;
|
||||
|
||||
revive_llvm_context::eravm_evm_memory::store(context, offset, value)?;
|
||||
revive_llvm_context::polkavm_evm_memory::store(context, offset, value)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Translates the library marker copying.
|
||||
pub fn library_marker<D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
offset: u64,
|
||||
value: u64,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
revive_llvm_context::eravm_evm_memory::store_byte(
|
||||
revive_llvm_context::polkavm_evm_memory::store_byte(
|
||||
context,
|
||||
context.field_const(offset),
|
||||
context.field_const(value),
|
||||
@@ -42,12 +42,12 @@ where
|
||||
|
||||
/// Translates the static data copying.
|
||||
pub fn static_data<'ctx, D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||
destination: inkwell::values::IntValue<'ctx>,
|
||||
source: &str,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let mut offset = 0;
|
||||
for (index, chunk) in source
|
||||
@@ -68,7 +68,7 @@ where
|
||||
format!("datacopy_destination_index_{index}").as_str(),
|
||||
)?;
|
||||
let datacopy_value = context.field_const_str_hex(value_string.as_str());
|
||||
revive_llvm_context::eravm_evm_memory::store(
|
||||
revive_llvm_context::polkavm_evm_memory::store(
|
||||
context,
|
||||
datacopy_destination,
|
||||
datacopy_value,
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
/// Translates the unconditional jump.
|
||||
pub fn unconditional<D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
destination: num::BigUint,
|
||||
stack_hash: md5::Digest,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let code_type = context
|
||||
.code_type()
|
||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?;
|
||||
let block_key = revive_llvm_context::EraVMFunctionBlockKey::new(code_type, destination);
|
||||
let block_key = revive_llvm_context::PolkaVMFunctionBlockKey::new(code_type, destination);
|
||||
|
||||
let block = context
|
||||
.current_function()
|
||||
@@ -26,24 +26,24 @@ where
|
||||
|
||||
/// Translates the conditional jump.
|
||||
pub fn conditional<D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
destination: num::BigUint,
|
||||
stack_hash: md5::Digest,
|
||||
stack_height: usize,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let code_type = context
|
||||
.code_type()
|
||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?;
|
||||
let block_key = revive_llvm_context::EraVMFunctionBlockKey::new(code_type, destination);
|
||||
let block_key = revive_llvm_context::PolkaVMFunctionBlockKey::new(code_type, destination);
|
||||
|
||||
let condition_pointer = context.evmla().stack[stack_height]
|
||||
.to_llvm()
|
||||
.into_pointer_value();
|
||||
let condition = context.build_load(
|
||||
revive_llvm_context::EraVMPointer::new_stack_field(context, condition_pointer),
|
||||
revive_llvm_context::PolkaVMPointer::new_stack_field(context, condition_pointer),
|
||||
format!("conditional_{block_key}_condition").as_str(),
|
||||
)?;
|
||||
let condition = context.builder().build_int_compare(
|
||||
|
||||
@@ -328,11 +328,11 @@ impl Instruction {
|
||||
/// Initializes a recursive function `Call` instruction.
|
||||
pub fn recursive_call(
|
||||
name: String,
|
||||
entry_key: revive_llvm_context::EraVMFunctionBlockKey,
|
||||
entry_key: revive_llvm_context::PolkaVMFunctionBlockKey,
|
||||
stack_hash: md5::Digest,
|
||||
input_size: usize,
|
||||
output_size: usize,
|
||||
return_address: revive_llvm_context::EraVMFunctionBlockKey,
|
||||
return_address: revive_llvm_context::PolkaVMFunctionBlockKey,
|
||||
previous: &Self,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -300,10 +300,10 @@ pub enum Name {
|
||||
/// The eponymous EVM instruction.
|
||||
CREATE2,
|
||||
|
||||
/// The eponymous EraVM instruction.
|
||||
/// The eponymous PolkaVM instruction.
|
||||
#[serde(rename = "$ZK_CREATE")]
|
||||
ZK_CREATE,
|
||||
/// The eponymous EraVM instruction.
|
||||
/// The eponymous PolkaVM instruction.
|
||||
#[serde(rename = "$ZK_CREATE2")]
|
||||
ZK_CREATE2,
|
||||
|
||||
@@ -370,7 +370,7 @@ pub enum Name {
|
||||
/// The called function name.
|
||||
name: String,
|
||||
/// The called function key.
|
||||
entry_key: revive_llvm_context::EraVMFunctionBlockKey,
|
||||
entry_key: revive_llvm_context::PolkaVMFunctionBlockKey,
|
||||
/// The stack state hash after return.
|
||||
stack_hash: md5::Digest,
|
||||
/// The input size.
|
||||
@@ -378,7 +378,7 @@ pub enum Name {
|
||||
/// The output size.
|
||||
output_size: usize,
|
||||
/// The return address.
|
||||
return_address: revive_llvm_context::EraVMFunctionBlockKey,
|
||||
return_address: revive_llvm_context::PolkaVMFunctionBlockKey,
|
||||
},
|
||||
/// The recursive function return instruction.
|
||||
#[serde(skip)]
|
||||
|
||||
@@ -4,11 +4,11 @@ use inkwell::values::BasicValue;
|
||||
|
||||
/// Translates the ordinar value push.
|
||||
pub fn push<'ctx, D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||
value: String,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let result = context
|
||||
.field_type()
|
||||
@@ -23,11 +23,11 @@ where
|
||||
|
||||
/// Translates the block tag label push.
|
||||
pub fn push_tag<'ctx, D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||
value: String,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let result = context
|
||||
.field_type()
|
||||
@@ -38,17 +38,17 @@ where
|
||||
|
||||
/// Translates the stack memory duplicate.
|
||||
pub fn dup<'ctx, D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
|
||||
offset: usize,
|
||||
height: usize,
|
||||
original: &mut Option<String>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let element = &context.evmla().stack[height - offset - 1];
|
||||
let value = context.build_load(
|
||||
revive_llvm_context::EraVMPointer::new_stack_field(
|
||||
revive_llvm_context::PolkaVMPointer::new_stack_field(
|
||||
context,
|
||||
element.to_llvm().into_pointer_value(),
|
||||
),
|
||||
@@ -62,22 +62,22 @@ where
|
||||
|
||||
/// Translates the stack memory swap.
|
||||
pub fn swap<D>(
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
offset: usize,
|
||||
height: usize,
|
||||
) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
let top_element = context.evmla().stack[height - 1].to_owned();
|
||||
let top_pointer = revive_llvm_context::EraVMPointer::new_stack_field(
|
||||
let top_pointer = revive_llvm_context::PolkaVMPointer::new_stack_field(
|
||||
context,
|
||||
top_element.to_llvm().into_pointer_value(),
|
||||
);
|
||||
let top_value = context.build_load(top_pointer, format!("swap{offset}_top_value").as_str())?;
|
||||
|
||||
let swap_element = context.evmla().stack[height - offset - 1].to_owned();
|
||||
let swap_pointer = revive_llvm_context::EraVMPointer::new_stack_field(
|
||||
let swap_pointer = revive_llvm_context::PolkaVMPointer::new_stack_field(
|
||||
context,
|
||||
swap_element.to_llvm().into_pointer_value(),
|
||||
);
|
||||
@@ -94,9 +94,9 @@ where
|
||||
}
|
||||
|
||||
/// Translates the stack memory pop.
|
||||
pub fn pop<D>(_context: &mut revive_llvm_context::EraVMContext<D>) -> anyhow::Result<()>
|
||||
pub fn pop<D>(_context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()>
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ impl Assembly {
|
||||
/// Gets the contract `keccak256` hash.
|
||||
pub fn keccak256(&self) -> String {
|
||||
let json = serde_json::to_vec(self).expect("Always valid");
|
||||
revive_llvm_context::eravm_utils::keccak256(json.as_slice())
|
||||
revive_llvm_context::polkavm_utils::keccak256(json.as_slice())
|
||||
}
|
||||
|
||||
/// Sets the full contract path.
|
||||
@@ -180,28 +180,28 @@ impl Assembly {
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Assembly
|
||||
impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for Assembly
|
||||
where
|
||||
D: revive_llvm_context::EraVMDependency + Clone,
|
||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||
{
|
||||
fn declare(
|
||||
&mut self,
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut entry = revive_llvm_context::EraVMEntryFunction::default();
|
||||
let mut entry = revive_llvm_context::PolkaVMEntryFunction::default();
|
||||
entry.declare(context)?;
|
||||
|
||||
let mut runtime = revive_llvm_context::EraVMRuntime::new(
|
||||
revive_llvm_context::EraVMAddressSpace::Heap,
|
||||
let mut runtime = revive_llvm_context::PolkaVMRuntime::new(
|
||||
revive_llvm_context::PolkaVMAddressSpace::Heap,
|
||||
);
|
||||
runtime.declare(context)?;
|
||||
|
||||
revive_llvm_context::EraVMDeployCodeFunction::new(
|
||||
revive_llvm_context::EraVMDummyLLVMWritable::default(),
|
||||
revive_llvm_context::PolkaVMDeployCodeFunction::new(
|
||||
revive_llvm_context::PolkaVMDummyLLVMWritable::default(),
|
||||
)
|
||||
.declare(context)?;
|
||||
revive_llvm_context::EraVMRuntimeCodeFunction::new(
|
||||
revive_llvm_context::EraVMDummyLLVMWritable::default(),
|
||||
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(
|
||||
revive_llvm_context::PolkaVMDummyLLVMWritable::default(),
|
||||
)
|
||||
.declare(context)?;
|
||||
|
||||
@@ -214,7 +214,7 @@ where
|
||||
|
||||
fn into_llvm(
|
||||
mut self,
|
||||
context: &mut revive_llvm_context::EraVMContext<D>,
|
||||
context: &mut revive_llvm_context::PolkaVMContext<D>,
|
||||
) -> anyhow::Result<()> {
|
||||
let full_path = self.full_path().to_owned();
|
||||
|
||||
@@ -223,7 +223,7 @@ where
|
||||
}
|
||||
let deploy_code_blocks = EtherealIR::get_blocks(
|
||||
context.evmla().version.to_owned(),
|
||||
revive_llvm_context::EraVMCodeType::Deploy,
|
||||
revive_llvm_context::PolkaVMCodeType::Deploy,
|
||||
self.code
|
||||
.as_deref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Deploy code instructions not found"))?,
|
||||
@@ -250,7 +250,7 @@ where
|
||||
};
|
||||
let runtime_code_blocks = EtherealIR::get_blocks(
|
||||
context.evmla().version.to_owned(),
|
||||
revive_llvm_context::EraVMCodeType::Runtime,
|
||||
revive_llvm_context::PolkaVMCodeType::Runtime,
|
||||
runtime_code_instructions.as_slice(),
|
||||
)?;
|
||||
|
||||
@@ -265,12 +265,12 @@ where
|
||||
ethereal_ir.declare(context)?;
|
||||
ethereal_ir.into_llvm(context)?;
|
||||
|
||||
revive_llvm_context::EraVMDeployCodeFunction::new(EntryLink::new(
|
||||
revive_llvm_context::EraVMCodeType::Deploy,
|
||||
revive_llvm_context::PolkaVMDeployCodeFunction::new(EntryLink::new(
|
||||
revive_llvm_context::PolkaVMCodeType::Deploy,
|
||||
))
|
||||
.into_llvm(context)?;
|
||||
revive_llvm_context::EraVMRuntimeCodeFunction::new(EntryLink::new(
|
||||
revive_llvm_context::EraVMCodeType::Runtime,
|
||||
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(EntryLink::new(
|
||||
revive_llvm_context::PolkaVMCodeType::Runtime,
|
||||
))
|
||||
.into_llvm(context)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user