Skip to content

Wrap instructions with position info for tracing#6

Open
bbyalcinkaya wants to merge 3 commits intomasterfrom
bytecode-location
Open

Wrap instructions with position info for tracing#6
bbyalcinkaya wants to merge 3 commits intomasterfrom
bytecode-location

Conversation

@bbyalcinkaya
Copy link
Copy Markdown
Member

@bbyalcinkaya bbyalcinkaya commented Apr 3, 2026

This PR introduces a helper instruction wrapper to attach source position metadata to parsed Wasm instructions:

class InstructionWithPos(NamedTuple):
    pos: tuple[int, int]
    instruction: BaseInstruction

    @property
    def opcode(self) -> BinaryOpcode:
        return self.instruction.opcode

Motivation

The K Wasm semantics does not carry position information for instructions. However, the debugger will rely on execution traces that can be mapped back to the original binary. This wrapper allows us to preserve byte offsets during parsing without affecting semantics.

Changes

  • Add InstrWithPos wrapper type
  • Update parse_instruction to return InstructionWithPos, wrapping parsed instructions with (pos_start, pos_end) byte offsets
  • Ensure existing instruction structure remains unchanged.

Notes

  • This is a non-semantic annotation used only for tracing/debugging
  • The K semantics is expected to unwrap this constructor during execution, so it will have no effect on behavior.

Follow-ups

  • Add corresponding support in wasm-semantics:
syntax Instr ::= #instrWithPos(inner: Instr, posStart: Int, posEnd: Int)
rule <instrs> #instrWithPos(I, _, _) => I ... </instrs>
  • Use this metadata in trace generation for debugger integration

Note: I have already implemented and tested the corresponding changes in wasm-semantics locally. I will open a separate PR there after this one is merged.

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.

1 participant