-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathop.go
87 lines (65 loc) · 1.31 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package dextk
import "fmt"
type OpCode int16
type opConfig struct {
Name string
Size func(r *OpReader) (int, error)
Reader func(r *OpReader) (Op, error)
}
const (
OpCodeInvalid OpCode = -1
OpCodePseudoPackedSwitchPayload OpCode = -10
OpCodePseudoSparseSwitchPayload OpCode = -11
OpCodePseudoFillArrayDataPayload OpCode = -12
)
func (c OpCode) String() string {
cfg, found := opConfigsExtra[c]
if found {
return cfg.Name
}
if c >= 0 && c <= 255 {
cfg := opConfigs[c]
if cfg.Name != "" {
return cfg.Name
}
}
return fmt.Sprintf("unknown(0x%x)", int16(c))
}
func (c OpCode) Size(r *OpReader) (int, error) {
cfg, found := opConfigsExtra[c]
if found {
return cfg.Size(r)
}
if c >= 0 && c <= 255 {
cfg := opConfigs[c]
if cfg.Name != "" {
return cfg.Size(r)
}
}
return 0, fmt.Errorf("%w: %x", ErrUnsupportedOp, int16(c))
}
func (c OpCode) Read(r *OpReader) (Op, error) {
cfg, found := opConfigsExtra[c]
if found {
return cfg.Reader(r)
}
if c >= 0 && c <= 255 {
cfg := opConfigs[c]
if cfg.Name != "" {
return cfg.Reader(r)
}
}
return nil, fmt.Errorf("%w: %x", ErrUnsupportedOp, int16(c))
}
type Op interface {
Code() OpCode
Pos() int
String() string
Fmt() Fmt
}
type opBase struct {
pos int
}
func (o opBase) Pos() int {
return o.pos
}