changes to merge f2 and c2. Added -f flag to act as f2.
[unix-history] / usr / src / old / pcc / c2.vax / c20.c
index aebf925..eef1a77 100644 (file)
@@ -1,6 +1,7 @@
-#
-static char sccsid[] = "@(#)c20.c 4.1 %G%";
-/* char C20[] = {"@(#)c20.c 1.33 80/08/08 10:01:02"}; /* sccs ident */
+#ifndef lint
+static char sccsid[] = "@(#)c20.c      4.8 (Berkeley) %G%";
+#endif
+
 /*
  *      C object code improver
  */
 /*
  *      C object code improver
  */
@@ -11,11 +12,12 @@ static      char sccsid[] = "@(#)c20.c 4.1 %G%";
 
 char _sibuf[BUFSIZ], _sobuf[BUFSIZ];
 int ioflag;
 
 char _sibuf[BUFSIZ], _sobuf[BUFSIZ];
 int ioflag;
-int    isn     = 2000000;
+int fflag;
+long   isn     = 2000000;
 struct optab *oplook();
 struct optab *getline();
 struct optab *oplook();
 struct optab *getline();
-int lgensym[10] =
-  {100000,200000,300000,400000,500000,600000,700000,800000,900000,1000000};
+long lgensym[10] =
+  {100000L,200000L,300000L,400000L,500000L,600000L,700000L,800000L,900000L,1000000L};
 
 struct node *
 alloc(an)
 
 struct node *
 alloc(an)
@@ -24,8 +26,8 @@ alloc(an)
        register char *p;
 
        n = an;
        register char *p;
 
        n = an;
-       n++;
-       n &= ~01;
+       n+=sizeof(char *)-1;
+       n &= ~(sizeof(char *)-1);
        if (lasta+n >= lastr) {
                if (sbrk(2000) == -1) {
                        fprintf(stderr, "Optimizer: out of space\n");
        if (lasta+n >= lastr) {
                if (sbrk(2000) == -1) {
                        fprintf(stderr, "Optimizer: out of space\n");
@@ -48,20 +50,23 @@ char **argv;
        while (argc>0) {/* get flags */
                if (**argv=='+') debug++;
                else if (**argv=='-') {
        while (argc>0) {/* get flags */
                if (**argv=='+') debug++;
                else if (**argv=='-') {
-                       if ((*argv)[1]=='i') ioflag++; else nflag++;
+                       if ((*argv)[1]=='i') ioflag++;
+                       else if ((*argv)[1]=='f') fflag++;
+                       else nflag++;
                } else if (infound==0) {
                        if (freopen(*argv, "r", stdin) ==NULL) {
                                fprintf(stderr,"C2: can't find %s\n", *argv);
                                exit(1);
                        }
                } else if (infound==0) {
                        if (freopen(*argv, "r", stdin) ==NULL) {
                                fprintf(stderr,"C2: can't find %s\n", *argv);
                                exit(1);
                        }
-                       setbuf(stdin,_sibuf); ++infound;
+                       ++infound;
                } else if (freopen(*argv, "w", stdout) ==NULL) {
                        fprintf(stderr,"C2: can't create %s\n", *argv);
                        exit(1);
                }
                } else if (freopen(*argv, "w", stdout) ==NULL) {
                        fprintf(stderr,"C2: can't create %s\n", *argv);
                        exit(1);
                }
-               setbuf(stdout,_sobuf);
                argc--; argv++;
        }
                argc--; argv++;
        }
+       setbuf(stdin, _sibuf);
+       setbuf(stdout, _sobuf);
        lasta = lastr = sbrk(2);
        opsetup();
        lasta = firstr = lastr = alloc(0);
        lasta = lastr = sbrk(2);
        opsetup();
        lasta = firstr = lastr = alloc(0);
@@ -129,7 +134,7 @@ input()
                        if (isdigit(line[0]) && (p->labno=locdef(line)) ||
                          (line[0] == 'L') && (p->labno=getnum(line+1))) {
                                p->combop = LABEL;
                        if (isdigit(line[0]) && (p->labno=locdef(line)) ||
                          (line[0] == 'L') && (p->labno=getnum(line+1))) {
                                p->combop = LABEL;
-                               if (isn<=p->labno) isn=1+p->labno;
+                               if (p->labno<100000L && isn<=p->labno) isn=1+p->labno;
                                p->code = 0;
                        } else {
                                p->combop = DLABEL;
                                p->code = 0;
                        } else {
                                p->combop = DLABEL;
@@ -331,6 +336,26 @@ output()
                if (casebas==0) printf("L%d:\n",casebas=isn++);
                printf(".word   L%d-L%d\n", t->labno, casebas);
                continue;
                if (casebas==0) printf("L%d:\n",casebas=isn++);
                printf(".word   L%d-L%d\n", t->labno, casebas);
                continue;
+       case MOV:
+               if (!fflag) goto std;
+               if (t->forw) if(t->forw->op == CBR) goto std;
+               if (*t->code == '$') goto std;
+               if (t->subop == FFLOAT)
+                       {
+                       printf("movl\t%s\n", t->code);
+                       continue;
+                       }
+               if (t->subop == DFLOAT || t->subop == GFLOAT)
+                       {
+                       printf("movq\t%s\n", t->code);
+                       continue;
+                       }
+               if (t->subop == HFLOAT)
+                       {
+                       printf("movo\t%s\n", t->code);
+                       continue;
+                       }
+               goto std;
 
        }
 }
 
        }
 }
@@ -376,7 +401,7 @@ opsetup()
        register struct optab *optp, **ophp;
        register int i,t;
 
        register struct optab *optp, **ophp;
        register int i,t;
 
-       for(i=NREG+5;--i>=0;) regs[i]=alloc(20);
+       for(i=NREG+5;--i>=0;) regs[i]=alloc(C2_ASIZE);
        for (optp = optab; optp->opstring[0]; optp++) {
                t=7; i=0; while (--t>=0) i+= i+optp->opstring[t];
                ophp = &ophash[i % OPHS];
        for (optp = optab; optp->opstring[0]; optp++) {
                t=7; i=0; while (--t>=0) i+= i+optp->opstring[t];
                ophp = &ophash[i % OPHS];