1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 // MakeRO returns a copy of v with the read-only flag set.
15 func MakeRO(v Value) Value {
16 v.flag |= flagStickyRO
20 // IsRO reports whether v's read-only flag is set.
21 func IsRO(v Value) bool {
22 return v.flag&flagStickyRO != 0
27 // FuncLayout calls funcLayout and returns a subset of the results for testing.
29 // Bitmaps like stack, gc, inReg, and outReg are expanded such that each bit
30 // takes up one byte, so that writing out test cases is a little clearer.
31 // If ptrs is false, gc will be nil.
32 func FuncLayout(t Type, rcvr Type) (frametype Type, argSize, retOffset uintptr, stack, gc, inReg, outReg []byte, ptrs bool) {
36 ft, _, abid = funcLayout((*funcType)(unsafe.Pointer(t.common())), rcvr.common())
38 ft, _, abid = funcLayout((*funcType)(unsafe.Pointer(t.(*rtype))), nil)
40 // Extract size information.
41 argSize = abid.stackCallArgsSize
42 retOffset = abid.retOffset
43 frametype = toType(ft)
45 // Expand stack pointer bitmap into byte-map.
46 for i := uint32(0); i < abid.stackPtrs.n; i++ {
47 stack = append(stack, abid.stackPtrs.data[i/8]>>(i%8)&1)
50 // Expand register pointer bitmaps into byte-maps.
51 bool2byte := func(b bool) byte {
57 for i := 0; i < intArgRegs; i++ {
58 inReg = append(inReg, bool2byte(abid.inRegPtrs.Get(i)))
59 outReg = append(outReg, bool2byte(abid.outRegPtrs.Get(i)))
61 if ft.Kind_&kindGCProg != 0 {
62 panic("can't handle gc programs")
65 // Expand frame type's GC bitmap into byte-map.
66 ptrs = ft.PtrBytes != 0
68 nptrs := ft.PtrBytes / goarch.PtrSize
69 gcdata := ft.GcSlice(0, (nptrs+7)/8)
70 for i := uintptr(0); i < nptrs; i++ {
71 gc = append(gc, gcdata[i/8]>>(i%8)&1)
77 func TypeLinks() []string {
79 sections, offset := typelinks()
80 for i, offs := range offset {
82 for _, off := range offs {
83 typ := (*rtype)(resolveTypeOff(rodata, off))
84 r = append(r, typ.String())
92 func gcbits(any) []byte // provided by runtime
94 func MapBucketOf(x, y Type) Type {
95 return toType(bucketOf(x.common(), y.common()))
98 func CachedBucketOf(m Type) Type {
100 if Kind(t.t.Kind_&kindMask) != Map {
103 tt := (*mapType)(unsafe.Pointer(t))
104 return toType(tt.Bucket)
107 type EmbedWithUnexpMeth struct{}
109 func (EmbedWithUnexpMeth) f() {}
111 type pinUnexpMeth interface {
115 var pinUnexpMethI = pinUnexpMeth(EmbedWithUnexpMeth{})
117 func FirstMethodNameBytes(t Type) *byte {
122 panic("type has no methods")
125 mname := t.(*rtype).nameOff(m.Name)
126 if *mname.DataChecked(0, "name flag field")&(1<<2) == 0 {
127 panic("method name does not have pkgPath *string")
132 type OtherPkgFields struct {
137 func IsExported(t Type) bool {
139 n := typ.nameOff(typ.t.Str)
140 return n.IsExported()
143 func ResolveReflectName(s string) {
144 resolveReflectName(newName(s, "", false, false))
151 func clearLayoutCache() {
152 layoutCache = sync.Map{}
155 func SetArgRegs(ints, floats int, floatSize uintptr) (oldInts, oldFloats int, oldFloatSize uintptr) {
157 oldFloats = floatArgRegs
158 oldFloatSize = floatRegSize
160 floatArgRegs = floats
161 floatRegSize = floatSize
166 var MethodValueCallCodePtr = methodValueCallCodePtr
168 var InternalIsZero = isZero