summaryrefslogtreecommitdiff
path: root/crates/parser/src/lib.rs
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-04-25 14:06:04 +0200
committerHenry <mail@henrygressmann.de>2026-04-25 14:06:04 +0200
commit4d829a824834b470ada9981ab3ab2caa3e289378 (patch)
tree962029814c19f14b5675acb5fee191abd2a43297 /crates/parser/src/lib.rs
parent19038bfea6a65e2aad89ec6a8fa51c41da35b219 (diff)
chore: reduce instantiation ovherhead & refactor optimize
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser/src/lib.rs')
-rw-r--r--crates/parser/src/lib.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index 7b3dfa2..949afa2 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -47,11 +47,22 @@ pub use tinywasm_types::Module;
pub struct ParserOptions {
/// Whether to optimize local memory allocation by skipping allocation of unused local memories.
pub optimize_local_memory_allocation: bool,
+ /// Whether to run the peephole rewrite optimizer.
+ pub optimize_rewrite: bool,
+ /// Whether to remove `Nop` and `MergeBarrier` instructions after rewriting.
+ pub optimize_remove_nop: bool,
+ /// Whether to invert conditional branches over an unconditional jump.
+ pub optimize_branch_inversion: bool,
}
impl Default for ParserOptions {
fn default() -> Self {
- Self { optimize_local_memory_allocation: true }
+ Self {
+ optimize_local_memory_allocation: true,
+ optimize_rewrite: true,
+ optimize_remove_nop: true,
+ optimize_branch_inversion: false,
+ }
}
}
@@ -66,6 +77,39 @@ impl ParserOptions {
pub const fn optimize_local_memory_allocation(&self) -> bool {
self.optimize_local_memory_allocation
}
+
+ /// Enable or disable the peephole rewrite optimizer.
+ pub const fn with_rewrite_optimization(mut self, enabled: bool) -> Self {
+ self.optimize_rewrite = enabled;
+ self
+ }
+
+ /// Returns whether the peephole rewrite optimizer is enabled.
+ pub const fn optimize_rewrite(&self) -> bool {
+ self.optimize_rewrite
+ }
+
+ /// Enable or disable `Nop`/`MergeBarrier` removal after rewriting.
+ pub const fn with_nop_removal_optimization(mut self, enabled: bool) -> Self {
+ self.optimize_remove_nop = enabled;
+ self
+ }
+
+ /// Returns whether `Nop`/`MergeBarrier` removal is enabled.
+ pub const fn optimize_remove_nop(&self) -> bool {
+ self.optimize_remove_nop
+ }
+
+ /// Enable or disable the optimization that inverts conditional branches over an unconditional jump.
+ pub const fn with_branch_inversion_optimization(mut self, enabled: bool) -> Self {
+ self.optimize_branch_inversion = enabled;
+ self
+ }
+
+ /// Returns whether conditional branch inversion optimization is enabled.
+ pub const fn optimize_branch_inversion(&self) -> bool {
+ self.optimize_branch_inversion
+ }
}
/// A WebAssembly parser