/* Generates contents of opcode switch from ip_spec.t, and parameter descriptions of em_flag.h. Call is: mkiswitch prefix ip_spec.t cases */ /* $Id$ */ #include extern FILE *popen(); #include #include #include extern char em_mnem[][4] ; extern char em_flag[] ; char *progname; FILE *ifp; /* Input File Pointer */ FILE *ofp; /* Output File Pointer */ char *Prefix; /* Prefix for function name */ main(argc, argv) int argc; char **argv; { char mnem[8]; /* Mnemonic */ char flgs[8]; /* Flags */ char argstr[256]; /* To build argument */ progname = argv[0]; if (argc != 4 ) { fatal("usage is: %s prefix ip_spec.t cases\n", argv[0]); } Prefix = argv[1]; if ((ifp = fopen(argv[2], "r")) == 0) { fatal("cannot open '%s' for reading\n", argv[2]); } if ((ofp = fopen(argv[3], "w")) == 0) { fatal("cannot open '%s' for writing\n", argv[3]); } /* Start reading the input file */ while (fscanf(ifp, "%s %s", mnem, flgs) >= 0) { int i; char *p; char *base; int cnt, first; int mnemcode; /* check flags */ for (p = flgs; *p; p++) { if (!in("-ms2u4eNPwo", *p)) { fatal("bad flags ip_spec: %s\n", flgs); } } if ( in(flgs, '-') + in(flgs, 'm') + in(flgs, 's') + in(flgs, '2') + in(flgs, 'u') + in(flgs, '4') != 1 ) { fatal("duplicate or missing opcode flag ip_spec: %s\n", flgs); } if ( in(flgs, 'N') + in(flgs, 'P') > 1 ) { fatal("duplicate restriction flags ip_spec: %s\n", flgs); } mnemcode = getmnem(mnem); /* capitalize mnemonic */ for (p = mnem; *p; p++) { *p += ('A' - 'a'); } /* scan rest of line */ if ( in(flgs, '-') || in(flgs, '2') || in(flgs, 'u') || in(flgs, '4') ) { fscanf(ifp, " %d \n", &first); } else { fscanf(ifp, " %d %d \n", &cnt, &first); } /* determine base */ if (in(flgs, 'e')) /* Escaped (secondary) opcode */ base = "SEC_BASE"; else if (in(flgs, '4')) /* Escaped (tertiary) opcode */ base = "TERT_BASE"; else base = "PRIM_BASE"; /* analyse the opcode */ if (in(flgs, '-')) { if ((em_flag[mnemcode] & EM_PAR) == PAR_W) { /* Implicit argument on stack */ ImplicitArg(argstr); OutCase(mnem, base, first, 0, argstr); } else { /* No arguments */ NoArgs(argstr); OutCase(mnem, base, first, 0, argstr); } } else if (in(flgs, 'm')) { /* Mini */ for (i = 0; i