diff --git a/mach/proto/mcg/table b/mach/proto/mcg/table index dc0bc0b3d..daf0fbbad 100644 --- a/mach/proto/mcg/table +++ b/mach/proto/mcg/table @@ -1,37 +1,6 @@ -%{ -#if 0 -#include -#include -#include -#include +PATTERNS -#define TRACE - -#define STATE_TYPE void* -typedef struct tree { - int op; - struct tree *kids[2]; - STATE_TYPE state_label; -} *NODEPTR_TYPE; -#define OP_LABEL(p) ((p)->op) -#define LEFT_CHILD(p) ((p)->kids[0]) -#define RIGHT_CHILD(p) ((p)->kids[1]) -#define STATE_LABEL(p) ((p)->state_label) -#define PANIC printf - -static void burm_trace(NODEPTR_TYPE p, int eruleno, int cost, int bestcost) { -#ifdef TRACE - extern const char *burm_string[]; - - fprintf(stderr, "0x%p matched %s with cost %d vs. %d\n", p, - burm_string[eruleno], cost, bestcost); -#endif -} -#endif -%} -%% - - stm = STORE4(addr:address, value:reg) + STORE4(addr:address, value:reg) ins value:GPR emit "str %value, %addr" cost 4; @@ -49,7 +18,7 @@ static void burm_trace(NODEPTR_TYPE p, int eruleno, int cost, int bestcost) { ins addr:GPR fragment "[%addr]"; - stm = reg; + reg; reg = ADD4(left:reg, right:aluparam) ins left:GPR, right:GPR diff --git a/util/mcgg/gram.y b/util/mcgg/gram.y index 5f100c7d2..82f8de7e1 100644 --- a/util/mcgg/gram.y +++ b/util/mcgg/gram.y @@ -7,14 +7,14 @@ #define YYDEBUG 1 static char rcsid[] = "$Id$"; -static int nextesn = 0; -static int nextern = 0; +static int nextern = 1; %} %union { int n; char* string; Tree tree; + Rule rule; Stringlist stringlist; char* stringpair[2]; } @@ -36,37 +36,16 @@ static int nextern = 0; %token STRING %type cost -%type lhs +%type pattern %type stringlist %type when %type rhs %type labelledid %% spec - : decls PPERCENT patterns - | decls + : PATTERNS patterns ; -decls : /* lambda */ - | decls decl - ; - -decl - : TERMINAL blist ';' - | START lhs ';' - { - if (nonterm($2)->number != 1) - yyerror("redeclaration of the start symbol\n"); - } - | ';' - | error ';' { yyerrok; } - ; - -blist - : /* nothing */ - | blist ID { term($2, nextesn++); } - ; - patterns : /* nothing */ | patterns pattern ';' @@ -75,13 +54,16 @@ patterns ; pattern - : lhs '=' rhs when ins outs emits cost { rule($1, $3, nextern++, $4, $8); } + : ID '=' rhs { nonterm($1); $$ = rule($1, $3, nextern++); } + | rhs { $$ = rule("stmt", $1, nextern++); } + | pattern WHEN stringlist { $$ = $1; $$->when = $3; } + | pattern INS ins { $$ = $1; } + | pattern OUTS outs { $$ = $1; } + | pattern EMIT STRING { $$ = $1; } + | pattern FRAGMENT STRING { $$ = $1; } + | pattern COST INT { $$ = $1; $$->cost = $3; } ; -lhs - : ID { $$ = $1; nonterm($$); } - ; - rhs : labelledid { $$ = tree($1[1], $1[0], NULL, NULL); } | labelledid '(' rhs ')' { $$ = tree($1[1], $1[0], $3, NULL); } @@ -104,12 +86,7 @@ stringlist ; ins - : /* nothing */ - | INS inslist - ; - -inslist - : inslist ',' in + : ins ',' in | in ; @@ -118,12 +95,7 @@ in ; outs - : /* nothing */ - | OUTS outslist - ; - -outslist - : outslist ',' out + : outs ',' out | out ; @@ -131,22 +103,6 @@ out : ID ':' ID ; -emits - : /* nothing */ - | EMIT STRING - | FRAGMENT STRING - ; - -cost - : /* lambda */ { $$ = 0; } - | COST INT { - if ($2 > maxcost) { - yyerror("%d exceeds maximum cost of %d\n", $2, maxcost); - $$ = maxcost; - } else - $$ = $2; - } - ; %% #include #include diff --git a/util/mcgg/iburg.c b/util/mcgg/iburg.c index b4ef1442e..e581b7b90 100644 --- a/util/mcgg/iburg.c +++ b/util/mcgg/iburg.c @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) for (;;) { - int opt = getopt(argc, argv, "p:i:o:"); + int opt = getopt(argc, argv, "p:i:o:y"); if (opt == -1) break; @@ -88,6 +88,13 @@ int main(int argc, char* argv[]) } break; + case 'y': + { + extern int yydebug; + yydebug = 1; + break; + } + default: yyerror("usage: %s [-p prefix] < input > output\n", argv[0]); exit(1); @@ -97,6 +104,8 @@ int main(int argc, char* argv[]) emitheader(); registerterminals(); + start = nonterm("stmt"); + yyin = infp; yyparse(); @@ -308,14 +317,13 @@ Tree tree(const char* id, const char* label, Tree left, Tree right) } /* rule - create & initialize a rule with the given fields */ -Rule rule(char* id, Tree pattern, int ern, Stringlist when, int cost) +Rule rule(char* id, Tree pattern, int ern) { Rule r = calloc(1, sizeof *r); Rule *q; Term p = pattern->op; nrules++; - r->when = when; r->lhs = nonterm(id); r->packed = ++r->lhs->lhscount; for (q = &r->lhs->rules; *q; q = &(*q)->decode) @@ -323,7 +331,6 @@ Rule rule(char* id, Tree pattern, int ern, Stringlist when, int cost) *q = r; r->pattern = pattern; r->ern = ern; - r->cost = cost; if (p->kind == TERM) { r->next = p->rules; diff --git a/util/mcgg/iburg.h b/util/mcgg/iburg.h index 59bbfd7d8..59c84a3ea 100644 --- a/util/mcgg/iburg.h +++ b/util/mcgg/iburg.h @@ -68,7 +68,7 @@ struct rule Rule kids; /* next rule with same burm_kids pattern */ Stringlist when; /* C predicate string */ }; -extern Rule rule(char* id, Tree pattern, int ern, Stringlist when, int cost); +extern Rule rule(char* id, Tree pattern, int ern); extern int maxcost; /* maximum cost */ /* gram.y: */