From 684d5a04a928ea4132d0c5e61bb4086fac9feb22 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 19 Apr 2026 15:12:25 +0200 Subject: feat: lazy memory allocation, fix instruction rewrite order Signed-off-by: Henry --- crates/parser/src/lib.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'crates/parser/src/lib.rs') diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index ad58cc2..0b5af2e 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -43,8 +43,30 @@ pub use tinywasm_types::TinyWasmModule; /// Parser optimization and lowering options. #[non_exhaustive] -#[derive(Debug, Clone, Default)] -pub struct ParserOptions {} +#[derive(Debug, Clone)] +pub struct ParserOptions { + /// Whether to optimize local memory allocation by skipping allocation of unused local memories. + pub optimize_local_memory_allocation: bool, +} + +impl Default for ParserOptions { + fn default() -> Self { + Self { optimize_local_memory_allocation: true } + } +} + +impl ParserOptions { + /// Enable or disable the optimization that skips allocating unused local memories. + pub const fn with_local_memory_allocation_optimization(mut self, enabled: bool) -> Self { + self.optimize_local_memory_allocation = enabled; + self + } + + /// Returns whether unused local memory allocation optimization is enabled. + pub const fn optimize_local_memory_allocation(&self) -> bool { + self.optimize_local_memory_allocation + } +} /// A WebAssembly parser #[derive(Debug, Default)] -- cgit v1.3.1