Starting to convert C compiler to asxxxx
authorNick Downing <nick@ndcode.org>
Sun, 7 Aug 2022 01:09:39 +0000 (11:09 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 7 Aug 2022 01:10:22 +0000 (11:10 +1000)
12 files changed:
.gitignore [new file with mode: 0644]
bin/aslink [new file with mode: 0755]
bin/aspdp11 [new file with mode: 0755]
lib/c2
usr/src/cmd/c.sh [new file with mode: 0755]
usr/src/cmd/c/c10.c
usr/src/cmd/c/c11.c
usr/src/cmd/c/c13.c
usr/src/cmd/c/c20.c
usr/src/cmd/c/c21.c
usr/src/cmd/c/table.s
usr/src/libc/a.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..0572c63
--- /dev/null
@@ -0,0 +1,3 @@
+*.a
+*.o
+/usr/sys/conf/unix
diff --git a/bin/aslink b/bin/aslink
new file mode 100755 (executable)
index 0000000..2b33be9
Binary files /dev/null and b/bin/aslink differ
diff --git a/bin/aspdp11 b/bin/aspdp11
new file mode 100755 (executable)
index 0000000..e0dbce6
Binary files /dev/null and b/bin/aspdp11 differ
diff --git a/lib/c2 b/lib/c2
index 7b36966..f1bb75c 100755 (executable)
Binary files a/lib/c2 and b/lib/c2 differ
diff --git a/usr/src/cmd/c.sh b/usr/src/cmd/c.sh
new file mode 100755 (executable)
index 0000000..39ca267
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+git checkout ../../../lib/c[012]
+mkdir --parents ../../../tmp
+export APOUT_ROOT=`pwd`/../../..
+export PATH=`pwd`/../../../bin:`pwd`
+(echo ==== c =====; cd c; make cp)
index 229391b..6d631d2 100644 (file)
@@ -59,7 +59,7 @@ char *argv[];
        /*
         * tack on the string file.
         */
-       printf(".globl\n.data\n");
+       printf(".area   data\n");
        if (*argv[2] != '-') {
                if (freopen(argv[2], "r", stdin)==NULL) {
                        error("Missing temp file");
@@ -289,8 +289,10 @@ again:
                }
                tree = atree;
                tree->op = CALL2;
+#if 0 /* seems to generate "jsr pc,*#label" instead of "jsr pc,label" */
                if (modf && tree->tr1->op==NAME && tree->tr1->class==EXTERN)
                        tree->op = CALL1;
+#endif
                if (cexpr(tree, regtab, reg)<0)
                        error("compiler botch: call");
                popstk(r);
@@ -495,14 +497,14 @@ struct table *table;
        string = opt->tabstring;
        p1 = tree->tr1;
        if (p1->op==FCON && p1->value>0) {
-               printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p1->value, p1->fvalue);
+               printf(".area   data\nL%d:%o;%o;%o;%o\n.area    text\n", p1->value, p1->fvalue);
                p1->value = -p1->value;
        }
        p2 = 0;
        if (opdope[tree->op]&BINARY) {
                p2 = tree->tr2;
                if (p2->op==FCON && p2->value>0) {
-                       printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p2->value, p2->fvalue);
+                       printf(".area   data\nL%d:%o;%o;%o;%o\n.area    text\n", p2->value, p2->fvalue);
                        p2->value = -p2->value;
                }
        }
@@ -780,7 +782,7 @@ loop:
         * Mask used in field assignments
         */
        case 'Z':
