]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libregexp/regprint.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libregexp / regprint.c
1 #include <u.h>
2 #include <libc.h>
3 #include <regexp.h>
4 #include <regimpl.h>
5
6 static int
7 fmtprinst(Fmt *f, Reinst *inst)
8 {
9         int r;
10
11         r = fmtprint(f, "%p ", inst);
12         switch(inst->op) {
13         case ORUNE:
14                 r += fmtprint(f, "ORUNE\t%C\n", inst->r);
15                 break;
16         case ONOTNL:
17                 r += fmtprint(f, "ONOTNL\n");
18                 break;
19         case OCLASS:
20                 r += fmtprint(f, "OCLASS\t%C-%C %p\n", inst->r, inst->r1, inst->a);
21                 break;
22         case OSPLIT:
23                 r += fmtprint(f, "OSPLIT\t%p %p\n", inst->a, inst->b);
24                 break;
25         case OJMP:
26                 r += fmtprint(f, "OJMP \t%p\n", inst->a);
27                 break;
28         case OSAVE:
29                 r += fmtprint(f, "OSAVE\t%d\n", inst->sub);
30                 break;
31         case OUNSAVE:
32                 r += fmtprint(f, "OUNSAVE\t%d\n", inst->sub);
33                 break;
34         case OANY:
35                 r += fmtprint(f, "OANY \t.\n");
36                 break;
37         case OEOL:
38                 r += fmtprint(f, "OEOL \t$\n");
39                 break;
40         case OBOL:
41                 r += fmtprint(f, "OBOL \t^\n");
42                 break;
43         }
44         return r;
45 }
46
47 static int
48 fmtprprog(Fmt *f, Reprog *reprog)
49 {
50         Reinst *inst;
51         int r;
52
53         r = 0;
54         for(inst = reprog->startinst; inst < reprog->startinst + reprog->len; inst++)
55                 r += fmtprinst(f, inst);
56         return r;
57 }
58
59 int
60 reprogfmt(Fmt *f)
61 {
62         Reprog *r;
63
64         r = va_arg(f->args, Reprog*);
65         return fmtprprog(f, r);
66 }