feat(riscv64): GOROOT instruction shapes, DATA order and offset expressions

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-19 19:58:43 +02:00
parent 1e77e58250
commit f37f183577
7 changed files with 310 additions and 95 deletions
+47 -16
View File
@@ -438,25 +438,56 @@ func parseAddress(g []token.Token) ast.Address {
// Optional leading displacement before a '(' base group. A sign pushes
// the parenthesis one token further out: -4(DX) has it at i+2.
if isSignedNumber(g, i) {
paren := i + 1
if g[i].Kind == token.Minus || g[i].Kind == token.Plus {
paren = i + 2
j := i
neg := false
if g[j].Kind == token.Minus {
neg = true
j++
} else if g[j].Kind == token.Plus {
j++
}
if paren < len(g) && g[paren].Kind == token.LParen {
neg := false
if g[i].Kind == token.Minus {
neg = true
i++
} else if g[i].Kind == token.Plus {
i++
if j < len(g) && g[j].Kind == token.Number {
v := parseInt(g[j].Text)
j++
// A term may carry a *number factor: 0*8(base).
for j+1 < len(g) && g[j].Kind == token.Star && g[j+1].Kind == token.Number {
v *= parseInt(g[j+1].Text)
j += 2
}
if i < len(g) && g[i].Kind == token.Number {
addr.Offset = parseInt(g[i].Text)
addr.HasOff = true
if neg {
addr.Offset = -addr.Offset
if neg {
v = -v
}
// Further +/- terms, each with its optional factor:
// 3*8+8(base), 8-4*2(base).
for {
termNeg := false
if j < len(g) && g[j].Kind == token.Minus {
termNeg = true
} else if j < len(g) && g[j].Kind == token.Plus {
} else {
break
}
i++
if j+1 < len(g) && g[j+1].Kind == token.Number {
tv := parseInt(g[j+1].Text)
j += 2
for j+1 < len(g) && g[j].Kind == token.Star && g[j+1].Kind == token.Number {
tv *= parseInt(g[j+1].Text)
j += 2
}
if termNeg {
tv = -tv
}
v += tv
continue
}
break
}
// Commit only when the expression is followed by the base
// group; a bare number stays untouched for the caller.
if j < len(g) && g[j].Kind == token.LParen {
addr.Offset = v
addr.HasOff = true
i = j
}
}
}