mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-05-08 20:38:05 +00:00
@@ -0,0 +1,15 @@
|
||||
//!
|
||||
//! The number base constants.
|
||||
//!
|
||||
|
||||
/// The binary number base.
|
||||
pub const BASE_BINARY: u32 = 2;
|
||||
|
||||
/// The octal number base.
|
||||
pub const BASE_OCTAL: u32 = 8;
|
||||
|
||||
/// The decimal number base.
|
||||
pub const BASE_DECIMAL: u32 = 10;
|
||||
|
||||
/// The hexadecimal number base.
|
||||
pub const BASE_HEXADECIMAL: u32 = 16;
|
||||
@@ -0,0 +1,22 @@
|
||||
//!
|
||||
//! The common sizes in bits.
|
||||
//!
|
||||
|
||||
/// The `bool` type bit-length.
|
||||
pub const BIT_LENGTH_BOOLEAN: usize = 1;
|
||||
|
||||
/// The `u8` type or byte bit-length.
|
||||
pub const BIT_LENGTH_BYTE: usize = 8;
|
||||
|
||||
/// The x86 word type (usually `u32`) bit-length.
|
||||
pub const BIT_LENGTH_X32: usize = crate::byte_length::BYTE_LENGTH_X32 * BIT_LENGTH_BYTE;
|
||||
|
||||
/// The x86_64 word type (usually `u64`) bit-length.
|
||||
pub const BIT_LENGTH_X64: usize = crate::byte_length::BYTE_LENGTH_X64 * BIT_LENGTH_BYTE;
|
||||
|
||||
/// The ETH address (usually `u160`) bit-length.
|
||||
pub const BIT_LENGTH_ETH_ADDRESS: usize =
|
||||
crate::byte_length::BYTE_LENGTH_ETH_ADDRESS * BIT_LENGTH_BYTE;
|
||||
|
||||
/// The field (usually `u256` or `i256`) bit-length.
|
||||
pub const BIT_LENGTH_FIELD: usize = crate::byte_length::BYTE_LENGTH_FIELD * BIT_LENGTH_BYTE;
|
||||
@@ -0,0 +1,18 @@
|
||||
//!
|
||||
//! The common sizes in bytes.
|
||||
//!
|
||||
|
||||
/// The byte-length.
|
||||
pub const BYTE_LENGTH_BYTE: usize = 1;
|
||||
|
||||
/// The x86 word byte-length.
|
||||
pub const BYTE_LENGTH_X32: usize = 4;
|
||||
|
||||
/// The x86_64 word byte-length.
|
||||
pub const BYTE_LENGTH_X64: usize = 8;
|
||||
|
||||
/// The ETH address byte-length.
|
||||
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
||||
|
||||
/// The field byte-length.
|
||||
pub const BYTE_LENGTH_FIELD: usize = 32;
|
||||
@@ -0,0 +1,120 @@
|
||||
//!
|
||||
//! The EraVM address constants.
|
||||
//!
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_TO_L1: u16 = 0xFFFF;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_CODE_ADDRESS: u16 = 0xFFFE;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_PRECOMPILE: u16 = 0xFFFD;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_META: u16 = 0xFFFC;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_MIMIC_CALL: u16 = 0xFFFB;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SYSTEM_MIMIC_CALL: u16 = 0xFFFA;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_MIMIC_CALL_BYREF: u16 = 0xFFF9;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SYSTEM_MIMIC_CALL_BYREF: u16 = 0xFFF8;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_RAW_FAR_CALL: u16 = 0xFFF7;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_RAW_FAR_CALL_BYREF: u16 = 0xFFF6;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SYSTEM_CALL: u16 = 0xFFF5;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SYSTEM_CALL_BYREF: u16 = 0xFFF4;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SET_CONTEXT_VALUE_CALL: u16 = 0xFFF3;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_SET_PUBDATA_PRICE: u16 = 0xFFF2;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_INCREMENT_TX_COUNTER: u16 = 0xFFF1;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_GET_GLOBAL_PTR_CALLDATA: u16 = 0xFFF0;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_GET_GLOBAL_CALL_FLAGS: u16 = 0xFFEF;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_GET_GLOBAL_PTR_RETURN_DATA: u16 = 0xFFEE;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_EVENT_INITIALIZE: u16 = 0xFFED;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_EVENT_WRITE: u16 = 0xFFEC;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_CALLDATA: u16 = 0xFFEB;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_RETURN_DATA: u16 = 0xFFEA;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_ADD: u16 = 0xFFE9;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_SHRINK: u16 = 0xFFE8;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_PACK: u16 = 0xFFE7;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_MULTIPLICATION_HIGH_REGISTER: u16 = 0xFFE6;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_GET_GLOBAL_EXTRA_ABI_DATA: u16 = 0xFFE5;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_LOAD: u16 = 0xFFE4;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_COPY: u16 = 0xFFE3;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_SIZE: u16 = 0xFFE2;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_CONST_ARRAY_DECLARE: u16 = 0xFFE1;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_CONST_ARRAY_SET: u16 = 0xFFE0;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_CONST_ARRAY_FINALIZE: u16 = 0xFFDF;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_CONST_ARRAY_GET: u16 = 0xFFDE;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_DECOMMIT: u16 = 0xFFDD;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_DECOMMIT: u16 = 0xFFDC;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_RETURN_FORWARD: u16 = 0xFFDB;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_REVERT_FORWARD: u16 = 0xFFDA;
|
||||
|
||||
/// The corresponding simulation predefined address.
|
||||
pub const ERAVM_ADDRESS_ACTIVE_PTR_SWAP: u16 = 0xFFD9;
|
||||
@@ -0,0 +1,5 @@
|
||||
//!
|
||||
//! The EraVM constants.
|
||||
//!
|
||||
|
||||
pub mod address;
|
||||
@@ -0,0 +1,91 @@
|
||||
//!
|
||||
//! The EVM version.
|
||||
//!
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
///
|
||||
/// The EVM version.
|
||||
///
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EVMVersion {
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "homestead")]
|
||||
Homestead,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "tangerineWhistle")]
|
||||
TangerineWhistle,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "spuriousDragon")]
|
||||
SpuriousDragon,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "byzantium")]
|
||||
Byzantium,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "constantinople")]
|
||||
Constantinople,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "petersburg")]
|
||||
Petersburg,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "istanbul")]
|
||||
Istanbul,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "berlin")]
|
||||
Berlin,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "london")]
|
||||
London,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "paris")]
|
||||
Paris,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "shanghai")]
|
||||
Shanghai,
|
||||
/// The corresponding EVM version.
|
||||
#[serde(rename = "cancun")]
|
||||
Cancun,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for EVMVersion {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
Ok(match value {
|
||||
"homestead" => Self::Homestead,
|
||||
"tangerineWhistle" => Self::TangerineWhistle,
|
||||
"spuriousDragon" => Self::SpuriousDragon,
|
||||
"byzantium" => Self::Byzantium,
|
||||
"constantinople" => Self::Constantinople,
|
||||
"petersburg" => Self::Petersburg,
|
||||
"istanbul" => Self::Istanbul,
|
||||
"berlin" => Self::Berlin,
|
||||
"london" => Self::London,
|
||||
"paris" => Self::Paris,
|
||||
"shanghai" => Self::Shanghai,
|
||||
"cancun" => Self::Cancun,
|
||||
_ => anyhow::bail!("Invalid EVM version: {}", value),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for EVMVersion {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Homestead => write!(f, "homestead"),
|
||||
Self::TangerineWhistle => write!(f, "tangerineWhistle"),
|
||||
Self::SpuriousDragon => write!(f, "spuriousDragon"),
|
||||
Self::Byzantium => write!(f, "byzantium"),
|
||||
Self::Constantinople => write!(f, "constantinople"),
|
||||
Self::Petersburg => write!(f, "petersburg"),
|
||||
Self::Istanbul => write!(f, "istanbul"),
|
||||
Self::Berlin => write!(f, "berlin"),
|
||||
Self::London => write!(f, "london"),
|
||||
Self::Paris => write!(f, "paris"),
|
||||
Self::Shanghai => write!(f, "shanghai"),
|
||||
Self::Cancun => write!(f, "cancun"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//!
|
||||
//! The exit code constants.
|
||||
//!
|
||||
|
||||
/// The common application success exit code.
|
||||
pub const EXIT_CODE_SUCCESS: i32 = 0;
|
||||
|
||||
/// The common application failure exit code.
|
||||
pub const EXIT_CODE_FAILURE: i32 = 1;
|
||||
@@ -0,0 +1,48 @@
|
||||
//!
|
||||
//! The file extensions.
|
||||
//!
|
||||
|
||||
/// The manifest file extension.
|
||||
pub static EXTENSION_MANIFEST: &str = "toml";
|
||||
|
||||
/// The JSON data file extension.
|
||||
pub static EXTENSION_JSON: &str = "json";
|
||||
|
||||
/// The ABI file extension.
|
||||
pub static EXTENSION_ABI: &str = "abi";
|
||||
|
||||
/// The Yul IR file extension.
|
||||
pub static EXTENSION_YUL: &str = "yul";
|
||||
|
||||
/// The EVM legacy assembly IR file extension.
|
||||
pub static EXTENSION_EVMLA: &str = "evmla";
|
||||
|
||||
/// The Ethereal IR file extension.
|
||||
pub static EXTENSION_ETHIR: &str = "ethir";
|
||||
|
||||
/// The EVM file extension.
|
||||
pub static EXTENSION_EVM: &str = "evm";
|
||||
|
||||
/// The EVM bytecode file extension.
|
||||
pub static EXTENSION_EVM_BINARY: &str = "bin";
|
||||
|
||||
/// The Solidity file extension.
|
||||
pub static EXTENSION_SOLIDITY: &str = "sol";
|
||||
|
||||
/// The LLL IR file extension.
|
||||
pub static EXTENSION_LLL: &str = "lll";
|
||||
|
||||
/// The Vyper file extension.
|
||||
pub static EXTENSION_VYPER: &str = "vy";
|
||||
|
||||
/// The LLVM source code file extension.
|
||||
pub static EXTENSION_LLVM_SOURCE: &str = "ll";
|
||||
|
||||
/// The LLVM bitcode file extension.
|
||||
pub static EXTENSION_LLVM_BINARY: &str = "bc";
|
||||
|
||||
/// The EraVM assembly file extension.
|
||||
pub static EXTENSION_ERAVM_ASSEMBLY: &str = "zasm";
|
||||
|
||||
/// The EraVM bytecode file extension.
|
||||
pub static EXTENSION_ERAVM_BINARY: &str = "zbin";
|
||||
@@ -0,0 +1,21 @@
|
||||
//!
|
||||
//! The compiler common library.
|
||||
//!
|
||||
|
||||
pub(crate) mod base;
|
||||
pub(crate) mod bit_length;
|
||||
pub(crate) mod byte_length;
|
||||
pub(crate) mod eravm;
|
||||
pub(crate) mod evm_version;
|
||||
pub(crate) mod exit_code;
|
||||
pub(crate) mod extension;
|
||||
pub(crate) mod utils;
|
||||
|
||||
pub use self::base::*;
|
||||
pub use self::bit_length::*;
|
||||
pub use self::byte_length::*;
|
||||
pub use self::eravm::address::*;
|
||||
pub use self::evm_version::EVMVersion;
|
||||
pub use self::exit_code::*;
|
||||
pub use self::extension::*;
|
||||
pub use self::utils::*;
|
||||
@@ -0,0 +1,35 @@
|
||||
//!
|
||||
//! The compiler common utils.
|
||||
//!
|
||||
|
||||
///
|
||||
/// Deserializes a `serde_json` object from slice with the recursion limit disabled.
|
||||
///
|
||||
/// Must be used for all JSON I/O to avoid crashes due to the aforementioned limit.
|
||||
///
|
||||
pub fn deserialize_from_slice<O>(input: &[u8]) -> anyhow::Result<O>
|
||||
where
|
||||
O: serde::de::DeserializeOwned,
|
||||
{
|
||||
let mut deserializer = serde_json::Deserializer::from_slice(input);
|
||||
deserializer.disable_recursion_limit();
|
||||
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
|
||||
let result = O::deserialize(deserializer)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
///
|
||||
/// Deserializes a `serde_json` object from string with the recursion limit disabled.
|
||||
///
|
||||
/// Must be used for all JSON I/O to avoid crashes due to the aforementioned limit.
|
||||
///
|
||||
pub fn deserialize_from_str<O>(input: &str) -> anyhow::Result<O>
|
||||
where
|
||||
O: serde::de::DeserializeOwned,
|
||||
{
|
||||
let mut deserializer = serde_json::Deserializer::from_str(input);
|
||||
deserializer.disable_recursion_limit();
|
||||
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
|
||||
let result = O::deserialize(deserializer)?;
|
||||
Ok(result)
|
||||
}
|
||||
Reference in New Issue
Block a user