diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2023-10-16 15:47:08 +0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-10-18 16:32:12 +0000 |
| commit | 070c1fcbc505f9c4b4fc759c6fafc60cff28edcb (patch) | |
| tree | a6e7ec7ccd2451be933ce19120d46b1bb537d109 /src/cmd | |
| parent | da7ac77380f68ed855ab4565c4ef2217249c53c2 (diff) | |
| download | go-070c1fcbc505f9c4b4fc759c6fafc60cff28edcb.tar.xz | |
cmd/compile: move ssagen.dvarint to objw.Uvarint
Follow up discussion in CL 535077.
Change-Id: I102c90839e39c463e878ff925872376303724e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/535636
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/compile/internal/objw/objw.go | 9 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssagen/ssa.go | 18 |
2 files changed, 11 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/objw/objw.go b/src/cmd/compile/internal/objw/objw.go index ec1be325f7..77744672c1 100644 --- a/src/cmd/compile/internal/objw/objw.go +++ b/src/cmd/compile/internal/objw/objw.go @@ -9,6 +9,7 @@ import ( "cmd/compile/internal/bitvec" "cmd/compile/internal/types" "cmd/internal/obj" + "encoding/binary" ) // Uint8 writes an unsigned byte v into s at offset off, @@ -29,6 +30,14 @@ func Uintptr(s *obj.LSym, off int, v uint64) int { return UintN(s, off, v, types.PtrSize) } +// Uvarint writes a varint v into s at offset off, +// and returns the next unused offset. +func Uvarint(s *obj.LSym, off int, v uint64) int { + var buf [binary.MaxVarintLen64]byte + n := binary.PutUvarint(buf[:], v) + return int(s.WriteBytes(base.Ctxt, int64(off), buf[:n])) +} + func Bool(s *obj.LSym, off int, v bool) int { w := 0 if v { diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index d3671a9773..5d5c79e581 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -7,7 +7,6 @@ package ssagen import ( "bufio" "bytes" - "encoding/binary" "fmt" "go/constant" "html" @@ -257,19 +256,6 @@ func abiForFunc(fn *ir.Func, abi0, abi1 *abi.ABIConfig) *abi.ABIConfig { return a } -// dvarint writes a varint v to the funcdata in symbol x and returns the new offset. -func dvarint(x *obj.LSym, off int, v int64) int { - if v < 0 { - panic(fmt.Sprintf("dvarint: bad offset for funcdata - %v", v)) - } - var buf [binary.MaxVarintLen64]byte - n := binary.PutUvarint(buf[:], uint64(v)) - for _, b := range buf[:n] { - off = objw.Uint8(x, off, b) - } - return off -} - // emitOpenDeferInfo emits FUNCDATA information about the defers in a function // that is using open-coded defers. This funcdata is used to determine the active // defers in a function and execute those defers during panic processing. @@ -298,8 +284,8 @@ func (s *state) emitOpenDeferInfo() { s.curfn.LSym.Func().OpenCodedDeferInfo = x off := 0 - off = dvarint(x, off, -s.deferBitsTemp.FrameOffset()) - off = dvarint(x, off, -firstOffset) + off = objw.Uvarint(x, off, uint64(-s.deferBitsTemp.FrameOffset())) + off = objw.Uvarint(x, off, uint64(-firstOffset)) } // buildssa builds an SSA function for fn. |
