BSD 4_3 release
[unix-history] / usr / src / usr.bin / f77 / src / f77pass1 / io.c
index 44c69e7..d087b78 100644 (file)
@@ -1,7 +1,52 @@
-/* @(#)io.c    1.3 (Berkeley) 6/1/81 */
-/* Routines to generate code for I/O statements.
-   Some corrections and improvements due to David Wasley, U. C. Berkeley
-*/
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)io.c        5.3 (Berkeley) 3/9/86";
+#endif
+
+/*
+ * io.c
+ *
+ * Routines to generate code for I/O statements.
+ * Some corrections and improvements due to David Wasley, U. C. Berkeley
+ *
+ * University of Utah CS Dept modification history:
+ *
+ * $Header: io.c,v 5.3 86/03/04 17:45:33 donn Exp $
+ * $Log:       io.c,v $
+ * Revision 5.3  86/03/04  17:45:33  donn
+ * Change the order of length and offset code in startrw() -- always emit
+ * the memoffset first, since it may define a temporary which is used in
+ * the length expression.
+ * 
+ * Revision 5.2  85/12/19  17:22:35  donn
+ * Don't permit more than one 'positional iocontrol' parameter unless we
+ * are doing a READ or a WRITE.
+ * 
+ * Revision 5.1  85/08/10  03:47:42  donn
+ * 4.3 alpha
+ * 
+ * Revision 2.4  85/02/23  21:09:02  donn
+ * Jerry Berkman's compiled format fixes move setfmt into a separate file.
+ * 
+ * Revision 2.3  85/01/10  22:33:41  donn
+ * Added some strategic cpexpr()s to prevent memory management bugs.
+ * 
+ * Revision 2.2  84/08/04  21:15:47  donn
+ * Removed code that creates extra statement labels, per Jerry Berkman's
+ * fixes to make ASSIGNs work right.
+ * 
+ * Revision 2.1  84/07/19  12:03:33  donn
+ * Changed comment headers for UofU.
+ * 
+ * Revision 1.2  84/02/26  06:35:57  donn
+ * Added Berkeley changes necessary for shortening offsets to data.
+ * 
+ */
 
 /* TEMPORARY */
 #define TYIOINT TYLONG
 
 /* TEMPORARY */
 #define TYIOINT TYLONG
@@ -170,10 +215,7 @@ if(lp == NULL)
        return(-1);
        }
 if(lp->labtype == LABUNKNOWN)
        return(-1);
        }
 if(lp->labtype == LABUNKNOWN)
-       {
        lp->labtype = LABFORMAT;
        lp->labtype = LABFORMAT;
-       lp->labelno = newlabel();
-       }
 else if(lp->labtype != LABFORMAT)
        {
        execerr("bad format number", CNULL);
 else if(lp->labtype != LABFORMAT)
        {
        execerr("bad format number", CNULL);
@@ -184,21 +226,6 @@ return(lp->labelno);
 
 
 
 
 
 
-setfmt(lp)
-struct Labelblock *lp;
-{
-int n;
-char *s, *lexline();
-
-s = lexline(&n);
-preven(ALILONG);
-prlabel(asmfile, lp->labelno);
-putstr(asmfile, s, n);
-flline();
-}
-
-
-
 startioctl()
 {
 register int i;
 startioctl()
 {
 register int i;
@@ -346,7 +373,8 @@ if(n == IOSBAD)
        return;
 if(n == IOSPOSITIONAL)
        {
        return;
 if(n == IOSPOSITIONAL)
        {
-       if(nioctl > IOSFMT)
+       if(nioctl > IOSFMT ||
+          nioctl > IOSUNIT && !(iostmt == IOREAD || iostmt == IOWRITE))
                {
                err("illegal positional iocontrol");
                return;
                {
                err("illegal positional iocontrol");
                return;
@@ -370,6 +398,7 @@ if(n == IOSFMT)
 iocp = & ioc[n];
 if(iocp->iocval == NULL)
        {
 iocp = & ioc[n];
 if(iocp->iocval == NULL)
        {
+       p = (expptr) cpexpr(p);
        if(n!=IOSFMT && ( n!=IOSUNIT || (p!=NULL && p->headblock.vtype!=TYCHAR) ) )
                p = fixtype(p);
        if(p!=NULL && ISCONST(p) && p->constblock.vtype==TYCHAR)
        if(n!=IOSFMT && ( n!=IOSUNIT || (p!=NULL && p->headblock.vtype!=TYCHAR) ) )
                p = fixtype(p);
        if(p!=NULL && ISCONST(p) && p->constblock.vtype==TYCHAR)
@@ -661,7 +690,7 @@ if(p = V(IOSFMT))
                if(np->vclass == CLNAMELIST)
                        {
                        ioformatted = NAMEDIRECTED;
                if(np->vclass == CLNAMELIST)
                        {
                        ioformatted = NAMEDIRECTED;
-                       fmtp = (Addrp) fixtype(p);
+                       fmtp = (Addrp) fixtype(cpexpr(p));
                        goto endfmt;
                        }
                vardcl(np);
                        goto endfmt;
                        }
                vardcl(np);
@@ -676,7 +705,7 @@ if(p = V(IOSFMT))
                        {
                        statstruct = NO;
                        varfmt = NO;
                        {
                        statstruct = NO;
                        varfmt = NO;
-                       fmtp = (Addrp) fixtype(p);
+                       fmtp = (Addrp) fixtype(cpexpr(p));
                        goto endfmt;
                        }
                }
                        goto endfmt;
                        }
                }
@@ -763,8 +792,9 @@ if(iostmt == IOREAD)
 if(intfile)
        {
        ioset(TYIOINT, XIRNUM, nump);
 if(intfile)
        {
        ioset(TYIOINT, XIRNUM, nump);
+       ioseta(XIUNIT, cpexpr(unitp));
        ioset(TYIOINT, XIRLEN, cpexpr(unitp->vleng) );
        ioset(TYIOINT, XIRLEN, cpexpr(unitp->vleng) );
-       ioseta(XIUNIT, unitp);
+       frexpr(unitp);
        }
 else
        ioset(TYIOINT, XUNIT, (expptr) unitp);
        }
 else
        ioset(TYIOINT, XUNIT, (expptr) unitp);
@@ -1085,7 +1115,7 @@ ftnint len;
 
 outiodata()
 {
 
 outiodata()
 {
-  static char *varfmt = "\t.align\t2\nv.%d:\n";
+  static char *varfmt = "v.%d:\n";
 
   register ioblock *p;
   register ioblock *t;
 
   register ioblock *p;
   register ioblock *t;
@@ -1096,6 +1126,7 @@ outiodata()
 
   while (p != NULL)
     {
 
   while (p != NULL)
     {
+      pralign(ALIDOUBLE);
       fprintf(initfile, varfmt, p->blkno);
       outolist(p->olist, p->len);
 
       fprintf(initfile, varfmt, p->blkno);
       outolist(p->olist, p->len);
 
@@ -1118,8 +1149,6 @@ register int len;
   static char *overlap = "overlapping i/o fields in outolist";
   static char *toolong = "offset too large in outolist";
 
   static char *overlap = "overlapping i/o fields in outolist";
   static char *toolong = "offset too large in outolist";
 
-  static char *spacefmt = "\t.space\t%d\n";
-
   register offsetlist *t;
   register ftnint clen;
   register Constp cp;
   register offsetlist *t;
   register ftnint clen;
   register Constp cp;
@@ -1134,7 +1163,7 @@ register int len;
 
       if (clen < op->offset)
        {
 
       if (clen < op->offset)
        {
-         fprintf(initfile, spacefmt, op->offset - clen);
+         prspace(op->offset - clen);
          clen = op->offset;
        }
 
          clen = op->offset;
        }
 
@@ -1179,7 +1208,7 @@ register int len;
     fatal(toolong);
 
   if (clen < len)
     fatal(toolong);
 
   if (clen < len)
-    fprintf(initfile, spacefmt, len - clen);
+    prspace(len - clen);
 
   return;
 }
 
   return;
 }