...
1
2
3
4
5 package typebits
6
7 import (
8 "cmd/compile/internal/base"
9 "cmd/compile/internal/bitvec"
10 "cmd/compile/internal/types"
11 )
12
13
14
15
16 func Set(t *types.Type, off int64, bv bitvec.BitVec) {
17 set(t, off, bv, false)
18 }
19
20
21 func SetNoCheck(t *types.Type, off int64, bv bitvec.BitVec) {
22 set(t, off, bv, true)
23 }
24
25 func set(t *types.Type, off int64, bv bitvec.BitVec, skip bool) {
26 if !skip && uint8(t.Alignment()) > 0 && off&int64(uint8(t.Alignment())-1) != 0 {
27 base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, uint8(t.Alignment()), off)
28 }
29 if !t.HasPointers() {
30
31
32 return
33 }
34
35 switch t.Kind() {
36 case types.TPTR, types.TUNSAFEPTR, types.TFUNC, types.TCHAN, types.TMAP:
37 if off&int64(types.PtrSize-1) != 0 {
38 base.Fatalf("typebits.Set: invalid alignment, %v", t)
39 }
40 bv.Set(int32(off / int64(types.PtrSize)))
41
42 case types.TSTRING:
43
44 if off&int64(types.PtrSize-1) != 0 {
45 base.Fatalf("typebits.Set: invalid alignment, %v", t)
46 }
47 bv.Set(int32(off / int64(types.PtrSize)))
48
49 case types.TINTER:
50
51
52
53 if off&int64(types.PtrSize-1) != 0 {
54 base.Fatalf("typebits.Set: invalid alignment, %v", t)
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68 bv.Set(int32(off/int64(types.PtrSize) + 1))
69
70 case types.TSLICE:
71
72 if off&int64(types.PtrSize-1) != 0 {
73 base.Fatalf("typebits.Set: invalid TARRAY alignment, %v", t)
74 }
75 bv.Set(int32(off / int64(types.PtrSize)))
76
77 case types.TARRAY:
78 elt := t.Elem()
79 if elt.Size() == 0 {
80
81 break
82 }
83 for i := int64(0); i < t.NumElem(); i++ {
84 set(elt, off, bv, skip)
85 off += elt.Size()
86 }
87
88 case types.TSTRUCT:
89 for _, f := range t.Fields() {
90 set(f.Type, off+f.Offset, bv, skip)
91 }
92
93 default:
94 base.Fatalf("typebits.Set: unexpected type, %v", t)
95 }
96 }
97
View as plain text