Skip to content

wasm-tools print: add option to print operand stack between instructions #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 1, 2025

Conversation

keithw
Copy link
Contributor

@keithw keithw commented Jun 28, 2025

Closes #1381 (mentioned in #2235 (comment))

Example output:

image

@keithw keithw requested a review from a team as a code owner June 28, 2025 06:25
@keithw keithw requested review from alexcrichton and removed request for a team June 28, 2025 06:25
@keithw keithw force-pushed the print-operand-stack branch 4 times, most recently from 294eddb to a67f457 Compare June 29, 2025 22:59
This prints the operand stack types within function bodies,
flagging newly pushed operands when color output is enabled. E.g.:
```wasm
(module
  (type (;0;) (func))
  (func (;0;) (type 0)
    i32.const 4
    ;; [i32]
    i32.const 5
    ;; [i32 i32]
    i32.add
    ;; [i32]
    drop
    ;; []
  )
)
```
@keithw keithw force-pushed the print-operand-stack branch from a67f457 to 405f3c3 Compare June 29, 2025 23:09
Minimize the `#[cfg]` in the "main code" by avoiding it entirely and
instead switching between two modules at compile time. Preserve the
property of not needing the validator when this feature is disabled,
however.
@alexcrichton
Copy link
Member

This is awesome, thank you so much for implementing this! Overall this looks great and the points I'd comment on are mostly Rust-related so I went ahead and sketched them out and PR'd as keithw#2. Notably I personally prefer to cut down on #[cfg] wherever possible, so that uses a strategy of having two modules, one which is just a skeleton, for handling the enabled-vs-not code with respect to runtime dependencies. I also added a few minor tests but nothing major.

@keithw
Copy link
Contributor Author

keithw commented Jun 30, 2025

That's a nice technique! Thanks, merged your PR.

@alexcrichton alexcrichton added this pull request to the merge queue Jul 1, 2025
Merged via the queue into bytecodealliance:main with commit 787fc6f Jul 1, 2025
32 checks passed
@fitzgen
Copy link
Member

fitzgen commented Jul 1, 2025

This is fantastic!! Thanks so much @keithw!!

@keithw keithw deleted the print-operand-stack branch July 1, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to show operand stack's types in disassembly
3 participants