mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: refactor funcLayout tests
This change refactors the existing funcLayout tests and sets them up to support the new register ABI by explicitly setting the register counts to zero. This allows the test to pass if GOEXPERIMENT=regabiargs is set. A follow-up change will add tests for a non-zero register count. For #40724. Change-Id: Ibbe061b4ed4fd70566eb38b9e6182dca32b81127 Reviewed-on: https://go-review.googlesource.com/c/go/+/307869 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
0a510478b0
commit
b084073b53
3 changed files with 157 additions and 187 deletions
|
|
@ -20,33 +20,49 @@ func IsRO(v Value) bool {
|
|||
return v.flag&flagStickyRO != 0
|
||||
}
|
||||
|
||||
var (
|
||||
IntArgRegs = &intArgRegs
|
||||
FloatArgRegs = &floatArgRegs
|
||||
FloatRegSize = &floatRegSize
|
||||
)
|
||||
|
||||
var CallGC = &callGC
|
||||
|
||||
const PtrSize = ptrSize
|
||||
|
||||
func FuncLayout(t Type, rcvr Type) (frametype Type, argSize, retOffset uintptr, stack []byte, gc []byte, ptrs bool) {
|
||||
// FuncLayout calls funcLayout and returns a subset of the results for testing.
|
||||
//
|
||||
// Bitmaps like stack, gc, inReg, and outReg are expanded such that each bit
|
||||
// takes up one byte, so that writing out test cases is a little clearer.
|
||||
// If ptrs is false, gc will be nil.
|
||||
func FuncLayout(t Type, rcvr Type) (frametype Type, argSize, retOffset uintptr, stack, gc, inReg, outReg []byte, ptrs bool) {
|
||||
var ft *rtype
|
||||
var abi abiDesc
|
||||
var abid abiDesc
|
||||
if rcvr != nil {
|
||||
ft, _, abi = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), rcvr.(*rtype))
|
||||
ft, _, abid = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), rcvr.(*rtype))
|
||||
} else {
|
||||
ft, _, abi = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), nil)
|
||||
ft, _, abid = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), nil)
|
||||
}
|
||||
argSize = abi.stackCallArgsSize
|
||||
retOffset = abi.retOffset
|
||||
// Extract size information.
|
||||
argSize = abid.stackCallArgsSize
|
||||
retOffset = abid.retOffset
|
||||
frametype = ft
|
||||
for i := uint32(0); i < abi.stackPtrs.n; i++ {
|
||||
stack = append(stack, abi.stackPtrs.data[i/8]>>(i%8)&1)
|
||||
|
||||
// Expand stack pointer bitmap into byte-map.
|
||||
for i := uint32(0); i < abid.stackPtrs.n; i++ {
|
||||
stack = append(stack, abid.stackPtrs.data[i/8]>>(i%8)&1)
|
||||
}
|
||||
|
||||
// Expand register pointer bitmaps into byte-maps.
|
||||
bool2byte := func(b bool) byte {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < intArgRegs; i++ {
|
||||
inReg = append(inReg, bool2byte(abid.inRegPtrs.Get(i)))
|
||||
outReg = append(outReg, bool2byte(abid.outRegPtrs.Get(i)))
|
||||
}
|
||||
if ft.kind&kindGCProg != 0 {
|
||||
panic("can't handle gc programs")
|
||||
}
|
||||
|
||||
// Expand frame type's GC bitmap into byte-map.
|
||||
ptrs = ft.ptrdata != 0
|
||||
if ptrs {
|
||||
nptrs := ft.ptrdata / ptrSize
|
||||
|
|
@ -132,6 +148,17 @@ type Buffer struct {
|
|||
buf []byte
|
||||
}
|
||||
|
||||
func ClearLayoutCache() {
|
||||
func clearLayoutCache() {
|
||||
layoutCache = sync.Map{}
|
||||
}
|
||||
|
||||
func SetArgRegs(ints, floats int, floatSize uintptr) (oldInts, oldFloats int, oldFloatSize uintptr) {
|
||||
oldInts = intArgRegs
|
||||
oldFloats = floatArgRegs
|
||||
oldFloatSize = floatRegSize
|
||||
intArgRegs = ints
|
||||
floatArgRegs = floats
|
||||
floatRegSize = floatSize
|
||||
clearLayoutCache()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue