]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: move ssagen.dvarint to objw.Uvarint
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 16 Oct 2023 08:47:08 +0000 (15:47 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 18 Oct 2023 16:32:12 +0000 (16:32 +0000)
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>

src/cmd/compile/internal/objw/objw.go
src/cmd/compile/internal/ssagen/ssa.go

index ec1be325f7647b3d4eb6914da557aac5cac07765..77744672c197a980e42b990414f4ccc66db86047 100644 (file)
@@ -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 {
index d3671a97738527f84ed768c2a166079ea9792ad6..5d5c79e58152f5a5826f15a763f504897af1d8e5 100644 (file)
@@ -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.