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 if uint8(t.Alignment()) > 0 && off&int64(uint8(t.Alignment())-1) != 0 {
18 base.Fatalf("typebits.Set: invalid initial alignment: type %v has alignment %d, but offset is %v", t, uint8(t.Alignment()), off)
19 }
20 if !t.HasPointers() {
21
22
23 return
24 }
25
26 switch t.Kind() {
27 case types.TPTR, types.TUNSAFEPTR, types.TFUNC, types.TCHAN, types.TMAP:
28 if off&int64(types.PtrSize-1) != 0 {
29 base.Fatalf("typebits.Set: invalid alignment, %v", t)
30 }
31 bv.Set(int32(off / int64(types.PtrSize)))
32
33 case types.TSTRING:
34
35 if off&int64(types.PtrSize-1) != 0 {
36 base.Fatalf("typebits.Set: invalid alignment, %v", t)
37 }
38 bv.Set(int32(off / int64(types.PtrSize)))
39
40 case types.TINTER:
41
42
43
44 if off&int64(types.PtrSize-1) != 0 {
45 base.Fatalf("typebits.Set: invalid alignment, %v", t)
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59 bv.Set(int32(off/int64(types.PtrSize) + 1))
60
61 case types.TSLICE:
62
63 if off&int64(types.PtrSize-1) != 0 {
64 base.Fatalf("typebits.Set: invalid TARRAY alignment, %v", t)
65 }
66 bv.Set(int32(off / int64(types.PtrSize)))
67
68 case types.TARRAY:
69 elt := t.Elem()
70 if elt.Size() == 0 {
71
72 break
73 }
74 for i := int64(0); i < t.NumElem(); i++ {
75 Set(elt, off, bv)
76 off += elt.Size()
77 }
78
79 case types.TSTRUCT:
80 for _, f := range t.Fields().Slice() {
81 Set(f.Type, off+f.Offset, bv)
82 }
83
84 default:
85 base.Fatalf("typebits.Set: unexpected type, %v", t)
86 }
87 }
88
View as plain text