Print unused rules

This commit is contained in:
Devine Lu Linvega 2024-04-22 15:29:54 -07:00
parent 6fb9f96b0c
commit e153eb797b
1 changed files with 11 additions and 7 deletions

View File

@ -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(!quiet) {
if(create)
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
else
fprintf(stderr, "%02d %s\n", r->id, src_);
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;
}