Debian Codegraph @

reg/set.go

raw symbols SCIP
1 package regscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/
2
3 // MaskSet maps register IDs to masks.
4 type MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# map[IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/ID#]uint16
5
6 // NewEmptyMaskSet builds an empty register mask set.
7 func NewEmptyMaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/NewEmptyMaskSet().() MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# {
8 return MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#{}
9 }
10
11 // NewMaskSetFromRegisters forms a mask set from the given register list.
12 func NewMaskSetFromRegistersscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/NewMaskSetFromRegisters().(rs []Registerscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#) MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# {
13 s := NewEmptyMaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/NewEmptyMaskSet().()
14 for _, r := range rs {
15 s.AddRegisterscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#AddRegister().(r)
16 }
17 return s
18 }
19
20 // Clone returns a copy of s.
21 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Clonescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Clone().() MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# {
22 c := NewEmptyMaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/NewEmptyMaskSet().()
23 for id, mask := range s {
24 c.Addscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Add().(id, mask)
25 }
26 return c
27 }
28
29 // Add mask to the given register ID.
30 // Reports whether this made any change to the set.
31 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Addscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Add().(id IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/ID#, mask uint16) bool {
32 if (s[id] & mask) == mask {
33 return false
34 }
35 s[id] |= mask
36 return true
37 }
38
39 // AddRegister is a convenience for adding the register's (ID, mask) to the set.
40 // Reports whether this made any change to the set.
41 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) AddRegisterscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#AddRegister().(r Registerscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#) bool {
42 return s.Addscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Add().(r.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#ID.(), r.Maskscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#Mask.())
43 }
44
45 // Discard clears masked bits from register ID.
46 // Reports whether this made any change to the set.
47 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Discardscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Discard().(id IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/ID#, mask uint16) bool {
48 if curr, found := s[id]; !found || (curr&mask) == 0 {
49 return false
50 }
51 s[id] &^= mask
52 if s[id] == 0 {
53 delete(s, id)
54 }
55 return true
56 }
57
58 // DiscardRegister is a convenience for discarding the register's (ID, mask) from the set.
59 // Reports whether this made any change to the set.
60 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) DiscardRegisterscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#DiscardRegister().(r Registerscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#) bool {
61 return s.Discardscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Discard().(r.IDscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#ID.(), r.Maskscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Register#Mask.())
62 }
63
64 // Update adds masks in t to s.
65 // Reports whether this made any change to the set.
66 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Updatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Update().(t MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) bool {
67 change := false
68 for id, mask := range t {
69 change = s.Addscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Add().(id, mask) || change
70 }
71 return change
72 }
73
74 // Difference returns the set of registers in s but not t.
75 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Differencescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Difference().(t MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# {
76 d := s.Clonescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Clone().()
77 d.DifferenceUpdatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#DifferenceUpdate().(t)
78 return d
79 }
80
81 // DifferenceUpdate removes every element of t from s.
82 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) DifferenceUpdatescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#DifferenceUpdate().(t MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) bool {
83 change := false
84 for id, mask := range t {
85 change = s.Discardscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Discard().(id, mask) || change
86 }
87 return change
88 }
89
90 // Equals returns true if s and t contain the same masks.
91 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) Equalsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Equals().(t MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) bool {
92 if len(s) != len(t) {
93 return false
94 }
95 for id, mask := range s {
96 if _, found := t[id]; !found || mask != t[id] {
97 return false
98 }
99 }
100 return true
101 }
102
103 // OfKind returns the set of elements of s with kind k.
104 func (s MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#) OfKindscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#OfKind().(k Kindscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/Kind#) MaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet# {
105 t := NewEmptyMaskSetscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/NewEmptyMaskSet().()
106 for id, mask := range s {
107 if id.Kindscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/ID#Kind().() == k {
108 t.Addscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/reg`/MaskSet#Add().(id, mask)
109 }
110 }
111 return t
112 }