/* * Conditional jump or branch. * Jump to lbl if tree == cond. */ jumpc(tree, lbl, cond) int tree[]; { extern cctab, block, rcexpr; rcexpr(block(1,easystmt()+103,tree,lbl,cond),cctab); } /* Write expression tree into output file. */ /* TODO: what's with the table? */ rcexpr(tree, table) int tree[], table; { extern space, ospace, putwrd, putchar, line; int c, sp[]; putchar('#'); c = space-ospace; c =/ 2; /* # addresses per word */ sp = ospace; putwrd(c); putwrd(tree); putwrd(table); putwrd(line); while(c--) putwrd(*sp++); } jump(lab) { extern printf; printf("jmp\tl%d\n", lab); } label(l) { extern printf; printf("l%d:", l); } retseq() { extern printf; printf("jmp\tretrn\n"); } /* A C label is a pointer to the code location. */ slabel() { extern csym[], printf; printf(".data; l%d: 1f; .text; 1:\n", csym[2]); } /* Set stack to depth a. Current depth stored in 'stack'. */ setstk(a) { extern printf, stack; auto ts; ts = a-stack; stack = a; /* Try to be code efficient. */ switch(ts) { case 0: return; case 0177776: /* -2 */ printf("tst -(sp)\n"); return; case 0177774: /* -4 */ printf("cmp -(sp),-(sp)\n"); return; } printf("add $%o,sp\n", ts); } /* An automatic vector is a pointer to the memory directly above it. */ defvec() { extern printf, stack; printf("mov\tsp,r0\nmov\tr0,-(sp)\n"); stack =- 2; } /* Define a static variable */ defstat(s) int s[]; { extern printf, length; int len; len = length(s[1]); if (s[3]) /* Vector */ printf(".data; l%d:1f; .bss; 1:.=.+%o; .even; .text\n", s[2], s[3]*len); else /* non-Vector */ printf(".bss; l%d:.=.+%o; .even; .text\n", s[2], len); } /* Size of a type. */ length(t) { /* What's this? */ if (t<0) t =+ 020; /* Any pointer is a word. */ if (t>=020) return(2); /* Standard types. */ switch(t) { case 0: return(2); case 1: return(1); case 2: return(4); case 3: return(8); case 4: return(4); } /* What's this? */ return(1024); } /* Size of a type on the stack. */ rlength(c) { extern length; auto l; return((l=length(c))==1? 2: l); } printn(n,b) { extern putchar; auto a; if(a=n/b) /* assignment, not test for equality */ printn(a, b); /* recursive */ putchar(n%b + '0'); } printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9) char fmt[]; { extern printn, putchar, namsiz, ncpw; char s[]; auto adx[], x, c, i[]; adx = &x1; /* argument pointer */ loop: while((c = *fmt++) != '%') { if(c == '\0') return; putchar(c); } x = *adx++; switch (c = *fmt++) { case 'd': /* decimal */ case 'o': /* octal */ if(x < 0) { x = -x; if(x<0) { /* - infinity */ if(c=='o') printf("100000"); else printf("-32767"); goto loop; } putchar('-'); } printn(x, c=='o'?8:10); goto loop; case 's': /* string */ s = x; while(c = *s++) putchar(c); goto loop; case 'p': s = x; putchar('_'); c = namsiz; while(c--) if(*s) putchar(*s++); goto loop; } putchar('%'); fmt--; adx--; goto loop; }