@@ -36,10 +36,18 @@ uint32_t DecodeBits(std::vector<bool>::const_iterator& bitpos, const std::vector
36
36
return -1 ;
37
37
}
38
38
39
+ enum class Instruction : uint32_t
40
+ {
41
+ RETURN = 0 ,
42
+ JUMP = 1 ,
43
+ MATCH = 2 ,
44
+ DEFAULT = 3 ,
45
+ };
46
+
39
47
const std::vector<uint8_t > TYPE_BIT_SIZES{0 , 0 , 1 };
40
- uint32_t DecodeType (std::vector<bool >::const_iterator& bitpos, const std::vector<bool >::const_iterator& endpos)
48
+ Instruction DecodeType (std::vector<bool >::const_iterator& bitpos, const std::vector<bool >::const_iterator& endpos)
41
49
{
42
- return DecodeBits (bitpos, endpos, 0 , TYPE_BIT_SIZES);
50
+ return Instruction ( DecodeBits (bitpos, endpos, 0 , TYPE_BIT_SIZES) );
43
51
}
44
52
45
53
const std::vector<uint8_t > ASN_BIT_SIZES{15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 };
@@ -70,20 +78,21 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
70
78
const std::vector<bool >::const_iterator endpos = asmap.end ();
71
79
uint8_t bits = ip.size ();
72
80
uint32_t default_asn = 0 ;
73
- uint32_t opcode, jump, match, matchlen;
81
+ uint32_t jump, match, matchlen;
82
+ Instruction opcode;
74
83
while (pos != endpos) {
75
84
opcode = DecodeType (pos, endpos);
76
- if (opcode == 0 ) {
85
+ if (opcode == Instruction::RETURN ) {
77
86
return DecodeASN (pos, endpos);
78
- } else if (opcode == 1 ) {
87
+ } else if (opcode == Instruction::JUMP ) {
79
88
jump = DecodeJump (pos, endpos);
80
89
if (bits == 0 ) break ;
81
90
if (ip[ip.size () - bits]) {
82
91
if (jump >= endpos - pos) break ;
83
92
pos += jump;
84
93
}
85
94
bits--;
86
- } else if (opcode == 2 ) {
95
+ } else if (opcode == Instruction::MATCH ) {
87
96
match = DecodeMatch (pos, endpos);
88
97
matchlen = CountBits (match) - 1 ;
89
98
for (uint32_t bit = 0 ; bit < matchlen; bit++) {
@@ -93,7 +102,7 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
93
102
}
94
103
bits--;
95
104
}
96
- } else if (opcode == 3 ) {
105
+ } else if (opcode == Instruction::DEFAULT ) {
97
106
default_asn = DecodeASN (pos, endpos);
98
107
} else {
99
108
break ;
0 commit comments