core: Rename IR variables
Because it is unclear which variables are expressions and subexpressions, all variables which are previously anonymous are named using (1) the control flow statement if available, (2) the possible name of the variable as inferred from the variable name in Rust, and (3) the "addr" prefix to indicate that the values are pointers. These three strings are joint together using '.', forming "for.i.addr" for instance.
This commit is contained in:
parent
ff23968544
commit
f1b0e05b3d
|
@ -84,7 +84,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap();
|
||||
let end_store = self.gen_store_target(ctx, &end, None)?;
|
||||
let end_store = self.gen_store_target(ctx, &end, Some("end_store.addr"))?;
|
||||
ctx.builder.build_store(end_store, max);
|
||||
}
|
||||
if let Some(start) = self.start.clone() {
|
||||
|
@ -140,7 +140,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
node: ExprKind::Name { id: start, ctx: name_ctx.clone() },
|
||||
custom: Some(ctx.primitives.int64),
|
||||
};
|
||||
let start = self.gen_store_target(ctx, &start_expr, None)?;
|
||||
let start = self.gen_store_target(ctx, &start_expr, Some("start.addr"))?;
|
||||
ctx.builder.build_store(start, now);
|
||||
Ok(Some(start_expr)) as Result<_, String>
|
||||
},
|
||||
|
@ -153,7 +153,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
node: ExprKind::Name { id: end, ctx: name_ctx.clone() },
|
||||
custom: Some(ctx.primitives.int64),
|
||||
};
|
||||
let end = self.gen_store_target(ctx, &end_expr, None)?;
|
||||
let end = self.gen_store_target(ctx, &end_expr, Some("end.addr"))?;
|
||||
ctx.builder.build_store(end, now);
|
||||
self.end = Some(end_expr);
|
||||
self.name_counter += 1;
|
||||
|
@ -204,7 +204,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap();
|
||||
let outer_end = self.gen_store_target(ctx, old_end, None)?;
|
||||
let outer_end = self.gen_store_target(ctx, old_end, Some("outer_end.addr"))?;
|
||||
ctx.builder.build_store(outer_end, max);
|
||||
}
|
||||
self.start = old_start;
|
||||
|
|
|
@ -810,7 +810,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
let zero_size_t = size_t.const_zero();
|
||||
let zero_32 = int32.const_zero();
|
||||
|
||||
let index = generator.gen_var_alloc(ctx, size_t.into(), None)?;
|
||||
let index = generator.gen_var_alloc(ctx, size_t.into(), Some("index.addr"))?;
|
||||
ctx.builder.build_store(index, zero_size_t);
|
||||
|
||||
let elem_ty = ctx.get_llvm_type(generator, elt.custom.unwrap());
|
||||
|
@ -853,7 +853,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
list_content =
|
||||
ctx.build_gep_and_load(list, &[zero_size_t, zero_32]).into_pointer_value();
|
||||
|
||||
let i = generator.gen_store_target(ctx, target, None)?;
|
||||
let i = generator.gen_store_target(ctx, target, Some("i.addr"))?;
|
||||
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
ctx.builder.position_at_end(test_bb);
|
||||
|
@ -888,7 +888,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
list = allocate_list(generator, ctx, elem_ty, length);
|
||||
list_content =
|
||||
ctx.build_gep_and_load(list, &[zero_size_t, zero_32]).into_pointer_value();
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), None)?;
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("counter.addr"))?;
|
||||
// counter = -1
|
||||
ctx.builder.build_store(counter, size_t.const_int(u64::max_value(), true));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
|
|
|
@ -193,7 +193,7 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
let ptr = generator.gen_store_target(ctx, target, None)?;
|
||||
let ptr = generator.gen_store_target(ctx, target, Some("target.addr"))?;
|
||||
if let ExprKind::Name { id, .. } = &target.node {
|
||||
let (_, static_value, counter) = ctx.var_assignment.get_mut(id).unwrap();
|
||||
*counter += 1;
|
||||
|
@ -239,8 +239,8 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||
if ctx.unifier.unioned(iter.custom.unwrap(), ctx.primitives.range) {
|
||||
// setup
|
||||
let iter_val = iter_val.into_pointer_value();
|
||||
let i = generator.gen_var_alloc(ctx, int32.into(), None)?;
|
||||
let user_i = generator.gen_store_target(ctx, target, None)?;
|
||||
let i = generator.gen_var_alloc(ctx, int32.into(), Some("for.i.addr"))?;
|
||||
let user_i = generator.gen_store_target(ctx, target, Some("for.user_i.addr"))?;
|
||||
let (start, end, step) = destructure_range(ctx, iter_val);
|
||||
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
|
@ -272,7 +272,7 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||
);
|
||||
ctx.builder.position_at_end(body_bb);
|
||||
} else {
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), None)?;
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("for.counter.addr"))?;
|
||||
// counter = -1
|
||||
ctx.builder.build_store(counter, size_t.const_int(u64::max_value(), true));
|
||||
let len = ctx
|
||||
|
@ -657,7 +657,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
|
|||
let mut final_data = None;
|
||||
let has_cleanup = !finalbody.is_empty();
|
||||
if has_cleanup {
|
||||
let final_state = generator.gen_var_alloc(ctx, ptr_type.into(), None)?;
|
||||
let final_state = generator.gen_var_alloc(ctx, ptr_type.into(), Some("try.final_state.addr"))?;
|
||||
final_data = Some((final_state, Vec::new(), Vec::new()));
|
||||
if let Some((continue_target, break_target)) = ctx.loop_target {
|
||||
let break_proxy = ctx.ctx.append_basic_block(current_fun, "try.break");
|
||||
|
@ -823,7 +823,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
|
|||
ctx.builder.position_at_end(handler_bb);
|
||||
if let Some(name) = name {
|
||||
let exn_ty = ctx.get_llvm_type(generator, type_.as_ref().unwrap().custom.unwrap());
|
||||
let exn_store = generator.gen_var_alloc(ctx, exn_ty, None)?;
|
||||
let exn_store = generator.gen_var_alloc(ctx, exn_ty, Some("try.exn_store.addr"))?;
|
||||
ctx.var_assignment.insert(*name, (exn_store, None, 0));
|
||||
ctx.builder.build_store(exn_store, exn.as_basic_value());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue