mirror of
https://github.com/golang/go
synced 2024-11-22 23:50:03 -07:00
cmd/internal/obj/riscv: simplify machine code output
Use cursym.WriteInt rather than building up a slice of bytes and then writing them out via PutUint32. This also allows for variable instruction sizes, which will be needed when support for compressed (2 byte length) instructions is added. Change-Id: I17c9ffa52d27c91a24e161317e3db28e224804ae Reviewed-on: https://go-review.googlesource.com/c/go/+/344460 Trust: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
da790cccc5
commit
f030043e37
@ -2019,7 +2019,6 @@ func assemble(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
ctxt.Retpoline = false // don't keep printing
|
ctxt.Retpoline = false // don't keep printing
|
||||||
}
|
}
|
||||||
|
|
||||||
var symcode []uint32
|
|
||||||
for p := cursym.Func().Text; p != nil; p = p.Link {
|
for p := cursym.Func().Text; p != nil; p = p.Link {
|
||||||
switch p.As {
|
switch p.As {
|
||||||
case AJALR:
|
case AJALR:
|
||||||
@ -2074,23 +2073,17 @@ func assemble(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
rel.Type = rt
|
rel.Type = rt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset := p.Pc
|
||||||
for _, ins := range instructionsForProg(p) {
|
for _, ins := range instructionsForProg(p) {
|
||||||
ic, err := ins.encode()
|
if ic, err := ins.encode(); err == nil {
|
||||||
if err != nil {
|
cursym.WriteInt(ctxt, offset, ins.length(), int64(ic))
|
||||||
break
|
offset += int64(ins.length())
|
||||||
}
|
}
|
||||||
if ins.usesRegTmp() {
|
if ins.usesRegTmp() {
|
||||||
p.Mark |= USES_REG_TMP
|
p.Mark |= USES_REG_TMP
|
||||||
}
|
}
|
||||||
symcode = append(symcode, ic)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursym.Size = int64(4 * len(symcode))
|
|
||||||
|
|
||||||
cursym.Grow(cursym.Size)
|
|
||||||
for p, i := cursym.P, 0; i < len(symcode); p, i = p[4:], i+1 {
|
|
||||||
ctxt.Arch.ByteOrder.PutUint32(p, symcode[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.MarkUnsafePoints(ctxt, cursym.Func().Text, newprog, isUnsafePoint, nil)
|
obj.MarkUnsafePoints(ctxt, cursym.Func().Text, newprog, isUnsafePoint, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user