1 /* $Id: makecldef.c,v 1.5 1994/06/24 10:30:29 ceriel Exp $ */
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".
10 * This program is used by several phases of the optimizer
11 * to make the file classdefs.h. It reads two files:
12 * - the em_mnem,h file, containing the definitions of the
14 * - the class-file, containing tuples:
15 * (mnemonic, src_class, res_class)
16 * where src_class and res_class are integers telling how
17 * to compute the number of bytes popped and pushed
19 * The output (standard output) is a C array.
26 convert(mnemfile,classfile)
27 FILE *mnemfile, *classfile;
29 char mnem1[10], mnem2[10],def[10];
30 int src,res,newcl,opc;
33 printf("struct class classtab[] = {\n");
34 printf("\tNOCLASS,\tNOCLASS,\n");
35 /* EM mnemonics start at 1, arrays in C at 0 */
37 fscanf(mnemfile,"%s%s%d",def,mnem1,&opc);
38 /* read a line like "#define op_aar 1" */
39 if (feof(mnemfile)) break;
40 if (strcmp(def,"#define") != 0) {
41 error("bad mnemonic file, #define expected");
44 fscanf(classfile,"%s%d%d",mnem2,&src,&res);
45 /* read a line like "op_loc 8 1" */
47 if (feof(classfile) || strcmp(mnem1,mnem2) != 0) {
48 /* there is no line for this mnemonic, so
51 printf("\tNOCLASS,\tNOCLASS,\n");
54 printf("\tCLASS%d,\t\tCLASS%d,\n",src,res);
55 /* print a line like "CLASS8, CLASS1," */
67 fprintf(stderr,"%s\n",s);
79 error("usage: makeclassdef mnemfile classfile");
81 if ((f1 = fopen(argv[1],"r")) == NULL) {
82 error("cannot open mnemonic file");
84 if ((f2 = fopen(argv[2],"r")) == NULL) {
85 error("cannot open class file");