From 6de0884dc13b648bcd0f8191f7beb6c76b1af3d5 Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 6 Sep 2023 11:09:15 +0800 Subject: [PATCH] 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. --- nac3core/src/codegen/stmt.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 851cc110..cf339bd1 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -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!(), -- 2.44.2