/
disasm.go
48 lines (43 loc) · 1.13 KB
/
disasm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2014-2015 Rocky Bernstein.
package gub
import (
"github.com/rocky/ssa-interp"
)
func DisasmPrefix(block *ssa2.BasicBlock) bool {
if block == nil {
Msg(":.nil:")
return false
} else if block.Scope != nil {
Section("# scope %d", block.Scope.ScopeId())
}
Section("Block .%s:", block)
return true
}
func DisasmCurrentInst() {
DisasmPrefix(curBlock)
Msg("%3d: %s", curFrame.PC(), ssa2.DisasmInst(*Instr, Maxwidth))
}
func DisasmInst(f *ssa2.Function, bnum int, inst uint64) {
if bnum < 0 || bnum >= len(f.Blocks) {
Errmsg("Block number %d is out of range. Should be between 0..%d",
bnum, len(f.Blocks)-1)
return
}
if b := f.Blocks[bnum]; DisasmPrefix(b) {
Msg("%3d: %s", inst, ssa2.DisasmInst(b.Instrs[inst], Maxwidth))
}
}
func DisasmBlock(f *ssa2.Function, i int, pc int) {
if i < 0 || i >= len(f.Blocks) {
Errmsg("Block number %d is out of range. Should be between 0..%d",
i, len(f.Blocks)-1)
return
}
if b := f.Blocks[i]; DisasmPrefix(b) {
for i, instr := range b.Instrs {
prefix := " "
if i == pc { prefix = "=>" }
Msg("%s%3d: %s", prefix, i, ssa2.DisasmInst(instr, Maxwidth))
}
}
}