123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
- /* This is the main program for the stand-alone version of the
- peephole optimizer.
- */
- #include <stdarg.h>
- #include "nopt.h"
- char *filename; /* Name of input file */
- int errors; /* Number of errors */
- int main(int argc, char *argv[])
- {
- static struct e_instr buff;
- p_instr p = &buff;
- if (argc >= 2) {
- filename = argv[1];
- }
- else filename = 0;
- if (!EM_open(filename)) {
- fatal(EM_error);
- }
- EM_getinstr(p);
- O_init((arith) EM_wordsize, (arith) EM_pointersize);
- if (argc >= 3) {
- if (!O_open(argv[2])) {
- fatal("O_open failed");
- }
- }
- else if (!O_open( (char *) 0)) fatal("O_open failed");
- O_magic();
- C_out(p);
- for(;;) {
- EM_getinstr(p=GETNXTPATT());
- switch(p->em_type) {
- case EM_DEFILB:
- p->em_opcode=op_lab;
- break;
- case EM_MNEM:
- switch(p->em_argtype) {
- case sof_ptyp:
- p->em_dnam = OO_freestr(p->em_dnam);
- break;
- case pro_ptyp:
- p->em_pnam = OO_freestr(p->em_pnam);
- break;
- case str_ptyp:
- case ico_ptyp:
- case uco_ptyp:
- case fco_ptyp:
- p->em_string = OO_freestr(p->em_string);
- break;
- }
- break;
- case EM_PSEU:
- switch(p->em_opcode) {
- case ps_pro:
- case ps_end:
- break;
- default:
- C_out(p);
- OO_nxtpatt--;
- continue;
- }
- break;
- default:
- C_out(p);
- OO_nxtpatt--;
- continue;
- case EM_EOF:
- goto got_eof;
- case EM_ERROR:
- error("%s", EM_error);
- continue;
- case EM_FATAL:
- fatal("%s", EM_error);
- }
- OO_dfa(p->em_opcode);
- }
- got_eof:
- O_close();
- EM_close();
- exit(errors);
- }
- /*VARARGS1*/
- static int verror(char *s, va_list ap)
- {
- fprintf(stderr,
- "%s, line %d: ",
- filename ? filename : "standard input",
- EM_lineno);
- vfprintf(stderr, s, ap);
- fprintf(stderr, "\n");
- errors++;
- return 0;
- }
- int error(char *s, ...)
- {
- va_list ap;
- va_start(ap, s);
- verror(s, ap);
- va_end(ap);
- return 0;
- }
- /*VARARGS1*/
- int fatal(char *s, ...)
- {
- va_list ap;
- va_start(ap, s);
- verror(s, ap);
- va_end(ap);
- exit(1);
- return 0;
- }
|