fix(asm): resolve negative numeric PC-relative jumps
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+17
-1
@@ -543,11 +543,27 @@ func pcJumpOffset(op *ast.Operand) (int, bool) {
|
||||
// pcJumpTarget resolves a numeric jump at statement index j: N counts the
|
||||
// instruction statements after the jump itself (N = 0 is the jump's own
|
||||
// address, the classic park loop), and the target is the start of the Nth
|
||||
// one. It reports false when the count runs past the end of the function.
|
||||
// one. A negative N counts the same way backwards, before the jump: the
|
||||
// exit loops write JMP -3(PC) to land three instructions earlier. Labels
|
||||
// count not, in either direction. It reports false when the count runs
|
||||
// past the end of the function, or before its first instruction.
|
||||
func pcJumpTarget(t *ast.Text, j, n int, pcs []int) (int, bool) {
|
||||
if n == 0 {
|
||||
return pcs[j], true
|
||||
}
|
||||
if n < 0 {
|
||||
seen := 0
|
||||
for k := j - 1; k >= 0; k-- {
|
||||
if _, ok := t.Body[k].(*ast.Instr); !ok {
|
||||
continue
|
||||
}
|
||||
seen--
|
||||
if seen == n {
|
||||
return pcs[k], true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
seen := 0
|
||||
for k := j + 1; k < len(t.Body); k++ {
|
||||
if _, ok := t.Body[k].(*ast.Instr); !ok {
|
||||
|
||||
Reference in New Issue
Block a user