@@ -36,10 +36,18 @@ uint32_t DecodeBits(std::vector<bool>::const_iterator& bitpos, const std::vector
3636 return -1 ;
3737}
3838
39+ enum class Instruction : uint32_t
40+ {
41+ RETURN = 0 ,
42+ JUMP = 1 ,
43+ MATCH = 2 ,
44+ DEFAULT = 3 ,
45+ };
46+
3947const 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)
4149{
42- return DecodeBits (bitpos, endpos, 0 , TYPE_BIT_SIZES);
50+ return Instruction ( DecodeBits (bitpos, endpos, 0 , TYPE_BIT_SIZES) );
4351}
4452
4553const 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)
7078 const std::vector<bool >::const_iterator endpos = asmap.end ();
7179 uint8_t bits = ip.size ();
7280 uint32_t default_asn = 0 ;
73- uint32_t opcode, jump, match, matchlen;
81+ uint32_t jump, match, matchlen;
82+ Instruction opcode;
7483 while (pos != endpos) {
7584 opcode = DecodeType (pos, endpos);
76- if (opcode == 0 ) {
85+ if (opcode == Instruction::RETURN ) {
7786 return DecodeASN (pos, endpos);
78- } else if (opcode == 1 ) {
87+ } else if (opcode == Instruction::JUMP ) {
7988 jump = DecodeJump (pos, endpos);
8089 if (bits == 0 ) break ;
8190 if (ip[ip.size () - bits]) {
8291 if (jump >= endpos - pos) break ;
8392 pos += jump;
8493 }
8594 bits--;
86- } else if (opcode == 2 ) {
95+ } else if (opcode == Instruction::MATCH ) {
8796 match = DecodeMatch (pos, endpos);
8897 matchlen = CountBits (match) - 1 ;
8998 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)
93102 }
94103 bits--;
95104 }
96- } else if (opcode == 3 ) {
105+ } else if (opcode == Instruction::DEFAULT ) {
97106 default_asn = DecodeASN (pos, endpos);
98107 } else {
99108 break ;
0 commit comments