Pristine Ack-5.5
[Ack-5.5.git] / util / ego / ra / makeitems.c
1 /* $Id: makeitems.c,v 1.6 1994/06/24 10:27:15 ceriel Exp $ */
2 /*
3  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4  * See the copyright notice in the ACK home directory, in the file "Copyright".
5  */
6 #include <stdio.h>
7
8 /*  MAKE ITEMS TABLE
9  *
10  * This program is used by the register allocation phase of the optimizer
11  * to make the file itemtab.h. It reads two files:
12  *  - the em_mnem.h file, containing the definitions of the
13  *    EM mnemonics
14  *  - the item-file, containing tuples:
15  *    (mnemonic, item_type)
16  * The output (standard output) is a C array.
17  */
18
19
20 #define TRUE  1
21 #define FALSE 0
22
23 convert(mnemfile,itemfile)
24         FILE *mnemfile, *itemfile;
25 {
26         char mnem1[20], mnem2[20],def[20],itemtype[20];
27         int newcl,opc,index;
28
29         newcl = TRUE;
30         printf("struct item_descr itemtab[] = {\n");
31         for (;;) {
32                 fscanf(mnemfile,"%s%s%d",def,mnem1,&opc);
33                 /* read a line like "#define op_aar 1" */
34                 if (feof(mnemfile)) break;
35                 if (strcmp(def,"#define") != 0) {
36                         error("bad mnemonic file, #define expected");
37                 }
38                 if (newcl) {
39                         fscanf(itemfile,"%s%s%d",mnem2,itemtype,&index);
40                         /* read a line like "op_loc CONST 4" */
41                 }
42                 if (feof(itemfile) || strcmp(mnem1,mnem2) != 0) {
43                         /* there is no line for this mnemonic, so
44                          * it has no type.
45                          */
46                         printf("{NO_ITEM,0}, /* %s */\n", mnem1);
47                         newcl = FALSE;
48                 } else {
49                         printf("{%s,%d}, /* %s */\n",itemtype,index, mnem1);
50                         newcl = TRUE;
51                 }
52         }
53         printf("};\n");
54 }
55
56
57
58 error(s)
59         char *s;
60 {
61         fprintf(stderr,"%s\n",s);
62         exit(-1);
63 }
64
65
66 main(argc,argv)
67         int argc;
68         char *argv[];
69 {
70         FILE *f1,*f2;
71
72         if (argc != 3) {
73                 error("usage: makeitems mnemfile itemfile");
74         }
75         if ((f1 = fopen(argv[1],"r")) == NULL) {
76                 error("cannot open mnemonic file");
77         }
78         if ((f2 = fopen(argv[2],"r")) == NULL) {
79                 error("cannot open item file");
80         }
81         convert(f1,f2);
82         exit(0);
83 }