Skip to content

Commit

Permalink
bump: inkwell beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Feb 5, 2021
1 parent c0185b7 commit feff1c4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ array-init="0.1.0"
tempfile = "3"
paste = "0.1.6"
parking_lot = "0.10"
inkwell = { version = "=0.1.0-llvm8sample", features = ["llvm8-0"]}
inkwell = { version = "=0.1.0-beta.2", features = ["llvm8-0", "no-libffi-linking"]}
by_address = "1.0.4"

[dev-dependencies]
Expand Down
17 changes: 12 additions & 5 deletions crates/mun_codegen/src/code_gen/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,18 @@ fn gen_get_info_fn<'ink>(
};

// Get access to the structs internals
let symbols_addr = unsafe { builder.build_struct_gep(result_ptr, 1, "symbols") };
let dispatch_table_addr = unsafe { builder.build_struct_gep(result_ptr, 3, "dispatch_table") };
let dependencies_addr = unsafe { builder.build_struct_gep(result_ptr, 5, "dependencies") };
let num_dependencies_addr =
unsafe { builder.build_struct_gep(result_ptr, 7, "num_dependencies") };
let symbols_addr = builder
.build_struct_gep(result_ptr, 1, "symbols")
.expect("could not retrieve `symbols` from result struct");
let dispatch_table_addr = builder
.build_struct_gep(result_ptr, 3, "dispatch_table")
.expect("could not retrieve `dispatch_table` from result struct");
let dependencies_addr = builder
.build_struct_gep(result_ptr, 5, "dependencies")
.expect("could not retrieve `dependencies` from result struct");
let num_dependencies_addr = builder
.build_struct_gep(result_ptr, 7, "num_dependencies")
.expect("could not retrieve `num_dependencies` from result struct");

// Assign the struct values one by one.
builder.build_store(symbols_addr, module_info.as_value(context).value);
Expand Down
23 changes: 17 additions & 6 deletions crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,19 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
let receiver_ptr = self
.opt_deref_value(receiver_expr, receiver_ptr.into())
.into_pointer_value();
let field_ptr = unsafe {
self.builder.build_struct_gep(
let field_ptr = self
.builder
.build_struct_gep(
receiver_ptr,
field_idx,
&format!("{}.{}_ptr", hir_struct_name, name),
)
};
.unwrap_or_else(|_| {
panic!(
"could not get pointer to field `{}::{}` at index {}",
hir_struct_name, name, field_idx
)
});
Some(self.builder.build_load(field_ptr, &field_ir_name))
} else {
let receiver_value = self.gen_expr(receiver_expr)?;
Expand Down Expand Up @@ -1389,13 +1395,18 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
let receiver_ptr = self
.opt_deref_value(receiver_expr, receiver_ptr.into())
.into_pointer_value();
unsafe {
self.builder.build_struct_gep(
self.builder
.build_struct_gep(
receiver_ptr,
field_idx,
&format!("{}.{}_ptr", hir_struct_name, name),
)
}
.unwrap_or_else(|_| {
panic!(
"could not get pointer to field `{}::{}` at index {}",
hir_struct_name, name, field_idx
)
})
}
}

Expand Down
11 changes: 8 additions & 3 deletions crates/mun_codegen/src/ir/dispatch_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ impl<'ink> DispatchTable<'ink> {
let table_ref = table_ref.expect("no dispatch table defined");

// Create an expression that finds the associated field in the table and returns this as a pointer access
let ptr_to_function_ptr = unsafe {
builder.build_struct_gep(
let ptr_to_function_ptr = builder
.build_struct_gep(
table_ref.as_pointer_value(),
index as u32,
&format!("{0}_ptr_ptr", function_name),
)
};
.unwrap_or_else(|_| {
panic!(
"could not get {} (index: {}) from dispatch table",
function_name, index
)
});

builder
.build_load(ptr_to_function_ptr, &format!("{0}_ptr", function_name))
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl_fundamental_static_type_info!(

impl<T: HasStaticTypeName> HasStaticTypeInfo for *mut T {
fn type_info(context: &Context, target: &TargetData) -> TypeInfo {
let ty = target.ptr_sized_int_type_in_context(context, None);
let ty = context.ptr_sized_int_type(target, None);
TypeInfo::new_fundamental(
format!("*mut {}", T::type_name(context, target)),
TypeSize::from_ir_type(&ty, target),
Expand All @@ -193,7 +193,7 @@ impl<T: HasStaticTypeName> HasStaticTypeInfo for *const T {
context: &inkwell::context::Context,
target: &inkwell::targets::TargetData,
) -> TypeInfo {
let ty = target.ptr_sized_int_type_in_context(context, None);
let ty = context.ptr_sized_int_type(target, None);
TypeInfo::new_fundamental(
format!("*const {}", T::type_name(context, target)),
TypeSize::from_ir_type(&ty, target),
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/array_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ macro_rules! impl_array_type {
$(
impl<'ink> ConstArrayType<'ink> for $inkwell_type {
fn const_array(self, values: &[<Self as TypeValue<'ink>>::Value]) -> inkwell::values::ArrayValue<'ink> {
<$inkwell_type>::const_array(&self, values)
<$inkwell_type>::const_array(self, values)
}
}

impl<'ink> ConstArrayValue<'ink> for $inkwell_value {
fn const_array(values: &[Self], ir_type: Self::Type) -> inkwell::values::ArrayValue<'ink> {
Self::Type::const_array(&ir_type, values)
Self::Type::const_array(ir_type, values)
}
}
)*
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ macro_rules! impl_value_type_value {
type Type = $ty;

fn get_type(&self) -> Self::Type {
Self::get_type(self)
Self::get_type(*self)
}
}
)*
Expand All @@ -235,7 +235,7 @@ macro_rules! impl_addressable_type_values {
$(
impl<'ink> AddressableTypeValue<'ink> for $ty {
fn ptr_type(&self, address_space: AddressSpace) -> inkwell::types::PointerType<'ink> {
Self::ptr_type(self, address_space)
Self::ptr_type(*self, address_space)
}
}
)*
Expand Down

0 comments on commit feff1c4

Please sign in to comment.