mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-11 23:01:02 +00:00
@@ -599,13 +599,7 @@ impl FunctionCall {
|
||||
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some)
|
||||
}
|
||||
era_compiler_llvm_context::EraVMCodeType::Runtime => {
|
||||
let code_source =
|
||||
era_compiler_llvm_context::eravm_general::code_source(context)?;
|
||||
era_compiler_llvm_context::eravm_evm_ext_code::size(
|
||||
context,
|
||||
code_source.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -837,7 +831,7 @@ impl FunctionCall {
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
Name::Create | Name::ZkCreate => {
|
||||
Name::Create => {
|
||||
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
|
||||
let value = arguments[0].into_int_value();
|
||||
@@ -852,7 +846,7 @@ impl FunctionCall {
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::Create2 | Name::ZkCreate2 => {
|
||||
Name::Create2 => {
|
||||
let arguments = self.pop_arguments_llvm::<D, 4>(context)?;
|
||||
|
||||
let value = arguments[0].into_int_value();
|
||||
@@ -1016,416 +1010,6 @@ impl FunctionCall {
|
||||
location
|
||||
)
|
||||
}
|
||||
|
||||
Name::ZkToL1 => {
|
||||
let [is_first, in_0, in_1] = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::to_l1(
|
||||
context,
|
||||
is_first.into_int_value(),
|
||||
in_0.into_int_value(),
|
||||
in_1.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkCodeSource => {
|
||||
era_compiler_llvm_context::eravm_general::code_source(context).map(Some)
|
||||
}
|
||||
Name::ZkPrecompile => {
|
||||
let [in_0, in_1] = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::precompile(
|
||||
context,
|
||||
in_0.into_int_value(),
|
||||
in_1.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkMeta => era_compiler_llvm_context::eravm_general::meta(context).map(Some),
|
||||
Name::ZkSetContextU128 => {
|
||||
let [value] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::set_context_value(
|
||||
context,
|
||||
value.into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkSetPubdataPrice => {
|
||||
let [value] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::set_pubdata_price(
|
||||
context,
|
||||
value.into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkIncrementTxCounter => {
|
||||
era_compiler_llvm_context::eravm_general::increment_tx_counter(context)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkEventInitialize => {
|
||||
let [operand_1, operand_2] = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::event(
|
||||
context,
|
||||
operand_1.into_int_value(),
|
||||
operand_2.into_int_value(),
|
||||
true,
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkEventWrite => {
|
||||
let [operand_1, operand_2] = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_general::event(
|
||||
context,
|
||||
operand_1.into_int_value(),
|
||||
operand_2.into_int_value(),
|
||||
false,
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
|
||||
Name::ZkMimicCall => {
|
||||
let [address, abi_data, mimic] = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call,
|
||||
address.into_int_value(),
|
||||
mimic.into_int_value(),
|
||||
abi_data.as_basic_value_enum(),
|
||||
vec![],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkSystemMimicCall => {
|
||||
let [address, abi_data, mimic, extra_value_1, extra_value_2] =
|
||||
self.pop_arguments_llvm::<D, 5>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call,
|
||||
address.into_int_value(),
|
||||
mimic.into_int_value(),
|
||||
abi_data.as_basic_value_enum(),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkMimicCallByRef => {
|
||||
let [address, mimic] = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call_byref,
|
||||
address.into_int_value(),
|
||||
mimic.into_int_value(),
|
||||
abi_data,
|
||||
vec![],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkSystemMimicCallByRef => {
|
||||
let [address, mimic, extra_value_1, extra_value_2] =
|
||||
self.pop_arguments_llvm::<D, 4>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call_byref,
|
||||
address.into_int_value(),
|
||||
mimic.into_int_value(),
|
||||
abi_data,
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkRawCall => {
|
||||
unimplemented!()
|
||||
}
|
||||
Name::ZkRawCallByRef => {
|
||||
let [address, output_offset, output_length] =
|
||||
self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().far_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
output_offset.into_int_value(),
|
||||
output_length.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkSystemCall => {
|
||||
unimplemented!()
|
||||
}
|
||||
Name::ZkSystemCallByRef => {
|
||||
let [address, extra_value_1, extra_value_2, extra_value_3, extra_value_4] =
|
||||
self.pop_arguments_llvm::<D, 5>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().far_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
extra_value_3.into_int_value(),
|
||||
extra_value_4.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkStaticRawCall => {
|
||||
let [address, abi_data, output_offset, output_length] =
|
||||
self.pop_arguments_llvm::<D, 4>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().static_call,
|
||||
address.into_int_value(),
|
||||
abi_data.as_basic_value_enum(),
|
||||
output_offset.into_int_value(),
|
||||
output_length.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkStaticRawCallByRef => {
|
||||
let [address, output_offset, output_length] =
|
||||
self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().static_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
output_offset.into_int_value(),
|
||||
output_length.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkStaticSystemCall => {
|
||||
let [address, abi_data, extra_value_1, extra_value_2, extra_value_3, extra_value_4] =
|
||||
self.pop_arguments_llvm::<D, 6>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().static_call,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
extra_value_3.into_int_value(),
|
||||
extra_value_4.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkStaticSystemCallByRef => {
|
||||
let [address, extra_value_1, extra_value_2, extra_value_3, extra_value_4] =
|
||||
self.pop_arguments_llvm::<D, 5>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().static_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
extra_value_3.into_int_value(),
|
||||
extra_value_4.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkDelegateRawCall => {
|
||||
let [address, abi_data, output_offset, output_length] =
|
||||
self.pop_arguments_llvm::<D, 4>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call,
|
||||
address.into_int_value(),
|
||||
abi_data.as_basic_value_enum(),
|
||||
output_offset.into_int_value(),
|
||||
output_length.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkDelegateRawCallByRef => {
|
||||
let [address, output_offset, output_length] =
|
||||
self.pop_arguments_llvm::<D, 3>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
output_offset.into_int_value(),
|
||||
output_length.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkDelegateSystemCall => {
|
||||
let [address, abi_data, extra_value_1, extra_value_2, extra_value_3, extra_value_4] =
|
||||
self.pop_arguments_llvm::<D, 6>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
extra_value_3.into_int_value(),
|
||||
extra_value_4.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkDelegateSystemCallByRef => {
|
||||
let [address, extra_value_1, extra_value_2, extra_value_3, extra_value_4] =
|
||||
self.pop_arguments_llvm::<D, 5>(context)?;
|
||||
let abi_data = context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call_byref,
|
||||
address.into_int_value(),
|
||||
abi_data,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
extra_value_1.into_int_value(),
|
||||
extra_value_2.into_int_value(),
|
||||
extra_value_3.into_int_value(),
|
||||
extra_value_4.into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
Name::ZkLoadCalldataIntoActivePtr => {
|
||||
era_compiler_llvm_context::eravm_abi::calldata_ptr_to_active(context).map(|_| None)
|
||||
}
|
||||
Name::ZkLoadReturndataIntoActivePtr => {
|
||||
era_compiler_llvm_context::eravm_abi::return_data_ptr_to_active(context)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkPtrAddIntoActive => {
|
||||
let [offset] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_add_assign(
|
||||
context,
|
||||
offset.into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkPtrShrinkIntoActive => {
|
||||
let [offset] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_shrink_assign(
|
||||
context,
|
||||
offset.into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
Name::ZkPtrPackIntoActive => {
|
||||
let [data] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_pack_assign(
|
||||
context,
|
||||
data.into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
|
||||
Name::ZkMultiplicationHigh => {
|
||||
let [operand_1, operand_2] = self.pop_arguments_llvm::<D, 2>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_math::multiplication_512(
|
||||
context,
|
||||
operand_1.into_int_value(),
|
||||
operand_2.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
Name::ZkGlobalLoad => {
|
||||
let [mut key] = self.pop_arguments::<D, 1>(context)?;
|
||||
let key = key.original.take().ok_or_else(|| {
|
||||
anyhow::anyhow!("{} `$zk_global_load` literal is missing", location)
|
||||
})?;
|
||||
|
||||
context.get_global_value(key.as_str()).map(Some)
|
||||
}
|
||||
Name::ZkGlobalExtraAbiData => {
|
||||
let [index] = self.pop_arguments_llvm::<D, 1>(context)?;
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::get_extra_abi_data(
|
||||
context,
|
||||
index.into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
Name::ZkGlobalStore => {
|
||||
let [mut key, value] = self.pop_arguments::<D, 2>(context)?;
|
||||
let key = key.original.take().ok_or_else(|| {
|
||||
anyhow::anyhow!("{} `$zk_global_store` literal is missing", location)
|
||||
})?;
|
||||
let value = value.value.into_int_value();
|
||||
|
||||
context.set_global(
|
||||
key.as_str(),
|
||||
context.field_type(),
|
||||
era_compiler_llvm_context::EraVMAddressSpace::Stack,
|
||||
value,
|
||||
);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,17 +157,6 @@ pub enum Name {
|
||||
///
|
||||
/// Passes bytecode to the system contracts.
|
||||
Create2,
|
||||
/// create new contract with code `mem[p…(p+n))` and send `v` wei and return the new address
|
||||
///
|
||||
/// Passes hash to the system contracts.
|
||||
ZkCreate,
|
||||
/// create new contract with code `mem[p…(p+n))` at address
|
||||
/// `keccak256(0xff . this . s . keccak256(mem[p…(p+n)))` and send `v` wei and return the
|
||||
/// new address, where `0xff` is a 1-byte value, this is the current contract’s address as a
|
||||
/// 20-byte value and `s` is a big-endian 256-bit value
|
||||
///
|
||||
/// Passes hash to the system contracts.
|
||||
ZkCreate2,
|
||||
/// returns the size in the data area
|
||||
DataSize,
|
||||
/// is equivalent to `CodeCopy`
|
||||
@@ -238,79 +227,6 @@ pub enum Name {
|
||||
ExtCodeCopy,
|
||||
/// end execution, destroy current contract and send funds to `a`
|
||||
SelfDestruct,
|
||||
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkToL1,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkCodeSource,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkPrecompile,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkMeta,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSetContextU128,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSetPubdataPrice,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkIncrementTxCounter,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkEventInitialize,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkEventWrite,
|
||||
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkMimicCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSystemMimicCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkMimicCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSystemMimicCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkRawCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkRawCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSystemCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkSystemCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkStaticRawCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkStaticRawCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkStaticSystemCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkStaticSystemCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkDelegateRawCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkDelegateRawCallByRef,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkDelegateSystemCall,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkDelegateSystemCallByRef,
|
||||
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkLoadCalldataIntoActivePtr,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkLoadReturndataIntoActivePtr,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkPtrAddIntoActive,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkPtrShrinkIntoActive,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkPtrPackIntoActive,
|
||||
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkMultiplicationHigh,
|
||||
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkGlobalLoad,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkGlobalExtraAbiData,
|
||||
/// The eponymous EraVM Yul extension instruction.
|
||||
ZkGlobalStore,
|
||||
}
|
||||
|
||||
impl Name {
|
||||
@@ -406,8 +322,6 @@ impl From<&str> for Name {
|
||||
|
||||
"create" => Self::Create,
|
||||
"create2" => Self::Create2,
|
||||
"$zk_create" => Self::ZkCreate,
|
||||
"$zk_create2" => Self::ZkCreate2,
|
||||
"datasize" => Self::DataSize,
|
||||
"dataoffset" => Self::DataOffset,
|
||||
"datacopy" => Self::DataCopy,
|
||||
@@ -446,45 +360,6 @@ impl From<&str> for Name {
|
||||
"extcodecopy" => Self::ExtCodeCopy,
|
||||
"selfdestruct" => Self::SelfDestruct,
|
||||
|
||||
"$zk_to_l1" => Self::ZkToL1,
|
||||
"$zk_code_source" => Self::ZkCodeSource,
|
||||
"$zk_precompile" => Self::ZkPrecompile,
|
||||
"$zk_meta" => Self::ZkMeta,
|
||||
"$zk_set_context_u128" => Self::ZkSetContextU128,
|
||||
"$zk_set_pubdata_price" => Self::ZkSetPubdataPrice,
|
||||
"$zk_increment_tx_counter" => Self::ZkIncrementTxCounter,
|
||||
"$zk_event_initialize" => Self::ZkEventInitialize,
|
||||
"$zk_event_write" => Self::ZkEventWrite,
|
||||
|
||||
"$zk_mimic_call" => Self::ZkMimicCall,
|
||||
"$zk_system_mimic_call" => Self::ZkSystemMimicCall,
|
||||
"$zk_mimic_call_byref" => Self::ZkMimicCallByRef,
|
||||
"$zk_system_mimic_call_byref" => Self::ZkSystemMimicCallByRef,
|
||||
"$zk_raw_call" => Self::ZkRawCall,
|
||||
"$zk_raw_call_byref" => Self::ZkRawCallByRef,
|
||||
"$zk_system_call" => Self::ZkSystemCall,
|
||||
"$zk_system_call_byref" => Self::ZkSystemCallByRef,
|
||||
"$zk_static_raw_call" => Self::ZkStaticRawCall,
|
||||
"$zk_static_raw_call_byref" => Self::ZkStaticRawCallByRef,
|
||||
"$zk_static_system_call" => Self::ZkStaticSystemCall,
|
||||
"$zk_static_system_call_byref" => Self::ZkStaticSystemCallByRef,
|
||||
"$zk_delegate_raw_call" => Self::ZkDelegateRawCall,
|
||||
"$zk_delegate_raw_call_byref" => Self::ZkDelegateRawCallByRef,
|
||||
"$zk_delegate_system_call" => Self::ZkDelegateSystemCall,
|
||||
"$zk_delegate_system_call_byref" => Self::ZkDelegateSystemCallByRef,
|
||||
|
||||
"$zk_load_calldata_into_active_ptr" => Self::ZkLoadCalldataIntoActivePtr,
|
||||
"$zk_load_returndata_into_active_ptr" => Self::ZkLoadReturndataIntoActivePtr,
|
||||
"$zk_ptr_add_into_active" => Self::ZkPtrAddIntoActive,
|
||||
"$zk_ptr_shrink_into_active" => Self::ZkPtrShrinkIntoActive,
|
||||
"$zk_ptr_pack_into_active" => Self::ZkPtrPackIntoActive,
|
||||
|
||||
"$zk_multiplication_high" => Self::ZkMultiplicationHigh,
|
||||
|
||||
"$zk_global_load" => Self::ZkGlobalLoad,
|
||||
"$zk_global_extra_abi_data" => Self::ZkGlobalExtraAbiData,
|
||||
"$zk_global_store" => Self::ZkGlobalStore,
|
||||
|
||||
input => Self::UserDefined(input.to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
//! Translates the verbatim simulations.
|
||||
//!
|
||||
|
||||
use anyhow::Ok;
|
||||
|
||||
use crate::yul::parser::statement::expression::function_call::FunctionCall;
|
||||
|
||||
///
|
||||
@@ -12,7 +10,7 @@ use crate::yul::parser::statement::expression::function_call::FunctionCall;
|
||||
pub fn verbatim<'ctx, D>(
|
||||
context: &mut era_compiler_llvm_context::EraVMContext<'ctx, D>,
|
||||
call: &mut FunctionCall,
|
||||
input_size: usize,
|
||||
_input_size: usize,
|
||||
output_size: usize,
|
||||
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
|
||||
where
|
||||
@@ -31,808 +29,7 @@ where
|
||||
.take()
|
||||
.ok_or_else(|| anyhow::anyhow!("{} Verbatim literal is missing", call.location))?;
|
||||
match identifier.as_str() {
|
||||
identifier @ "to_l1" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::to_l1(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "code_source" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_general::code_source(context).map(Some)
|
||||
}
|
||||
identifier @ "precompile" => {
|
||||
const ARGUMENTS_COUNT: usize = 2;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::precompile(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "meta" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_general::meta(context).map(Some)
|
||||
}
|
||||
identifier @ "mimic_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2],
|
||||
vec![context.field_const(0), context.field_const(0)],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "mimic_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 2;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
vec![context.field_const(0), context.field_const(0)],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_mimic_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 7;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2],
|
||||
vec![
|
||||
arguments[3].into_int_value(),
|
||||
arguments[4].into_int_value(),
|
||||
arguments[5].into_int_value(),
|
||||
arguments[6].into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_mimic_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 6;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::mimic(
|
||||
context,
|
||||
context.llvm_runtime().mimic_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
vec![
|
||||
arguments[2].into_int_value(),
|
||||
arguments[3].into_int_value(),
|
||||
arguments[4].into_int_value(),
|
||||
arguments[5].into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "raw_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 4;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let _arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
todo!()
|
||||
//era_compiler_llvm_context::eravm_call::raw_far(
|
||||
// context,
|
||||
// context.llvm_runtime().far_call,
|
||||
// arguments[0].into_int_value(),
|
||||
// arguments[1],
|
||||
// arguments[2].into_int_value(),
|
||||
// arguments[3].into_int_value(),
|
||||
//)
|
||||
//.map(Some)
|
||||
}
|
||||
identifier @ "raw_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().far_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
_identifier @ "system_call" => {
|
||||
unimplemented!()
|
||||
}
|
||||
identifier @ "system_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 5;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().far_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
context.field_const(0),
|
||||
context.field_const(0),
|
||||
vec![
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
arguments[3].into_int_value(),
|
||||
arguments[4].into_int_value(),
|
||||
],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "raw_static_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 4;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().static_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1],
|
||||
arguments[2].into_int_value(),
|
||||
arguments[3].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "raw_static_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().static_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_static_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 6;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().static_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1],
|
||||
arguments[4].into_int_value(),
|
||||
arguments[5].into_int_value(),
|
||||
vec![arguments[2].into_int_value(), arguments[3].into_int_value()],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_static_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 5;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().static_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
arguments[3].into_int_value(),
|
||||
arguments[4].into_int_value(),
|
||||
vec![arguments[1].into_int_value(), arguments[2].into_int_value()],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "raw_delegate_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 4;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1],
|
||||
arguments[2].into_int_value(),
|
||||
arguments[3].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "raw_delegate_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::raw_far(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_delegate_call" => {
|
||||
const ARGUMENTS_COUNT: usize = 6;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1],
|
||||
arguments[4].into_int_value(),
|
||||
arguments[5].into_int_value(),
|
||||
vec![arguments[2].into_int_value(), arguments[3].into_int_value()],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "system_delegate_call_byref" => {
|
||||
const ARGUMENTS_COUNT: usize = 5;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_call::system(
|
||||
context,
|
||||
context.llvm_runtime().delegate_call_byref,
|
||||
arguments[0].into_int_value(),
|
||||
context.get_global_value(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_ACTIVE_POINTER,
|
||||
)?,
|
||||
arguments[3].into_int_value(),
|
||||
arguments[4].into_int_value(),
|
||||
vec![arguments[1].into_int_value(), arguments[2].into_int_value()],
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "set_context_u128" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::set_context_value(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "set_pubdata_price" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::set_pubdata_price(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "increment_tx_counter" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_general::increment_tx_counter(context).map(Some)
|
||||
}
|
||||
identifier @ "event_initialize" => {
|
||||
const ARGUMENTS_COUNT: usize = 2;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::event(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
true,
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "event_write" => {
|
||||
const ARGUMENTS_COUNT: usize = 2;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_general::event(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
false,
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "calldata_ptr_to_active" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::calldata_ptr_to_active(context).map(Some)
|
||||
}
|
||||
identifier @ "return_data_ptr_to_active" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::return_data_ptr_to_active(context).map(Some)
|
||||
}
|
||||
identifier @ "active_ptr_add_assign" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_add_assign(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "active_ptr_shrink_assign" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_shrink_assign(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "active_ptr_pack_assign" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_pack_assign(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "mul_high" => {
|
||||
const ARGUMENTS_COUNT: usize = 2;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_math::multiplication_512(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "throw" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_utils::throw(context);
|
||||
Ok(None)
|
||||
}
|
||||
identifier
|
||||
if identifier.starts_with(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_VERBATIM_GETTER_PREFIX,
|
||||
) =>
|
||||
{
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
match identifier
|
||||
.strip_prefix(era_compiler_llvm_context::eravm_const::GLOBAL_VERBATIM_GETTER_PREFIX)
|
||||
{
|
||||
Some(identifier)
|
||||
if identifier
|
||||
== era_compiler_llvm_context::eravm_const::GLOBAL_CALLDATA_POINTER =>
|
||||
{
|
||||
context.get_global_value(identifier).map(Some)
|
||||
}
|
||||
Some(identifier)
|
||||
if identifier == era_compiler_llvm_context::eravm_const::GLOBAL_CALL_FLAGS =>
|
||||
{
|
||||
context.get_global_value(identifier).map(Some)
|
||||
}
|
||||
Some(identifier)
|
||||
if identifier
|
||||
== era_compiler_llvm_context::eravm_const::GLOBAL_RETURN_DATA_POINTER =>
|
||||
{
|
||||
context.get_global_value(identifier).map(Some)
|
||||
}
|
||||
Some(identifier)
|
||||
if identifier.starts_with(
|
||||
era_compiler_llvm_context::eravm_const::GLOBAL_EXTRA_ABI_DATA,
|
||||
) =>
|
||||
{
|
||||
let stripped = identifier
|
||||
.strip_prefix(era_compiler_llvm_context::eravm_const::GLOBAL_EXTRA_ABI_DATA)
|
||||
.expect("Always exists");
|
||||
let stripped = stripped.strip_prefix('_').ok_or_else(|| {
|
||||
anyhow::anyhow!(
|
||||
"{} Invalid global variable identifier `{:?}`",
|
||||
call.location,
|
||||
identifier
|
||||
)
|
||||
})?;
|
||||
let index = stripped.parse::<u64>().map_err(|error| {
|
||||
anyhow::anyhow!(
|
||||
"{} Invalid global variable identifier `{:?}`: {}",
|
||||
call.location,
|
||||
identifier,
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
if index >= (era_compiler_llvm_context::eravm_const::EXTRA_ABI_DATA_SIZE as u64)
|
||||
{
|
||||
anyhow::bail!(
|
||||
"{} Extra ABI data overflow. Only indexes `0..=9` are allowed",
|
||||
call.location,
|
||||
);
|
||||
}
|
||||
era_compiler_llvm_context::eravm_abi::get_extra_abi_data(
|
||||
context,
|
||||
context.field_const(index),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier => Err(anyhow::anyhow!(
|
||||
"{} Invalid global variable identifier `{:?}`",
|
||||
call.location,
|
||||
identifier
|
||||
)),
|
||||
}
|
||||
}
|
||||
identifier @ "active_ptr_data_load" => {
|
||||
const ARGUMENTS_COUNT: usize = 1;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_data_load(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
identifier @ "active_ptr_data_size" => {
|
||||
const ARGUMENTS_COUNT: usize = 0;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_data_size(context).map(Some)
|
||||
}
|
||||
identifier @ "active_ptr_data_copy" => {
|
||||
const ARGUMENTS_COUNT: usize = 3;
|
||||
if input_size != ARGUMENTS_COUNT {
|
||||
anyhow::bail!(
|
||||
"{} Internal function `{}` expected {} arguments, found {}",
|
||||
call.location,
|
||||
identifier,
|
||||
ARGUMENTS_COUNT,
|
||||
input_size
|
||||
);
|
||||
}
|
||||
|
||||
let arguments = call.pop_arguments_llvm::<D, ARGUMENTS_COUNT>(context)?;
|
||||
era_compiler_llvm_context::eravm_abi::active_ptr_data_copy(
|
||||
context,
|
||||
arguments[0].into_int_value(),
|
||||
arguments[1].into_int_value(),
|
||||
arguments[2].into_int_value(),
|
||||
)
|
||||
.map(|_| None)
|
||||
}
|
||||
identifier => anyhow::bail!(
|
||||
_ => anyhow::bail!(
|
||||
"{} Found unknown internal function `{}`",
|
||||
call.location,
|
||||
identifier
|
||||
|
||||
Reference in New Issue
Block a user