refactor Access into AccessAtIndex

This commit is contained in:
Folkert 2020-03-22 20:14:15 +01:00
parent 18f34710e1
commit e2a7c970bc
4 changed files with 43 additions and 94 deletions

View file

@ -281,36 +281,6 @@ pub fn build_expr<'a, B: Backend>(
.ins()
.stack_addr(cfg.pointer_type(), slot, Offset32::new(0))
}
Access {
label,
field_layout,
struct_layout: Layout::Struct(sorted_fields),
record,
} => {
let cfg = env.cfg;
// Find the offset we are trying to access
let mut offset = 0;
for (local_label, local_field_layout) in sorted_fields.iter() {
if local_label == label {
break;
}
offset += local_field_layout.stack_size(ptr_bytes);
}
let offset = i32::try_from(offset)
.expect("TODO gracefully handle usize -> i32 conversion in struct access");
let mem_flags = MemFlags::new();
let record = build_expr(env, scope, module, builder, record, procs);
let field_type = type_from_layout(cfg, field_layout);
builder
.ins()
.load(field_type, mem_flags, record, Offset32::new(offset))
}
AccessAtIndex {
index,
field_layouts,

View file

@ -72,9 +72,6 @@ pub fn build_expr<'a, 'ctx, 'env>(
build_branch2(env, scope, parent, conditional, procs)
}
Branches { .. } => {
panic!("TODO build_branches(env, scope, parent, cond_lhs, branches, procs)");
}
Switch {
cond,
branches,
@ -476,27 +473,6 @@ pub fn build_expr<'a, 'ctx, 'env>(
.unwrap();
wrapper_val.into_struct_value().into()
}
Access {
label,
struct_layout: Layout::Struct(sorted_fields),
record,
..
} => {
let builder = env.builder;
// Get index
let index = sorted_fields
.iter()
.position(|(local_label, _)| local_label == label)
.unwrap() as u32; // TODO
// Get Struct val
let struct_val = build_expr(env, &scope, parent, record, procs).into_struct_value();
builder
.build_extract_value(struct_val, index, "field_access")
.unwrap()
}
AccessAtIndex {
index,
expr,