-               printf("$%o", tree->mask);
+               printf("#%o", tree->mask);
                goto loop;
 
        /*
@@ -1056,7 +1058,7 @@ int *flagp;
                } else {
                        if (retval!=0)
                                printf("mov     r%d,r0\n", retval);
-                       printf("mov     $%o,r1\n", size);
+                       printf("mov     #%o,r1\n", size);
                        printf("L%d:mov -(r0),-(sp)\ndec\tr1\njne\tL%d\n", isn, isn);
                        isn++;
                }
index 332b66c..004aab9 100644 (file)
@@ -49,12 +49,12 @@ loop:
        switch(p->op) {
 
        case LCON:
-               printf("$%o", flag>10? p->lvalue.intx[1]:p->lvalue.intx[0]);
+               printf("#%o", flag>10? p->lvalue.intx[1]:p->lvalue.intx[0]);
                return;
 
        case SFCON:
        case CON:
-               printf("$");
+               printf("#");
                psoct(p->value);
                return;
 
@@ -97,7 +97,7 @@ loop:
                return;
 
        case AMPER:
-               putchar('$');
+               putchar('#');
                p = p->tr1;
                if (p->op==NAME && p->class==REG)
                        regerr();
@@ -335,21 +335,21 @@ arlength(t)
  */
 
 char   dirsw[] {"\
-cmp    r0,$%o\n\
+cmp    r0,#%o\n\
 jhi    L%d\n\
 asl    r0\n\
 jmp    *L%d(r0)\n\
-.data\n\
+.area  data\n\
 L%d:\
 " };
 
 char   hashsw[] {"\
 mov    r0,r1\n\
 clr    r0\n\
-div    $%o,r0\n\
+div    #%o,r0\n\
 asl    r1\n\
 jmp    *L%d(r1)\n\
-.data\n\
+.area  data\n\
 L%d:\
 "};
 
@@ -380,7 +380,7 @@ struct swtab *afp, *alp;
        /* direct switch */
        if (range>0 && range <= 3*ncase) {
                if (fp->swval)
-                       printf("sub     $%o,r0\n", fp->swval);
+                       printf("sub     #%o,r0\n", fp->swval);
                printf(dirsw, range, deflab, isn, isn);
                isn++;
                for (i=fp->swval; ; i++) {
@@ -392,7 +392,7 @@ struct swtab *afp, *alp;
                        } else
                                printf("L%d\n", deflab);
                }
-               printf(".text\n");
+               printf(".area   text\n");
                return;
        }
        /* simple switch */
@@ -425,7 +425,7 @@ struct swtab *afp, *alp;
        isn++;
        for (i=0; i<tabs; i++)
                printf("L%d\n", isn+i);
-       printf(".text\n");
+       printf(".area   text\n");
        for (i=0; i<tabs; i++) {
                printf("L%d:", isn++);
                for (swp=fp; swp<=lp; swp++) {
@@ -444,7 +444,7 @@ breq(v, l)
        if (v==0)
                printf("tst     r0\n");
        else
-               printf("cmp     r0,$%o\n", v);
+               printf("cmp     r0,#%o\n", v);
        printf("jeq     L%d\n", l);
 }
 
@@ -665,7 +665,7 @@ struct tnode *atree;
        }
        if (cexpr(tree, cctab, reg) < 0) {
                reg = rcexpr(tree, regtab, reg);
-               printf("ashc    $0,r%d\n", reg);
+               printf("ashc    #0,r%d\n", reg);
                branch(xlab1, op, 0);
        }
        xlab1 = xl1;
@@ -738,7 +738,7 @@ popstk(a)
                printf("cmp     (sp)+,(sp)+\n");
                return;
        }
-       printf("add     $%o,sp\n", a);
+       printf("add     #%o,sp\n", a);
 }
 
 error(s, p1, p2, p3, p4, p5, p6)
@@ -816,15 +816,15 @@ getree()
                break;
 
        case PROG:
-               printf(".text\n");
+               printf(".area   text\n");
                break;
 
        case DATA:
-               printf(".data\n");
+               printf(".area   data\n");
                break;
 
        case BSS:
-               printf(".bss\n");
+               printf(".area   bss\n");
                break;
 
        case SYMDEF:
@@ -834,7 +834,7 @@ getree()
                break;
 
        case RETRN:
-               printf("jmp     cret\n");
+               printf(".globl  cret\njmp       cret\n");
                break;
 
        case CSPACE:
@@ -852,7 +852,7 @@ getree()
                break;
 
        case SAVE:
-               printf("jsr     r5,csv\n");
+               printf(".globl  csv\njsr        r5,csv\n");
                break;
 
        case SETSTK:
@@ -860,28 +860,28 @@ getree()
                if (t==2)
                        printf("tst     -(sp)\n");
                else if (t != 0)
-                       printf("sub     $%o,sp\n", t);
+                       printf("sub     #%o,sp\n", t);
                break;
 
        case PROFIL:
                t = geti();
