From 3e21bb741184ec10b32f55974960a9a5595f81d4 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Sat, 13 Nov 2021 23:02:47 -0800 Subject: [PATCH] Add info about disjoint local indices to values. --- src/frontend.rs | 7 +++++-- src/ir.rs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) 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)]