Skip to content

Commit 0b94855

Browse files
Explore: Print instruction offsets in disassembly
1 parent baf442b commit 0b94855

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/WasmKit/Execution/Instructions/InstructionSupport.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ extension InstructionSequence {
226226
}
227227
target.write("0x\(hexOffset): ")
228228
let instruction = Instruction.load(from: &cursor)
229-
context.print(instruction: instruction, to: &target)
229+
context.print(
230+
instruction: instruction,
231+
instructionOffset: cursor - cursorStart,
232+
to: &target
233+
)
230234
target.write("\n")
231235
}
232236
}
@@ -271,6 +275,7 @@ struct InstructionPrintingContext {
271275

272276
mutating func print<Target>(
273277
instruction: Instruction,
278+
instructionOffset: Int,
274279
to target: inout Target
275280
) where Target : TextOutputStream {
276281
switch instruction {
@@ -317,7 +322,8 @@ struct InstructionPrintingContext {
317322
case .brIf(let op):
318323
target.write("br_if \(reg(op.condition)), +\(op.offset)")
319324
case .br(let offset):
320-
target.write("br \(offset > 0 ? "+" : "")\(offset)")
325+
let iseqOffset = instructionOffset + Int(offset)
326+
target.write("br \(offset > 0 ? "+" : "")\(offset) ; 0x\(String(iseqOffset, radix: 16))")
321327
case .brTable(let table):
322328
target.write("br_table \(reg(table.index)), \(table.count) cases")
323329
for i in 0..<table.count {

0 commit comments

Comments
 (0)