00001 # include <stdio.h>
00002 # include "../parm.h"
00003 # include "codegen.h"
00004 # include "op_codes.h"
00005
00006 # define NONE ((char *) 0)
00007
00008 FILE * in_file;
00009
00010 char label_buf[MAXLABELSZ+1];
00011
00012 extern char * op_code_table[];
00013
00014 main(argc, argv)
00015 int argc;
00016 char ** argv;
00017 {
00018 int opc;
00019 char * op_mnem;
00020 int i;
00021 int arg;
00022
00023 if (argc == 1) {
00024 in_file = stdin;
00025 } else if (argc == 2) {
00026 in_file = fopen(argv[1], "r");
00027 if (in_file == NULL) {
00028 fprintf(stderr, "Can't open %s\n", argv[1]);
00029 exit(1);
00030 }
00031 } else {
00032 fprintf(stderr, "Usage: %s [%s]\n", argv[0], argv[1]);
00033 }
00034 while (!feof(in_file)) {
00035 opc = getw(in_file);
00036 if (feof(in_file)) {
00037
00038 exit(0);
00039 }
00040 if (opc >= 0 && opc < N_OP_CODES) {
00041 op_mnem = op_code_table[opc];
00042 } else {
00043 op_mnem = NONE;
00044 }
00045 if (op_mnem == NONE) {
00046 printf("(%d)", opc);
00047 } else {
00048 printf("%s", op_mnem);
00049 }
00050 if (opc <= MAX_LABEL_OP) {
00051 char *p = label_buf;
00052 int c;
00053 int i = 0;
00054
00055 while ((c = getc(in_file)) != '\0' && c != EOF) {
00056 *p++ = c;
00057 if (++i >= MAXLABELSZ) {
00058 fprintf(stderr, "Label too long\n");
00059 p = label_buf;
00060 }
00061 }
00062 *p = '\0';
00063 printf("\t%s", label_buf);
00064 } else {
00065 for ( i = 0; i < 3; i++ ) {
00066 arg = getw(in_file);
00067 switch (arg) {
00068 case AR:
00069 printf("\t%d(AR)", AR);
00070 break;
00071 case SP:
00072 printf("\t%d(SP)", SP);
00073 break;
00074 case GF:
00075 printf("\t%d(GF)", GF);
00076 break;
00077 case UN:
00078 printf("\t%d(UN)", UN);
00079 break;
00080 case SK:
00081 printf("\t%d(SK)", SK);
00082 break;
00083 case TL:
00084 printf("\t%d(TL)", TL);
00085 break;
00086 case RL:
00087 printf("\t%d(RL)", RL);
00088 break;
00089 case C0:
00090 printf("\t%d(C0)", C0);
00091 break;
00092 case C1:
00093 printf("\t%d(C1)", C1);
00094 break;
00095 case C2:
00096 printf("\t%d(C2)", C2);
00097 break;
00098 case C3:
00099 printf("\t%d(C3)", C3);
00100 break;
00101 case C4:
00102 printf("\t%d(C4)", C4);
00103 break;
00104 default:
00105 printf("\t%d", arg);
00106 }
00107 }
00108 }
00109 printf("\n");
00110 }
00111 }