Skip to content

Annotate Wasm AST nodes (Instrs) with bytecode position metadata for tracing/debugging#753

Draft
bbyalcinkaya wants to merge 6 commits intomasterfrom
bytecode-pos
Draft

Annotate Wasm AST nodes (Instrs) with bytecode position metadata for tracing/debugging#753
bbyalcinkaya wants to merge 6 commits intomasterfrom
bytecode-pos

Conversation

@bbyalcinkaya
Copy link
Copy Markdown
Member

This PR adds support for position-annotated instructions in the Wasm AST, enabling execution traces to carry bytecode position metadata for debugging.

Changes

  • Update py-wasm to the version that supports this feature (currently linked to a branch; will point to the released version once the corresponding py-wasm PR is merged)
  • Add #instrWithPos(inner: Instr, posStart: Int, posEnd: Int) syntax
  • Add execution rule to unwrap the wrapper:
rule <instrs> #instrWithPos(I, _, _) => I ... </instrs>
  • Update AST translation in wasm2kast to handle wrapped instructions

Notes

@bbyalcinkaya bbyalcinkaya changed the title Add position-annotated instructions for tracing/debugging Annotate Wasm AST nodes (Instrs) with bytecode position metadata for tracing/debugging Apr 3, 2026
Comment on lines +337 to +338
Helper wrapper to attach source position metadata to instructions for tracing/debugging.
`posStart` and `posEnd` represent the byte/code offsets of the instruction in the original Wasm bytecode file.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify if postStart and postEnd start at 0 or 1, and if they're inclusive or exclusive?
Also, it might be worth considering using an offset+length pair instead of a start+end pair for consistency with Python coding conventions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I switched to an offset + length representation and added more comments.

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.

3 participants