-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop.go
73 lines (58 loc) · 1.58 KB
/
op.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ossa
type Op int
const (
opInvalid Op = iota
OpGlobalSym
OpLocalSym
OpArgument
OpAuxLiteral
OpPhi
OpLoad
OpStore
OpCall
// we also have some internal-only operations used to deal with CFG-related
// concerns. These are not visible to callers.
opBasicBlock
// This special value represents the split between value operations and
// terminator operations.
opEndValues
OpJump
OpBranch
OpSwitch
OpReturn
OpYield
OpAwait
OpUnreachable
opEndTerminators
)
//go:generate stringer -type Op
// Valid returns true if the receiving op is valid, which is to say it is one
// of the constant values defined in this package. The zero value of
// Op is not valid.
func (o Op) Valid() bool {
// This excludes opInvalid, opEndValues and opEndTerminators, along with
// any values greater than opEndTerminators that are not defined yet.
return o.Value() || o.Terminator()
}
// Value returns true if the receiving op belongs to the set of operations
// used with Values, as opposed to Terminators.
func (o Op) Value() bool {
return o > opInvalid && o < opEndValues
}
// Terminator returns true if the receiving op belongs to the set of operations
// used with Terminators, as opposed to Values.
func (o Op) Terminator() bool {
return o > opEndValues && o < opEndTerminators
}
// assertValue panics if the reciever is not a value
func (o Op) assertValue() {
if !o.Value() {
panic("operation is not suitable for value")
}
}
// assertValue panics if the reciever is not a value
func (o Op) assertTerminator() {
if !o.Terminator() {
panic("operation is not suitable for terminator")
}
}