1: /*
   2:  * tree printer routine for C
   3:  */
   4: 
   5: #include "c1.h"
   6: 
   7: char *strop[] {
   8: "0",
   9: ";",
  10: "{",
  11: "}",
  12: "[",
  13: "]",
  14: "(",
  15: ")",
  16: ":",
  17: ",",
  18: "10",
  19: "11",
  20: "12",
  21: "13",
  22: "14",
  23: "15",
  24: "16",
  25: "17",
  26: "18",
  27: "19",
  28: "",
  29: "",
  30: "string",
  31: "fcon",
  32: "sfcon",
  33: "25",
  34: "26",
  35: "",
  36: "",
  37: "sizeof",
  38: "++pre",
  39: "--pre",
  40: "++post",
  41: "--post",
  42: "!un",
  43: "&un",
  44: "*un",
  45: "-un",
  46: "~un",
  47: ".",
  48: "+",
  49: "-",
  50: "*",
  51: "/",
  52: "%",
  53: ">>",
  54: "<<",
  55: "&",
  56: "|",
  57: "^",
  58: "->",
  59: "itof",
  60: "ftoi",
  61: "&&",
  62: "||",
  63: "&~",
  64: "ftol",
  65: "ltof",
  66: "itol",
  67: "ltoi",
  68: "==",
  69: "!=",
  70: "<=",
  71: "<",
  72: ">=",
  73: ">",
  74: "<p",
  75: "<=p",
  76: ">p",
  77: ">=p",
  78: "=+",
  79: "=-",
  80: "=*",
  81: "=/",
  82: "=%",
  83: "=>>",
  84: "=<<",
  85: "=&",
  86: "=|",
  87: "=^",
  88: "=",
  89: "&(test)",
  90: "82",
  91: "83",
  92: "84",
  93: "=&~",
  94: "86",
  95: "87",
  96: "88",
  97: "89",
  98: "?",
  99: "91",
 100: "92",
 101: "93",
 102: "94",
 103: "95",
 104: "96",
 105: "97",
 106: "98",
 107: "99",
 108: "call",
 109: "mcall",
 110: "jump",
 111: "cbranch",
 112: "init",
 113: "setreg",
 114: "106",
 115: "107",
 116: "108",
 117: "109",
 118: "forcereg",
 119: };
 120: 
 121: treeprint(tp)
 122: struct tnode *tp;
 123: {
 124:     register f;
 125:     extern fout;
 126:     static tout;
 127: 
 128:     if (tout==0)
 129:         tout = dup(1);
 130:     flush();
 131:     f = fout;
 132:     fout = tout;
 133:     printf("\n");
 134:     tprt(tp, 0);
 135:     flush();
 136:     fout = f;
 137: }
 138: 
 139: tprt(at, al)
 140: struct tnode *at;
 141: {
 142:     register struct tnode *t;
 143:     register i, l;
 144: 
 145:     t = at;
 146:     l = al;
 147:     if (i=l)
 148:         do
 149:             printf(". ");
 150:         while (--i);
 151:     if (t<treebase || t>=spacemax) {
 152:         printf("%o: bad tree ptr\n", t);
 153:         return;
 154:     }
 155:     if (t->op<0 || t->op>RFORCE) {
 156:         printf("%d\n", t->op);
 157:         return;
 158:     }
 159:     printf("%s", strop[t->op]);
 160:     switch (t->op) {
 161: 
 162:     case SETREG:
 163:         printf("%d\n", t->type);
 164:         return;
 165: 
 166:     case PLUS:
 167:     case MINUS:
 168:     case TIMES:
 169:     case DIVIDE:
 170:     case MOD:
 171:     case LSHIFT:
 172:     case RSHIFT:
 173:     case AND:
 174:     case OR:
 175:     case EXOR:
 176:     case NAND:
 177:     case LOGAND:
 178:     case LOGOR:
 179:     case EQUAL:
 180:     case NEQUAL:
 181:     case LESSEQ:
 182:     case LESS:
 183:     case GREATEQ:
 184:     case GREAT:
 185:     case LESSEQP:
 186:     case LESSP:
 187:     case GREATQP:
 188:     case GREATP:
 189:     case ASPLUS:
 190:     case ASMINUS:
 191:     case ASTIMES:
 192:     case ASDIV:
 193:     case ASMOD:
 194:     case ASRSH:
 195:     case ASLSH:
 196:     case ASSAND:
 197:     case ASSNAND:
 198:     case ASOR:
 199:     case ASXOR:
 200:     case ASSIGN:
 201:     case QUEST:
 202:     case CALL:
 203:     case MCALL:
 204:     case CALL1:
 205:     case CALL2:
 206:     case TAND:
 207:         prtype(t);
 208: 
 209:     case COLON:
 210:     case COMMA:
 211:         printf("\n");
 212:         tprt(t->tr1, l+1);
 213:         tprt(t->tr2, l+1);
 214:         return;
 215: 
 216:     case INCBEF:
 217:     case INCAFT:
 218:     case DECBEF:
 219:     case DECAFT:
 220:         printf(" (%d)", t->tr2);
 221: 
 222:     case EXCLA:
 223:     case AMPER:
 224:     case STAR:
 225:     case NEG:
 226:     case COMPL:
 227:     case INIT:
 228:     case JUMP:
 229:     case LOAD:
 230:     case RFORCE:
 231:     case ITOF:
 232:     case FTOI:
 233:     case FTOL:
 234:     case LTOF:
 235:     case LTOI:
 236:     case ITOL:
 237:         prtype(t);
 238:         printf("\n");
 239:         tprt(t->tr1, l+1);
 240:         return;
 241: 
 242:     case NAME:
 243:     case CON:
 244:     case SFCON:
 245:     case FCON:
 246:     case AUTOI:
 247:     case AUTOD:
 248:         pname(t, 0);
 249:         prtype(t);
 250:         printf("\n");
 251:         return;
 252: 
 253:     case CBRANCH:
 254:         printf(" (L%d)\n", t->lbl);
 255:         tprt(t->btree, l+1);
 256:         return;
 257: 
 258:     default:
 259:         printf(" unknown\n");
 260:         return;
 261:     }
 262: }
 263: 
 264: char *typetab[] {
 265:     "int",
 266:     "char",
 267:     "float",
 268:     "double",
 269:     "struct",
 270:     "(?5)",
 271:     "long",
 272:     "(?7)",
 273: };
 274: 
 275: char    *modtab[] {
 276:     0,
 277:     "*",
 278:     "()",
 279:     "[]",
 280: };
 281: 
 282: prtype(atp)
 283: struct tnode *atp;
 284: {
 285:     register struct tnode *tp;
 286:     register t;
 287: 
 288:     tp = atp;
 289:     printf(" %s", typetab[tp->type&07]);
 290:     t = (tp->type>>3) & 017777;
 291:     while (t&03) {
 292:         printf(modtab[t&03]);
 293:         t =>> 2;
 294:     }
 295:     printf(" (%d)", tp->degree);
 296: }

Defined functions

prtype defined in line 282; used 3 times
tprt defined in line 139; used 5 times
treeprint defined in line 121; never used

Defined variables

modtab defined in line 275; used 1 times
strop defined in line 7; used 1 times
typetab defined in line 264; used 1 times
Last modified: 1986-10-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2199
Valid CSS Valid XHTML 1.0 Strict