From a6a683ec16322df2307446f53c478b41128b8908 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 4 Nov 2022 21:37:08 +0100 Subject: [PATCH] Expose more mutability --- src/ir/mod.rs | 3 ++- src/module/locals.rs | 5 +++++ src/ty.rs | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ir/mod.rs b/src/ir/mod.rs index b6c5e385..7123a2e8 100644 --- a/src/ir/mod.rs +++ b/src/ir/mod.rs @@ -23,7 +23,8 @@ pub type LocalId = Id; #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Local { id: LocalId, - ty: ValType, + /// The type of this local + pub ty: ValType, /// A human-readable name for this local, often useful when debugging pub name: Option, } diff --git a/src/module/locals.rs b/src/module/locals.rs index 3567d727..b0f334c8 100644 --- a/src/module/locals.rs +++ b/src/module/locals.rs @@ -34,4 +34,9 @@ impl ModuleLocals { pub fn iter(&self) -> impl Iterator { self.arena.iter().map(|(_, f)| f) } + + /// Get a mutable reference to this module's globals. + pub fn iter_mut(&mut self) -> impl Iterator { + self.arena.iter_mut().map(|(_, f)| f) + } } diff --git a/src/ty.rs b/src/ty.rs index bcbede96..f0b1946a 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -117,6 +117,18 @@ impl Type { &*self.results } + /// Get the parameters to this function type. + #[inline] + pub fn params_mut(&mut self) -> &mut [ValType] { + &mut *self.params + } + + /// Get the results of this function type. + #[inline] + pub fn results_mut(&mut self) -> &mut [ValType] { + &mut *self.results + } + pub(crate) fn is_for_function_entry(&self) -> bool { self.is_for_function_entry }