mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Build erased load in llvm
This commit is contained in:
parent
fcb907b0c9
commit
f37cc48e88
2 changed files with 35 additions and 2 deletions
|
@ -1,8 +1,9 @@
|
|||
use inkwell::{
|
||||
types::StructType,
|
||||
types::{PointerType, StructType},
|
||||
values::{PointerValue, StructValue},
|
||||
AddressSpace,
|
||||
};
|
||||
use roc_mono::ir::ErasedField;
|
||||
|
||||
use super::build::Env;
|
||||
|
||||
|
@ -64,3 +65,28 @@ pub fn build<'a, 'ctx>(
|
|||
|
||||
struct_value.into_struct_value()
|
||||
}
|
||||
|
||||
pub fn load<'ctx>(
|
||||
env: &Env<'_, 'ctx, '_>,
|
||||
erasure: StructValue<'ctx>,
|
||||
field: ErasedField,
|
||||
as_type: PointerType<'ctx>,
|
||||
) -> PointerValue<'ctx> {
|
||||
let index = match field {
|
||||
ErasedField::Value => 0,
|
||||
ErasedField::Callee => 1,
|
||||
};
|
||||
|
||||
let value = env
|
||||
.builder
|
||||
.build_extract_value(erasure, index, "extract_value")
|
||||
.unwrap()
|
||||
.into_pointer_value();
|
||||
|
||||
let value = env
|
||||
.builder
|
||||
.build_bitcast(value, as_type, "bitcast_to_type")
|
||||
.into_pointer_value();
|
||||
|
||||
value
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue