Print unused rules
This commit is contained in:
parent
6fb9f96b0c
commit
e153eb797b
18
src/modal.c
18
src/modal.c
|
@ -1,11 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
int id, refs;
|
||||
char *a, *b;
|
||||
} Rule;
|
||||
|
||||
static int flip, rmin = 0xff, rmax = 0x00, cycles = 0x10000;
|
||||
static int flip, quiet, rmin = 0xff, rmax = 0x00, cycles = 0x10000;
|
||||
static Rule rules[0x1000], lambda, *rules_ = rules;
|
||||
static char dict[0x8000], *dict_ = dict;
|
||||
static char bank_a[0x4000], *src_ = bank_a;
|
||||
|
@ -122,10 +122,12 @@ commit_rule(Rule *r, char *s, int create)
|
|||
src_ = bank_b, dst_ = bank_a;
|
||||
else
|
||||
src_ = bank_a, dst_ = bank_b;
|
||||
if(create)
|
||||
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||
else
|
||||
fprintf(stderr, "%02d %s\n", r->id, src_);
|
||||
if(!quiet) {
|
||||
if(create)
|
||||
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||
else
|
||||
fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -209,7 +211,7 @@ main(int argc, char **argv)
|
|||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||
switch(argv[i][1]) {
|
||||
case 'v': /* version */ return !printf("Modal Interpreter, 22 Apr 2024.\n");
|
||||
case 'q': /* quiet */ fclose(stderr); break;
|
||||
case 'q': /* quiet */ quiet = 1; break;
|
||||
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
||||
}
|
||||
}
|
||||
|
@ -232,5 +234,7 @@ main(int argc, char **argv)
|
|||
return !fprintf(stdout, "Modal program imbalanced.\n");
|
||||
while(rewrite())
|
||||
if(!cycles--) return !fprintf(stdout, "Modal rewrites exceeded.\n");
|
||||
while(rules_-- > rules && !quiet)
|
||||
if(!rules_->refs) printf("-- Unused rule: %d <> (%s) (%s)\n", rules_->refs, rules_->a, rules_->b);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue