remove some v9 specific code
[oota-llvm.git] / utils / Burg / burs.c
1 char rcsid_burs[] = "$Id$";
2
3 #include "b.h"
4
5 Item_Set errorState;
6
7 static void doLeaf ARGS((Operator));
8
9 static void
10 doLeaf(leaf) Operator leaf;
11 {
12   int new;
13   List pl;
14   Item_Set ts;
15   Item_Set tmp;
16
17   assert(leaf->arity == 0);
18
19   ts = newItem_Set(leaf->table->relevant);
20
21   for (pl = rules; pl; pl = pl->next) {
22     Rule p = (Rule) pl->x;
23     if (p->pat->op == leaf) {
24       if (!ts->virgin[p->lhs->num].rule || p->delta < ts->virgin[p->lhs->num].delta) {
25         ts->virgin[p->lhs->num].rule = p;
26         ASSIGNCOST(ts->virgin[p->lhs->num].delta, p->delta);
27         ts->op = leaf;
28       }
29     }
30   }
31   trim(ts);
32   zero(ts);
33   tmp = encode(globalMap, ts, &new);
34   if (new) {
35     closure(ts);
36     leaf->table->transition[0] = ts;
37     addQ(globalQ, ts);
38   } else {
39     leaf->table->transition[0] = tmp;
40     freeItem_Set(ts);
41   }
42 }
43
44 void
45 build()
46 {
47   int new;
48   List ol;
49   Item_Set ts;
50
51   globalQ = newQ();
52   globalMap = newMapping(GLOBAL_MAP_SIZE);
53
54   ts = newItem_Set(0);
55   errorState = encode(globalMap, ts, &new);
56   ts->closed = ts->virgin;
57   addQ(globalQ, ts);
58
59   foreachList((ListFn) doLeaf, leaves);
60
61   debug(debugTables, printf("---initial set of states ---\n"));
62   debug(debugTables, dumpMapping(globalMap));
63   debug(debugTables, foreachList((ListFn) dumpItem_Set, globalQ->head));
64
65   for (ts = popQ(globalQ); ts; ts = popQ(globalQ)) {
66     for (ol = operators; ol; ol = ol->next) {
67       Operator op = (Operator) ol->x;
68       addToTable(op->table, ts);
69     }
70   }
71 }