1
0
forked from M-Labs/nac3

core: Use anonymous name for variables if unspecified

The current default prefix is only derived from the instruction type,
which is not helpful during the comprehension of the IR. Changing to
anonymous names (e.g. %1) helps understand that the variable is only
needed as part of a larger (possibly named) expression.
This commit is contained in:
David Mak 2023-09-06 11:09:15 +08:00
parent f1b0e05b3d
commit 6de0884dc1

View File

@ -30,7 +30,7 @@ pub fn gen_var<'ctx, 'a>(
let current = ctx.builder.get_insert_block().unwrap();
// position before the last branching instruction...
ctx.builder.position_before(&ctx.init_bb.get_last_instruction().unwrap());
let ptr = ctx.builder.build_alloca(ty, name.unwrap_or("tmp"));
let ptr = ctx.builder.build_alloca(ty, name.unwrap_or(""));
ctx.builder.position_at_end(current);
Ok(ptr)
}
@ -76,7 +76,7 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
ctx.ctx.i32_type().const_zero(),
ctx.ctx.i32_type().const_int(index as u64, false),
],
name.unwrap_or("attr"),
name.unwrap_or(""),
)
}
}
@ -137,7 +137,7 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
let arr_ptr = ctx
.build_gep_and_load(v, &[i32_type.const_zero(), i32_type.const_zero()])
.into_pointer_value();
ctx.builder.build_gep(arr_ptr, &[index], name.unwrap_or("loadarrgep"))
ctx.builder.build_gep(arr_ptr, &[index], name.unwrap_or(""))
}
}
_ => unreachable!(),