diff --git a/src/frontend.rs b/src/frontend.rs index 6ddcf47..c3402b7 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -129,6 +129,7 @@ fn parse_body<'a, 'b>( builder.body.values.push(ValueDef { kind: ValueKind::Arg(arg_idx), ty: arg_ty, + local: Some(local_idx), }); trace!("defining local {} to value {}", local_idx, value); builder.locals.insert(local_idx, (arg_ty, value)); @@ -149,8 +150,6 @@ fn parse_body<'a, 'b>( Ok(ret) } -type LocalId = u32; - #[derive(Debug)] struct FunctionBodyBuilder<'a, 'b> { module: &'b Module<'a>, @@ -315,6 +314,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> { self.body.values.push(ValueDef { ty, kind: ValueKind::Inst(block, inst, 0), + local: Some(*local_index), }); value } else { @@ -887,6 +887,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> { self.body.values.push(ValueDef { kind: ValueKind::BlockParam(block, block_param_num), ty, + local: None, }); self.op_stack.push((ty, value_id)); block_param_num += 1; @@ -901,6 +902,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> { self.body.values.push(ValueDef { kind: ValueKind::BlockParam(block, block_param_num), ty, + local: Some(local_id), }); block_param_num += 1; self.locals.insert(local_id, (ty, value_id)); @@ -936,6 +938,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> { self.body.values.push(ValueDef { kind: ValueKind::Inst(block, inst, i), ty: output_ty, + local: None, }); self.op_stack.push((output_ty, val)); } diff --git a/src/ir.rs b/src/ir.rs index 9ed0d82..c93491c 100644 --- a/src/ir.rs +++ b/src/ir.rs @@ -9,6 +9,7 @@ pub type FuncId = usize; pub type BlockId = usize; pub type InstId = usize; pub type ValueId = usize; +pub type LocalId = u32; pub const NO_VALUE: ValueId = usize::MAX; @@ -46,6 +47,7 @@ pub struct FunctionBody<'a> { pub struct ValueDef { pub kind: ValueKind, pub ty: Type, + pub local: Option, } #[derive(Clone, Debug)]