mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 05:41:08 +00:00
@@ -11,7 +11,7 @@ pub struct Build {
|
||||
/// The PolkaVM text assembly.
|
||||
pub assembly_text: String,
|
||||
/// The metadata hash.
|
||||
pub metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
||||
pub metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||
/// The PolkaVM binary bytecode.
|
||||
pub bytecode: Vec<u8>,
|
||||
/// The PolkaVM bytecode hash.
|
||||
@@ -24,7 +24,7 @@ impl Build {
|
||||
/// A shortcut constructor.
|
||||
pub fn new(
|
||||
assembly_text: String,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||
bytecode: Vec<u8>,
|
||||
bytecode_hash: String,
|
||||
) -> Self {
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<'ctx> Intrinsics<'ctx> {
|
||||
) -> Self {
|
||||
let void_type = llvm.void_type();
|
||||
let bool_type = llvm.bool_type();
|
||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
|
||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32);
|
||||
let _stack_field_pointer_type = llvm.ptr_type(AddressSpace::Stack.into());
|
||||
let heap_field_pointer_type = llvm.ptr_type(AddressSpace::Heap.into());
|
||||
let generic_byte_pointer_type = llvm.ptr_type(AddressSpace::Generic.into());
|
||||
@@ -114,7 +114,7 @@ impl<'ctx> Intrinsics<'ctx> {
|
||||
llvm: &'ctx inkwell::context::Context,
|
||||
name: &str,
|
||||
) -> Vec<inkwell::types::BasicTypeEnum<'ctx>> {
|
||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
|
||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32);
|
||||
|
||||
match name {
|
||||
name if name == Self::FUNCTION_MEMORY_COPY => vec![
|
||||
|
||||
@@ -187,10 +187,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let div = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_DIV,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -206,10 +206,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let r#mod = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_MOD,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -225,10 +225,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sdiv = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SDIV,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -244,10 +244,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let smod = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SMOD,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -263,10 +263,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let shl = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SHL,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -282,10 +282,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let shr = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SHR,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -301,10 +301,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sar = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SAR,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -320,10 +320,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let byte = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_BYTE,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
2
|
||||
@@ -358,13 +358,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sha3 = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SHA3,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.ptr_type(AddressSpace::Heap.into())
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32)
|
||||
@@ -388,16 +388,16 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let system_request = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SYSTEM_REQUEST,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.ptr_type(AddressSpace::Stack.into())
|
||||
@@ -412,7 +412,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Function::set_default_attributes(llvm, system_request, optimizer);
|
||||
|
||||
let external_call_arguments: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
crate::polkavm::context::function::runtime::entry::Entry::MANDATORY_ARGUMENTS_COUNT
|
||||
@@ -420,7 +420,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
];
|
||||
let mut mimic_call_arguments = external_call_arguments.clone();
|
||||
mimic_call_arguments.push(
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
);
|
||||
@@ -429,13 +429,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
llvm.ptr_type(AddressSpace::Generic.into())
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
];
|
||||
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
|
||||
llvm.custom_width_int_type(
|
||||
revive_common::BIT_LENGTH_FIELD as u32
|
||||
revive_common::BIT_LENGTH_WORD as u32
|
||||
)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
@@ -443,7 +443,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
]);
|
||||
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
|
||||
mimic_call_arguments_by_ref.push(
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
);
|
||||
@@ -522,7 +522,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Self::FUNCTION_RETURN,
|
||||
llvm.void_type().fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
3
|
||||
@@ -538,7 +538,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Self::FUNCTION_REVERT,
|
||||
llvm.void_type().fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
3
|
||||
|
||||
@@ -49,7 +49,7 @@ impl<'ctx> Return<'ctx> {
|
||||
|
||||
/// Returns the return data size in bytes, based on the default stack alignment.
|
||||
pub fn return_data_size(&self) -> usize {
|
||||
revive_common::BYTE_LENGTH_FIELD
|
||||
revive_common::BYTE_LENGTH_WORD
|
||||
* match self {
|
||||
Self::None => 0,
|
||||
Self::Primitive { .. } => 1,
|
||||
|
||||
@@ -81,12 +81,12 @@ where
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type = context.function_type(
|
||||
vec![
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
],
|
||||
1,
|
||||
false,
|
||||
@@ -144,7 +144,7 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
let status_code_result_pointer = context.build_alloca(
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"contract_call_result_status_code_pointer",
|
||||
);
|
||||
/*
|
||||
|
||||
@@ -62,19 +62,19 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Deploy);
|
||||
if let Some(vyper) = context.vyper_data.as_ref() {
|
||||
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_FIELD {
|
||||
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_WORD {
|
||||
let offset = (crate::polkavm::r#const::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||
as usize)
|
||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_FIELD;
|
||||
let value = index * revive_common::BYTE_LENGTH_FIELD;
|
||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_WORD;
|
||||
let value = index * revive_common::BYTE_LENGTH_WORD;
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(offset as u64),
|
||||
context.word_type(),
|
||||
context.word_const(offset as u64),
|
||||
"immutable_index_initializer",
|
||||
);
|
||||
context.build_store(pointer, context.field_const(value as u64))?;
|
||||
context.build_store(pointer, context.word_const(value as u64))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ where
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type = context.function_type(
|
||||
vec![
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
],
|
||||
1,
|
||||
false,
|
||||
@@ -124,7 +124,7 @@ where
|
||||
let signature_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
input_offset,
|
||||
"deployer_call_signature_pointer",
|
||||
);
|
||||
@@ -132,13 +132,13 @@ where
|
||||
|
||||
let salt_offset = context.builder().build_int_add(
|
||||
input_offset,
|
||||
context.field_const(revive_common::BYTE_LENGTH_X32 as u64),
|
||||
context.word_const(revive_common::BYTE_LENGTH_X32 as u64),
|
||||
"deployer_call_salt_offset",
|
||||
)?;
|
||||
let salt_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
salt_offset,
|
||||
"deployer_call_salt_pointer",
|
||||
);
|
||||
@@ -146,47 +146,47 @@ where
|
||||
|
||||
let arguments_offset_offset = context.builder().build_int_add(
|
||||
salt_offset,
|
||||
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
|
||||
context.word_const((revive_common::BYTE_LENGTH_WORD * 2) as u64),
|
||||
"deployer_call_arguments_offset_offset",
|
||||
)?;
|
||||
let arguments_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
arguments_offset_offset,
|
||||
"deployer_call_arguments_offset_pointer",
|
||||
);
|
||||
context.build_store(
|
||||
arguments_offset_pointer,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE
|
||||
- (revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD))
|
||||
- (revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD))
|
||||
as u64,
|
||||
),
|
||||
)?;
|
||||
|
||||
let arguments_length_offset = context.builder().build_int_add(
|
||||
arguments_offset_offset,
|
||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
||||
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||
"deployer_call_arguments_length_offset",
|
||||
)?;
|
||||
let arguments_length_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
arguments_length_offset,
|
||||
"deployer_call_arguments_length_pointer",
|
||||
);
|
||||
let arguments_length_value = context.builder().build_int_sub(
|
||||
input_length,
|
||||
context.field_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64),
|
||||
context.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64),
|
||||
"deployer_call_arguments_length",
|
||||
)?;
|
||||
context.build_store(arguments_length_pointer, arguments_length_value)?;
|
||||
|
||||
let result_pointer =
|
||||
context.build_alloca(context.field_type(), "deployer_call_result_pointer");
|
||||
context.build_store(result_pointer, context.field_const(0))?;
|
||||
context.build_alloca(context.word_type(), "deployer_call_result_pointer");
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
let deployer_call_result_type = context.structure_type(&[
|
||||
context
|
||||
.llvm()
|
||||
@@ -203,7 +203,7 @@ where
|
||||
let is_value_zero = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
value,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
"deployer_call_is_value_zero",
|
||||
)?;
|
||||
context.build_conditional_branch(is_value_zero, value_zero_block, value_non_zero_block)?;
|
||||
@@ -252,7 +252,7 @@ where
|
||||
let result_abi_data_pointer = context.build_gep(
|
||||
deployer_call_result_pointer,
|
||||
&[
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
context
|
||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||
.const_zero(),
|
||||
@@ -269,7 +269,7 @@ where
|
||||
let result_status_code_pointer = context.build_gep(
|
||||
deployer_call_result_pointer,
|
||||
&[
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
context
|
||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||
.const_int(1, false),
|
||||
@@ -288,7 +288,7 @@ where
|
||||
|
||||
context.set_basic_block(success_block);
|
||||
let result_abi_data_pointer = Pointer::new(
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Generic,
|
||||
result_abi_data.into_pointer_value(),
|
||||
);
|
||||
|
||||
@@ -55,26 +55,26 @@ impl Entry {
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_undef(),
|
||||
context.word_undef(),
|
||||
);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALL_FLAGS,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
);
|
||||
|
||||
let extra_abi_data_type = context.array_type(
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
crate::polkavm::EXTRA_ABI_DATA_SIZE,
|
||||
);
|
||||
context.set_global(
|
||||
@@ -84,6 +84,13 @@ impl Entry {
|
||||
extra_abi_data_type.const_zero(),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_WORD_SIZE,
|
||||
context.xlen_type(),
|
||||
AddressSpace::Stack,
|
||||
context.integer_const(crate::polkavm::XLEN, revive_common::BYTE_LENGTH_WORD as u64),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -125,12 +132,12 @@ impl Entry {
|
||||
.into_int_value();
|
||||
let calldata_size_casted = context.builder().build_int_z_extend(
|
||||
calldata_size,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"zext_input_len",
|
||||
)?;
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
calldata_size_casted,
|
||||
);
|
||||
|
||||
@@ -230,7 +230,7 @@ where
|
||||
pub fn build(
|
||||
mut self,
|
||||
contract_path: &str,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||
) -> anyhow::Result<Build> {
|
||||
let module_clone = self.module.clone();
|
||||
|
||||
@@ -437,12 +437,12 @@ where
|
||||
0 => FunctionReturn::none(),
|
||||
1 => {
|
||||
self.set_basic_block(entry_block);
|
||||
let pointer = self.build_alloca(self.field_type(), "return_pointer");
|
||||
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
||||
FunctionReturn::primitive(pointer)
|
||||
}
|
||||
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
||||
let first_argument = value.get_first_param().expect("Always exists");
|
||||
let r#type = self.structure_type(vec![self.field_type(); size].as_slice());
|
||||
let r#type = self.structure_type(vec![self.word_type(); size].as_slice());
|
||||
let pointer = first_argument.into_pointer_value();
|
||||
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
||||
}
|
||||
@@ -450,7 +450,7 @@ where
|
||||
self.set_basic_block(entry_block);
|
||||
let pointer = self.build_alloca(
|
||||
self.structure_type(
|
||||
vec![self.field_type().as_basic_type_enum(); size].as_slice(),
|
||||
vec![self.word_type().as_basic_type_enum(); size].as_slice(),
|
||||
),
|
||||
"return_pointer",
|
||||
);
|
||||
@@ -561,7 +561,7 @@ where
|
||||
.ok_or_else(|| anyhow::anyhow!("The dependency manager is unset"))
|
||||
.and_then(|manager| {
|
||||
let address = manager.resolve_library(path)?;
|
||||
let address = self.field_const_str_hex(address.as_str());
|
||||
let address = self.word_const_str_hex(address.as_str());
|
||||
Ok(address)
|
||||
})
|
||||
}
|
||||
@@ -647,7 +647,7 @@ where
|
||||
AddressSpace::Storage => {
|
||||
let storage_key_value = self.builder().build_ptr_to_int(
|
||||
pointer.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"storage_ptr_to_int",
|
||||
)?;
|
||||
let storage_key_pointer =
|
||||
@@ -658,7 +658,7 @@ where
|
||||
"storage_key_pointer_casted",
|
||||
)?;
|
||||
|
||||
let storage_value_pointer = self.build_alloca(self.field_type(), "storage_value");
|
||||
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
||||
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
||||
storage_value_pointer.value,
|
||||
self.xlen_type(),
|
||||
@@ -679,7 +679,7 @@ where
|
||||
storage_value_length_pointer.value,
|
||||
self.integer_const(
|
||||
crate::polkavm::XLEN,
|
||||
revive_common::BIT_LENGTH_FIELD as u64,
|
||||
revive_common::BYTE_LENGTH_WORD as u64,
|
||||
),
|
||||
)?;
|
||||
|
||||
@@ -745,7 +745,7 @@ where
|
||||
|
||||
let value = value.as_basic_value_enum();
|
||||
let value = match value.get_type().into_int_type().get_bit_width() as usize {
|
||||
revive_common::BIT_LENGTH_FIELD => self.build_byte_swap(value),
|
||||
revive_common::BIT_LENGTH_WORD => self.build_byte_swap(value),
|
||||
revive_common::BIT_LENGTH_BYTE => value,
|
||||
_ => unreachable!("Only word and byte sized values can be stored on EVM heap"),
|
||||
};
|
||||
@@ -759,7 +759,7 @@ where
|
||||
AddressSpace::Storage => {
|
||||
let storage_key_value = self.builder().build_ptr_to_int(
|
||||
pointer.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"storage_ptr_to_int",
|
||||
)?;
|
||||
let storage_key_pointer =
|
||||
@@ -1052,18 +1052,18 @@ where
|
||||
) -> anyhow::Result<()> {
|
||||
let pointer_casted = self.builder.build_ptr_to_int(
|
||||
source.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
format!("{name}_pointer_casted").as_str(),
|
||||
)?;
|
||||
let return_data_size_shifted = self.builder.build_right_shift(
|
||||
pointer_casted,
|
||||
self.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
||||
self.word_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
||||
false,
|
||||
format!("{name}_return_data_size_shifted").as_str(),
|
||||
)?;
|
||||
let return_data_size_truncated = self.builder.build_and(
|
||||
return_data_size_shifted,
|
||||
self.field_const(u32::MAX as u64),
|
||||
self.word_const(u32::MAX as u64),
|
||||
format!("{name}_return_data_size_truncated").as_str(),
|
||||
)?;
|
||||
let is_return_data_size_lesser = self.builder.build_int_compare(
|
||||
@@ -1162,7 +1162,7 @@ where
|
||||
)?;
|
||||
let extended = self.builder().build_int_z_extend_or_bit_cast(
|
||||
truncated,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"offset_extended",
|
||||
)?;
|
||||
let is_overflow = self.builder().build_int_compare(
|
||||
@@ -1337,26 +1337,26 @@ where
|
||||
self.integer_type(bit_length).const_int(value, false)
|
||||
}
|
||||
|
||||
/// Returns a 256-bit field type constant.
|
||||
pub fn field_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type().const_int(value, false)
|
||||
/// Returns a word type constant.
|
||||
pub fn word_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type().const_int(value, false)
|
||||
}
|
||||
|
||||
/// Returns a 256-bit field type undefined value.
|
||||
pub fn field_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type().get_undef()
|
||||
/// Returns a word type undefined value.
|
||||
pub fn word_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type().get_undef()
|
||||
}
|
||||
|
||||
/// Returns a field type constant from a decimal string.
|
||||
pub fn field_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type()
|
||||
/// Returns a word type constant from a decimal string.
|
||||
pub fn word_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type()
|
||||
.const_int_from_string(value, inkwell::types::StringRadix::Decimal)
|
||||
.unwrap_or_else(|| panic!("Invalid string constant `{value}`"))
|
||||
}
|
||||
|
||||
/// Returns a field type constant from a hexadecimal string.
|
||||
pub fn field_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type()
|
||||
/// Returns a word type constant from a hexadecimal string.
|
||||
pub fn word_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type()
|
||||
.const_int_from_string(
|
||||
value.strip_prefix("0x").unwrap_or(value),
|
||||
inkwell::types::StringRadix::Hexadecimal,
|
||||
@@ -1396,10 +1396,10 @@ where
|
||||
.custom_width_int_type(revive_common::BIT_LENGTH_VALUE as u32)
|
||||
}
|
||||
|
||||
/// Returns the default field type.
|
||||
pub fn field_type(&self) -> inkwell::types::IntType<'ctx> {
|
||||
/// Returns the default word type.
|
||||
pub fn word_type(&self) -> inkwell::types::IntType<'ctx> {
|
||||
self.llvm
|
||||
.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
||||
.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
}
|
||||
|
||||
/// Returns the array type with the specified length.
|
||||
@@ -1441,14 +1441,14 @@ where
|
||||
.llvm
|
||||
.void_type()
|
||||
.fn_type(argument_types.as_slice(), false),
|
||||
1 => self.field_type().fn_type(argument_types.as_slice(), false),
|
||||
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
||||
_size if is_near_call_abi && self.is_system_mode() => {
|
||||
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
||||
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
||||
return_type.fn_type(argument_types.as_slice(), false)
|
||||
}
|
||||
size => self
|
||||
.structure_type(vec![self.field_type().as_basic_type_enum(); size].as_slice())
|
||||
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
||||
.fn_type(argument_types.as_slice(), false),
|
||||
}
|
||||
}
|
||||
@@ -1508,14 +1508,14 @@ where
|
||||
inkwell::attributes::AttributeLoc::Param(index as u32),
|
||||
self.llvm.create_enum_attribute(
|
||||
Attribute::Dereferenceable as u32,
|
||||
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
|
||||
(revive_common::BIT_LENGTH_WORD * 2) as u64,
|
||||
),
|
||||
);
|
||||
call_site_value.add_attribute(
|
||||
inkwell::attributes::AttributeLoc::Return,
|
||||
self.llvm.create_enum_attribute(
|
||||
Attribute::Dereferenceable as u32,
|
||||
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
|
||||
(revive_common::BIT_LENGTH_WORD * 2) as u64,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl<'ctx> Pointer<'ctx> {
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
Self {
|
||||
r#type: context.field_type().as_basic_type_enum(),
|
||||
r#type: context.word_type().as_basic_type_enum(),
|
||||
address_space: AddressSpace::Stack,
|
||||
value,
|
||||
}
|
||||
@@ -88,6 +88,17 @@ impl<'ctx> Pointer<'ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Cast this pointer to a register sized integer value.
|
||||
pub fn to_int<D>(&self, context: &Context<'ctx, D>) -> inkwell::values::IntValue<'ctx>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
context
|
||||
.builder()
|
||||
.build_ptr_to_int(self.value, context.xlen_type(), "ptr_to_xlen")
|
||||
.expect("we should be positioned")
|
||||
}
|
||||
|
||||
pub fn address_space_cast<D>(
|
||||
self,
|
||||
context: &Context<'ctx, D>,
|
||||
|
||||
@@ -19,14 +19,14 @@ impl SolidityData {
|
||||
|
||||
/// Returns the current number of immutables values in the contract.
|
||||
pub fn immutables_size(&self) -> usize {
|
||||
self.immutables.len() * revive_common::BYTE_LENGTH_FIELD
|
||||
self.immutables.len() * revive_common::BYTE_LENGTH_WORD
|
||||
}
|
||||
|
||||
/// Allocates memory for an immutable value in the auxiliary heap.
|
||||
/// If the identifier is already known, just returns its offset.
|
||||
pub fn allocate_immutable(&mut self, identifier: &str) -> usize {
|
||||
let number_of_elements = self.immutables.len();
|
||||
let new_offset = number_of_elements * revive_common::BYTE_LENGTH_FIELD;
|
||||
let new_offset = number_of_elements * revive_common::BYTE_LENGTH_WORD;
|
||||
*self
|
||||
.immutables
|
||||
.entry(identifier.to_owned())
|
||||
|
||||
@@ -27,8 +27,8 @@ pub fn check_attribute_null_pointer_is_invalid() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -50,8 +50,8 @@ pub fn check_attribute_optimize_for_size_mode_3() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -73,8 +73,8 @@ pub fn check_attribute_optimize_for_size_mode_z() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -96,8 +96,8 @@ pub fn check_attribute_min_size_mode_3() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -119,8 +119,8 @@ pub fn check_attribute_min_size_mode_z() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user