use opaque pointer types everywhere

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-04-15 16:02:38 +02:00
parent 7aa27516e4
commit d6ae7daab1
7 changed files with 26 additions and 44 deletions
@@ -46,11 +46,10 @@ impl<'ctx> Intrinsics<'ctx> {
) -> Self { ) -> Self {
let void_type = llvm.void_type(); let void_type = llvm.void_type();
let bool_type = llvm.bool_type(); let bool_type = llvm.bool_type();
let byte_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32);
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_FIELD as u32);
let _stack_field_pointer_type = field_type.ptr_type(AddressSpace::Stack.into()); let _stack_field_pointer_type = llvm.ptr_type(AddressSpace::Stack.into());
let heap_field_pointer_type = byte_type.ptr_type(AddressSpace::Heap.into()); let heap_field_pointer_type = llvm.ptr_type(AddressSpace::Heap.into());
let generic_byte_pointer_type = byte_type.ptr_type(AddressSpace::Generic.into()); let generic_byte_pointer_type = llvm.ptr_type(AddressSpace::Generic.into());
let trap = Self::declare( let trap = Self::declare(
llvm, llvm,
@@ -130,20 +129,16 @@ impl<'ctx> Intrinsics<'ctx> {
match name { match name {
name if name == Self::FUNCTION_MEMORY_COPY => vec![ name if name == Self::FUNCTION_MEMORY_COPY => vec![
field_type llvm.ptr_type(AddressSpace::Heap.into())
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum(), .as_basic_type_enum(),
field_type llvm.ptr_type(AddressSpace::Heap.into())
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum(), .as_basic_type_enum(),
field_type.as_basic_type_enum(), field_type.as_basic_type_enum(),
], ],
name if name == Self::FUNCTION_MEMORY_COPY_FROM_GENERIC => vec![ name if name == Self::FUNCTION_MEMORY_COPY_FROM_GENERIC => vec![
field_type llvm.ptr_type(AddressSpace::Heap.into())
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum(), .as_basic_type_enum(),
field_type llvm.ptr_type(AddressSpace::Generic.into())
.ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(), .as_basic_type_enum(),
field_type.as_basic_type_enum(), field_type.as_basic_type_enum(),
], ],
@@ -186,8 +186,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
Self::FUNCTION_CXA_THROW, Self::FUNCTION_CXA_THROW,
llvm.void_type().fn_type( llvm.void_type().fn_type(
vec![ vec![
llvm.i8_type() llvm.ptr_type(AddressSpace::Stack.into())
.ptr_type(AddressSpace::Stack.into())
.as_basic_type_enum() .as_basic_type_enum()
.into(); .into();
3 3
@@ -432,8 +431,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
Self::FUNCTION_MSTORE8, Self::FUNCTION_MSTORE8,
llvm.void_type().fn_type( llvm.void_type().fn_type(
vec![ vec![
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32) llvm.ptr_type(AddressSpace::Heap.into())
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum() .as_basic_type_enum()
.into(), .into(),
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
@@ -463,8 +461,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type( .fn_type(
vec![ vec![
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32) llvm.ptr_type(AddressSpace::Heap.into())
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum() .as_basic_type_enum()
.into(), .into(),
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
@@ -503,8 +500,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum() .as_basic_type_enum()
.into(), .into(),
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.ptr_type(AddressSpace::Stack.into())
.ptr_type(AddressSpace::Stack.into())
.as_basic_type_enum() .as_basic_type_enum()
.into(), .into(),
] ]
@@ -537,8 +533,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
); );
let mut external_call_arguments_by_ref: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![ let mut external_call_arguments_by_ref: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32) llvm.ptr_type(AddressSpace::Generic.into())
.ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum() .as_basic_type_enum()
.into(), .into(),
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32) llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
@@ -563,8 +558,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
let external_call_result_type = llvm let external_call_result_type = llvm
.struct_type( .struct_type(
&[ &[
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32) llvm.ptr_type(AddressSpace::Generic.into())
.ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(), .as_basic_type_enum(),
llvm.bool_type().as_basic_type_enum(), llvm.bool_type().as_basic_type_enum(),
], ],
@@ -197,7 +197,7 @@ where
context.build_store(result_pointer, context.field_const(0))?; context.build_store(result_pointer, context.field_const(0))?;
let deployer_call_result_type = context.structure_type(&[ let deployer_call_result_type = context.structure_type(&[
context context
.byte_type() .llvm()
.ptr_type(AddressSpace::Generic.into()) .ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(), .as_basic_type_enum(),
context.bool_type().as_basic_type_enum(), context.bool_type().as_basic_type_enum(),
@@ -266,7 +266,7 @@ where
.const_zero(), .const_zero(),
], ],
context context
.byte_type() .llvm()
.ptr_type(AddressSpace::Generic.into()) .ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(), .as_basic_type_enum(),
"deployer_call_result_abi_data_pointer", "deployer_call_result_abi_data_pointer",
@@ -44,7 +44,7 @@ impl Entry {
context.set_global( context.set_global(
crate::eravm::GLOBAL_HEAP_MEMORY_POINTER, crate::eravm::GLOBAL_HEAP_MEMORY_POINTER,
context.byte_type().ptr_type(AddressSpace::Generic.into()), context.llvm().ptr_type(AddressSpace::Generic.into()),
AddressSpace::Stack, AddressSpace::Stack,
context.xlen_type().get_undef(), context.xlen_type().get_undef(),
); );
@@ -145,7 +145,7 @@ impl Entry {
input_pointer, input_pointer,
&[calldata_size_casted], &[calldata_size_casted],
context context
.byte_type() .llvm()
.ptr_type(AddressSpace::Generic.into()) .ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(), .as_basic_type_enum(),
"return_data_abi_initializer", "return_data_abi_initializer",
+6 -9
View File
@@ -990,7 +990,7 @@ where
self.set_basic_block(catch_block); self.set_basic_block(catch_block);
let landing_pad_type = self.structure_type(&[ let landing_pad_type = self.structure_type(&[
self.byte_type() self.llvm()
.ptr_type(AddressSpace::Stack.into()) .ptr_type(AddressSpace::Stack.into())
.as_basic_type_enum(), .as_basic_type_enum(),
self.integer_type(revive_common::BIT_LENGTH_X32) self.integer_type(revive_common::BIT_LENGTH_X32)
@@ -1001,7 +1001,7 @@ where
landing_pad_type, landing_pad_type,
self.llvm_runtime.personality.value, self.llvm_runtime.personality.value,
&[self &[self
.byte_type() .llvm()
.ptr_type(AddressSpace::Stack.into()) .ptr_type(AddressSpace::Stack.into())
.const_zero() .const_zero()
.as_basic_value_enum()], .as_basic_value_enum()],
@@ -1272,7 +1272,7 @@ where
let return_is_nil = self.builder().build_int_compare( let return_is_nil = self.builder().build_int_compare(
inkwell::IntPredicate::EQ, inkwell::IntPredicate::EQ,
end_of_memory, end_of_memory,
self.byte_type().ptr_type(Default::default()).const_null(), self.llvm().ptr_type(Default::default()).const_null(),
"compare_end_of_memory_nil", "compare_end_of_memory_nil",
)?; )?;
@@ -1350,7 +1350,7 @@ where
pub fn write_abi_pointer(&mut self, pointer: Pointer<'ctx>, global_name: &str) { pub fn write_abi_pointer(&mut self, pointer: Pointer<'ctx>, global_name: &str) {
self.set_global( self.set_global(
global_name, global_name,
self.byte_type().ptr_type(AddressSpace::Generic.into()), self.llvm().ptr_type(AddressSpace::Generic.into()),
AddressSpace::Stack, AddressSpace::Stack,
pointer.value, pointer.value,
); );
@@ -1528,11 +1528,8 @@ where
.void_type() .void_type()
.fn_type(argument_types.as_slice(), false), .fn_type(argument_types.as_slice(), false),
1 => self.field_type().fn_type(argument_types.as_slice(), false), 1 => self.field_type().fn_type(argument_types.as_slice(), false),
size if is_near_call_abi && self.is_system_mode() => { _size if is_near_call_abi && self.is_system_mode() => {
let return_types: Vec<_> = vec![self.field_type().as_basic_type_enum(); size]; let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
let return_type = self
.structure_type(return_types.as_slice())
.ptr_type(AddressSpace::Stack.into());
argument_types.insert(0, return_type.as_basic_type_enum().into()); argument_types.insert(0, return_type.as_basic_type_enum().into());
return_type.fn_type(argument_types.as_slice(), false) return_type.fn_type(argument_types.as_slice(), false)
} }
@@ -81,11 +81,7 @@ impl<'ctx> Pointer<'ctx> {
let offset = context.safe_truncate_int_to_i32(offset).unwrap(); let offset = context.safe_truncate_int_to_i32(offset).unwrap();
let value = context let value = context
.builder .builder
.build_int_to_ptr( .build_int_to_ptr(offset, context.llvm().ptr_type(address_space.into()), name)
offset,
context.byte_type().ptr_type(address_space.into()),
name,
)
.unwrap(); .unwrap();
Self::new(r#type, address_space, value) Self::new(r#type, address_space, value)
} }
@@ -115,7 +111,7 @@ impl<'ctx> Pointer<'ctx> {
{ {
let value = context.builder().build_address_space_cast( let value = context.builder().build_address_space_cast(
self.value, self.value,
self.r#type.ptr_type(address_space.into()), context.llvm().ptr_type(address_space.into()),
name, name,
)?; )?;
+1 -1
View File
@@ -54,7 +54,7 @@ where
context.build_call( context.build_call(
context.llvm_runtime().cxa_throw, context.llvm_runtime().cxa_throw,
&[context &[context
.byte_type() .llvm()
.ptr_type(AddressSpace::Stack.into()) .ptr_type(AddressSpace::Stack.into())
.get_undef() .get_undef()
.as_basic_value_enum(); 3], .as_basic_value_enum(); 3],