1 // Copyright 2014 Paul Sokolovsky.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 
5 #include "re1.5.h"
6 
re1_5_dumpcode(ByteProg * prog)7 void re1_5_dumpcode(ByteProg *prog)
8 {
9     int pc = 0;
10     char *code = prog->insts;
11     while (pc < prog->bytelen) {
12                 printf("%2d: ", pc);
13                 switch(code[pc++]) {
14                 default:
15                         assert(0);
16 //                        re1_5_fatal("printprog");
17                 case Split:
18                         printf("split %d (%d)\n", pc + (signed char)code[pc] + 1, (signed char)code[pc]);
19                         pc++;
20                         break;
21                 case RSplit:
22                         printf("rsplit %d (%d)\n", pc + (signed char)code[pc] + 1, (signed char)code[pc]);
23                         pc++;
24                         break;
25                 case Jmp:
26                         printf("jmp %d (%d)\n", pc + (signed char)code[pc] + 1, (signed char)code[pc]);
27                         pc++;
28                         break;
29                 case Char:
30                         printf("char %c\n", code[pc++]);
31                         break;
32                 case Any:
33                         printf("any\n");
34                         break;
35                 case Class:
36                 case ClassNot: {
37                         int num = code[pc];
38                         printf("class%s %d", (code[pc - 1] == ClassNot ? "not" : ""), num);
39                         pc++;
40                         while (num--) {
41                             printf(" 0x%02x-0x%02x", code[pc], code[pc + 1]);
42                             pc += 2;
43                         }
44                         printf("\n");
45                         break;
46                 }
47                 case NamedClass:
48                         printf("namedclass %c\n", code[pc++]);
49                         break;
50                 case Match:
51                         printf("match\n");
52                         break;
53                 case Save:
54                         printf("save %d\n", (unsigned char)code[pc++]);
55                         break;
56                 case Bol:
57                         printf("assert bol\n");
58                         break;
59                 case Eol:
60                         printf("assert eol\n");
61                         break;
62                 }
63     }
64     printf("Bytes: %d, insts: %d\n", prog->bytelen, prog->len);
65 }
66