rename llvm-context crate

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-01 15:45:09 +02:00
parent 9b341853b4
commit 72515254fe
55 changed files with 529 additions and 529 deletions
Generated
+26 -26
View File
@@ -672,30 +672,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "era-compiler-llvm-context"
version = "1.4.1"
dependencies = [
"anyhow",
"hex",
"inkwell",
"itertools 0.12.1",
"md5",
"num",
"once_cell",
"pallet-contracts-pvm-llapi",
"regex",
"revive-builtins",
"revive-common",
"revive-linker",
"revive-stdlib",
"semver 1.0.22",
"serde",
"sha2",
"sha3",
"zkevm_opcode_defs",
]
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.8" version = "0.3.8"
@@ -1670,10 +1646,10 @@ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-sol-types", "alloy-sol-types",
"env_logger", "env_logger",
"era-compiler-llvm-context",
"hex", "hex",
"polkavm", "polkavm",
"revive-differential", "revive-differential",
"revive-llvm-context",
"revive-solidity", "revive-solidity",
"serde", "serde",
"serde_json", "serde_json",
@@ -1694,13 +1670,36 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "revive-llvm-context"
version = "1.4.1"
dependencies = [
"anyhow",
"hex",
"inkwell",
"itertools 0.12.1",
"md5",
"num",
"once_cell",
"pallet-contracts-pvm-llapi",
"regex",
"revive-builtins",
"revive-common",
"revive-linker",
"revive-stdlib",
"semver 1.0.22",
"serde",
"sha2",
"sha3",
"zkevm_opcode_defs",
]
[[package]] [[package]]
name = "revive-solidity" name = "revive-solidity"
version = "1.4.0" version = "1.4.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"colored", "colored",
"era-compiler-llvm-context",
"hex", "hex",
"inkwell", "inkwell",
"md5", "md5",
@@ -1712,6 +1711,7 @@ dependencies = [
"rayon", "rayon",
"regex", "regex",
"revive-common", "revive-common",
"revive-llvm-context",
"semver 1.0.22", "semver 1.0.22",
"serde", "serde",
"serde_json", "serde_json",
+1 -1
View File
@@ -14,7 +14,7 @@ env_logger = { workspace = true }
revive-solidity = { path = "../solidity" } revive-solidity = { path = "../solidity" }
revive-differential = { path = "../differential" } revive-differential = { path = "../differential" }
era-compiler-llvm-context = { path = "../llvm-context" } revive-llvm-context = { path = "../llvm-context" }
[dev-dependencies] [dev-dependencies]
sha1 = { workspace = true } sha1 = { workspace = true }
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"ERC20": 53186, "ERC20": 53186,
"Baseline": 3912, "Baseline": 3912,
"Fibonacci": 5971,
"Flipper": 4354, "Flipper": 4354,
"Computation": 7380 "Computation": 7380,
"Fibonacci": 5971
} }
+1 -1
View File
@@ -53,7 +53,7 @@ pub fn compile_blob_with_options(
Default::default(), Default::default(),
None, None,
pipeline, pipeline,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
solc_optimizer_enabled, solc_optimizer_enabled,
) )
.expect("source should compile") .expect("source should compile")
+1 -1
View File
@@ -1,5 +1,5 @@
[package] [package]
name = "era-compiler-llvm-context" name = "revive-llvm-context"
version = "1.4.1" version = "1.4.1"
authors = [ authors = [
"Oleksandr Zarudnyi <a.zarudnyy@matterlabs.dev>", "Oleksandr Zarudnyi <a.zarudnyy@matterlabs.dev>",
+1 -1
View File
@@ -38,7 +38,7 @@ md5 = { workspace = true }
inkwell = { workspace = true } inkwell = { workspace = true }
revive-common = { path = "../common" } revive-common = { path = "../common" }
era-compiler-llvm-context = { path = "../llvm-context" } revive-llvm-context = { path = "../llvm-context" }
[target.'cfg(target_env = "musl")'.dependencies] [target.'cfg(target_env = "musl")'.dependencies]
+2 -2
View File
@@ -23,7 +23,7 @@ pub struct Contract {
/// The auxiliary identifier. Used to identify Yul objects. /// The auxiliary identifier. Used to identify Yul objects.
pub identifier: String, pub identifier: String,
/// The LLVM module build. /// The LLVM module build.
pub build: era_compiler_llvm_context::EraVMBuild, pub build: revive_llvm_context::EraVMBuild,
/// The metadata JSON. /// The metadata JSON.
pub metadata_json: serde_json::Value, pub metadata_json: serde_json::Value,
/// The factory dependencies. /// The factory dependencies.
@@ -37,7 +37,7 @@ impl Contract {
pub fn new( pub fn new(
path: String, path: String,
identifier: String, identifier: String,
build: era_compiler_llvm_context::EraVMBuild, build: revive_llvm_context::EraVMBuild,
metadata_json: serde_json::Value, metadata_json: serde_json::Value,
factory_dependencies: HashSet<String>, factory_dependencies: HashSet<String>,
) -> Self { ) -> Self {
@@ -6,12 +6,12 @@
/// Translates the contract hash copying. /// Translates the contract hash copying.
/// ///
pub fn contract_hash<'ctx, D>( pub fn contract_hash<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
offset: inkwell::values::IntValue<'ctx>, offset: inkwell::values::IntValue<'ctx>,
value: inkwell::values::IntValue<'ctx>, value: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let offset = context.builder().build_int_add( let offset = context.builder().build_int_add(
offset, offset,
@@ -21,7 +21,7 @@ where
"datacopy_contract_hash_offset", "datacopy_contract_hash_offset",
)?; )?;
era_compiler_llvm_context::eravm_evm_memory::store(context, offset, value)?; revive_llvm_context::eravm_evm_memory::store(context, offset, value)?;
Ok(()) Ok(())
} }
@@ -30,14 +30,14 @@ where
/// Translates the library marker copying. /// Translates the library marker copying.
/// ///
pub fn library_marker<D>( pub fn library_marker<D>(
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
offset: u64, offset: u64,
value: u64, value: u64,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
era_compiler_llvm_context::eravm_evm_memory::store_byte( revive_llvm_context::eravm_evm_memory::store_byte(
context, context,
context.field_const(offset), context.field_const(offset),
context.field_const(value), context.field_const(value),
@@ -50,12 +50,12 @@ where
/// Translates the static data copying. /// Translates the static data copying.
/// ///
pub fn static_data<'ctx, D>( pub fn static_data<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
destination: inkwell::values::IntValue<'ctx>, destination: inkwell::values::IntValue<'ctx>,
source: &str, source: &str,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let mut offset = 0; let mut offset = 0;
for (index, chunk) in source for (index, chunk) in source
@@ -76,7 +76,7 @@ where
format!("datacopy_destination_index_{index}").as_str(), format!("datacopy_destination_index_{index}").as_str(),
)?; )?;
let datacopy_value = context.field_const_str_hex(value_string.as_str()); let datacopy_value = context.field_const_str_hex(value_string.as_str());
era_compiler_llvm_context::eravm_evm_memory::store( revive_llvm_context::eravm_evm_memory::store(
context, context,
datacopy_destination, datacopy_destination,
datacopy_value, datacopy_value,
@@ -6,17 +6,17 @@
/// Translates the unconditional jump. /// Translates the unconditional jump.
/// ///
pub fn unconditional<D>( pub fn unconditional<D>(
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
destination: num::BigUint, destination: num::BigUint,
stack_hash: md5::Digest, stack_hash: md5::Digest,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let code_type = context let code_type = context
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?; .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?;
let block_key = era_compiler_llvm_context::EraVMFunctionBlockKey::new(code_type, destination); let block_key = revive_llvm_context::EraVMFunctionBlockKey::new(code_type, destination);
let block = context let block = context
.current_function() .current_function()
@@ -32,24 +32,24 @@ where
/// Translates the conditional jump. /// Translates the conditional jump.
/// ///
pub fn conditional<D>( pub fn conditional<D>(
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
destination: num::BigUint, destination: num::BigUint,
stack_hash: md5::Digest, stack_hash: md5::Digest,
stack_height: usize, stack_height: usize,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let code_type = context let code_type = context
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?; .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?;
let block_key = era_compiler_llvm_context::EraVMFunctionBlockKey::new(code_type, destination); let block_key = revive_llvm_context::EraVMFunctionBlockKey::new(code_type, destination);
let condition_pointer = context.evmla().stack[stack_height] let condition_pointer = context.evmla().stack[stack_height]
.to_llvm() .to_llvm()
.into_pointer_value(); .into_pointer_value();
let condition = context.build_load( let condition = context.build_load(
era_compiler_llvm_context::EraVMPointer::new_stack_field(context, condition_pointer), revive_llvm_context::EraVMPointer::new_stack_field(context, condition_pointer),
format!("conditional_{block_key}_condition").as_str(), format!("conditional_{block_key}_condition").as_str(),
)?; )?;
let condition = context.builder().build_int_compare( let condition = context.builder().build_int_compare(
@@ -342,11 +342,11 @@ impl Instruction {
/// ///
pub fn recursive_call( pub fn recursive_call(
name: String, name: String,
entry_key: era_compiler_llvm_context::EraVMFunctionBlockKey, entry_key: revive_llvm_context::EraVMFunctionBlockKey,
stack_hash: md5::Digest, stack_hash: md5::Digest,
input_size: usize, input_size: usize,
output_size: usize, output_size: usize,
return_address: era_compiler_llvm_context::EraVMFunctionBlockKey, return_address: revive_llvm_context::EraVMFunctionBlockKey,
previous: &Self, previous: &Self,
) -> Self { ) -> Self {
Self { Self {
@@ -374,7 +374,7 @@ pub enum Name {
/// The called function name. /// The called function name.
name: String, name: String,
/// The called function key. /// The called function key.
entry_key: era_compiler_llvm_context::EraVMFunctionBlockKey, entry_key: revive_llvm_context::EraVMFunctionBlockKey,
/// The stack state hash after return. /// The stack state hash after return.
stack_hash: md5::Digest, stack_hash: md5::Digest,
/// The input size. /// The input size.
@@ -382,7 +382,7 @@ pub enum Name {
/// The output size. /// The output size.
output_size: usize, output_size: usize,
/// The return address. /// The return address.
return_address: era_compiler_llvm_context::EraVMFunctionBlockKey, return_address: revive_llvm_context::EraVMFunctionBlockKey,
}, },
/// The recursive function return instruction. /// The recursive function return instruction.
#[serde(skip)] #[serde(skip)]
@@ -8,11 +8,11 @@ use inkwell::values::BasicValue;
/// Translates the ordinar value push. /// Translates the ordinar value push.
/// ///
pub fn push<'ctx, D>( pub fn push<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
value: String, value: String,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let result = context let result = context
.field_type() .field_type()
@@ -29,11 +29,11 @@ where
/// Translates the block tag label push. /// Translates the block tag label push.
/// ///
pub fn push_tag<'ctx, D>( pub fn push_tag<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
value: String, value: String,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let result = context let result = context
.field_type() .field_type()
@@ -46,17 +46,17 @@ where
/// Translates the stack memory duplicate. /// Translates the stack memory duplicate.
/// ///
pub fn dup<'ctx, D>( pub fn dup<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
offset: usize, offset: usize,
height: usize, height: usize,
original: &mut Option<String>, original: &mut Option<String>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let element = &context.evmla().stack[height - offset - 1]; let element = &context.evmla().stack[height - offset - 1];
let value = context.build_load( let value = context.build_load(
era_compiler_llvm_context::EraVMPointer::new_stack_field( revive_llvm_context::EraVMPointer::new_stack_field(
context, context,
element.to_llvm().into_pointer_value(), element.to_llvm().into_pointer_value(),
), ),
@@ -72,22 +72,22 @@ where
/// Translates the stack memory swap. /// Translates the stack memory swap.
/// ///
pub fn swap<D>( pub fn swap<D>(
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
offset: usize, offset: usize,
height: usize, height: usize,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let top_element = context.evmla().stack[height - 1].to_owned(); let top_element = context.evmla().stack[height - 1].to_owned();
let top_pointer = era_compiler_llvm_context::EraVMPointer::new_stack_field( let top_pointer = revive_llvm_context::EraVMPointer::new_stack_field(
context, context,
top_element.to_llvm().into_pointer_value(), top_element.to_llvm().into_pointer_value(),
); );
let top_value = context.build_load(top_pointer, format!("swap{offset}_top_value").as_str())?; 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_element = context.evmla().stack[height - offset - 1].to_owned();
let swap_pointer = era_compiler_llvm_context::EraVMPointer::new_stack_field( let swap_pointer = revive_llvm_context::EraVMPointer::new_stack_field(
context, context,
swap_element.to_llvm().into_pointer_value(), swap_element.to_llvm().into_pointer_value(),
); );
@@ -106,9 +106,9 @@ where
/// ///
/// Translates the stack memory pop. /// Translates the stack memory pop.
/// ///
pub fn pop<D>(_context: &mut era_compiler_llvm_context::EraVMContext<D>) -> anyhow::Result<()> pub fn pop<D>(_context: &mut revive_llvm_context::EraVMContext<D>) -> anyhow::Result<()>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
Ok(()) Ok(())
} }
+18 -18
View File
@@ -51,7 +51,7 @@ impl Assembly {
/// ///
pub fn keccak256(&self) -> String { pub fn keccak256(&self) -> String {
let json = serde_json::to_vec(self).expect("Always valid"); let json = serde_json::to_vec(self).expect("Always valid");
era_compiler_llvm_context::eravm_utils::keccak256(json.as_slice()) revive_llvm_context::eravm_utils::keccak256(json.as_slice())
} }
/// ///
@@ -197,28 +197,28 @@ impl Assembly {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Assembly impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Assembly
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut entry = era_compiler_llvm_context::EraVMEntryFunction::default(); let mut entry = revive_llvm_context::EraVMEntryFunction::default();
entry.declare(context)?; entry.declare(context)?;
let mut runtime = era_compiler_llvm_context::EraVMRuntime::new( let mut runtime = revive_llvm_context::EraVMRuntime::new(
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
); );
runtime.declare(context)?; runtime.declare(context)?;
era_compiler_llvm_context::EraVMDeployCodeFunction::new( revive_llvm_context::EraVMDeployCodeFunction::new(
era_compiler_llvm_context::EraVMDummyLLVMWritable::default(), revive_llvm_context::EraVMDummyLLVMWritable::default(),
) )
.declare(context)?; .declare(context)?;
era_compiler_llvm_context::EraVMRuntimeCodeFunction::new( revive_llvm_context::EraVMRuntimeCodeFunction::new(
era_compiler_llvm_context::EraVMDummyLLVMWritable::default(), revive_llvm_context::EraVMDummyLLVMWritable::default(),
) )
.declare(context)?; .declare(context)?;
@@ -231,7 +231,7 @@ where
fn into_llvm( fn into_llvm(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let full_path = self.full_path().to_owned(); let full_path = self.full_path().to_owned();
@@ -240,7 +240,7 @@ where
} }
let deploy_code_blocks = EtherealIR::get_blocks( let deploy_code_blocks = EtherealIR::get_blocks(
context.evmla().version.to_owned(), context.evmla().version.to_owned(),
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
self.code self.code
.as_deref() .as_deref()
.ok_or_else(|| anyhow::anyhow!("Deploy code instructions not found"))?, .ok_or_else(|| anyhow::anyhow!("Deploy code instructions not found"))?,
@@ -267,7 +267,7 @@ where
}; };
let runtime_code_blocks = EtherealIR::get_blocks( let runtime_code_blocks = EtherealIR::get_blocks(
context.evmla().version.to_owned(), context.evmla().version.to_owned(),
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
runtime_code_instructions.as_slice(), runtime_code_instructions.as_slice(),
)?; )?;
@@ -282,12 +282,12 @@ where
ethereal_ir.declare(context)?; ethereal_ir.declare(context)?;
ethereal_ir.into_llvm(context)?; ethereal_ir.into_llvm(context)?;
era_compiler_llvm_context::EraVMDeployCodeFunction::new(EntryLink::new( revive_llvm_context::EraVMDeployCodeFunction::new(EntryLink::new(
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
)) ))
.into_llvm(context)?; .into_llvm(context)?;
era_compiler_llvm_context::EraVMRuntimeCodeFunction::new(EntryLink::new( revive_llvm_context::EraVMRuntimeCodeFunction::new(EntryLink::new(
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
)) ))
.into_llvm(context)?; .into_llvm(context)?;
@@ -14,25 +14,25 @@ use crate::evmla::ethereal_ir::EtherealIR;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct EntryLink { pub struct EntryLink {
/// The code part type. /// The code part type.
pub code_type: era_compiler_llvm_context::EraVMCodeType, pub code_type: revive_llvm_context::EraVMCodeType,
} }
impl EntryLink { impl EntryLink {
/// ///
/// A shortcut constructor. /// A shortcut constructor.
/// ///
pub fn new(code_type: era_compiler_llvm_context::EraVMCodeType) -> Self { pub fn new(code_type: revive_llvm_context::EraVMCodeType) -> Self {
Self { code_type } Self { code_type }
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for EntryLink impl<D> revive_llvm_context::EraVMWriteLLVM<D> for EntryLink
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let target = context let target = context
.get_function(EtherealIR::DEFAULT_ENTRY_FUNCTION_NAME) .get_function(EtherealIR::DEFAULT_ENTRY_FUNCTION_NAME)
@@ -40,10 +40,10 @@ where
.borrow() .borrow()
.declaration(); .declaration();
let is_deploy_code = match self.code_type { let is_deploy_code = match self.code_type {
era_compiler_llvm_context::EraVMCodeType::Deploy => context revive_llvm_context::EraVMCodeType::Deploy => context
.integer_type(revive_common::BIT_LENGTH_BOOLEAN) .integer_type(revive_common::BIT_LENGTH_BOOLEAN)
.const_int(1, false), .const_int(1, false),
era_compiler_llvm_context::EraVMCodeType::Runtime => context revive_llvm_context::EraVMCodeType::Runtime => context
.integer_type(revive_common::BIT_LENGTH_BOOLEAN) .integer_type(revive_common::BIT_LENGTH_BOOLEAN)
.const_int(0, false), .const_int(0, false),
}; };
@@ -52,10 +52,10 @@ impl Element {
/// ///
fn pop_arguments_llvm<'ctx, D>( fn pop_arguments_llvm<'ctx, D>(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> Vec<inkwell::values::BasicValueEnum<'ctx>> ) -> Vec<inkwell::values::BasicValueEnum<'ctx>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let input_size = self.instruction.input_size(&context.evmla().version); let input_size = self.instruction.input_size(&context.evmla().version);
let output_size = self.instruction.output_size(); let output_size = self.instruction.output_size();
@@ -67,7 +67,7 @@ impl Element {
.into_pointer_value(); .into_pointer_value();
let value = context let value = context
.build_load( .build_load(
era_compiler_llvm_context::EraVMPointer::new_stack_field(context, pointer), revive_llvm_context::EraVMPointer::new_stack_field(context, pointer),
format!("argument_{index}").as_str(), format!("argument_{index}").as_str(),
) )
.unwrap(); .unwrap();
@@ -77,13 +77,13 @@ impl Element {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Element impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Element
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'_, D>, context: &mut revive_llvm_context::EraVMContext<'_, D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut original = self.instruction.value.clone(); let mut original = self.instruction.value.clone();
@@ -135,7 +135,7 @@ where
) )
.map(Some), .map(Some),
InstructionName::PUSH_ContractHash => { InstructionName::PUSH_ContractHash => {
era_compiler_llvm_context::eravm_evm_create::contract_hash( revive_llvm_context::eravm_evm_create::contract_hash(
context, context,
self.instruction self.instruction
.value .value
@@ -144,7 +144,7 @@ where
.map(|argument| Some(argument.value)) .map(|argument| Some(argument.value))
} }
InstructionName::PUSH_ContractHashSize => { InstructionName::PUSH_ContractHashSize => {
era_compiler_llvm_context::eravm_evm_create::header_size( revive_llvm_context::eravm_evm_create::header_size(
context, context,
self.instruction self.instruction
.value .value
@@ -433,7 +433,7 @@ where
InstructionName::ADD => { InstructionName::ADD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::addition( revive_llvm_context::eravm_evm_arithmetic::addition(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -442,7 +442,7 @@ where
} }
InstructionName::SUB => { InstructionName::SUB => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::subtraction( revive_llvm_context::eravm_evm_arithmetic::subtraction(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -451,7 +451,7 @@ where
} }
InstructionName::MUL => { InstructionName::MUL => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::multiplication( revive_llvm_context::eravm_evm_arithmetic::multiplication(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -460,7 +460,7 @@ where
} }
InstructionName::DIV => { InstructionName::DIV => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::division( revive_llvm_context::eravm_evm_arithmetic::division(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -469,7 +469,7 @@ where
} }
InstructionName::MOD => { InstructionName::MOD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::remainder( revive_llvm_context::eravm_evm_arithmetic::remainder(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -478,7 +478,7 @@ where
} }
InstructionName::SDIV => { InstructionName::SDIV => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::division_signed( revive_llvm_context::eravm_evm_arithmetic::division_signed(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -487,7 +487,7 @@ where
} }
InstructionName::SMOD => { InstructionName::SMOD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_arithmetic::remainder_signed( revive_llvm_context::eravm_evm_arithmetic::remainder_signed(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -497,7 +497,7 @@ where
InstructionName::LT => { InstructionName::LT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -507,7 +507,7 @@ where
} }
InstructionName::GT => { InstructionName::GT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -517,7 +517,7 @@ where
} }
InstructionName::EQ => { InstructionName::EQ => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -527,7 +527,7 @@ where
} }
InstructionName::ISZERO => { InstructionName::ISZERO => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
context.field_const(0), context.field_const(0),
@@ -537,7 +537,7 @@ where
} }
InstructionName::SLT => { InstructionName::SLT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -547,7 +547,7 @@ where
} }
InstructionName::SGT => { InstructionName::SGT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -558,7 +558,7 @@ where
InstructionName::OR => { InstructionName::OR => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::or( revive_llvm_context::eravm_evm_bitwise::or(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -567,7 +567,7 @@ where
} }
InstructionName::XOR => { InstructionName::XOR => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::xor( revive_llvm_context::eravm_evm_bitwise::xor(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -576,7 +576,7 @@ where
} }
InstructionName::NOT => { InstructionName::NOT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::xor( revive_llvm_context::eravm_evm_bitwise::xor(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
context.field_type().const_all_ones(), context.field_type().const_all_ones(),
@@ -585,7 +585,7 @@ where
} }
InstructionName::AND => { InstructionName::AND => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::and( revive_llvm_context::eravm_evm_bitwise::and(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -594,7 +594,7 @@ where
} }
InstructionName::SHL => { InstructionName::SHL => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::shift_left( revive_llvm_context::eravm_evm_bitwise::shift_left(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -603,7 +603,7 @@ where
} }
InstructionName::SHR => { InstructionName::SHR => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::shift_right( revive_llvm_context::eravm_evm_bitwise::shift_right(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -612,7 +612,7 @@ where
} }
InstructionName::SAR => { InstructionName::SAR => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::shift_right_arithmetic( revive_llvm_context::eravm_evm_bitwise::shift_right_arithmetic(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -621,7 +621,7 @@ where
} }
InstructionName::BYTE => { InstructionName::BYTE => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_bitwise::byte( revive_llvm_context::eravm_evm_bitwise::byte(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -631,7 +631,7 @@ where
InstructionName::ADDMOD => { InstructionName::ADDMOD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_math::add_mod( revive_llvm_context::eravm_evm_math::add_mod(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -641,7 +641,7 @@ where
} }
InstructionName::MULMOD => { InstructionName::MULMOD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_math::mul_mod( revive_llvm_context::eravm_evm_math::mul_mod(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -651,7 +651,7 @@ where
} }
InstructionName::EXP => { InstructionName::EXP => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_math::exponent( revive_llvm_context::eravm_evm_math::exponent(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -660,7 +660,7 @@ where
} }
InstructionName::SIGNEXTEND => { InstructionName::SIGNEXTEND => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_math::sign_extend( revive_llvm_context::eravm_evm_math::sign_extend(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -670,7 +670,7 @@ where
InstructionName::SHA3 | InstructionName::KECCAK256 => { InstructionName::SHA3 | InstructionName::KECCAK256 => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_crypto::sha3( revive_llvm_context::eravm_evm_crypto::sha3(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -680,7 +680,7 @@ where
InstructionName::MLOAD => { InstructionName::MLOAD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_memory::load( revive_llvm_context::eravm_evm_memory::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -688,7 +688,7 @@ where
} }
InstructionName::MSTORE => { InstructionName::MSTORE => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_memory::store( revive_llvm_context::eravm_evm_memory::store(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -697,7 +697,7 @@ where
} }
InstructionName::MSTORE8 => { InstructionName::MSTORE8 => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_memory::store_byte( revive_llvm_context::eravm_evm_memory::store_byte(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -706,16 +706,16 @@ where
} }
InstructionName::MCOPY => { InstructionName::MCOPY => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
let destination = era_compiler_llvm_context::EraVMPointer::new_with_offset( let destination = revive_llvm_context::EraVMPointer::new_with_offset(
context, context,
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
context.byte_type(), context.byte_type(),
arguments[0].into_int_value(), arguments[0].into_int_value(),
"mcopy_destination", "mcopy_destination",
); );
let source = era_compiler_llvm_context::EraVMPointer::new_with_offset( let source = revive_llvm_context::EraVMPointer::new_with_offset(
context, context,
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
context.byte_type(), context.byte_type(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
"mcopy_source", "mcopy_source",
@@ -733,7 +733,7 @@ where
InstructionName::SLOAD => { InstructionName::SLOAD => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_storage::load( revive_llvm_context::eravm_evm_storage::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -741,7 +741,7 @@ where
} }
InstructionName::SSTORE => { InstructionName::SSTORE => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_storage::store( revive_llvm_context::eravm_evm_storage::store(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -767,7 +767,7 @@ where
.get_or_allocate_immutable(key.as_str()); .get_or_allocate_immutable(key.as_str());
let index = context.field_const(offset as u64); let index = context.field_const(offset as u64);
era_compiler_llvm_context::eravm_evm_immutable::load(context, index).map(Some) revive_llvm_context::eravm_evm_immutable::load(context, index).map(Some)
} }
InstructionName::ASSIGNIMMUTABLE => { InstructionName::ASSIGNIMMUTABLE => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
@@ -781,7 +781,7 @@ where
let index = context.field_const(offset as u64); let index = context.field_const(offset as u64);
let value = arguments.pop().expect("Always exists").into_int_value(); let value = arguments.pop().expect("Always exists").into_int_value();
era_compiler_llvm_context::eravm_evm_immutable::store(context, index, value) revive_llvm_context::eravm_evm_immutable::store(context, index, value)
.map(|_| None) .map(|_| None)
} }
@@ -790,12 +790,12 @@ where
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum())) Ok(Some(context.field_const(0).as_basic_value_enum()))
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_calldata::load( revive_llvm_context::eravm_evm_calldata::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -808,11 +808,11 @@ where
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum())) Ok(Some(context.field_const(0).as_basic_value_enum()))
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some) revive_llvm_context::eravm_evm_calldata::size(context).map(Some)
} }
} }
} }
@@ -823,11 +823,11 @@ where
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
let calldata_size = let calldata_size =
era_compiler_llvm_context::eravm_evm_calldata::size(context)?; revive_llvm_context::eravm_evm_calldata::size(context)?;
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
calldata_size.into_int_value(), calldata_size.into_int_value(),
@@ -835,8 +835,8 @@ where
) )
.map(|_| None) .map(|_| None)
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -851,10 +851,10 @@ where
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some) revive_llvm_context::eravm_evm_calldata::size(context).map(Some)
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
todo!() todo!()
} }
} }
@@ -887,18 +887,18 @@ where
match context.code_type().ok_or_else(|| { match context.code_type().ok_or_else(|| {
anyhow::anyhow!("The contract code part type is undefined") anyhow::anyhow!("The contract code part type is undefined")
})? { })? {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
arguments[2].into_int_value(), arguments[2].into_int_value(),
) )
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
let calldata_size = let calldata_size =
era_compiler_llvm_context::eravm_evm_calldata::size(context)?; revive_llvm_context::eravm_evm_calldata::size(context)?;
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
calldata_size.into_int_value(), calldata_size.into_int_value(),
@@ -912,11 +912,11 @@ where
} }
InstructionName::PUSHSIZE => Ok(Some(context.field_const(0).as_basic_value_enum())), InstructionName::PUSHSIZE => Ok(Some(context.field_const(0).as_basic_value_enum())),
InstructionName::RETURNDATASIZE => { InstructionName::RETURNDATASIZE => {
era_compiler_llvm_context::eravm_evm_return_data::size(context).map(Some) revive_llvm_context::eravm_evm_return_data::size(context).map(Some)
} }
InstructionName::RETURNDATACOPY => { InstructionName::RETURNDATACOPY => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_return_data::copy( revive_llvm_context::eravm_evm_return_data::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -926,7 +926,7 @@ where
} }
InstructionName::EXTCODESIZE => { InstructionName::EXTCODESIZE => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_ext_code::size( revive_llvm_context::eravm_evm_ext_code::size(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -934,7 +934,7 @@ where
} }
InstructionName::EXTCODEHASH => { InstructionName::EXTCODEHASH => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_ext_code::hash( revive_llvm_context::eravm_evm_ext_code::hash(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -943,7 +943,7 @@ where
InstructionName::RETURN => { InstructionName::RETURN => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_return::r#return( revive_llvm_context::eravm_evm_return::r#return(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -952,7 +952,7 @@ where
} }
InstructionName::REVERT => { InstructionName::REVERT => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_return::revert( revive_llvm_context::eravm_evm_return::revert(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -960,15 +960,15 @@ where
.map(|_| None) .map(|_| None)
} }
InstructionName::STOP => { InstructionName::STOP => {
era_compiler_llvm_context::eravm_evm_return::stop(context).map(|_| None) revive_llvm_context::eravm_evm_return::stop(context).map(|_| None)
} }
InstructionName::INVALID => { InstructionName::INVALID => {
era_compiler_llvm_context::eravm_evm_return::invalid(context).map(|_| None) revive_llvm_context::eravm_evm_return::invalid(context).map(|_| None)
} }
InstructionName::LOG0 => { InstructionName::LOG0 => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
@@ -981,7 +981,7 @@ where
} }
InstructionName::LOG1 => { InstructionName::LOG1 => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
@@ -994,7 +994,7 @@ where
} }
InstructionName::LOG2 => { InstructionName::LOG2 => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
@@ -1007,7 +1007,7 @@ where
} }
InstructionName::LOG3 => { InstructionName::LOG3 => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
@@ -1020,7 +1020,7 @@ where
} }
InstructionName::LOG4 => { InstructionName::LOG4 => {
let mut arguments = self.pop_arguments_llvm(context); let mut arguments = self.pop_arguments_llvm(context);
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
arguments.remove(0).into_int_value(), arguments.remove(0).into_int_value(),
@@ -1045,7 +1045,7 @@ where
todo!() todo!()
/* /*
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().far_call, context.llvm_runtime().far_call,
gas, gas,
@@ -1070,7 +1070,7 @@ where
let output_offset = arguments.remove(0).into_int_value(); let output_offset = arguments.remove(0).into_int_value();
let output_size = arguments.remove(0).into_int_value(); let output_size = arguments.remove(0).into_int_value();
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().static_call, context.llvm_runtime().static_call,
gas, gas,
@@ -1094,7 +1094,7 @@ where
let output_offset = arguments.remove(0).into_int_value(); let output_offset = arguments.remove(0).into_int_value();
let output_size = arguments.remove(0).into_int_value(); let output_size = arguments.remove(0).into_int_value();
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().delegate_call, context.llvm_runtime().delegate_call,
gas, gas,
@@ -1116,7 +1116,7 @@ where
let input_offset = arguments[1].into_int_value(); let input_offset = arguments[1].into_int_value();
let input_length = arguments[2].into_int_value(); let input_length = arguments[2].into_int_value();
era_compiler_llvm_context::eravm_evm_create::create( revive_llvm_context::eravm_evm_create::create(
context, context,
value, value,
input_offset, input_offset,
@@ -1132,7 +1132,7 @@ where
let input_length = arguments[2].into_int_value(); let input_length = arguments[2].into_int_value();
let salt = arguments[3].into_int_value(); let salt = arguments[3].into_int_value();
era_compiler_llvm_context::eravm_evm_create::create2( revive_llvm_context::eravm_evm_create::create2(
context, context,
value, value,
input_offset, input_offset,
@@ -1146,44 +1146,44 @@ where
InstructionName::CALLER => todo!(), InstructionName::CALLER => todo!(),
InstructionName::CALLVALUE => { InstructionName::CALLVALUE => {
era_compiler_llvm_context::eravm_evm_ether_gas::value(context).map(Some) revive_llvm_context::eravm_evm_ether_gas::value(context).map(Some)
} }
InstructionName::GAS => { InstructionName::GAS => {
era_compiler_llvm_context::eravm_evm_ether_gas::gas(context).map(Some) revive_llvm_context::eravm_evm_ether_gas::gas(context).map(Some)
} }
InstructionName::BALANCE => { InstructionName::BALANCE => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
let address = arguments[0].into_int_value(); let address = arguments[0].into_int_value();
era_compiler_llvm_context::eravm_evm_ether_gas::balance(context, address).map(Some) revive_llvm_context::eravm_evm_ether_gas::balance(context, address).map(Some)
} }
InstructionName::SELFBALANCE => todo!(), InstructionName::SELFBALANCE => todo!(),
InstructionName::GASLIMIT => { InstructionName::GASLIMIT => {
era_compiler_llvm_context::eravm_evm_contract_context::gas_limit(context).map(Some) revive_llvm_context::eravm_evm_contract_context::gas_limit(context).map(Some)
} }
InstructionName::GASPRICE => { InstructionName::GASPRICE => {
era_compiler_llvm_context::eravm_evm_contract_context::gas_price(context).map(Some) revive_llvm_context::eravm_evm_contract_context::gas_price(context).map(Some)
} }
InstructionName::ORIGIN => { InstructionName::ORIGIN => {
era_compiler_llvm_context::eravm_evm_contract_context::origin(context).map(Some) revive_llvm_context::eravm_evm_contract_context::origin(context).map(Some)
} }
InstructionName::CHAINID => { InstructionName::CHAINID => {
era_compiler_llvm_context::eravm_evm_contract_context::chain_id(context).map(Some) revive_llvm_context::eravm_evm_contract_context::chain_id(context).map(Some)
} }
InstructionName::TIMESTAMP => { InstructionName::TIMESTAMP => {
era_compiler_llvm_context::eravm_evm_contract_context::block_timestamp(context) revive_llvm_context::eravm_evm_contract_context::block_timestamp(context)
.map(Some) .map(Some)
} }
InstructionName::NUMBER => { InstructionName::NUMBER => {
era_compiler_llvm_context::eravm_evm_contract_context::block_number(context) revive_llvm_context::eravm_evm_contract_context::block_number(context)
.map(Some) .map(Some)
} }
InstructionName::BLOCKHASH => { InstructionName::BLOCKHASH => {
let arguments = self.pop_arguments_llvm(context); let arguments = self.pop_arguments_llvm(context);
let index = arguments[0].into_int_value(); let index = arguments[0].into_int_value();
era_compiler_llvm_context::eravm_evm_contract_context::block_hash(context, index) revive_llvm_context::eravm_evm_contract_context::block_hash(context, index)
.map(Some) .map(Some)
} }
InstructionName::BLOBHASH => { InstructionName::BLOBHASH => {
@@ -1191,19 +1191,19 @@ where
anyhow::bail!("The `BLOBHASH` instruction is not supported until zkVM v1.5.0"); anyhow::bail!("The `BLOBHASH` instruction is not supported until zkVM v1.5.0");
} }
InstructionName::DIFFICULTY | InstructionName::PREVRANDAO => { InstructionName::DIFFICULTY | InstructionName::PREVRANDAO => {
era_compiler_llvm_context::eravm_evm_contract_context::difficulty(context).map(Some) revive_llvm_context::eravm_evm_contract_context::difficulty(context).map(Some)
} }
InstructionName::COINBASE => { InstructionName::COINBASE => {
era_compiler_llvm_context::eravm_evm_contract_context::coinbase(context).map(Some) revive_llvm_context::eravm_evm_contract_context::coinbase(context).map(Some)
} }
InstructionName::BASEFEE => { InstructionName::BASEFEE => {
era_compiler_llvm_context::eravm_evm_contract_context::basefee(context).map(Some) revive_llvm_context::eravm_evm_contract_context::basefee(context).map(Some)
} }
InstructionName::BLOBBASEFEE => { InstructionName::BLOBBASEFEE => {
anyhow::bail!("The `BLOBBASEFEE` instruction is not supported until zkVM v1.5.0"); anyhow::bail!("The `BLOBBASEFEE` instruction is not supported until zkVM v1.5.0");
} }
InstructionName::MSIZE => { InstructionName::MSIZE => {
era_compiler_llvm_context::eravm_evm_contract_context::msize(context).map(Some) revive_llvm_context::eravm_evm_contract_context::msize(context).map(Some)
} }
InstructionName::CALLCODE => { InstructionName::CALLCODE => {
@@ -1252,7 +1252,7 @@ where
.to_llvm() .to_llvm()
.into_pointer_value(); .into_pointer_value();
context.build_store( context.build_store(
era_compiler_llvm_context::EraVMPointer::new_stack_field( revive_llvm_context::EraVMPointer::new_stack_field(
context, pointer, context, pointer,
), ),
value, value,
@@ -1269,9 +1269,9 @@ where
format!("return_value_element_{}", index).as_str(), format!("return_value_element_{}", index).as_str(),
) )
.expect("Always exists"); .expect("Always exists");
let pointer = era_compiler_llvm_context::EraVMPointer::new( let pointer = revive_llvm_context::EraVMPointer::new(
context.field_type(), context.field_type(),
era_compiler_llvm_context::EraVMAddressSpace::Stack, revive_llvm_context::EraVMAddressSpace::Stack,
context.evmla().stack context.evmla().stack
[self.stack.elements.len() - output_size + index] [self.stack.elements.len() - output_size + index]
.to_llvm() .to_llvm()
@@ -1300,12 +1300,12 @@ where
arguments.pop(); arguments.pop();
match context.current_function().borrow().r#return() { match context.current_function().borrow().r#return() {
era_compiler_llvm_context::EraVMFunctionReturn::None => {} revive_llvm_context::EraVMFunctionReturn::None => {}
era_compiler_llvm_context::EraVMFunctionReturn::Primitive { pointer } => { revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
assert_eq!(arguments.len(), 1); assert_eq!(arguments.len(), 1);
context.build_store(pointer, arguments.remove(0))?; context.build_store(pointer, arguments.remove(0))?;
} }
era_compiler_llvm_context::EraVMFunctionReturn::Compound { revive_llvm_context::EraVMFunctionReturn::Compound {
pointer, .. pointer, ..
} => { } => {
for (index, argument) in arguments.into_iter().enumerate() { for (index, argument) in arguments.into_iter().enumerate() {
@@ -1335,7 +1335,7 @@ where
.to_llvm() .to_llvm()
.into_pointer_value(); .into_pointer_value();
context.build_store( context.build_store(
era_compiler_llvm_context::EraVMPointer::new_stack_field(context, pointer), revive_llvm_context::EraVMPointer::new_stack_field(context, pointer),
result, result,
)?; )?;
context.evmla_mut().stack[self.stack.elements.len() - 1].original = original; context.evmla_mut().stack[self.stack.elements.len() - 1].original = original;
@@ -22,13 +22,13 @@ pub struct Block {
/// The Solidity compiler version. /// The Solidity compiler version.
pub solc_version: semver::Version, pub solc_version: semver::Version,
/// The block key. /// The block key.
pub key: era_compiler_llvm_context::EraVMFunctionBlockKey, pub key: revive_llvm_context::EraVMFunctionBlockKey,
/// The block instance. /// The block instance.
pub instance: Option<usize>, pub instance: Option<usize>,
/// The block elements relevant to the stack consistency. /// The block elements relevant to the stack consistency.
pub elements: Vec<Element>, pub elements: Vec<Element>,
/// The block predecessors. /// The block predecessors.
pub predecessors: HashSet<(era_compiler_llvm_context::EraVMFunctionBlockKey, usize)>, pub predecessors: HashSet<(revive_llvm_context::EraVMFunctionBlockKey, usize)>,
/// The initial stack state. /// The initial stack state.
pub initial_stack: ElementStack, pub initial_stack: ElementStack,
/// The stack. /// The stack.
@@ -48,7 +48,7 @@ impl Block {
/// ///
pub fn try_from_instructions( pub fn try_from_instructions(
solc_version: semver::Version, solc_version: semver::Version,
code_type: era_compiler_llvm_context::EraVMCodeType, code_type: revive_llvm_context::EraVMCodeType,
slice: &[Instruction], slice: &[Instruction],
) -> anyhow::Result<(Self, usize)> { ) -> anyhow::Result<(Self, usize)> {
let mut cursor = 0; let mut cursor = 0;
@@ -69,7 +69,7 @@ impl Block {
let mut block = Self { let mut block = Self {
solc_version: solc_version.clone(), solc_version: solc_version.clone(),
key: era_compiler_llvm_context::EraVMFunctionBlockKey::new(code_type, tag), key: revive_llvm_context::EraVMFunctionBlockKey::new(code_type, tag),
instance: None, instance: None,
elements: Vec::with_capacity(Self::ELEMENTS_VECTOR_DEFAULT_CAPACITY), elements: Vec::with_capacity(Self::ELEMENTS_VECTOR_DEFAULT_CAPACITY),
predecessors: HashSet::with_capacity(Self::PREDECESSORS_HASHSET_DEFAULT_CAPACITY), predecessors: HashSet::with_capacity(Self::PREDECESSORS_HASHSET_DEFAULT_CAPACITY),
@@ -114,20 +114,20 @@ impl Block {
/// ///
pub fn insert_predecessor( pub fn insert_predecessor(
&mut self, &mut self,
key: era_compiler_llvm_context::EraVMFunctionBlockKey, key: revive_llvm_context::EraVMFunctionBlockKey,
instance: usize, instance: usize,
) { ) {
self.predecessors.insert((key, instance)); self.predecessors.insert((key, instance));
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Block impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Block
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
context.set_code_type(self.key.code_type); context.set_code_type(self.key.code_type);
@@ -47,7 +47,7 @@ pub struct Function {
/// The function name. /// The function name.
pub name: String, pub name: String,
/// The separately labelled blocks. /// The separately labelled blocks.
pub blocks: BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Vec<Block>>, pub blocks: BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Vec<Block>>,
/// The function type. /// The function type.
pub r#type: Type, pub r#type: Type,
/// The function stack size. /// The function stack size.
@@ -82,8 +82,8 @@ impl Function {
/// ///
pub fn traverse( pub fn traverse(
&mut self, &mut self,
blocks: &HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: &HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
functions: &mut BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Self>, functions: &mut BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Self>,
extra_metadata: &ExtraMetadata, extra_metadata: &ExtraMetadata,
visited_functions: &mut BTreeSet<VisitedElement>, visited_functions: &mut BTreeSet<VisitedElement>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@@ -92,8 +92,8 @@ impl Function {
match self.r#type { match self.r#type {
Type::Initial => { Type::Initial => {
for code_type in [ for code_type in [
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
] { ] {
self.consume_block( self.consume_block(
blocks, blocks,
@@ -102,7 +102,7 @@ impl Function {
visited_functions, visited_functions,
&mut visited_blocks, &mut visited_blocks,
QueueElement::new( QueueElement::new(
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
code_type, code_type,
num::BigUint::zero(), num::BigUint::zero(),
), ),
@@ -148,8 +148,8 @@ impl Function {
/// ///
fn consume_block( fn consume_block(
&mut self, &mut self,
blocks: &HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: &HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
functions: &mut BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Self>, functions: &mut BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Self>,
extra_metadata: &ExtraMetadata, extra_metadata: &ExtraMetadata,
visited_functions: &mut BTreeSet<VisitedElement>, visited_functions: &mut BTreeSet<VisitedElement>,
visited_blocks: &mut BTreeSet<VisitedElement>, visited_blocks: &mut BTreeSet<VisitedElement>,
@@ -227,11 +227,11 @@ impl Function {
/// ///
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn handle_instruction( fn handle_instruction(
blocks: &HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: &HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
functions: &mut BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Self>, functions: &mut BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Self>,
extra_metadata: &ExtraMetadata, extra_metadata: &ExtraMetadata,
visited_functions: &mut BTreeSet<VisitedElement>, visited_functions: &mut BTreeSet<VisitedElement>,
code_type: era_compiler_llvm_context::EraVMCodeType, code_type: revive_llvm_context::EraVMCodeType,
instance: usize, instance: usize,
block_stack: &mut Stack, block_stack: &mut Stack,
block_element: &mut BlockElement, block_element: &mut BlockElement,
@@ -260,13 +260,13 @@ impl Function {
.ok_or_else(|| anyhow::anyhow!("Destination tag is missing"))? .ok_or_else(|| anyhow::anyhow!("Destination tag is missing"))?
{ {
Element::Tag(destination) if destination > &num::BigUint::from(u32::MAX) => { Element::Tag(destination) if destination > &num::BigUint::from(u32::MAX) => {
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
destination.to_owned() - num::BigUint::from(1u64 << 32), destination.to_owned() - num::BigUint::from(1u64 << 32),
) )
} }
Element::Tag(destination) => { Element::Tag(destination) => {
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
code_type, code_type,
destination.to_owned(), destination.to_owned(),
) )
@@ -324,13 +324,13 @@ impl Function {
.ok_or_else(|| anyhow::anyhow!("Destination tag is missing"))? .ok_or_else(|| anyhow::anyhow!("Destination tag is missing"))?
{ {
Element::Tag(destination) if destination > &num::BigUint::from(u32::MAX) => { Element::Tag(destination) if destination > &num::BigUint::from(u32::MAX) => {
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
destination.to_owned() - num::BigUint::from(1u64 << 32), destination.to_owned() - num::BigUint::from(1u64 << 32),
) )
} }
Element::Tag(destination) => { Element::Tag(destination) => {
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
code_type, code_type,
destination.to_owned(), destination.to_owned(),
) )
@@ -360,7 +360,7 @@ impl Function {
} => { } => {
let tag: num::BigUint = tag.parse().expect("Always valid"); let tag: num::BigUint = tag.parse().expect("Always valid");
let block_key = let block_key =
era_compiler_llvm_context::EraVMFunctionBlockKey::new(code_type, tag); revive_llvm_context::EraVMFunctionBlockKey::new(code_type, tag);
queue_element.predecessor = Some((queue_element.block_key.clone(), instance)); queue_element.predecessor = Some((queue_element.block_key.clone(), instance));
queue_element.block_key = block_key.clone(); queue_element.block_key = block_key.clone();
@@ -1023,16 +1023,16 @@ impl Function {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn handle_recursive_function_call( fn handle_recursive_function_call(
recursive_function: &RecursiveFunction, recursive_function: &RecursiveFunction,
blocks: &HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: &HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
functions: &mut BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Self>, functions: &mut BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Self>,
extra_metadata: &ExtraMetadata, extra_metadata: &ExtraMetadata,
visited_functions: &mut BTreeSet<VisitedElement>, visited_functions: &mut BTreeSet<VisitedElement>,
block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: revive_llvm_context::EraVMFunctionBlockKey,
block_stack: &mut Stack, block_stack: &mut Stack,
block_element: &mut BlockElement, block_element: &mut BlockElement,
version: &semver::Version, version: &semver::Version,
) -> anyhow::Result<( ) -> anyhow::Result<(
era_compiler_llvm_context::EraVMFunctionBlockKey, revive_llvm_context::EraVMFunctionBlockKey,
Vec<Element>, Vec<Element>,
)> { )> {
let return_address_offset = block_stack.elements.len() - 2 - recursive_function.input_size; let return_address_offset = block_stack.elements.len() - 2 - recursive_function.input_size;
@@ -1041,7 +1041,7 @@ impl Function {
let return_address = match block_stack.elements[return_address_offset] { let return_address = match block_stack.elements[return_address_offset] {
Element::Tag(ref return_address) => { Element::Tag(ref return_address) => {
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
block_key.code_type, block_key.code_type,
return_address.to_owned(), return_address.to_owned(),
) )
@@ -1126,14 +1126,14 @@ impl Function {
/// Checks both deploy and runtime code. /// Checks both deploy and runtime code.
/// ///
fn is_tag_value_valid( fn is_tag_value_valid(
blocks: &HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: &HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
tag: &num::BigUint, tag: &num::BigUint,
) -> bool { ) -> bool {
blocks.contains_key(&era_compiler_llvm_context::EraVMFunctionBlockKey::new( blocks.contains_key(&revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
tag & num::BigUint::from(u32::MAX), tag & num::BigUint::from(u32::MAX),
)) || blocks.contains_key(&era_compiler_llvm_context::EraVMFunctionBlockKey::new( )) || blocks.contains_key(&revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
tag & num::BigUint::from(u32::MAX), tag & num::BigUint::from(u32::MAX),
)) ))
} }
@@ -1157,13 +1157,13 @@ impl Function {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Function impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Function
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let (function_type, output_size) = match self.r#type { let (function_type, output_size) = match self.r#type {
Type::Initial => { Type::Initial => {
@@ -1202,7 +1202,7 @@ where
Some(inkwell::module::Linkage::Private), Some(inkwell::module::Linkage::Private),
)?; )?;
function.borrow_mut().set_evmla_data( function.borrow_mut().set_evmla_data(
era_compiler_llvm_context::EraVMFunctionEVMLAData::new(self.stack_size), revive_llvm_context::EraVMFunctionEVMLAData::new(self.stack_size),
); );
Ok(()) Ok(())
@@ -1210,7 +1210,7 @@ where
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
context.set_current_function(self.name.as_str())?; context.set_current_function(self.name.as_str())?;
@@ -1220,8 +1220,8 @@ where
let mut stack_hashes = vec![block.initial_stack.hash()]; let mut stack_hashes = vec![block.initial_stack.hash()];
stack_hashes.extend_from_slice(block.extra_hashes.as_slice()); stack_hashes.extend_from_slice(block.extra_hashes.as_slice());
let evmla_data = let evmla_data =
era_compiler_llvm_context::EraVMFunctionBlockEVMLAData::new(stack_hashes); revive_llvm_context::EraVMFunctionBlockEVMLAData::new(stack_hashes);
let mut block = era_compiler_llvm_context::EraVMFunctionBlock::new(inner); let mut block = revive_llvm_context::EraVMFunctionBlock::new(inner);
block.set_evmla_data(evmla_data); block.set_evmla_data(evmla_data);
context context
.current_function() .current_function()
@@ -1253,7 +1253,7 @@ where
_ => context.field_const(0).as_basic_value_enum(), _ => context.field_const(0).as_basic_value_enum(),
}; };
context.build_store(pointer, value)?; context.build_store(pointer, value)?;
stack_variables.push(era_compiler_llvm_context::EraVMArgument::new( stack_variables.push(revive_llvm_context::EraVMArgument::new(
pointer.value.as_basic_value_enum(), pointer.value.as_basic_value_enum(),
)); ));
} }
@@ -1267,15 +1267,15 @@ where
.get_nth_param(0) .get_nth_param(0)
.into_int_value(); .into_int_value();
let deploy_code_block = context.current_function().borrow().evmla().find_block( let deploy_code_block = context.current_function().borrow().evmla().find_block(
&era_compiler_llvm_context::EraVMFunctionBlockKey::new( &revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
num::BigUint::zero(), num::BigUint::zero(),
), ),
&Stack::default().hash(), &Stack::default().hash(),
)?; )?;
let runtime_code_block = context.current_function().borrow().evmla().find_block( let runtime_code_block = context.current_function().borrow().evmla().find_block(
&era_compiler_llvm_context::EraVMFunctionBlockKey::new( &revive_llvm_context::EraVMFunctionBlockKey::new(
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
num::BigUint::zero(), num::BigUint::zero(),
), ),
&Stack::default().hash(), &Stack::default().hash(),
@@ -1321,14 +1321,14 @@ where
context.set_basic_block(context.current_function().borrow().return_block()); context.set_basic_block(context.current_function().borrow().return_block());
match context.current_function().borrow().r#return() { match context.current_function().borrow().r#return() {
era_compiler_llvm_context::EraVMFunctionReturn::None => { revive_llvm_context::EraVMFunctionReturn::None => {
context.build_return(None); context.build_return(None);
} }
era_compiler_llvm_context::EraVMFunctionReturn::Primitive { pointer } => { revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
let return_value = context.build_load(pointer, "return_value")?; let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value)); context.build_return(Some(&return_value));
} }
era_compiler_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => { revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => {
let return_value = context.build_load(pointer, "return_value")?; let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value)); context.build_return(Some(&return_value));
} }
@@ -10,9 +10,9 @@ use crate::evmla::ethereal_ir::function::block::element::stack::Stack;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct QueueElement { pub struct QueueElement {
/// The block key. /// The block key.
pub block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, pub block_key: revive_llvm_context::EraVMFunctionBlockKey,
/// The block predecessor. /// The block predecessor.
pub predecessor: Option<(era_compiler_llvm_context::EraVMFunctionBlockKey, usize)>, pub predecessor: Option<(revive_llvm_context::EraVMFunctionBlockKey, usize)>,
/// The predecessor's last stack state. /// The predecessor's last stack state.
pub stack: Stack, pub stack: Stack,
} }
@@ -22,8 +22,8 @@ impl QueueElement {
/// A shortcut constructor. /// A shortcut constructor.
/// ///
pub fn new( pub fn new(
block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: revive_llvm_context::EraVMFunctionBlockKey,
predecessor: Option<(era_compiler_llvm_context::EraVMFunctionBlockKey, usize)>, predecessor: Option<(revive_llvm_context::EraVMFunctionBlockKey, usize)>,
stack: Stack, stack: Stack,
) -> Self { ) -> Self {
Self { Self {
@@ -14,7 +14,7 @@ pub enum Type {
/// The function name. /// The function name.
name: String, name: String,
/// The function initial block key. /// The function initial block key.
block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: revive_llvm_context::EraVMFunctionBlockKey,
/// The size of stack input (in cells or 256-bit words). /// The size of stack input (in cells or 256-bit words).
input_size: usize, input_size: usize,
/// The size of stack output (in cells or 256-bit words). /// The size of stack output (in cells or 256-bit words).
@@ -35,7 +35,7 @@ impl Type {
/// ///
pub fn new_recursive( pub fn new_recursive(
name: String, name: String,
block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: revive_llvm_context::EraVMFunctionBlockKey,
input_size: usize, input_size: usize,
output_size: usize, output_size: usize,
) -> Self { ) -> Self {
@@ -10,7 +10,7 @@ use std::cmp::Ordering;
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VisitedElement { pub struct VisitedElement {
/// The block key. /// The block key.
pub block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, pub block_key: revive_llvm_context::EraVMFunctionBlockKey,
/// The initial stack state hash. /// The initial stack state hash.
pub stack_hash: md5::Digest, pub stack_hash: md5::Digest,
} }
@@ -20,7 +20,7 @@ impl VisitedElement {
/// A shortcut constructor. /// A shortcut constructor.
/// ///
pub fn new( pub fn new(
block_key: era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: revive_llvm_context::EraVMFunctionBlockKey,
stack_hash: md5::Digest, stack_hash: md5::Digest,
) -> Self { ) -> Self {
Self { Self {
@@ -40,20 +40,20 @@ impl Ord for VisitedElement {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
match (self.block_key.code_type, other.block_key.code_type) { match (self.block_key.code_type, other.block_key.code_type) {
( (
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
) => Ordering::Less, ) => Ordering::Less,
( (
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
) => Ordering::Greater, ) => Ordering::Greater,
( (
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
era_compiler_llvm_context::EraVMCodeType::Deploy, revive_llvm_context::EraVMCodeType::Deploy,
) )
| ( | (
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
era_compiler_llvm_context::EraVMCodeType::Runtime, revive_llvm_context::EraVMCodeType::Runtime,
) => { ) => {
let tag_comparison = self.block_key.tag.cmp(&other.block_key.tag); let tag_comparison = self.block_key.tag.cmp(&other.block_key.tag);
if tag_comparison == Ordering::Equal { if tag_comparison == Ordering::Equal {
+9 -9
View File
@@ -37,7 +37,7 @@ pub struct EtherealIR {
/// The all-inlined function. /// The all-inlined function.
pub entry_function: Function, pub entry_function: Function,
/// The recursive functions. /// The recursive functions.
pub recursive_functions: BTreeMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Function>, pub recursive_functions: BTreeMap<revive_llvm_context::EraVMFunctionBlockKey, Function>,
} }
impl EtherealIR { impl EtherealIR {
@@ -53,7 +53,7 @@ impl EtherealIR {
pub fn new( pub fn new(
solc_version: semver::Version, solc_version: semver::Version,
extra_metadata: ExtraMetadata, extra_metadata: ExtraMetadata,
blocks: HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>, blocks: HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
let mut entry_function = Function::new(solc_version.clone(), FunctionType::new_initial()); let mut entry_function = Function::new(solc_version.clone(), FunctionType::new_initial());
let mut recursive_functions = BTreeMap::new(); let mut recursive_functions = BTreeMap::new();
@@ -78,9 +78,9 @@ impl EtherealIR {
/// ///
pub fn get_blocks( pub fn get_blocks(
solc_version: semver::Version, solc_version: semver::Version,
code_type: era_compiler_llvm_context::EraVMCodeType, code_type: revive_llvm_context::EraVMCodeType,
instructions: &[Instruction], instructions: &[Instruction],
) -> anyhow::Result<HashMap<era_compiler_llvm_context::EraVMFunctionBlockKey, Block>> { ) -> anyhow::Result<HashMap<revive_llvm_context::EraVMFunctionBlockKey, Block>> {
let mut blocks = HashMap::with_capacity(Self::BLOCKS_HASHMAP_DEFAULT_CAPACITY); let mut blocks = HashMap::with_capacity(Self::BLOCKS_HASHMAP_DEFAULT_CAPACITY);
let mut offset = 0; let mut offset = 0;
@@ -91,7 +91,7 @@ impl EtherealIR {
&instructions[offset..], &instructions[offset..],
)?; )?;
blocks.insert( blocks.insert(
era_compiler_llvm_context::EraVMFunctionBlockKey::new( revive_llvm_context::EraVMFunctionBlockKey::new(
code_type, code_type,
block.key.tag.clone(), block.key.tag.clone(),
), ),
@@ -104,13 +104,13 @@ impl EtherealIR {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for EtherealIR impl<D> revive_llvm_context::EraVMWriteLLVM<D> for EtherealIR
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.entry_function.declare(context)?; self.entry_function.declare(context)?;
@@ -123,7 +123,7 @@ where
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
context.evmla_mut().stack = vec![]; context.evmla_mut().stack = vec![];
+13 -13
View File
@@ -54,10 +54,10 @@ use std::path::PathBuf;
pub fn yul( pub fn yul(
input_files: &[PathBuf], input_files: &[PathBuf],
solc: &mut SolcCompiler, solc: &mut SolcCompiler,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Build> { ) -> anyhow::Result<Build> {
let path = match input_files.len() { let path = match input_files.len() {
1 => input_files.first().expect("Always exists"), 1 => input_files.first().expect("Always exists"),
@@ -99,10 +99,10 @@ pub fn yul(
/// ///
pub fn llvm_ir( pub fn llvm_ir(
input_files: &[PathBuf], input_files: &[PathBuf],
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Build> { ) -> anyhow::Result<Build> {
let path = match input_files.len() { let path = match input_files.len() {
1 => input_files.first().expect("Always exists"), 1 => input_files.first().expect("Always exists"),
@@ -132,7 +132,7 @@ pub fn llvm_ir(
pub fn zkasm( pub fn zkasm(
input_files: &[PathBuf], input_files: &[PathBuf],
include_metadata_hash: bool, include_metadata_hash: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Build> { ) -> anyhow::Result<Build> {
let path = match input_files.len() { let path = match input_files.len() {
1 => input_files.first().expect("Always exists"), 1 => input_files.first().expect("Always exists"),
@@ -145,7 +145,7 @@ pub fn zkasm(
let project = Project::try_from_zkasm_path(path)?; let project = Project::try_from_zkasm_path(path)?;
let optimizer_settings = era_compiler_llvm_context::OptimizerSettings::none(); let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
let build = project.compile( let build = project.compile(
optimizer_settings, optimizer_settings,
false, false,
@@ -167,7 +167,7 @@ pub fn standard_output(
solc: &mut SolcCompiler, solc: &mut SolcCompiler,
evm_version: Option<revive_common::EVMVersion>, evm_version: Option<revive_common::EVMVersion>,
solc_optimizer_enabled: bool, solc_optimizer_enabled: bool,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
force_evmla: bool, force_evmla: bool,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
@@ -176,7 +176,7 @@ pub fn standard_output(
allow_paths: Option<String>, allow_paths: Option<String>,
remappings: Option<BTreeSet<String>>, remappings: Option<BTreeSet<String>>,
suppressed_warnings: Option<Vec<Warning>>, suppressed_warnings: Option<Vec<Warning>>,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Build> { ) -> anyhow::Result<Build> {
let solc_version = solc.version()?; let solc_version = solc.version()?;
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla); let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
@@ -262,7 +262,7 @@ pub fn standard_json(
base_path: Option<String>, base_path: Option<String>,
include_paths: Vec<String>, include_paths: Vec<String>,
allow_paths: Option<String>, allow_paths: Option<String>,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let solc_version = solc.version()?; let solc_version = solc.version()?;
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla); let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
@@ -276,11 +276,11 @@ pub fn standard_json(
.collect(); .collect();
let optimizer_settings = let optimizer_settings =
era_compiler_llvm_context::OptimizerSettings::try_from(&solc_input.settings.optimizer)?; revive_llvm_context::OptimizerSettings::try_from(&solc_input.settings.optimizer)?;
let include_metadata_hash = match solc_input.settings.metadata { let include_metadata_hash = match solc_input.settings.metadata {
Some(ref metadata) => { Some(ref metadata) => {
metadata.bytecode_hash != Some(era_compiler_llvm_context::EraVMMetadataHash::None) metadata.bytecode_hash != Some(revive_llvm_context::EraVMMetadataHash::None)
} }
None => true, None => true,
}; };
@@ -343,7 +343,7 @@ pub fn combined_json(
solc: &mut SolcCompiler, solc: &mut SolcCompiler,
evm_version: Option<revive_common::EVMVersion>, evm_version: Option<revive_common::EVMVersion>,
solc_optimizer_enabled: bool, solc_optimizer_enabled: bool,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
force_evmla: bool, force_evmla: bool,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
@@ -352,7 +352,7 @@ pub fn combined_json(
allow_paths: Option<String>, allow_paths: Option<String>,
remappings: Option<BTreeSet<String>>, remappings: Option<BTreeSet<String>>,
suppressed_warnings: Option<Vec<Warning>>, suppressed_warnings: Option<Vec<Warning>>,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
output_directory: Option<PathBuf>, output_directory: Option<PathBuf>,
overwrite: bool, overwrite: bool,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
+4 -4
View File
@@ -26,9 +26,9 @@ pub struct Input {
/// Enables the test bytecode encoding. /// Enables the test bytecode encoding.
pub enable_test_encoding: bool, pub enable_test_encoding: bool,
/// The optimizer settings. /// The optimizer settings.
pub optimizer_settings: era_compiler_llvm_context::OptimizerSettings, pub optimizer_settings: revive_llvm_context::OptimizerSettings,
/// The debug output config. /// The debug output config.
pub debug_config: Option<era_compiler_llvm_context::DebugConfig>, pub debug_config: Option<revive_llvm_context::DebugConfig>,
} }
impl Input { impl Input {
@@ -41,8 +41,8 @@ impl Input {
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
enable_test_encoding: bool, enable_test_encoding: bool,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> Self { ) -> Self {
Self { Self {
contract, contract,
@@ -38,20 +38,20 @@ impl EVMLA {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for EVMLA impl<D> revive_llvm_context::EraVMWriteLLVM<D> for EVMLA
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.assembly.declare(context) self.assembly.declare(context)
} }
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.assembly.into_llvm(context) self.assembly.into_llvm(context)
} }
@@ -81,13 +81,13 @@ impl IR {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for IR impl<D> revive_llvm_context::EraVMWriteLLVM<D> for IR
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { match self {
Self::Yul(inner) => inner.declare(context), Self::Yul(inner) => inner.declare(context),
@@ -99,7 +99,7 @@ where
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
match self { match self {
Self::Yul(inner) => inner.into_llvm(context), Self::Yul(inner) => inner.into_llvm(context),
@@ -39,20 +39,20 @@ impl Yul {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Yul impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Yul
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.object.declare(context) self.object.declare(context)
} }
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.object.into_llvm(context) self.object.into_llvm(context)
} }
@@ -20,7 +20,7 @@ pub struct Metadata {
/// The EraVM compiler version. /// The EraVM compiler version.
pub zk_version: semver::Version, pub zk_version: semver::Version,
/// The EraVM compiler optimizer settings. /// The EraVM compiler optimizer settings.
pub optimizer_settings: era_compiler_llvm_context::OptimizerSettings, pub optimizer_settings: revive_llvm_context::OptimizerSettings,
} }
impl Metadata { impl Metadata {
@@ -32,7 +32,7 @@ impl Metadata {
solc_version: semver::Version, solc_version: semver::Version,
solc_zkvm_edition: Option<semver::Version>, solc_zkvm_edition: Option<semver::Version>,
zk_version: semver::Version, zk_version: semver::Version,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
) -> Self { ) -> Self {
Self { Self {
solc_metadata, solc_metadata,
+12 -12
View File
@@ -11,7 +11,7 @@ use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use sha3::Digest; use sha3::Digest;
use era_compiler_llvm_context::EraVMWriteLLVM; use revive_llvm_context::EraVMWriteLLVM;
use crate::build::contract::Contract as ContractBuild; use crate::build::contract::Contract as ContractBuild;
use crate::project::Project; use crate::project::Project;
@@ -91,13 +91,13 @@ impl Contract {
pub fn compile( pub fn compile(
mut self, mut self,
project: Project, project: Project,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<ContractBuild> { ) -> anyhow::Result<ContractBuild> {
let llvm = inkwell::context::Context::create(); let llvm = inkwell::context::Context::create();
let optimizer = era_compiler_llvm_context::Optimizer::new(optimizer_settings); let optimizer = revive_llvm_context::Optimizer::new(optimizer_settings);
let version = project.version.clone(); let version = project.version.clone();
let identifier = self.identifier().to_owned(); let identifier = self.identifier().to_owned();
@@ -129,7 +129,7 @@ impl Contract {
.map_err(|error| anyhow::anyhow!(error.to_string()))? .map_err(|error| anyhow::anyhow!(error.to_string()))?
} }
IR::ZKASM(ref zkasm) => { IR::ZKASM(ref zkasm) => {
let build = era_compiler_llvm_context::eravm_build_assembly_text( let build = revive_llvm_context::eravm_build_assembly_text(
self.path.as_str(), self.path.as_str(),
zkasm.source.as_str(), zkasm.source.as_str(),
metadata_hash, metadata_hash,
@@ -145,7 +145,7 @@ impl Contract {
} }
_ => llvm.create_module(self.path.as_str()), _ => llvm.create_module(self.path.as_str()),
}; };
let mut context = era_compiler_llvm_context::EraVMContext::new( let mut context = revive_llvm_context::EraVMContext::new(
&llvm, &llvm,
module, module,
optimizer, optimizer,
@@ -153,15 +153,15 @@ impl Contract {
include_metadata_hash, include_metadata_hash,
debug_config, debug_config,
); );
context.set_solidity_data(era_compiler_llvm_context::EraVMContextSolidityData::default()); context.set_solidity_data(revive_llvm_context::EraVMContextSolidityData::default());
match self.ir { match self.ir {
IR::Yul(_) => { IR::Yul(_) => {
let yul_data = era_compiler_llvm_context::EraVMContextYulData::new(is_system_mode); let yul_data = revive_llvm_context::EraVMContextYulData::new(is_system_mode);
context.set_yul_data(yul_data); context.set_yul_data(yul_data);
} }
IR::EVMLA(_) => { IR::EVMLA(_) => {
let evmla_data = let evmla_data =
era_compiler_llvm_context::EraVMContextEVMLAData::new(version.default); revive_llvm_context::EraVMContextEVMLAData::new(version.default);
context.set_evmla_data(evmla_data); context.set_evmla_data(evmla_data);
} }
IR::LLVMIR(_) => {} IR::LLVMIR(_) => {}
@@ -206,18 +206,18 @@ impl Contract {
impl<D> EraVMWriteLLVM<D> for Contract impl<D> EraVMWriteLLVM<D> for Contract
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.ir.declare(context) self.ir.declare(context)
} }
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.ir.into_llvm(context) self.ir.into_llvm(context)
} }
+7 -7
View File
@@ -69,11 +69,11 @@ impl Project {
/// ///
pub fn compile( pub fn compile(
self, self,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
bytecode_encoding_testing: bool, bytecode_encoding_testing: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Build> { ) -> anyhow::Result<Build> {
let project = self.clone(); let project = self.clone();
let results: BTreeMap<String, anyhow::Result<ContractBuild>> = self let results: BTreeMap<String, anyhow::Result<ContractBuild>> = self
@@ -230,7 +230,7 @@ impl Project {
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into(); let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
let source_version = let source_version =
SolcVersion::new_simple(era_compiler_llvm_context::eravm_const::LLVM_VERSION); SolcVersion::new_simple(revive_llvm_context::eravm_const::LLVM_VERSION);
let path = path.to_string_lossy().to_string(); let path = path.to_string_lossy().to_string();
let mut project_contracts = BTreeMap::new(); let mut project_contracts = BTreeMap::new();
@@ -262,7 +262,7 @@ impl Project {
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into(); let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
let source_version = let source_version =
SolcVersion::new_simple(era_compiler_llvm_context::eravm_const::ZKEVM_VERSION); SolcVersion::new_simple(revive_llvm_context::eravm_const::ZKEVM_VERSION);
let path = path.to_string_lossy().to_string(); let path = path.to_string_lossy().to_string();
let mut project_contracts = BTreeMap::new(); let mut project_contracts = BTreeMap::new();
@@ -285,14 +285,14 @@ impl Project {
} }
} }
impl era_compiler_llvm_context::EraVMDependency for Project { impl revive_llvm_context::EraVMDependency for Project {
fn compile( fn compile(
project: Self, project: Self,
identifier: &str, identifier: &str,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
is_system_mode: bool, is_system_mode: bool,
include_metadata_hash: bool, include_metadata_hash: bool,
debug_config: Option<era_compiler_llvm_context::DebugConfig>, debug_config: Option<revive_llvm_context::DebugConfig>,
) -> anyhow::Result<String> { ) -> anyhow::Result<String> {
let contract_path = project.resolve_path(identifier)?; let contract_path = project.resolve_path(identifier)?;
let contract = project let contract = project
@@ -13,14 +13,14 @@ use serde::Serialize;
pub struct Metadata { pub struct Metadata {
/// The bytecode hash mode. /// The bytecode hash mode.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub bytecode_hash: Option<era_compiler_llvm_context::EraVMMetadataHash>, pub bytecode_hash: Option<revive_llvm_context::EraVMMetadataHash>,
} }
impl Metadata { impl Metadata {
/// ///
/// A shortcut constructor. /// A shortcut constructor.
/// ///
pub fn new(bytecode_hash: era_compiler_llvm_context::EraVMMetadataHash) -> Self { pub fn new(bytecode_hash: revive_llvm_context::EraVMMetadataHash) -> Self {
Self { Self {
bytecode_hash: Some(bytecode_hash), bytecode_hash: Some(bytecode_hash),
} }
@@ -63,7 +63,7 @@ impl Optimizer {
} }
} }
impl TryFrom<&Optimizer> for era_compiler_llvm_context::OptimizerSettings { impl TryFrom<&Optimizer> for revive_llvm_context::OptimizerSettings {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: &Optimizer) -> Result<Self, Self::Error> { fn try_from(value: &Optimizer) -> Result<Self, Self::Error> {
@@ -26,18 +26,18 @@ impl ExtraMetadata {
/// ///
pub fn get( pub fn get(
&self, &self,
block_key: &era_compiler_llvm_context::EraVMFunctionBlockKey, block_key: &revive_llvm_context::EraVMFunctionBlockKey,
) -> Option<&RecursiveFunction> { ) -> Option<&RecursiveFunction> {
for function in self.recursive_functions.iter() { for function in self.recursive_functions.iter() {
match block_key.code_type { match block_key.code_type {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
if let Some(creation_tag) = function.creation_tag { if let Some(creation_tag) = function.creation_tag {
if num::BigUint::from(creation_tag) == block_key.tag { if num::BigUint::from(creation_tag) == block_key.tag {
return Some(function); return Some(function);
} }
} }
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
if let Some(runtime_tag) = function.runtime_tag { if let Some(runtime_tag) = function.runtime_tag {
if num::BigUint::from(runtime_tag) == block_key.tag { if num::BigUint::from(runtime_tag) == block_key.tag {
return Some(function); return Some(function);
@@ -62,7 +62,7 @@ impl Output {
libraries: BTreeMap<String, BTreeMap<String, String>>, libraries: BTreeMap<String, BTreeMap<String, String>>,
pipeline: SolcPipeline, pipeline: SolcPipeline,
solc_version: &SolcVersion, solc_version: &SolcVersion,
debug_config: Option<&era_compiler_llvm_context::DebugConfig>, debug_config: Option<&revive_llvm_context::DebugConfig>,
) -> anyhow::Result<Project> { ) -> anyhow::Result<Project> {
if let SolcPipeline::EVMLA = pipeline { if let SolcPipeline::EVMLA = pipeline {
self.preprocess_dependencies()?; self.preprocess_dependencies()?;
+7 -7
View File
@@ -37,7 +37,7 @@ pub fn build_solidity(
libraries: BTreeMap<String, BTreeMap<String, String>>, libraries: BTreeMap<String, BTreeMap<String, String>>,
remappings: Option<BTreeSet<String>>, remappings: Option<BTreeSet<String>>,
pipeline: SolcPipeline, pipeline: SolcPipeline,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
) -> anyhow::Result<SolcStandardJsonOutput> { ) -> anyhow::Result<SolcStandardJsonOutput> {
build_solidity_with_options( build_solidity_with_options(
sources, sources,
@@ -57,13 +57,13 @@ pub fn build_solidity_with_options(
libraries: BTreeMap<String, BTreeMap<String, String>>, libraries: BTreeMap<String, BTreeMap<String, String>>,
remappings: Option<BTreeSet<String>>, remappings: Option<BTreeSet<String>>,
pipeline: SolcPipeline, pipeline: SolcPipeline,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings, optimizer_settings: revive_llvm_context::OptimizerSettings,
solc_optimizer_enabled: bool, solc_optimizer_enabled: bool,
) -> anyhow::Result<SolcStandardJsonOutput> { ) -> anyhow::Result<SolcStandardJsonOutput> {
check_dependencies(); check_dependencies();
inkwell::support::enable_llvm_pretty_stack_trace(); inkwell::support::enable_llvm_pretty_stack_trace();
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM); revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
@@ -112,7 +112,7 @@ pub fn build_solidity_with_options_evm(
check_dependencies(); check_dependencies();
inkwell::support::enable_llvm_pretty_stack_trace(); inkwell::support::enable_llvm_pretty_stack_trace();
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM); revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
@@ -165,7 +165,7 @@ pub fn build_solidity_and_detect_missing_libraries(
check_dependencies(); check_dependencies();
inkwell::support::enable_llvm_pretty_stack_trace(); inkwell::support::enable_llvm_pretty_stack_trace();
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM); revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME)); let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?; let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
@@ -210,8 +210,8 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
check_dependencies(); check_dependencies();
inkwell::support::enable_llvm_pretty_stack_trace(); inkwell::support::enable_llvm_pretty_stack_trace();
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM); revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
let optimizer_settings = era_compiler_llvm_context::OptimizerSettings::none(); let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
let project = let project =
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?; Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
@@ -54,7 +54,7 @@ fn default() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Build failure"); .expect("Build failure");
+2 -2
View File
@@ -31,7 +31,7 @@ contract Test {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
@@ -87,7 +87,7 @@ contract Test {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::EVMLA, SolcPipeline::EVMLA,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
assert!( assert!(
+3 -3
View File
@@ -57,7 +57,7 @@ fn optimizer() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::none(), revive_llvm_context::OptimizerSettings::none(),
) )
.expect("Build failure"); .expect("Build failure");
let build_optimized_for_cycles = super::build_solidity( let build_optimized_for_cycles = super::build_solidity(
@@ -65,7 +65,7 @@ fn optimizer() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Build failure"); .expect("Build failure");
let build_optimized_for_size = super::build_solidity( let build_optimized_for_size = super::build_solidity(
@@ -73,7 +73,7 @@ fn optimizer() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::size(), revive_llvm_context::OptimizerSettings::size(),
) )
.expect("Build failure"); .expect("Build failure");
+1 -1
View File
@@ -49,7 +49,7 @@ fn default() {
BTreeMap::new(), BTreeMap::new(),
Some(remappings), Some(remappings),
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
+1 -1
View File
@@ -32,7 +32,7 @@ contract Test {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -37,7 +37,7 @@ contract FixedCodeCopy {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -76,7 +76,7 @@ fn callcode_evmla() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::EVMLA, SolcPipeline::EVMLA,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -92,7 +92,7 @@ fn callcode_yul() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -150,7 +150,7 @@ fn extcodecopy_evmla() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::EVMLA, SolcPipeline::EVMLA,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -166,7 +166,7 @@ fn extcodecopy_yul() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -200,7 +200,7 @@ fn selfdestruct_evmla() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::EVMLA, SolcPipeline::EVMLA,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -216,7 +216,7 @@ fn selfdestruct_yul() {
BTreeMap::new(), BTreeMap::new(),
None, None,
SolcPipeline::Yul, SolcPipeline::Yul,
era_compiler_llvm_context::OptimizerSettings::cycles(), revive_llvm_context::OptimizerSettings::cycles(),
) )
.expect("Test failure"); .expect("Test failure");
} }
@@ -115,13 +115,13 @@ impl Assignment {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Assignment impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Assignment
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let value = match self.initializer.into_llvm(context)? { let value = match self.initializer.into_llvm(context)? {
Some(value) => value, Some(value) => value,
@@ -136,13 +136,13 @@ impl Block {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Block impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Block
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let current_function = context.current_function().borrow().name().to_owned(); let current_function = context.current_function().borrow().name().to_owned();
let current_block = context.basic_block(); let current_block = context.basic_block();
@@ -63,13 +63,13 @@ impl Code {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Code impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Code
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.block.into_llvm(context)?; self.block.into_llvm(context)?;
@@ -127,17 +127,17 @@ impl FunctionCall {
/// ///
pub fn into_llvm<'ctx, D>( pub fn into_llvm<'ctx, D>(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> ) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let location = self.location; let location = self.location;
match self.name { match self.name {
Name::UserDefined(name) Name::UserDefined(name)
if name.starts_with( if name.starts_with(
era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX, revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
) && context.is_system_mode() => ) && context.is_system_mode() =>
{ {
unimplemented!(); unimplemented!();
@@ -176,7 +176,7 @@ impl FunctionCall {
Name::Add => { Name::Add => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::addition( revive_llvm_context::eravm_evm_arithmetic::addition(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -185,7 +185,7 @@ impl FunctionCall {
} }
Name::Sub => { Name::Sub => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::subtraction( revive_llvm_context::eravm_evm_arithmetic::subtraction(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -194,7 +194,7 @@ impl FunctionCall {
} }
Name::Mul => { Name::Mul => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::multiplication( revive_llvm_context::eravm_evm_arithmetic::multiplication(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -203,7 +203,7 @@ impl FunctionCall {
} }
Name::Div => { Name::Div => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::division( revive_llvm_context::eravm_evm_arithmetic::division(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -212,7 +212,7 @@ impl FunctionCall {
} }
Name::Mod => { Name::Mod => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::remainder( revive_llvm_context::eravm_evm_arithmetic::remainder(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -221,7 +221,7 @@ impl FunctionCall {
} }
Name::Sdiv => { Name::Sdiv => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::division_signed( revive_llvm_context::eravm_evm_arithmetic::division_signed(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -230,7 +230,7 @@ impl FunctionCall {
} }
Name::Smod => { Name::Smod => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_arithmetic::remainder_signed( revive_llvm_context::eravm_evm_arithmetic::remainder_signed(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -240,7 +240,7 @@ impl FunctionCall {
Name::Lt => { Name::Lt => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -250,7 +250,7 @@ impl FunctionCall {
} }
Name::Gt => { Name::Gt => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -260,7 +260,7 @@ impl FunctionCall {
} }
Name::Eq => { Name::Eq => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -270,7 +270,7 @@ impl FunctionCall {
} }
Name::IsZero => { Name::IsZero => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
context.field_const(0), context.field_const(0),
@@ -280,7 +280,7 @@ impl FunctionCall {
} }
Name::Slt => { Name::Slt => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -290,7 +290,7 @@ impl FunctionCall {
} }
Name::Sgt => { Name::Sgt => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_comparison::compare( revive_llvm_context::eravm_evm_comparison::compare(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -301,7 +301,7 @@ impl FunctionCall {
Name::Or => { Name::Or => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::or( revive_llvm_context::eravm_evm_bitwise::or(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -310,7 +310,7 @@ impl FunctionCall {
} }
Name::Xor => { Name::Xor => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::xor( revive_llvm_context::eravm_evm_bitwise::xor(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -319,7 +319,7 @@ impl FunctionCall {
} }
Name::Not => { Name::Not => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::xor( revive_llvm_context::eravm_evm_bitwise::xor(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
context.field_type().const_all_ones(), context.field_type().const_all_ones(),
@@ -328,7 +328,7 @@ impl FunctionCall {
} }
Name::And => { Name::And => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::and( revive_llvm_context::eravm_evm_bitwise::and(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -337,7 +337,7 @@ impl FunctionCall {
} }
Name::Shl => { Name::Shl => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::shift_left( revive_llvm_context::eravm_evm_bitwise::shift_left(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -346,7 +346,7 @@ impl FunctionCall {
} }
Name::Shr => { Name::Shr => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::shift_right( revive_llvm_context::eravm_evm_bitwise::shift_right(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -355,7 +355,7 @@ impl FunctionCall {
} }
Name::Sar => { Name::Sar => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::shift_right_arithmetic( revive_llvm_context::eravm_evm_bitwise::shift_right_arithmetic(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -364,7 +364,7 @@ impl FunctionCall {
} }
Name::Byte => { Name::Byte => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_bitwise::byte( revive_llvm_context::eravm_evm_bitwise::byte(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -378,7 +378,7 @@ impl FunctionCall {
Name::AddMod => { Name::AddMod => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
era_compiler_llvm_context::eravm_evm_math::add_mod( revive_llvm_context::eravm_evm_math::add_mod(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -388,7 +388,7 @@ impl FunctionCall {
} }
Name::MulMod => { Name::MulMod => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
era_compiler_llvm_context::eravm_evm_math::mul_mod( revive_llvm_context::eravm_evm_math::mul_mod(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -398,7 +398,7 @@ impl FunctionCall {
} }
Name::Exp => { Name::Exp => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_math::exponent( revive_llvm_context::eravm_evm_math::exponent(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -407,7 +407,7 @@ impl FunctionCall {
} }
Name::SignExtend => { Name::SignExtend => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_math::sign_extend( revive_llvm_context::eravm_evm_math::sign_extend(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -417,7 +417,7 @@ impl FunctionCall {
Name::Keccak256 => { Name::Keccak256 => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_crypto::sha3( revive_llvm_context::eravm_evm_crypto::sha3(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -427,7 +427,7 @@ impl FunctionCall {
Name::MLoad => { Name::MLoad => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_memory::load( revive_llvm_context::eravm_evm_memory::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -435,7 +435,7 @@ impl FunctionCall {
} }
Name::MStore => { Name::MStore => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_memory::store( revive_llvm_context::eravm_evm_memory::store(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -444,7 +444,7 @@ impl FunctionCall {
} }
Name::MStore8 => { Name::MStore8 => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_memory::store_byte( revive_llvm_context::eravm_evm_memory::store_byte(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -453,16 +453,16 @@ impl FunctionCall {
} }
Name::MCopy => { Name::MCopy => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
let destination = era_compiler_llvm_context::EraVMPointer::new_with_offset( let destination = revive_llvm_context::EraVMPointer::new_with_offset(
context, context,
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
context.byte_type(), context.byte_type(),
arguments[0].into_int_value(), arguments[0].into_int_value(),
"mcopy_destination", "mcopy_destination",
); );
let source = era_compiler_llvm_context::EraVMPointer::new_with_offset( let source = revive_llvm_context::EraVMPointer::new_with_offset(
context, context,
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
context.byte_type(), context.byte_type(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
"mcopy_source", "mcopy_source",
@@ -480,7 +480,7 @@ impl FunctionCall {
Name::SLoad => { Name::SLoad => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_storage::load( revive_llvm_context::eravm_evm_storage::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -488,7 +488,7 @@ impl FunctionCall {
} }
Name::SStore => { Name::SStore => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_storage::store( revive_llvm_context::eravm_evm_storage::store(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -524,7 +524,7 @@ impl FunctionCall {
let index = context.field_const(offset as u64); let index = context.field_const(offset as u64);
let value = arguments[2].value.into_int_value(); let value = arguments[2].value.into_int_value();
era_compiler_llvm_context::eravm_evm_immutable::store(context, index, value) revive_llvm_context::eravm_evm_immutable::store(context, index, value)
.map(|_| None) .map(|_| None)
} }
@@ -535,11 +535,11 @@ impl FunctionCall {
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum())) Ok(Some(context.field_const(0).as_basic_value_enum()))
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::load( revive_llvm_context::eravm_evm_calldata::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -552,11 +552,11 @@ impl FunctionCall {
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum())) Ok(Some(context.field_const(0).as_basic_value_enum()))
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some) revive_llvm_context::eravm_evm_calldata::size(context).map(Some)
} }
} }
} }
@@ -567,11 +567,11 @@ impl FunctionCall {
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
let calldata_size = let calldata_size =
era_compiler_llvm_context::eravm_evm_calldata::size(context)?; revive_llvm_context::eravm_evm_calldata::size(context)?;
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
calldata_size.into_int_value(), calldata_size.into_int_value(),
@@ -579,8 +579,8 @@ impl FunctionCall {
) )
.map(|_| None) .map(|_| None)
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -595,16 +595,16 @@ impl FunctionCall {
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
era_compiler_llvm_context::EraVMCodeType::Deploy => { revive_llvm_context::EraVMCodeType::Deploy => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some) revive_llvm_context::eravm_evm_calldata::size(context).map(Some)
} }
era_compiler_llvm_context::EraVMCodeType::Runtime => { revive_llvm_context::EraVMCodeType::Runtime => {
todo!() todo!()
} }
} }
} }
Name::CodeCopy => { Name::CodeCopy => {
if let era_compiler_llvm_context::EraVMCodeType::Runtime = context if let revive_llvm_context::EraVMCodeType::Runtime = context
.code_type() .code_type()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))? .ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{ {
@@ -615,7 +615,7 @@ impl FunctionCall {
} }
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
era_compiler_llvm_context::eravm_evm_calldata::copy( revive_llvm_context::eravm_evm_calldata::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -624,11 +624,11 @@ impl FunctionCall {
.map(|_| None) .map(|_| None)
} }
Name::ReturnDataSize => { Name::ReturnDataSize => {
era_compiler_llvm_context::eravm_evm_return_data::size(context).map(Some) revive_llvm_context::eravm_evm_return_data::size(context).map(Some)
} }
Name::ReturnDataCopy => { Name::ReturnDataCopy => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
era_compiler_llvm_context::eravm_evm_return_data::copy( revive_llvm_context::eravm_evm_return_data::copy(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -638,7 +638,7 @@ impl FunctionCall {
} }
Name::ExtCodeSize => { Name::ExtCodeSize => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_ext_code::size( revive_llvm_context::eravm_evm_ext_code::size(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -646,7 +646,7 @@ impl FunctionCall {
} }
Name::ExtCodeHash => { Name::ExtCodeHash => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
era_compiler_llvm_context::eravm_evm_ext_code::hash( revive_llvm_context::eravm_evm_ext_code::hash(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
) )
@@ -655,7 +655,7 @@ impl FunctionCall {
Name::Return => { Name::Return => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_return::r#return( revive_llvm_context::eravm_evm_return::r#return(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -664,21 +664,21 @@ impl FunctionCall {
} }
Name::Revert => { Name::Revert => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_return::revert( revive_llvm_context::eravm_evm_return::revert(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
) )
.map(|_| None) .map(|_| None)
} }
Name::Stop => era_compiler_llvm_context::eravm_evm_return::stop(context).map(|_| None), Name::Stop => revive_llvm_context::eravm_evm_return::stop(context).map(|_| None),
Name::Invalid => { Name::Invalid => {
era_compiler_llvm_context::eravm_evm_return::invalid(context).map(|_| None) revive_llvm_context::eravm_evm_return::invalid(context).map(|_| None)
} }
Name::Log0 => { Name::Log0 => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -688,7 +688,7 @@ impl FunctionCall {
} }
Name::Log1 => { Name::Log1 => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -701,7 +701,7 @@ impl FunctionCall {
} }
Name::Log2 => { Name::Log2 => {
let arguments = self.pop_arguments_llvm::<D, 4>(context)?; let arguments = self.pop_arguments_llvm::<D, 4>(context)?;
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -714,7 +714,7 @@ impl FunctionCall {
} }
Name::Log3 => { Name::Log3 => {
let arguments = self.pop_arguments_llvm::<D, 5>(context)?; let arguments = self.pop_arguments_llvm::<D, 5>(context)?;
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -727,7 +727,7 @@ impl FunctionCall {
} }
Name::Log4 => { Name::Log4 => {
let arguments = self.pop_arguments_llvm::<D, 6>(context)?; let arguments = self.pop_arguments_llvm::<D, 6>(context)?;
era_compiler_llvm_context::eravm_evm_event::log( revive_llvm_context::eravm_evm_event::log(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -757,7 +757,7 @@ impl FunctionCall {
todo!() todo!()
/* /*
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().far_call, context.llvm_runtime().far_call,
gas, gas,
@@ -787,7 +787,7 @@ impl FunctionCall {
.map(|mut argument| argument.constant.take()) .map(|mut argument| argument.constant.take())
.collect(); .collect();
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().static_call, context.llvm_runtime().static_call,
gas, gas,
@@ -816,7 +816,7 @@ impl FunctionCall {
.map(|mut argument| argument.constant.take()) .map(|mut argument| argument.constant.take())
.collect(); .collect();
era_compiler_llvm_context::eravm_evm_call::default( revive_llvm_context::eravm_evm_call::default(
context, context,
context.llvm_runtime().delegate_call, context.llvm_runtime().delegate_call,
gas, gas,
@@ -838,7 +838,7 @@ impl FunctionCall {
let input_offset = arguments[1].into_int_value(); let input_offset = arguments[1].into_int_value();
let input_length = arguments[2].into_int_value(); let input_length = arguments[2].into_int_value();
era_compiler_llvm_context::eravm_evm_create::create( revive_llvm_context::eravm_evm_create::create(
context, context,
value, value,
input_offset, input_offset,
@@ -854,7 +854,7 @@ impl FunctionCall {
let input_length = arguments[2].into_int_value(); let input_length = arguments[2].into_int_value();
let salt = arguments[3].into_int_value(); let salt = arguments[3].into_int_value();
era_compiler_llvm_context::eravm_evm_create::create2( revive_llvm_context::eravm_evm_create::create2(
context, context,
value, value,
input_offset, input_offset,
@@ -870,7 +870,7 @@ impl FunctionCall {
anyhow::anyhow!("{} `dataoffset` object identifier is missing", location) anyhow::anyhow!("{} `dataoffset` object identifier is missing", location)
})?; })?;
era_compiler_llvm_context::eravm_evm_create::contract_hash(context, identifier) revive_llvm_context::eravm_evm_create::contract_hash(context, identifier)
.map(|argument| Some(argument.value)) .map(|argument| Some(argument.value))
} }
Name::DataSize => { Name::DataSize => {
@@ -880,7 +880,7 @@ impl FunctionCall {
anyhow::anyhow!("{} `dataoffset` object identifier is missing", location) anyhow::anyhow!("{} `dataoffset` object identifier is missing", location)
})?; })?;
era_compiler_llvm_context::eravm_evm_create::header_size(context, identifier) revive_llvm_context::eravm_evm_create::header_size(context, identifier)
.map(|argument| Some(argument.value)) .map(|argument| Some(argument.value))
} }
Name::DataCopy => { Name::DataCopy => {
@@ -892,7 +892,7 @@ impl FunctionCall {
), ),
"datacopy_contract_hash_offset", "datacopy_contract_hash_offset",
)?; )?;
era_compiler_llvm_context::eravm_evm_memory::store( revive_llvm_context::eravm_evm_memory::store(
context, context,
offset, offset,
arguments[1].into_int_value(), arguments[1].into_int_value(),
@@ -922,42 +922,42 @@ impl FunctionCall {
} }
Name::CallValue => { Name::CallValue => {
era_compiler_llvm_context::eravm_evm_ether_gas::value(context).map(Some) revive_llvm_context::eravm_evm_ether_gas::value(context).map(Some)
} }
Name::Gas => era_compiler_llvm_context::eravm_evm_ether_gas::gas(context).map(Some), Name::Gas => revive_llvm_context::eravm_evm_ether_gas::gas(context).map(Some),
Name::Balance => { Name::Balance => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
let address = arguments[0].into_int_value(); let address = arguments[0].into_int_value();
era_compiler_llvm_context::eravm_evm_ether_gas::balance(context, address).map(Some) revive_llvm_context::eravm_evm_ether_gas::balance(context, address).map(Some)
} }
Name::SelfBalance => todo!(), Name::SelfBalance => todo!(),
Name::GasLimit => { Name::GasLimit => {
era_compiler_llvm_context::eravm_evm_contract_context::gas_limit(context).map(Some) revive_llvm_context::eravm_evm_contract_context::gas_limit(context).map(Some)
} }
Name::GasPrice => { Name::GasPrice => {
era_compiler_llvm_context::eravm_evm_contract_context::gas_price(context).map(Some) revive_llvm_context::eravm_evm_contract_context::gas_price(context).map(Some)
} }
Name::Origin => { Name::Origin => {
era_compiler_llvm_context::eravm_evm_contract_context::origin(context).map(Some) revive_llvm_context::eravm_evm_contract_context::origin(context).map(Some)
} }
Name::ChainId => { Name::ChainId => {
era_compiler_llvm_context::eravm_evm_contract_context::chain_id(context).map(Some) revive_llvm_context::eravm_evm_contract_context::chain_id(context).map(Some)
} }
Name::Timestamp => { Name::Timestamp => {
era_compiler_llvm_context::eravm_evm_contract_context::block_timestamp(context) revive_llvm_context::eravm_evm_contract_context::block_timestamp(context)
.map(Some) .map(Some)
} }
Name::Number => { Name::Number => {
era_compiler_llvm_context::eravm_evm_contract_context::block_number(context) revive_llvm_context::eravm_evm_contract_context::block_number(context)
.map(Some) .map(Some)
} }
Name::BlockHash => { Name::BlockHash => {
let arguments = self.pop_arguments_llvm::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
let index = arguments[0].into_int_value(); let index = arguments[0].into_int_value();
era_compiler_llvm_context::eravm_evm_contract_context::block_hash(context, index) revive_llvm_context::eravm_evm_contract_context::block_hash(context, index)
.map(Some) .map(Some)
} }
Name::BlobHash => { Name::BlobHash => {
@@ -968,13 +968,13 @@ impl FunctionCall {
); );
} }
Name::Difficulty | Name::Prevrandao => { Name::Difficulty | Name::Prevrandao => {
era_compiler_llvm_context::eravm_evm_contract_context::difficulty(context).map(Some) revive_llvm_context::eravm_evm_contract_context::difficulty(context).map(Some)
} }
Name::CoinBase => { Name::CoinBase => {
era_compiler_llvm_context::eravm_evm_contract_context::coinbase(context).map(Some) revive_llvm_context::eravm_evm_contract_context::coinbase(context).map(Some)
} }
Name::BaseFee => { Name::BaseFee => {
era_compiler_llvm_context::eravm_evm_contract_context::basefee(context).map(Some) revive_llvm_context::eravm_evm_contract_context::basefee(context).map(Some)
} }
Name::BlobBaseFee => { Name::BlobBaseFee => {
anyhow::bail!( anyhow::bail!(
@@ -983,7 +983,7 @@ impl FunctionCall {
); );
} }
Name::MSize => { Name::MSize => {
era_compiler_llvm_context::eravm_evm_contract_context::msize(context).map(Some) revive_llvm_context::eravm_evm_contract_context::msize(context).map(Some)
} }
Name::Verbatim { Name::Verbatim {
@@ -1018,10 +1018,10 @@ impl FunctionCall {
/// ///
fn pop_arguments_llvm<'ctx, D, const N: usize>( fn pop_arguments_llvm<'ctx, D, const N: usize>(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<[inkwell::values::BasicValueEnum<'ctx>; N]> ) -> anyhow::Result<[inkwell::values::BasicValueEnum<'ctx>; N]>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let mut arguments = Vec::with_capacity(N); let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() { for expression in self.arguments.drain(0..N).rev() {
@@ -1037,10 +1037,10 @@ impl FunctionCall {
/// ///
fn pop_arguments<'ctx, D, const N: usize>( fn pop_arguments<'ctx, D, const N: usize>(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<[era_compiler_llvm_context::EraVMArgument<'ctx>; N]> ) -> anyhow::Result<[revive_llvm_context::EraVMArgument<'ctx>; N]>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
let mut arguments = Vec::with_capacity(N); let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() { for expression in self.arguments.drain(0..N).rev() {
@@ -8,13 +8,13 @@ use crate::yul::parser::statement::expression::function_call::FunctionCall;
/// Translates the verbatim simulations. /// Translates the verbatim simulations.
/// ///
pub fn verbatim<'ctx, D>( pub fn verbatim<'ctx, D>(
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
call: &mut FunctionCall, call: &mut FunctionCall,
_input_size: usize, _input_size: usize,
output_size: usize, output_size: usize,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> ) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
if output_size > 1 { if output_size > 1 {
anyhow::bail!( anyhow::bail!(
@@ -80,10 +80,10 @@ impl Literal {
/// ///
pub fn into_llvm<'ctx, D>( pub fn into_llvm<'ctx, D>(
self, self,
context: &era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<era_compiler_llvm_context::EraVMArgument<'ctx>> ) -> anyhow::Result<revive_llvm_context::EraVMArgument<'ctx>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
match self.inner { match self.inner {
LexicalLiteral::Boolean(inner) => { LexicalLiteral::Boolean(inner) => {
@@ -105,7 +105,7 @@ impl Literal {
BooleanLiteral::True => num::BigUint::one(), BooleanLiteral::True => num::BigUint::one(),
}; };
Ok(era_compiler_llvm_context::EraVMArgument::new_with_constant( Ok(revive_llvm_context::EraVMArgument::new_with_constant(
value, constant, value, constant,
)) ))
} }
@@ -135,7 +135,7 @@ impl Literal {
} }
.expect("Always valid"); .expect("Always valid");
Ok(era_compiler_llvm_context::EraVMArgument::new_with_constant( Ok(revive_llvm_context::EraVMArgument::new_with_constant(
value, constant, value, constant,
)) ))
} }
@@ -209,7 +209,7 @@ impl Literal {
}; };
if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 { if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
return Ok(era_compiler_llvm_context::EraVMArgument::new_with_original( return Ok(revive_llvm_context::EraVMArgument::new_with_original(
r#type.const_zero().as_basic_value_enum(), r#type.const_zero().as_basic_value_enum(),
string, string,
)); ));
@@ -229,7 +229,7 @@ impl Literal {
) )
.expect("The value is valid") .expect("The value is valid")
.as_basic_value_enum(); .as_basic_value_enum();
Ok(era_compiler_llvm_context::EraVMArgument::new_with_original( Ok(revive_llvm_context::EraVMArgument::new_with_original(
value, string, value, string,
)) ))
} }
@@ -108,10 +108,10 @@ impl Expression {
/// ///
pub fn into_llvm<'ctx, D>( pub fn into_llvm<'ctx, D>(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<Option<era_compiler_llvm_context::EraVMArgument<'ctx>>> ) -> anyhow::Result<Option<revive_llvm_context::EraVMArgument<'ctx>>>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
match self { match self {
Self::Literal(literal) => literal Self::Literal(literal) => literal
@@ -149,7 +149,7 @@ impl Expression {
match constant { match constant {
Some(constant) => Ok(Some( Some(constant) => Ok(Some(
era_compiler_llvm_context::EraVMArgument::new_with_constant( revive_llvm_context::EraVMArgument::new_with_constant(
value, constant, value, constant,
), ),
)), )),
@@ -158,7 +158,7 @@ impl Expression {
} }
Self::FunctionCall(call) => Ok(call Self::FunctionCall(call) => Ok(call
.into_llvm(context)? .into_llvm(context)?
.map(era_compiler_llvm_context::EraVMArgument::new)), .map(revive_llvm_context::EraVMArgument::new)),
} }
} }
} }
@@ -68,13 +68,13 @@ impl ForLoop {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for ForLoop impl<D> revive_llvm_context::EraVMWriteLLVM<D> for ForLoop
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.initializer.into_llvm(context)?; self.initializer.into_llvm(context)?;
@@ -40,7 +40,7 @@ pub struct FunctionDefinition {
/// The function body block. /// The function body block.
pub body: Block, pub body: Block,
/// The function LLVM attributes encoded in the identifier. /// The function LLVM attributes encoded in the identifier.
pub attributes: BTreeSet<era_compiler_llvm_context::EraVMAttribute>, pub attributes: BTreeSet<revive_llvm_context::EraVMAttribute>,
} }
impl FunctionDefinition { impl FunctionDefinition {
@@ -102,7 +102,7 @@ impl FunctionDefinition {
let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?; let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?;
if identifier if identifier
.inner .inner
.contains(era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX) .contains(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
{ {
if arguments.is_empty() { if arguments.is_empty() {
return Err(ParserError::InvalidNumberOfArguments { return Err(ParserError::InvalidNumberOfArguments {
@@ -117,7 +117,7 @@ impl FunctionDefinition {
arguments.remove(0); arguments.remove(0);
} }
if identifier.inner.contains( if identifier.inner.contains(
era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER, revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER,
) && !arguments.is_empty() ) && !arguments.is_empty()
{ {
return Err(ParserError::InvalidNumberOfArguments { return Err(ParserError::InvalidNumberOfArguments {
@@ -192,7 +192,7 @@ impl FunctionDefinition {
/// ///
pub fn get_llvm_attributes( pub fn get_llvm_attributes(
identifier: &Identifier, identifier: &Identifier,
) -> Result<BTreeSet<era_compiler_llvm_context::EraVMAttribute>, Error> { ) -> Result<BTreeSet<revive_llvm_context::EraVMAttribute>, Error> {
let mut valid_attributes = BTreeSet::new(); let mut valid_attributes = BTreeSet::new();
let llvm_begin = identifier.inner.find(Self::LLVM_ATTRIBUTE_PREFIX); let llvm_begin = identifier.inner.find(Self::LLVM_ATTRIBUTE_PREFIX);
@@ -209,7 +209,7 @@ impl FunctionDefinition {
let mut invalid_attributes = BTreeSet::new(); let mut invalid_attributes = BTreeSet::new();
for value in attribute_string.split('_') { for value in attribute_string.split('_') {
match era_compiler_llvm_context::EraVMAttribute::try_from(value) { match revive_llvm_context::EraVMAttribute::try_from(value) {
Ok(attribute) => valid_attributes.insert(attribute), Ok(attribute) => valid_attributes.insert(attribute),
Err(value) => invalid_attributes.insert(value), Err(value) => invalid_attributes.insert(value),
}; };
@@ -227,13 +227,13 @@ impl FunctionDefinition {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for FunctionDefinition impl<D> revive_llvm_context::EraVMWriteLLVM<D> for FunctionDefinition
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let argument_types: Vec<_> = self let argument_types: Vec<_> = self
.arguments .arguments
@@ -248,7 +248,7 @@ where
argument_types, argument_types,
self.result.len(), self.result.len(),
self.identifier self.identifier
.starts_with(era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX), .starts_with(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX),
); );
let function = context.add_function( let function = context.add_function(
@@ -257,7 +257,7 @@ where
self.result.len(), self.result.len(),
Some(inkwell::module::Linkage::Private), Some(inkwell::module::Linkage::Private),
)?; )?;
era_compiler_llvm_context::EraVMFunction::set_attributes( revive_llvm_context::EraVMFunction::set_attributes(
context.llvm(), context.llvm(),
function.borrow().declaration(), function.borrow().declaration(),
self.attributes.clone().into_iter().collect(), self.attributes.clone().into_iter().collect(),
@@ -265,22 +265,22 @@ where
); );
function function
.borrow_mut() .borrow_mut()
.set_yul_data(era_compiler_llvm_context::EraVMFunctionYulData::default()); .set_yul_data(revive_llvm_context::EraVMFunctionYulData::default());
Ok(()) Ok(())
} }
fn into_llvm( fn into_llvm(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
context.set_current_function(self.identifier.as_str())?; context.set_current_function(self.identifier.as_str())?;
let r#return = context.current_function().borrow().r#return(); let r#return = context.current_function().borrow().r#return();
context.set_basic_block(context.current_function().borrow().entry_block()); context.set_basic_block(context.current_function().borrow().entry_block());
match r#return { match r#return {
era_compiler_llvm_context::EraVMFunctionReturn::None => {} revive_llvm_context::EraVMFunctionReturn::None => {}
era_compiler_llvm_context::EraVMFunctionReturn::Primitive { pointer } => { revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
let identifier = self.result.pop().expect("Always exists"); let identifier = self.result.pop().expect("Always exists");
let r#type = identifier.r#type.unwrap_or_default(); let r#type = identifier.r#type.unwrap_or_default();
context.build_store(pointer, r#type.into_llvm(context).const_zero())?; context.build_store(pointer, r#type.into_llvm(context).const_zero())?;
@@ -289,7 +289,7 @@ where
.borrow_mut() .borrow_mut()
.insert_stack_pointer(identifier.inner, pointer); .insert_stack_pointer(identifier.inner, pointer);
} }
era_compiler_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => { revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => {
for (index, identifier) in self.result.into_iter().enumerate() { for (index, identifier) in self.result.into_iter().enumerate() {
let r#type = identifier.r#type.unwrap_or_default().into_llvm(context); let r#type = identifier.r#type.unwrap_or_default().into_llvm(context);
let pointer = context.build_gep( let pointer = context.build_gep(
@@ -328,10 +328,10 @@ where
.insert_stack_pointer(argument.inner.clone(), pointer); .insert_stack_pointer(argument.inner.clone(), pointer);
if self if self
.identifier .identifier
.starts_with(era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX) .starts_with(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
&& matches!( && matches!(
context.current_function().borrow().r#return(), context.current_function().borrow().r#return(),
era_compiler_llvm_context::EraVMFunctionReturn::Compound { .. } revive_llvm_context::EraVMFunctionReturn::Compound { .. }
) )
&& context.is_system_mode() && context.is_system_mode()
{ {
@@ -357,21 +357,21 @@ where
context.set_basic_block(context.current_function().borrow().return_block()); context.set_basic_block(context.current_function().borrow().return_block());
match context.current_function().borrow().r#return() { match context.current_function().borrow().r#return() {
era_compiler_llvm_context::EraVMFunctionReturn::None => { revive_llvm_context::EraVMFunctionReturn::None => {
context.build_return(None); context.build_return(None);
} }
era_compiler_llvm_context::EraVMFunctionReturn::Primitive { pointer } => { revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
let return_value = context.build_load(pointer, "return_value")?; let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value)); context.build_return(Some(&return_value));
} }
era_compiler_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. }
if context.current_function().borrow().name().starts_with( if context.current_function().borrow().name().starts_with(
era_compiler_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX, revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
) => ) =>
{ {
context.build_return(Some(&pointer.value)); context.build_return(Some(&pointer.value));
} }
era_compiler_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => { revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => {
let return_value = context.build_load(pointer, "return_value")?; let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value)); context.build_return(Some(&return_value));
} }
@@ -56,13 +56,13 @@ impl IfConditional {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for IfConditional impl<D> revive_llvm_context::EraVMWriteLLVM<D> for IfConditional
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let condition = self let condition = self
.condition .condition
@@ -183,35 +183,35 @@ impl Object {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Object impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Object
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn declare( fn declare(
&mut self, &mut self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut entry = era_compiler_llvm_context::EraVMEntryFunction::default(); let mut entry = revive_llvm_context::EraVMEntryFunction::default();
entry.declare(context)?; entry.declare(context)?;
let mut runtime = era_compiler_llvm_context::EraVMRuntime::new( let mut runtime = revive_llvm_context::EraVMRuntime::new(
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
); );
runtime.declare(context)?; runtime.declare(context)?;
era_compiler_llvm_context::EraVMDeployCodeFunction::new( revive_llvm_context::EraVMDeployCodeFunction::new(
era_compiler_llvm_context::EraVMDummyLLVMWritable::default(), revive_llvm_context::EraVMDummyLLVMWritable::default(),
) )
.declare(context)?; .declare(context)?;
era_compiler_llvm_context::EraVMRuntimeCodeFunction::new( revive_llvm_context::EraVMRuntimeCodeFunction::new(
era_compiler_llvm_context::EraVMDummyLLVMWritable::default(), revive_llvm_context::EraVMDummyLLVMWritable::default(),
) )
.declare(context)?; .declare(context)?;
for name in [ for name in [
era_compiler_llvm_context::EraVMRuntime::FUNCTION_DEPLOY_CODE, revive_llvm_context::EraVMRuntime::FUNCTION_DEPLOY_CODE,
era_compiler_llvm_context::EraVMRuntime::FUNCTION_RUNTIME_CODE, revive_llvm_context::EraVMRuntime::FUNCTION_RUNTIME_CODE,
era_compiler_llvm_context::EraVMRuntime::FUNCTION_ENTRY, revive_llvm_context::EraVMRuntime::FUNCTION_ENTRY,
] ]
.into_iter() .into_iter()
{ {
@@ -219,7 +219,7 @@ where
.get_function(name) .get_function(name)
.expect("Always exists") .expect("Always exists")
.borrow_mut() .borrow_mut()
.set_yul_data(era_compiler_llvm_context::EraVMFunctionYulData::default()); .set_yul_data(revive_llvm_context::EraVMFunctionYulData::default());
} }
entry.into_llvm(context)?; entry.into_llvm(context)?;
@@ -229,13 +229,13 @@ where
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if self.identifier.ends_with("_deployed") { if self.identifier.ends_with("_deployed") {
era_compiler_llvm_context::EraVMRuntimeCodeFunction::new(self.code) revive_llvm_context::EraVMRuntimeCodeFunction::new(self.code)
.into_llvm(context)?; .into_llvm(context)?;
} else { } else {
era_compiler_llvm_context::EraVMDeployCodeFunction::new(self.code) revive_llvm_context::EraVMDeployCodeFunction::new(self.code)
.into_llvm(context)?; .into_llvm(context)?;
} }
@@ -244,8 +244,8 @@ where
object.into_llvm(context)?; object.into_llvm(context)?;
} }
None => { None => {
let runtime = era_compiler_llvm_context::EraVMRuntime::new( let runtime = revive_llvm_context::EraVMRuntime::new(
era_compiler_llvm_context::EraVMAddressSpace::Heap, revive_llvm_context::EraVMAddressSpace::Heap,
); );
runtime.into_llvm(context)?; runtime.into_llvm(context)?;
} }
@@ -128,13 +128,13 @@ impl Switch {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for Switch impl<D> revive_llvm_context::EraVMWriteLLVM<D> for Switch
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm( fn into_llvm(
self, self,
context: &mut era_compiler_llvm_context::EraVMContext<D>, context: &mut revive_llvm_context::EraVMContext<D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let scrutinee = self.expression.into_llvm(context)?; let scrutinee = self.expression.into_llvm(context)?;
@@ -99,13 +99,13 @@ impl VariableDeclaration {
} }
} }
impl<D> era_compiler_llvm_context::EraVMWriteLLVM<D> for VariableDeclaration impl<D> revive_llvm_context::EraVMWriteLLVM<D> for VariableDeclaration
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
fn into_llvm<'ctx>( fn into_llvm<'ctx>(
mut self, mut self,
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &mut revive_llvm_context::EraVMContext<'ctx, D>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if self.bindings.len() == 1 { if self.bindings.len() == 1 {
let identifier = self.bindings.remove(0); let identifier = self.bindings.remove(0);
+2 -2
View File
@@ -73,10 +73,10 @@ impl Type {
/// ///
pub fn into_llvm<'ctx, D>( pub fn into_llvm<'ctx, D>(
self, self,
context: &era_compiler_llvm_context::EraVMContext<'ctx, D>, context: &revive_llvm_context::EraVMContext<'ctx, D>,
) -> inkwell::types::IntType<'ctx> ) -> inkwell::types::IntType<'ctx>
where where
D: era_compiler_llvm_context::EraVMDependency + Clone, D: revive_llvm_context::EraVMDependency + Clone,
{ {
match self { match self {
Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN), Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN),
+6 -6
View File
@@ -50,7 +50,7 @@ fn main_inner() -> anyhow::Result<()> {
.build_global() .build_global()
.expect("Thread pool configuration failure"); .expect("Thread pool configuration failure");
inkwell::support::enable_llvm_pretty_stack_trace(); inkwell::support::enable_llvm_pretty_stack_trace();
era_compiler_llvm_context::initialize_target(era_compiler_llvm_context::Target::PVM); // TODO: pass from CLI revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM); // TODO: pass from CLI
if arguments.recursive_process { if arguments.recursive_process {
return revive_solidity::run_process(); return revive_solidity::run_process();
@@ -59,7 +59,7 @@ fn main_inner() -> anyhow::Result<()> {
let debug_config = match arguments.debug_output_directory { let debug_config = match arguments.debug_output_directory {
Some(ref debug_output_directory) => { Some(ref debug_output_directory) => {
std::fs::create_dir_all(debug_output_directory.as_path())?; std::fs::create_dir_all(debug_output_directory.as_path())?;
Some(era_compiler_llvm_context::DebugConfig::new( Some(revive_llvm_context::DebugConfig::new(
debug_output_directory.to_owned(), debug_output_directory.to_owned(),
)) ))
} }
@@ -87,8 +87,8 @@ fn main_inner() -> anyhow::Result<()> {
}; };
let mut optimizer_settings = match arguments.optimization { let mut optimizer_settings = match arguments.optimization {
Some(mode) => era_compiler_llvm_context::OptimizerSettings::try_from_cli(mode)?, Some(mode) => revive_llvm_context::OptimizerSettings::try_from_cli(mode)?,
None => era_compiler_llvm_context::OptimizerSettings::cycles(), None => revive_llvm_context::OptimizerSettings::cycles(),
}; };
if arguments.fallback_to_optimizing_for_size { if arguments.fallback_to_optimizing_for_size {
optimizer_settings.enable_fallback_to_size(); optimizer_settings.enable_fallback_to_size();
@@ -102,8 +102,8 @@ fn main_inner() -> anyhow::Result<()> {
let include_metadata_hash = match arguments.metadata_hash { let include_metadata_hash = match arguments.metadata_hash {
Some(metadata_hash) => { Some(metadata_hash) => {
let metadata = let metadata =
era_compiler_llvm_context::EraVMMetadataHash::from_str(metadata_hash.as_str())?; revive_llvm_context::EraVMMetadataHash::from_str(metadata_hash.as_str())?;
metadata != era_compiler_llvm_context::EraVMMetadataHash::None metadata != revive_llvm_context::EraVMMetadataHash::None
} }
None => true, None => true,
}; };