-               printf("mov     $L%d,r0\njsr    pc,mcount\n", t);
-               printf(".bss\nL%d:.=.+2\n.text\n", t);
+               printf("mov     #L%d,r0\n.globl mcount\njsr     pc,mcount\n", t);
+               printf(".area   bss\nL%d:.=.+2\n.area   text\n", t);
                break;
 
        case SNAME:
                t = outname(s);
-               printf("~%s=L%d\n", t+1, geti());
+               printf(";~%s=L%d\n", t+1, geti());
                break;
 
        case ANAME:
                t = outname(s);
-               printf("~%s=%o\n", t+1, geti());
+               printf(";~%s=%o\n", t+1, geti());
                break;
 
        case RNAME:
                t = outname(s);
-               printf("~%s=r%d\n", t+1, geti());
+               printf(";~%s=r%d\n", t+1, geti());
                break;
 
        case SWIT:
@@ -919,7 +919,7 @@ getree()
                else {
                        if ((*sp)->type==LONG) {
                                rcexpr(tnode(RFORCE, (*sp)->type, *sp), efftab, 0);
-                               printf("ashc    $0,r0\n");
+                               printf("ashc    #0,r0\n");
                        } else {
                                rcexpr(*sp, cctab, 0);
                                if (isfloat(*sp))
@@ -1011,7 +1011,7 @@ getree()
 
        case RLABEL:
                t = outname(s);
-               printf("%.8s:\n~~%s:\n", t, t+1);
+               printf("%.8s:\n;~~%s:\n", t, t+1);
                break;
 
        case BRANCH:
@@ -1075,11 +1075,11 @@ struct fasgn *atp;
                if (tp->op==RFORCE) {   /* function return */
                        if (sfuncr.nloc==0) {
                                sfuncr.nloc = isn++;
-                               printf(".bss\nL%d:.=.+%o\n.text\n", sfuncr.nloc, nwords*sizeof(int));
+                               printf(".area   bss\nL%d:.=.+%o\n.area  text\n", sfuncr.nloc, nwords*sizeof(int));
                        }
                        atp->tr1 = tnode(ASSIGN, STRUCT, &sfuncr, tp->tr1);
                        strasg(atp);
-                       printf("mov     $L%d,r0\n", sfuncr.nloc);
+                       printf("mov     #L%d,r0\n", sfuncr.nloc);
                        return;
                }
                if (tp->op==CALL) {
@@ -1113,7 +1113,7 @@ struct fasgn *atp;
                }
                if (nreg<=1)
                        printf("mov     r2,-(sp)\n");
-               printf("mov     $%o,r2\n", nwords);
+               printf("mov     #%o,r2\n", nwords);
                printf("L%d:mov (r1)+,(r0)+\ndec\tr2\njne\tL%d\n", isn, isn);
                isn++;
                if (nreg<=1)
index 0af8ae7..944afb1 100644 (file)
@@ -262,15 +262,15 @@ char      asr[]   "asr";
 char   ash[]   "ash";
 char   asl[]   "asl";
 char   bic[]   "bic";
-char   bic1[]  "bic $1,";
+char   bic1[]  "bic #1,";
 char   bit[]   "bit";
-char   bit1[]  "bit $1,";
+char   bit1[]  "bit #1,";
 char   bis[]   "bis";
-char   bis1[]  "bis $1,";
+char   bis1[]  "bis #1,";
 char   xor[]   "xor";
 char   neg[]   "neg";
 char   com[]   "com";
-char   stdol[] "*$";
+char   stdol[] "*#";
 char   ashc[]  "ashc";
 char   slmul[] "lmul";
 char   sldiv[] "ldiv";
index 8bee9fe..9e5cc45 100644 (file)
@@ -38,9 +38,9 @@ struct optab optab[] {
        "mul",  MUL,
        "ash",  ASH,
        "xor",  XOR,
-       ".text",TEXT,
-       ".data",DATA,
-       ".bss", BSS,
+       ".area  text", TEXT,
+       ".area  data", DATA,
+       ".area  bss", BSS,
        ".even",EVEN,
        "movf", MOVF,
        "movof",MOVOF,
@@ -308,7 +308,7 @@ output()
 
 /*
  * Notice addresses of the form
- * $xx,xx(r)
+ * #xx,xx(r)
  * and replace them with (pc),xx(r)
  *     -- Thanx and a tip of the Hatlo hat to Bliss-11.
  */
@@ -320,7 +320,7 @@ struct node *at;
        register struct node *t;
 
        t = at;
-       if (*t->code != '$')
+       if (*t->code != '#')
                return;
        c1 = t->code;
        while (*c1 != ',')
index 267c824..03a7e7b 100644 (file)
@@ -34,7 +34,7 @@ rmove()
                                continue;
                        }
                }
-               if (equstr(regs[RT1], "$0")) {
+               if (equstr(regs[RT1], "#0")) {
                        p->op = CLR;
                        strcpy(regs[RT1], regs[RT2]);
                        regs[RT2][0] = 0;
@@ -75,14 +75,14 @@ rmove()
        case ASH:
        dble:
                dualop(p);
-               if (p->op==BIC && (equstr(regs[RT1], "$-1") || equstr(regs[RT1], "$177777"))) {
+               if (p->op==BIC && (equstr(regs[RT1], "#-1") || equstr(regs[RT1], "#177777"))) {
                        p->op = CLR;
                        strcpy(regs[RT1], regs[RT2]);
                        regs[RT2][0] = 0;
                        p->code = copy(1, regs[RT1]);
                        goto sngl;
                }
-               if ((p->op==BIC || p->op==BIS) && equstr(regs[RT1], "$0")) {
+               if ((p->op==BIC || p->op==BIS) && equstr(regs[RT1], "#0")) {
                        if (p->forw->op!=CBR) {
                                p->back->forw = p->forw;
                                p->forw->back = p->back;
@@ -114,9 +114,9 @@ rmove()
                dest(regs[RT1], flt);
                if (p->op==CLR && flt==0)
                        if ((r = isreg(regs[RT1])) >= 0)
-                               savereg(r, "$0");
+                               savereg(r, "#0");
                        else
-                               setcon("$0", regs[RT1]);
+                               setcon("#0", regs[RT1]);
                ccloc[0] = 0;
                continue;
 
@@ -145,27 +145,27 @@ rmove()
                source(regs[RT1]);
                source(regs[RT2]);
                if(p->op==BIT) {
-                       if (equstr(regs[RT1], "$-1") || equstr(regs[RT1], "$177777")) {
+                       if (equstr(regs[RT1], "#-1") || equstr(regs[RT1], "#177777")) {
                                p->op = TST;
                                strcpy(regs[RT1], regs[RT2]);
                                regs[RT2][0] = 0;
                                p->code = copy(1, regs[RT1]);
                                nchange++;
                                nsaddr++;
-                       } else if (equstr(regs[RT2], "$-1") || equstr(regs[RT2], "$177777")) {
+                       } else if (equstr(regs[RT2], "#-1") || equstr(regs[RT2], "#177777")) {
                                p->op = TST;
                                regs[RT2][0] = 0;
                                p->code = copy(1, regs[RT1]);
                                nchange++;
                                nsaddr++;
                        }
-                       if (equstr(regs[RT1], "$0")) {
+                       if (equstr(regs[RT1], "#0")) {
                                p->op = TST;
                                regs[RT2][0] = 0;
                                p->code = copy(1, regs[RT1]);
                                nchange++;
                                nsaddr++;
-                       } else if (equstr(regs[RT2], "$0")) {
+                       } else if (equstr(regs[RT2], "#0")) {
                                p->op = TST;
                                strcpy(regs[RT1], regs[RT2]);
                                regs[RT2][0] = 0;
@@ -182,7 +182,7 @@ rmove()
                if (p->back->op==TST || p->back->op==CMP) {
                        if (p->back->op==TST) {
                                singop(p->back);
-                               savereg(RT2, "$0");
+                               savereg(RT2, "#0");
                        } else
                                dualop(p->back);
                        r = compare(p->subop, findcon(RT1), findcon(RT2));
@@ -431,7 +431,7 @@ char *as;
        while (*s) {
                if ((*s=='(' && (*(s+1)!='r' || *(s+2)!='5')) || *s++=='*') {
                        for (i=0; i<NREG+NREG; i++) {
-                               if (regs[i][0] != '$')
+                               if (regs[i][0] != '#')
                                        regs[i][0] = 0;
                                conloc[0] = 0;
                        }
@@ -642,7 +642,7 @@ register struct node *p;
        p1 = nonlab(p1);
        if (p1->op==TST) {
                singop(p1);
-               savereg(RT2, "$0");
+               savereg(RT2, "#0");
        } else if (p1->op==CMP)
                dualop(p1);
        else
@@ -669,7 +669,7 @@ findcon(i)
        register r;
 
        p = regs[i];
-       if (*p=='$')
+       if (*p=='#')
                return(p);
        if ((r = isreg(p)) >= 0)
                return(regs[r]);
@@ -683,7 +683,7 @@ register char *cp1, *cp2;
 {
        register unsigned n1, n2;
 
-       if (*cp1++ != '$' || *cp2++ != '$')
+       if (*cp1++ != '#' || *cp2++ != '#')
                return(-1);
        n1 = 0;
        while (*cp2 >= '0' && *cp2 <= '7') {
@@ -737,7 +737,7 @@ char *ar1, *ar2;
 
        cl = ar2;
        cv = ar1;
-       if (*cv != '$')
+       if (*cv != '#')
                return;
        if (!natural(cl))
                return;
index f8ead47..1da42db 100644 (file)
@@ -71,6 +71,7 @@ cr102:
 / call
 cr100:
 %a,n
+       .globl  IA1
        jsr     pc,IA1
 
 %n*,n
@@ -151,21 +152,21 @@ cr32:
 
 %al,1
        F
-       I       $1,A1+
+       I       #1,A1+
        V       A1
 
 %el*,1
        F1*
        mov     #1+2(R1),R+
        mov     #1(R1),R
-       I       $1,#1+2(R1)
+       I       #1,#1+2(R1)
        V       #1(R1)
 
 %nl*,1
        F*
        mov     #1+2(R),-(sp)
        mov     #1(R),-(sp)
-       I       $1,#1+2(R)
+       I       #1,#1+2(R)
        V       #1(R)
        mov     (sp)+,R
        mov     (sp)+,R+
@@ -251,7 +252,7 @@ cr80:
        FS*
        S
        mov     R,*(sp)
-       add     $2,(sp)
+       add     #2,(sp)
        mov     R+,*(sp)+
 
 / field assign, value in reg.
@@ -803,7 +804,7 @@ cr82:
        SS
        FS
        jsr     pc,I
-       add     $10,sp
+       add     #10,sp
 
 / =*, =/, =rem for longs
 / Operands of the form &x op y, so stack space is known.
@@ -812,7 +813,7 @@ cr86:
        SS
        FS
        jsr     pc,I
-       add     $6,sp
+       add     #6,sp
 
 / convert integer to character (sign extend)
 cr109:
@@ -1221,7 +1222,7 @@ cr92:
        mov     (R),R
        ashc    (sp)+,R
        mov     R,*(sp)
-       add     $2,(sp)
+       add     #2,(sp)
        mov     R+,*(sp)+
 
 / field = ...
@@ -1470,7 +1471,7 @@ cc81:
 
 %al,c
 %al,au
-       /bit    $0,A1
+       /bit    #0,A1
        /X0
        bit     A2,A1+
        X1
@@ -1478,7 +1479,7 @@ cc81:
 %nl*,c
 %nl*,au
        F*
-       /bit    $0,#2(R)
+       /bit    #0,#2(R)
        /X0
        bit     A2,#2+2(R)
        X1
@@ -1504,7 +1505,7 @@ cc81:
 %nl,c
 %nl,au
        F
-       /bit    $0,R
+       /bit    #0,R
        /X0
        bit     A2,R+
        X1
diff --git a/usr/src/libc/a.sh b/usr/src/libc/a.sh
new file mode 100755 (executable)
index 0000000..d229056
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+mkdir --parents ../../../tmp
+export APOUT_ROOT=`pwd`/../../..
+export PATH=`pwd`/../../../bin:`pwd`
+cc -S -O /usr/src/libc/stdio/filbuf.c