add common crate

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-03-22 16:19:18 +01:00
parent 50f2dd9b74
commit c52a8d0f20
65 changed files with 839 additions and 271 deletions
@@ -155,7 +155,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type().as_basic_type_enum(),
@@ -894,9 +894,7 @@ impl FunctionCall {
let offset = context.builder().build_int_add(
arguments[0].into_int_value(),
context.field_const(
(era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
),
"datacopy_contract_hash_offset",
)?;
@@ -125,13 +125,12 @@ impl Literal {
.as_basic_value_enum();
let constant = match inner {
IntegerLiteral::Decimal { ref inner } => num::BigUint::from_str_radix(
inner.as_str(),
era_compiler_common::BASE_DECIMAL,
),
IntegerLiteral::Decimal { ref inner } => {
num::BigUint::from_str_radix(inner.as_str(), revive_common::BASE_DECIMAL)
}
IntegerLiteral::Hexadecimal { ref inner } => num::BigUint::from_str_radix(
&inner["0x".len()..],
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
),
}
.expect("Always valid");
@@ -148,7 +147,7 @@ impl Literal {
string.clone()
} else {
let mut hex_string =
String::with_capacity(era_compiler_common::BYTE_LENGTH_FIELD * 2);
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -165,7 +164,7 @@ impl Literal {
let codepoint_str = &string[index + 1..index + 5];
let codepoint = u32::from_str_radix(
codepoint_str,
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
)
.map_err(|error| {
anyhow::anyhow!(
@@ -209,16 +208,16 @@ impl Literal {
hex_string
};
if hex_string.len() > era_compiler_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(
r#type.const_zero().as_basic_value_enum(),
string,
));
}
if hex_string.len() < era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() < revive_common::BYTE_LENGTH_FIELD * 2 {
hex_string.push_str(
"0".repeat((era_compiler_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
.as_str(),
);
}
@@ -297,7 +297,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type(),
@@ -195,7 +195,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
binding.r#type.unwrap_or_default().into_llvm(context),
+2 -2
View File
@@ -31,7 +31,7 @@ pub enum Type {
impl Default for Type {
fn default() -> Self {
Self::UInt(era_compiler_common::BIT_LENGTH_FIELD)
Self::UInt(revive_common::BIT_LENGTH_FIELD)
}
}
@@ -79,7 +79,7 @@ impl Type {
D: era_compiler_llvm_context::EraVMDependency + Clone,
{
match self {
Self::Bool => context.integer_type(era_compiler_common::BIT_LENGTH_BOOLEAN),
Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN),
Self::Int(bitlength) => context.integer_type(bitlength),
Self::UInt(bitlength) => context.integer_type(bitlength),
Self::Custom(_) => context.field_type(),