BSD 4_2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Mon, 27 Jun 1983 14:29:27 +0000 (06:29 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Mon, 27 Jun 1983 14:29:27 +0000 (06:29 -0800)
Work on file usr/src/usr.bin/f77/src/f77pass1/conv.c
Work on file usr/src/usr.bin/f77/src/f77pass1/equiv.c
Work on file usr/src/usr.bin/f77/src/f77pass1/gram.dcl
Work on file usr/src/usr.bin/f77/src/f77pass1/put.c
Work on file usr/src/usr.bin/f77/src/f77pass1/vax.c

Synthesized-from: CSRG/cd1/4.2

usr/src/usr.bin/f77/src/f77pass1/conv.c [new file with mode: 0644]
usr/src/usr.bin/f77/src/f77pass1/equiv.c [new file with mode: 0644]
usr/src/usr.bin/f77/src/f77pass1/gram.dcl [new file with mode: 0644]
usr/src/usr.bin/f77/src/f77pass1/put.c [new file with mode: 0644]
usr/src/usr.bin/f77/src/f77pass1/vax.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/f77/src/f77pass1/conv.c b/usr/src/usr.bin/f77/src/f77pass1/conv.c
new file mode 100644 (file)
index 0000000..7f907b0
--- /dev/null
@@ -0,0 +1,911 @@
+
+#include "defs.h"
+#include "conv.h"
+
+int badvalue;
+
+
+/*  The following constants are used to check the limits of  */
+/*  conversions.  Dmaxword is the largest double precision   */
+/*  number which can be converted to a two-byte integer      */
+/*  without overflow.  Dminword is the smallest double       */
+/*  precision value which can be converted to a two-byte     */
+/*  integer without overflow.  Dmaxint and dminint are the   */
+/*  analogous values for four-byte integers.                 */
+
+
+LOCAL long dmaxword[] = { 0xfeff47ff, 0xffffffff };
+LOCAL long dminword[] = { 0x00ffc800, 0xffffffff };
+
+LOCAL long dmaxint[]  = { 0xffff4fff, 0xfffffeff };
+LOCAL long dminint[]  = { 0x0000d000, 0xffff00ff };
+
+LOCAL long dmaxreal[] = { 0xffff7fff, 0xffff7fff };
+LOCAL long dminreal[] = { 0x0000f800, 0xffffffff };
+
+\f
+
+/*  The routines which follow are used to convert  */
+/*  constants into constants of other types.       */
+
+LOCAL char *
+grabbits(len, cp)
+int len;
+Constp cp;
+{
+
+  static char *toobig = "bit value too large";
+
+  register char *p;
+  register char *bits;
+  register int i;
+  register int k;
+  register int lenb;
+
+  bits = cp->const.ccp;
+  lenb = cp->vleng->constblock.const.ci;
+
+  p = (char *) ckalloc(len);
+
+  if (len >= lenb)
+    k = lenb;
+  else
+    {
+      k = len;
+      if ( badvalue == 0 )
+       {
+#if (TARGET == PDP11 || TARGET == VAX)
+         i = len;
+         while ( i < lenb && bits[i] == 0 )
+           i++;
+         if (i < lenb)
+           badvalue = 1;
+#else
+         i = lenb - len - 1;
+         while ( i >= 0 && bits[i] == 0)
+           i--;
+         if (i >= 0)
+           badvalue = 1;
+#endif
+         if (badvalue)
+           warn(toobig);
+       }
+    }
+
+#if (TARGET == PDP11 || TARGET == VAX)
+  i = 0;
+  while (i < k)
+    {
+      p[i] = bits[i];
+      i++;
+    }
+#else
+  i = lenb;
+  while (k > 0)
+    p[--k] = bits[--i];
+#endif
+
+  return (p);
+}
+
+\f
+
+LOCAL char *
+grabbytes(len, cp)
+int len;
+Constp cp;
+{
+  register char *p;
+  register char *bytes;
+  register int i;
+  register int k;
+  register int lenb;
+
+  bytes = cp->const.ccp;
+  lenb = cp->vleng->constblock.const.ci;
+
+  p = (char *) ckalloc(len);
+
+  if (len >= lenb)
+    k = lenb;
+  else
+    k = len;
+
+  i = 0;
+  while (i < k)
+    {
+      p[i] = bytes[i];
+      i++;
+    }
+
+  while (i < len)
+    p[i++] = BLANK;
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+cshort(cp)
+Constp cp;
+{
+  static char *toobig = "data value too large";
+  static char *reserved = "reserved operand assigned to an integer";
+  static char *compat1 = "logical datum assigned to an integer variable";
+  static char *compat2 = "character datum assigned to an integer variable";
+
+  register expptr p;
+  register short *shortp;
+  register ftnint value;
+  register long *rp;
+  register double *minp;
+  register double *maxp;
+  realvalue x;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      shortp = (short *) grabbits(2, cp);
+      p = (expptr) mkconst(TYSHORT);
+      p->constblock.const.ci = *shortp;
+      free((char *) shortp);
+      break;
+
+    case TYSHORT:
+      p = (expptr) cpexpr(cp);
+      break;
+
+    case TYLONG:
+      value = cp->const.ci;
+      if (value >= MINWORD && value <= MAXWORD)
+       {
+         p = (expptr) mkconst(TYSHORT);
+         p->constblock.const.ci = value;
+       }
+      else
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(toobig);
+           }
+         p = errnode();
+       }
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      minp = (double *) dminword;
+      maxp = (double *) dmaxword;
+      rp = (long *) &(cp->const.cd[0]);
+      x.q.word1 = rp[0];
+      x.q.word2 = rp[1];
+      if (x.f.sign == 1 && x.f.exp == 0)
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(reserved);
+           }
+         p = errnode();
+       }
+      else if (x.d >= *minp && x.d <= *maxp)
+       {
+         p = (expptr) mkconst(TYSHORT);
+         p->constblock.const.ci = x.d;
+       }
+      else
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(toobig);
+           }
+         p = errnode();
+       }
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0 )
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      shortp = (short *) grabbytes(2, cp);
+      p = (expptr) mkconst(TYSHORT);
+      p->constblock.const.ci = *shortp;
+      free((char *) shortp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+clong(cp)
+Constp cp;
+{
+  static char *toobig = "data value too large";
+  static char *reserved = "reserved operand assigned to an integer";
+  static char *compat1 = "logical datum assigned to an integer variable";
+  static char *compat2 = "character datum assigned to an integer variable";
+
+  register expptr p;
+  register ftnint *longp;
+  register long *rp;
+  register double *minp;
+  register double *maxp;
+  realvalue x;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      longp = (ftnint *) grabbits(4, cp);
+      p = (expptr) mkconst(TYLONG);
+      p->constblock.const.ci = *longp;
+      free((char *) longp);
+      break;
+
+    case TYSHORT:
+      p = (expptr) mkconst(TYLONG);
+      p->constblock.const.ci = cp->const.ci;
+      break;
+
+    case TYLONG:
+      p = (expptr) cpexpr(cp);
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      minp = (double *) dminint;
+      maxp = (double *) dmaxint;
+      rp = (long *) &(cp->const.cd[0]);
+      x.q.word1 = rp[0];
+      x.q.word2 = rp[1];
+      if (x.f.sign == 1 && x.f.exp == 0)
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(reserved);
+           }
+         p = errnode();
+       }
+      else if (x.d >= *minp && x.d <= *maxp)
+       {
+         p = (expptr) mkconst(TYLONG);
+         p->constblock.const.ci = x.d;
+       }
+      else
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(toobig);
+           }
+         p = errnode();
+       }
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0 )
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      longp = (ftnint *) grabbytes(4, cp);
+      p = (expptr) mkconst(TYLONG);
+      p->constblock.const.ci = *longp;
+      free((char *) longp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+creal(cp)
+Constp cp;
+{
+  static char *toobig = "data value too large";
+  static char *compat1 = "logical datum assigned to a real variable";
+  static char *compat2 = "character datum assigned to a real variable";
+
+  register expptr p;
+  register long *longp;
+  register long *rp;
+  register double *minp;
+  register double *maxp;
+  realvalue x;
+  float y;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      longp = (long *) grabbits(4, cp);
+      p = (expptr) mkconst(TYREAL);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = *longp;
+      free((char *) longp);
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+      p = (expptr) mkconst(TYREAL);
+      p->constblock.const.cd[0] = cp->const.ci;
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      minp = (double *) dminreal;
+      maxp = (double *) dmaxreal;
+      rp = (long *) &(cp->const.cd[0]);
+      x.q.word1 = rp[0];
+      x.q.word2 = rp[1];
+      if (x.f.sign == 1 && x.f.exp == 0)
+       {
+         p = (expptr) mkconst(TYREAL);
+         rp = (long *) &(p->constblock.const.cd[0]);
+         rp[0] = x.q.word1;
+       }
+      else if (x.d >= *minp && x.d <= *maxp)
+       {
+         p = (expptr) mkconst(TYREAL);
+         y = x.d;
+         p->constblock.const.cd[0] = y;
+       }
+      else
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(toobig);
+           }
+         p = errnode();
+       }
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0)
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      longp = (long *) grabbytes(4, cp);
+      p = (expptr) mkconst(TYREAL);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = *longp;
+      free((char *) longp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+cdreal(cp)
+Constp cp;
+{
+  static char *compat1 =
+       "logical datum assigned to a double precision variable";
+  static char *compat2 =
+       "character datum assigned to a double precision variable";
+
+  register expptr p;
+  register long *longp;
+  register long *rp;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      longp = (long *) grabbits(8, cp);
+      p = (expptr) mkconst(TYDREAL);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      free((char *) longp);
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+      p = (expptr) mkconst(TYDREAL);
+      p->constblock.const.cd[0] = cp->const.ci;
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      p = (expptr) mkconst(TYDREAL);
+      longp = (long *) &(cp->const.cd[0]);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0 )
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      longp = (long *) grabbytes(8, cp);
+      p = (expptr) mkconst(TYDREAL);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      free((char *) longp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+ccomplex(cp)
+Constp cp;
+{
+  static char *toobig = "data value too large";
+  static char *compat1 = "logical datum assigned to a complex variable";
+  static char *compat2 = "character datum assigned to a complex variable";
+
+  register expptr p;
+  register long *longp;
+  register long *rp;
+  register double *minp;
+  register double *maxp;
+  realvalue re, im;
+  int overflow;
+  float x;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      longp = (long *) grabbits(8, cp);
+      p = (expptr) mkconst(TYCOMPLEX);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[2] = longp[1];
+      free((char *) longp);
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+      p = (expptr) mkconst(TYCOMPLEX);
+      p->constblock.const.cd[0] = cp->const.ci;
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      overflow = 0;
+      minp = (double *) dminreal;
+      maxp = (double *) dmaxreal;
+      rp = (long *) &(cp->const.cd[0]);
+      re.q.word1 = rp[0];
+      re.q.word2 = rp[1];
+      im.q.word1 = rp[2];
+      im.q.word2 = rp[3];
+      if (((re.f.sign == 0 || re.f.exp != 0) &&
+          (re.d < *minp || re.d > *maxp))       ||
+         ((im.f.sign == 0 || re.f.exp != 0) &&
+          (im.d < *minp || re.d > *maxp)))
+       {
+         if (badvalue <= 1)
+           {
+             badvalue = 2;
+             err(toobig);
+           }
+         p = errnode();
+       }
+      else
+       {
+         p = (expptr) mkconst(TYCOMPLEX);
+         if (re.f.sign == 1 && re.f.exp == 0)
+           re.q.word2 = 0;
+         else
+           {
+             x = re.d;
+             re.d = x;
+           }
+         if (im.f.sign == 1 && im.f.exp == 0)
+           im.q.word2 = 0;
+         else
+           {
+             x = im.d;
+             im.d = x;
+           }
+         rp = (long *) &(p->constblock.const.cd[0]);
+         rp[0] = re.q.word1;
+         rp[1] = re.q.word2;
+         rp[2] = im.q.word1;
+         rp[3] = im.q.word2;
+       }
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0)
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      longp = (long *) grabbytes(8, cp);
+      p = (expptr) mkconst(TYCOMPLEX);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[2] = longp[1];
+      free((char *) longp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+cdcomplex(cp)
+Constp cp;
+{
+  static char *compat1 = "logical datum assigned to a complex variable";
+  static char *compat2 = "character datum assigned to a complex variable";
+
+  register expptr p;
+  register long *longp;
+  register long *rp;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      longp = (long *) grabbits(16, cp);
+      p = (expptr) mkconst(TYDCOMPLEX);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      rp[2] = longp[2];
+      rp[3] = longp[3];
+      free((char *) longp);
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+      p = (expptr) mkconst(TYDCOMPLEX);
+      p->constblock.const.cd[0] = cp->const.ci;
+      break;
+
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      p = (expptr) mkconst(TYDCOMPLEX);
+      longp = (long *) &(cp->const.cd[0]);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      rp[2] = longp[2];
+      rp[3] = longp[3];
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0 )
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      longp = (long *) grabbytes(16, cp);
+      p = (expptr) mkconst(TYDCOMPLEX);
+      rp = (long *) &(p->constblock.const.cd[0]);
+      rp[0] = longp[0];
+      rp[1] = longp[1];
+      rp[2] = longp[2];
+      rp[3] = longp[3];
+      free((char *) longp);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+clogical(cp)
+Constp cp;
+{
+  static char *compat1 = "numeric datum assigned to a logical variable";
+  static char *compat2 = "character datum assigned to a logical variable";
+
+  register expptr p;
+  register long *longp;
+  register short *shortp;
+  register int size;
+
+  size = typesize[tylogical];
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      p = (expptr) mkconst(tylogical);
+      if (tylogical == TYSHORT)
+       {
+         shortp = (short *) grabbits(size, cp);
+         p->constblock.const.ci = (int) *shortp;
+         free((char *) shortp);
+       }
+      else
+       {
+         longp = (long *) grabbits(size, cp);
+         p->constblock.const.ci = *longp;
+         free((char *) longp);
+       }
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYLOGICAL:
+      p = (expptr) cpexpr(cp);
+      p->constblock.vtype = tylogical;
+      break;
+
+    case TYCHAR:
+      if ( !ftn66flag && badvalue == 0 )
+       {
+         badvalue = 1;
+         warn(compat2);
+       }
+
+    case TYHOLLERITH:
+      p = (expptr) mkconst(tylogical);
+      if (tylogical == TYSHORT)
+       {
+         shortp = (short *) grabbytes(size, cp);
+         p->constblock.const.ci = (int) *shortp;
+         free((char *) shortp);
+       }
+      else
+       {
+         longp = (long *) grabbytes(4, cp);
+         p->constblock.const.ci = *longp;
+         free((char *) longp);
+       }
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+LOCAL expptr
+cchar(len, cp)
+int len;
+Constp cp;
+{
+  static char *compat1 = "numeric datum assigned to a character variable";
+  static char *compat2 = "logical datum assigned to a character variable";
+
+  register expptr p;
+  register char *value;
+
+  switch (cp->vtype)
+    {
+    case TYBITSTR:
+      value = grabbits(len, cp);
+      p = (expptr) mkstrcon(len, value);
+      free(value);
+      break;
+
+    case TYSHORT:
+    case TYLONG:
+    case TYREAL:
+    case TYDREAL:
+    case TYCOMPLEX:
+    case TYDCOMPLEX:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat1);
+       }
+      p = errnode();
+      break;
+
+    case TYLOGICAL:
+      if (badvalue <= 1)
+       {
+         badvalue = 2;
+         err(compat2);
+       }
+      p = errnode();
+      break;
+
+    case TYCHAR:
+    case TYHOLLERITH:
+      value = grabbytes(len, cp);
+      p = (expptr) mkstrcon(len, value);
+      free(value);
+      break;
+
+    case TYERROR:
+      p = errnode();
+      break;
+    }
+
+  return (p);
+}
+
+\f
+
+expptr
+convconst(type, len, const)
+int type;
+int len;
+Constp const;
+{
+  register expptr p;
+
+  switch (type)
+    {
+    case TYSHORT:
+      p = cshort(const);
+      break;
+
+    case TYLONG:
+      p = clong(const);
+      break;
+
+    case TYREAL:
+      p = creal(const);
+      break;
+
+    case TYDREAL:
+      p = cdreal(const);
+      break;
+
+    case TYCOMPLEX:
+      p = ccomplex(const);
+      break;
+
+    case TYDCOMPLEX:
+      p = cdcomplex(const);
+      break;
+
+    case TYLOGICAL:
+      p = clogical(const);
+      break;
+
+    case TYCHAR:
+      p = cchar(len, const);
+      break;
+
+    case TYERROR:
+    case TYUNKNOWN:
+      p = errnode();
+      break;
+
+    default:
+      badtype("convconst", type);
+    }
+
+  return (p);
+}
diff --git a/usr/src/usr.bin/f77/src/f77pass1/equiv.c b/usr/src/usr.bin/f77/src/f77pass1/equiv.c
new file mode 100644 (file)
index 0000000..430261a
--- /dev/null
@@ -0,0 +1,303 @@
+#include "defs.h"
+
+#ifdef SDB
+#      include <a.out.h>
+#      ifndef N_SO
+#              include <stab.h>
+#      endif
+#endif
+
+/* ROUTINES RELATED TO EQUIVALENCE CLASS PROCESSING */
+
+/* called at end of declarations section to process chains
+   created by EQUIVALENCE statements
+ */
+
+doequiv()
+{
+register int i;
+int inequiv, comno, ovarno;
+ftnint comoffset, offset, leng;
+register struct Equivblock *p;
+register struct Eqvchain *q;
+struct Primblock *itemp;
+register Namep np;
+expptr offp, suboffset();
+int ns, nsubs();
+chainp cp;
+char *memname();
+
+for(i = 0 ; i < nequiv ; ++i)
+       {
+       p = &eqvclass[i];
+       p->eqvbottom = p->eqvtop = 0;
+       comno = -1;
+
+       for(q = p->equivs ; q ; q = q->eqvnextp)
+               {
+               offset = 0;
+               itemp = q->eqvitem.eqvlhs;
+               equivdcl = YES;
+               vardcl(np = itemp->namep);
+               equivdcl = NO;
+               if(itemp->argsp || itemp->fcharp)
+                       {
+                       if(np->vdim!=NULL && np->vdim->ndim>1 &&
+                          nsubs(itemp->argsp)==1 )
+                               {
+                               if(! ftn66flag)
+                                       warn("1-dim subscript in EQUIVALENCE");
+                               cp = NULL;
+                               ns = np->vdim->ndim;
+                               while(--ns > 0)
+                                       cp = mkchain( ICON(1), cp);
+                               itemp->argsp->listp->nextp = cp;
+                               }
+
+                       offp = suboffset(itemp);
+                       if(ISICON(offp))
+                               offset = offp->constblock.const.ci;
+                       else    {
+                               dclerr("nonconstant subscript in equivalence ",
+                                       np);
+                               np = NULL;
+                               }
+                       frexpr(offp);
+                       }
+               frexpr(itemp);
+
+               if(np && (leng = iarrlen(np))<0)
+                       {
+                       dclerr("adjustable in equivalence", np);
+                       np = NULL;
+                       }
+
+               if(np) switch(np->vstg)
+                       {
+                       case STGUNKNOWN:
+                       case STGBSS:
+                       case STGEQUIV:
+                               break;
+
+                       case STGCOMMON:
+                               comno = np->vardesc.varno;
+                               comoffset = np->voffset + offset;
+                               break;
+
+                       default:
+                               dclerr("bad storage class in equivalence", np);
+                               np = NULL;
+                               break;
+                       }
+
+               if(np)
+                       {
+                       q->eqvoffset = offset;
+                       p->eqvbottom = lmin(p->eqvbottom, -offset);
+                       p->eqvtop = lmax(p->eqvtop, leng-offset);
+                       }
+               q->eqvitem.eqvname = np;
+               }
+
+       if(comno >= 0)
+               eqvcommon(p, comno, comoffset);
+       else  for(q = p->equivs ; q ; q = q->eqvnextp)
+               {
+               if(np = q->eqvitem.eqvname)
+                       {
+                       inequiv = NO;
+                       if(np->vstg==STGEQUIV)
+                               if( (ovarno = np->vardesc.varno) == i)
+                                       {
+                                       if(np->voffset + q->eqvoffset != 0)
+                                               dclerr("inconsistent equivalence", np);
+                                       }
+                               else    {
+                                       offset = np->voffset;
+                                       inequiv = YES;
+                                       }
+
+                       np->vstg = STGEQUIV;
+                       np->vardesc.varno = i;
+                       np->voffset = - q->eqvoffset;
+
+                       if(inequiv)
+                               eqveqv(i, ovarno, q->eqvoffset + offset);
+                       }
+               }
+       }
+
+for(i = 0 ; i < nequiv ; ++i)
+       {
+       p = & eqvclass[i];
+       if(p->eqvbottom!=0 || p->eqvtop!=0)     /* a live chain */
+               {
+               for(q = p->equivs ; q; q = q->eqvnextp)
+                       {
+                       np = q->eqvitem.eqvname;
+                       np->voffset -= p->eqvbottom;
+                       if(np->voffset % typealign[np->vtype] != 0)
+                               dclerr("bad alignment forced by equivalence", np);
+                       }
+               p->eqvtop -= p->eqvbottom;
+               p->eqvbottom = 0;
+               }
+       freqchain(p);
+       }
+}
+
+
+
+
+
+/* put equivalence chain p at common block comno + comoffset */
+
+LOCAL eqvcommon(p, comno, comoffset)
+struct Equivblock *p;
+int comno;
+ftnint comoffset;
+{
+int ovarno;
+ftnint k, offq;
+register Namep np;
+register struct Eqvchain *q;
+
+if(comoffset + p->eqvbottom < 0)
+       {
+       errstr("attempt to extend common %s backward",
+               nounder(XL, extsymtab[comno].extname) );
+       freqchain(p);
+       return;
+       }
+
+if( (k = comoffset + p->eqvtop) > extsymtab[comno].extleng)
+       extsymtab[comno].extleng = k;
+
+#ifdef SDB
+if(sdbflag)
+       prstab( varstr(XL,extsymtab[comno].extname), N_BCOMM,0,0);
+#endif
+
+for(q = p->equivs ; q ; q = q->eqvnextp)
+       if(np = q->eqvitem.eqvname)
+               {
+               switch(np->vstg)
+                       {
+                       case STGUNKNOWN:
+                       case STGBSS:
+                               np->vstg = STGCOMMON;
+                               np->vardesc.varno = comno;
+                               np->voffset = comoffset - q->eqvoffset;
+#ifdef SDB
+                               if(sdbflag)
+                                       {
+                                       namestab(np);
+                                       }
+#endif
+                               break;
+
+                       case STGEQUIV:
+                               ovarno = np->vardesc.varno;
+                               offq = comoffset - q->eqvoffset - np->voffset;
+                               np->vstg = STGCOMMON;
+                               np->vardesc.varno = comno;
+                               np->voffset = comoffset - q->eqvoffset;
+                               if(ovarno != (p - eqvclass))
+                                       eqvcommon(&eqvclass[ovarno], comno, offq);
+#ifdef SDB
+                               if(sdbflag)
+                                       {
+                                       namestab(np);
+                                       }
+#endif
+                               break;
+
+                       case STGCOMMON:
+                               if(comno != np->vardesc.varno ||
+                                  comoffset != np->voffset+q->eqvoffset)
+                                       dclerr("inconsistent common usage", np);
+                               break;
+
+
+                       default:
+                               badstg("eqvcommon", np->vstg);
+                       }
+               }
+
+#ifdef SDB
+if(sdbflag)
+       prstab( varstr(XL,extsymtab[comno].extname), N_ECOMM,0,0);
+#endif
+
+freqchain(p);
+p->eqvbottom = p->eqvtop = 0;
+}
+
+
+/* put all items on ovarno chain on front of nvarno chain
+ * adjust offsets of ovarno elements and top and bottom of nvarno chain
+ */
+
+LOCAL eqveqv(nvarno, ovarno, delta)
+int ovarno, nvarno;
+ftnint delta;
+{
+register struct Equivblock *p0, *p;
+register Namep np;
+struct Eqvchain *q, *q1;
+
+p0 = eqvclass + nvarno;
+p = eqvclass + ovarno;
+p0->eqvbottom = lmin(p0->eqvbottom, p->eqvbottom - delta);
+p0->eqvtop = lmax(p0->eqvtop, p->eqvtop - delta);
+p->eqvbottom = p->eqvtop = 0;
+
+for(q = p->equivs ; q ; q = q1)
+       {
+       q1 = q->eqvnextp;
+       if( (np = q->eqvitem.eqvname) && np->vardesc.varno==ovarno)
+               {
+               q->eqvnextp = p0->equivs;
+               p0->equivs = q;
+               q->eqvoffset -= delta;
+               np->vardesc.varno = nvarno;
+               np->voffset -= delta;
+               }
+       else    free( (charptr) q);
+       }
+p->equivs = NULL;
+}
+
+
+
+
+LOCAL freqchain(p)
+register struct Equivblock *p;
+{
+register struct Eqvchain *q, *oq;
+
+for(q = p->equivs ; q ; q = oq)
+       {
+       oq = q->eqvnextp;
+       free( (charptr) q);
+       }
+p->equivs = NULL;
+}
+
+
+
+
+
+LOCAL nsubs(p)
+register struct Listblock *p;
+{
+register int n;
+register chainp q;
+
+n = 0;
+if(p)
+       for(q = p->listp ; q ; q = q->nextp)
+               ++n;
+
+return(n);
+}
diff --git a/usr/src/usr.bin/f77/src/f77pass1/gram.dcl b/usr/src/usr.bin/f77/src/f77pass1/gram.dcl
new file mode 100644 (file)
index 0000000..1b19842
--- /dev/null
@@ -0,0 +1,539 @@
+spec:    dcl
+       | common
+       | external
+       | intrinsic
+       | equivalence
+       | implicit
+       | data
+       | namelist
+       | SSAVE
+               { NO66("SAVE statement");
+                 saveall = YES; }
+       | SSAVE savelist
+               { NO66("SAVE statement"); }
+       | SFORMAT
+               {
+               if (parstate < INDCL)
+                       parstate = INDCL;
+               fmtstmt(thislabel);
+               setfmt(thislabel);
+               }
+       | SPARAM in_dcl SLPAR paramlist SRPAR
+               { NO66("PARAMETER statement"); }
+       ;
+
+dcl:     type opt_comma name in_dcl dims lengspec
+               { settype($3, $1, $6);
+                 if(ndim>0) setbound($3,ndim,dims);
+               }
+       | dcl SCOMMA name dims lengspec
+               { settype($3, $1, $5);
+                 if(ndim>0) setbound($3,ndim,dims);
+               }
+       ;
+
+type:    typespec lengspec
+               { varleng = $2; }
+       ;
+
+typespec:  typename
+               { varleng = ($1<0 || $1==TYLONG ? 0 : typesize[$1]); }
+       ;
+
+typename:    SINTEGER  { $$ = TYLONG; }
+       | SREAL         { $$ = TYREAL; }
+       | SCOMPLEX      { $$ = TYCOMPLEX; }
+       | SDOUBLE       { $$ = TYDREAL; }
+       | SDCOMPLEX     { NOEXT("DOUBLE COMPLEX statement"); $$ = TYDCOMPLEX; }
+       | SLOGICAL      { $$ = TYLOGICAL; }
+       | SCHARACTER    { NO66("CHARACTER statement"); $$ = TYCHAR; }
+       | SUNDEFINED    { $$ = TYUNKNOWN; }
+       | SDIMENSION    { $$ = TYUNKNOWN; }
+       | SAUTOMATIC    { NOEXT("AUTOMATIC statement"); $$ = - STGAUTO; }
+       | SSTATIC       { NOEXT("STATIC statement"); $$ = - STGBSS; }
+       ;
+
+lengspec:
+               { $$ = varleng; }
+       | SSTAR intonlyon expr intonlyoff
+               {
+               expptr p;
+               p = $3;
+               NO66("length specification *n");
+               if( ! ISICON(p) || p->constblock.const.ci<0 )
+                       {
+                       $$ = 0;
+                       dclerr("length must be a positive integer constant",
+                               PNULL);
+                       }
+               else $$ = p->constblock.const.ci;
+               }
+       | SSTAR intonlyon SLPAR SSTAR SRPAR intonlyoff
+               { NO66("length specification *(*)"); $$ = -1; }
+       ;
+
+common:          SCOMMON in_dcl var
+               { incomm( $$ = comblock(0, CNULL) , $3 ); }
+       | SCOMMON in_dcl comblock var
+               { $$ = $3;  incomm($3, $4); }
+       | common opt_comma comblock opt_comma var
+               { $$ = $3;  incomm($3, $5); }
+       | common SCOMMA var
+               { incomm($1, $3); }
+       ;
+
+comblock:  SCONCAT
+               { $$ = comblock(0, CNULL); }
+       | SSLASH SNAME SSLASH
+               { $$ = comblock(toklen, token); }
+       ;
+
+external: SEXTERNAL in_dcl name
+               { setext($3); }
+       | external SCOMMA name
+               { setext($3); }
+       ;
+
+intrinsic:  SINTRINSIC in_dcl name
+               { NO66("INTRINSIC statement"); setintr($3); }
+       | intrinsic SCOMMA name
+               { setintr($3); }
+       ;
+
+equivalence:  SEQUIV in_dcl equivset
+       | equivalence SCOMMA equivset
+       ;
+
+equivset:  SLPAR equivlist SRPAR
+               {
+               struct Equivblock *p;
+               if(nequiv >= maxequiv)
+                       many("equivalences", 'q');
+               p  =  & eqvclass[nequiv++];
+               p->eqvinit = NO;
+               p->eqvbottom = 0;
+               p->eqvtop = 0;
+               p->equivs = $2;
+               p->init = NO;
+               p->initoffset = 0;
+               }
+       ;
+
+equivlist:  lhs
+               { $$=ALLOC(Eqvchain);
+                 $$->eqvitem.eqvlhs = (struct Primblock *)$1;
+               }
+       | equivlist SCOMMA lhs
+               { $$=ALLOC(Eqvchain);
+                 $$->eqvitem.eqvlhs = (struct Primblock *) $3;
+                 $$->eqvnextp = $1;
+               }
+       ;
+
+
+savelist: saveitem
+       | savelist SCOMMA saveitem
+       ;
+
+saveitem: name
+               { int k;
+                 $1->vsave = YES;
+                 k = $1->vstg;
+               if( ! ONEOF(k, M(STGUNKNOWN)|M(STGBSS)|M(STGINIT)) )
+                       dclerr("can only save static variables", $1);
+               }
+       | comblock
+               { $1->extsave = 1; }
+       ;
+
+paramlist:  paramitem
+       | paramlist SCOMMA paramitem
+       ;
+
+paramitem:  name SEQUALS expr
+               {
+                 if ($1->vclass == CLUNKNOWN)
+                   $1->vclass = CLPARAM;
+                 else
+                   dclerr("%s redefined", $1);
+
+                 if ($1->vclass == CLPARAM)
+                   {
+                     if (!ISCONST($3))
+                       $3 = fixtype($3);
+
+                     if ($1->vtype == TYUNKNOWN)
+                       {
+                         char c;
+
+                         c = $1->varname[0];
+                         if (c >= 'A' && c <= 'Z')
+                           c = c - 'A';
+                         else
+                           c = c - 'a';
+                         $1->vtype = impltype[c];
+                         $1->vleng = ICON(implleng[c]);
+                       }
+                     if ($1->vtype == TYUNKNOWN)
+                       { 
+                         warn1("type undefined for %s",
+                               varstr(VL, $1->varname));
+                         ((struct Paramblock *) ($1))->paramval = $3;
+                       }
+                     else
+                       {
+                         extern int badvalue;
+                         extern expptr constconv();
+                         int type;
+                         ftnint len;
+
+                         type = $1->vtype;
+                         if (type == TYCHAR)
+                           {
+                             if ($1->vleng != NULL)
+                               len = $1->vleng->constblock.const.ci;
+                             else if (ISCONST($3) &&
+                                       $3->constblock.vtype == TYCHAR)
+                               len = $3->constblock.vleng->
+                                       constblock.const.ci;
+                             else
+                               len = 1;
+                           }
+                         badvalue = 0;
+                         if (ISCONST($3))
+                           {
+                             ((struct Paramblock *) ($1))->paramval =
+                               convconst($1->vtype, len, $3);
+                             if (type == TYLOGICAL)
+                               ((struct Paramblock *) ($1))->paramval->
+                                 headblock.vtype = TYLOGICAL;
+                             frexpr((tagptr) $3);
+                           }
+                         else
+                           {
+                             warn1("%s set to a nonconstant",
+                                   varstr(VL, $1->varname));
+                             ((struct Paramblock *) ($1))->paramval = $3;
+                           }
+                       }
+                   }
+               }
+       ;
+
+var:     name dims
+               { if(ndim>0) setbound($1, ndim, dims); }
+       ;
+
+
+dims:
+               { ndim = 0; }
+       | SLPAR dimlist SRPAR
+       ;
+
+dimlist:   { ndim = 0; }   dim
+       | dimlist SCOMMA dim
+       ;
+
+dim:     ubound
+               { if(ndim == maxdim)
+                       err("too many dimensions");
+                 else if(ndim < maxdim)
+                       { dims[ndim].lb = 0;
+                         dims[ndim].ub = $1;
+                       }
+                 ++ndim;
+               }
+       | expr SCOLON ubound
+               { if(ndim == maxdim)
+                       err("too many dimensions");
+                 else if(ndim < maxdim)
+                       { dims[ndim].lb = $1;
+                         dims[ndim].ub = $3;
+                       }
+                 ++ndim;
+               }
+       ;
+
+ubound:          SSTAR
+               { $$ = 0; }
+       | expr
+       ;
+
+labellist: label
+               { nstars = 1; labarray[0] = $1; }
+       | labellist SCOMMA label
+               { if(nstars < MAXLABLIST)  labarray[nstars++] = $3; }
+       ;
+
+label:   SICON
+               { $$ = execlab( convci(toklen, token) ); }
+       ;
+
+implicit:  SIMPLICIT in_dcl implist
+               { NO66("IMPLICIT statement"); }
+       | implicit SCOMMA implist
+       ;
+
+implist:  imptype SLPAR letgroups SRPAR
+       ;
+
+imptype:   { needkwd = 1; } type
+               { vartype = $2; }
+       ;
+
+letgroups: letgroup
+       | letgroups SCOMMA letgroup
+       ;
+
+letgroup:  letter
+               { setimpl(vartype, varleng, $1, $1); }
+       | letter SMINUS letter
+               { setimpl(vartype, varleng, $1, $3); }
+       ;
+
+letter:  SNAME
+               { if(toklen!=1 || token[0]<'a' || token[0]>'z')
+                       {
+                       dclerr("implicit item must be single letter", PNULL);
+                       $$ = 0;
+                       }
+                 else $$ = token[0];
+               }
+       ;
+
+namelist:      SNAMELIST
+       | namelist namelistentry
+       ;
+
+namelistentry:  SSLASH name SSLASH namelistlist
+               {
+               if($2->vclass == CLUNKNOWN)
+                       {
+                       $2->vclass = CLNAMELIST;
+                       $2->vtype = TYINT;
+                       $2->vstg = STGINIT;
+                       $2->varxptr.namelist = $4;
+                       $2->vardesc.varno = ++lastvarno;
+                       }
+               else dclerr("cannot be a namelist name", $2);
+               }
+       ;
+
+namelistlist:  name
+               { $$ = mkchain($1, CHNULL); }
+       | namelistlist SCOMMA name
+               { $$ = hookup($1, mkchain($3, CHNULL)); }
+       ;
+
+in_dcl:
+               { switch(parstate)      
+                       {
+                       case OUTSIDE:   newproc();
+                                       startproc(PNULL, CLMAIN);
+                       case INSIDE:    parstate = INDCL;
+                       case INDCL:     break;
+
+                       default:
+                               dclerr("declaration among executables", PNULL);
+                       }
+               }
+       ;
+
+data:  data1
+       {
+         if (overlapflag == YES)
+           warn("overlapping initializations");
+       }
+
+data1: SDATA in_data datapair
+    |  data1 opt_comma datapair
+    ;
+
+in_data:
+               { if(parstate == OUTSIDE)
+                       {
+                       newproc();
+                       startproc(PNULL, CLMAIN);
+                       }
+                 if(parstate < INDATA)
+                       {
+                       enddcl();
+                       parstate = INDATA;
+                       }
+                 overlapflag = NO;
+               }
+       ;
+
+datapair:      datalvals SSLASH datarvals SSLASH
+                       { savedata($1, $3); }
+       ;
+
+datalvals:     datalval
+               { $$ = preplval(NULL, $1); }
+        |      datalvals SCOMMA datalval
+               { $$ = preplval($1, $3); }
+        ;
+
+datarvals:     datarval
+        |      datarvals SCOMMA datarval
+                       {
+                         $3->next = $1;
+                         $$ = $3;
+                       }
+        ;
+
+datalval:      dataname
+                       { $$ = mkdlval($1, NULL, NULL); }
+       |       dataname datasubs
+                       { $$ = mkdlval($1, $2, NULL); }
+       |       dataname datarange
+                       { $$ = mkdlval($1, NULL, $2); }
+       |       dataname datasubs datarange
+                       { $$ = mkdlval($1, $2, $3); }
+       |       dataimplieddo
+       ;
+
+dataname:      SNAME { $$ = mkdname(toklen, token); }
+       ;
+
+datasubs:      SLPAR iconexprlist SRPAR
+                       { $$ = revvlist($2); }
+       ;
+
+datarange:     SLPAR opticonexpr SCOLON opticonexpr SRPAR
+                       { $$ = mkdrange($2, $4); }
+        ;
+
+iconexprlist:  iconexpr
+                       {
+                         $$ = prepvexpr(NULL, $1);
+                       }
+           |   iconexprlist SCOMMA iconexpr
+                       {
+                         $$ = prepvexpr($1, $3);
+                       }
+           ;
+
+opticonexpr:                   { $$ = NULL; }
+          |    iconexpr        { $$ = $1; }
+          ;
+
+dataimplieddo: SLPAR dlist SCOMMA dataname SEQUALS iconexprlist SRPAR
+               { $$ = mkdatado($2, $4, $6); }
+            ;
+
+dlist: dataelt
+       { $$ = preplval(NULL, $1); }
+     | dlist SCOMMA dataelt
+       { $$ = preplval($1, $3); }
+     ;
+
+dataelt:       dataname datasubs
+               { $$ = mkdlval($1, $2, NULL); }
+       |       dataname datarange
+               { $$ = mkdlval($1, NULL, $2); }
+       |       dataname datasubs datarange
+               { $$ = mkdlval($1, $2, $3); }
+       |       dataimplieddo
+       ;
+
+datarval:      datavalue
+                       {
+                         static dvalue one = { DVALUE, NORMAL, 1 };
+
+                         $$ = mkdrval(&one, $1);
+                       }
+       |       dataname SSTAR datavalue
+                       {
+                         $$ = mkdrval($1, $3);
+                         frvexpr($1);
+                       }
+       |       unsignedint SSTAR datavalue
+                       {
+                         $$ = mkdrval($1, $3);
+                         frvexpr($1);
+                       }
+       ;
+
+datavalue:     dataname
+                       {
+                         $$ = evparam($1);
+                         free((char *) $1);
+                       }
+        |      int_const
+                       {
+                         $$ = ivaltoicon($1);
+                         frvexpr($1);
+                       }
+
+        |      real_const
+        |      complex_const
+        |      STRUE           { $$ = mklogcon(1); }
+        |      SFALSE          { $$ = mklogcon(0); }
+        |      SHOLLERITH      { $$ = mkstrcon(toklen, token); }
+        |      SSTRING         { $$ = mkstrcon(toklen, token); }
+        |      bit_const
+        ;
+
+int_const:     unsignedint
+        |      SPLUS unsignedint
+                       { $$ = $2; }
+        |      SMINUS unsignedint
+                       {
+                         $$ = negival($2);
+                         frvexpr($2);
+                       }
+                               
+        ;
+
+unsignedint:   SICON { $$ = evicon(toklen, token); }
+          ;
+
+real_const:    unsignedreal
+         |     SPLUS unsignedreal
+                       { $$ = $2; }
+         |     SMINUS unsignedreal
+                       {
+                         consnegop($2);
+                         $$ = $2;
+                       }
+         ;
+
+unsignedreal:  SRCON { $$ = mkrealcon(TYREAL, convcd(toklen, token)); }
+           |   SDCON { $$ = mkrealcon(TYDREAL, convcd(toklen, token)); }
+           ;
+
+bit_const:     SHEXCON { $$ = mkbitcon(4, toklen, token); }
+        |      SOCTCON { $$ = mkbitcon(3, toklen, token); }
+        |      SBITCON { $$ = mkbitcon(1, toklen, token); }
+        ;
+
+iconexpr:      iconterm
+       |       SPLUS iconterm
+                       { $$ = $2; }
+       |       SMINUS iconterm
+                       { $$ = mkdexpr(OPNEG, NULL, $2); }
+       |       iconexpr SPLUS iconterm
+                       { $$ = mkdexpr(OPPLUS, $1, $3); }
+       |       iconexpr SMINUS iconterm
+                       { $$ = mkdexpr(OPMINUS, $1, $3); }
+       ;
+
+iconterm:      iconfactor
+       |       iconterm SSTAR iconfactor
+                       { $$ = mkdexpr(OPSTAR, $1, $3); }
+       |       iconterm SSLASH iconfactor
+                       { $$ = mkdexpr(OPSLASH, $1, $3); }
+       ;
+
+iconfactor:    iconprimary
+         |     iconprimary SPOWER iconfactor
+                       { $$ = mkdexpr(OPPOWER, $1, $3); }
+         ;
+
+iconprimary:   SICON
+                       { $$ = evicon(toklen, token); }
+          |    dataname
+          |    SLPAR iconexpr SRPAR
+                       { $$ = $2; }
+          ;
diff --git a/usr/src/usr.bin/f77/src/f77pass1/put.c b/usr/src/usr.bin/f77/src/f77pass1/put.c
new file mode 100644 (file)
index 0000000..58e15ae
--- /dev/null
@@ -0,0 +1,352 @@
+/*
+ * INTERMEDIATE CODE GENERATION PROCEDURES COMMON TO BOTH
+ * JOHNSON (PORTABLE) AND RITCHIE FAMILIES OF SECOND PASSES
+*/
+
+#include "defs.h"
+
+#if FAMILY == PCC
+#      include "pccdefs.h"
+#else
+#      include "dmrdefs.h"
+#endif
+
+/*
+char *ops [ ] =
+       {
+       "??", "+", "-", "*", "/", "**", "-",
+       "OR", "AND", "EQV", "NEQV", "NOT",
+       "CONCAT",
+       "<", "==", ">", "<=", "!=", ">=",
+       " of ", " ofC ", " = ", " += ", " *= ", " CONV ", " << ", " % ",
+       " , ", " ? ", " : "
+       " abs ", " min ", " max ", " addr ", " indirect ",
+       " bitor ", " bitand ", " bitxor ", " bitnot ", " >> ", " () "
+       };
+*/
+
+int ops2 [ ] =
+       {
+       P2BAD, P2PLUS, P2MINUS, P2STAR, P2SLASH, P2BAD, P2NEG,
+       P2OROR, P2ANDAND, P2EQ, P2NE, P2NOT,
+       P2BAD,
+       P2LT, P2EQ, P2GT, P2LE, P2NE, P2GE,
+       P2CALL, P2CALL, P2ASSIGN, P2PLUSEQ, P2STAREQ, P2CONV, P2LSHIFT, P2MOD,
+       P2COMOP, P2QUEST, P2COLON,
+       P2BAD, P2BAD, P2BAD, P2BAD, P2INDIRECT,
+       P2BITOR, P2BITAND, P2BITXOR, P2BITNOT, P2RSHIFT, P2BAD
+       };
+
+
+int types2 [ ] =
+       {
+       P2BAD, P2INT|P2PTR, P2SHORT, P2LONG, P2REAL, P2DREAL,
+#if TARGET == INTERDATA
+       P2BAD, P2BAD, P2LONG, P2CHAR, P2INT, P2BAD
+#else
+       P2REAL, P2DREAL, P2LONG, P2CHAR, P2INT, P2BAD
+#endif
+       };
+
+
+setlog()
+{
+types2[TYLOGICAL] = types2[tylogical];
+typesize[TYLOGICAL] = typesize[tylogical];
+typealign[TYLOGICAL] = typealign[tylogical];
+}
+
+
+putex1(p)
+expptr p;
+{
+putx( fixtype(p) );
+
+if (!optimflag)
+       {
+       templist = hookup(templist, holdtemps);
+       holdtemps = NULL;
+       }
+}
+
+
+
+
+
+putassign(lp, rp)
+expptr lp, rp;
+{
+putx( fixexpr( mkexpr(OPASSIGN, lp, rp) ));
+}
+
+
+
+
+puteq(lp, rp)
+expptr lp, rp;
+{
+putexpr( mkexpr(OPASSIGN, lp, rp) );
+}
+
+
+
+
+/* put code for  a *= b */
+
+putsteq(a, b)
+expptr a, b;
+{
+putx( fixexpr( mkexpr(OPSTAREQ, cpexpr(a), cpexpr(b)) ));
+}
+
+
+
+
+
+Addrp realpart(p)
+register Addrp p;
+{
+register Addrp q;
+
+q = (Addrp) cpexpr(p);
+if( ISCOMPLEX(p->vtype) )
+       q->vtype += (TYREAL-TYCOMPLEX);
+return(q);
+}
+
+
+
+
+expptr imagpart(p)
+register expptr p;
+{
+register Addrp q;
+expptr mkrealcon();
+
+if (ISCONST(p))
+       {
+       if (ISCOMPLEX(p->constblock.vtype))
+               return(mkrealcon(p->constblock.vtype == TYCOMPLEX ?
+                                       TYREAL : TYDREAL,
+                               p->constblock.const.cd[1]));
+       else if (p->constblock.vtype == TYDREAL)
+               return(mkrealcon(TYDREAL, 0.0));
+       else
+               return(mkrealcon(TYREAL, 0.0));
+       }
+else if (p->tag == TADDR)
+       {
+       if( ISCOMPLEX(p->addrblock.vtype) )
+               {
+               q = (Addrp) cpexpr(p);
+               q->vtype += (TYREAL-TYCOMPLEX);
+               q->memoffset = mkexpr(OPPLUS, q->memoffset,
+                                       ICON(typesize[q->vtype]));
+               return( (expptr) q );
+               }
+       else
+               return( mkrealcon( ISINT(p->addrblock.vtype) ?
+                       TYDREAL : p->addrblock.vtype , 0.0));
+       }
+else
+       badtag("imagpart", p->tag);
+}
+
+
+
+
+ncat(p)
+register expptr p;
+{
+if(p->tag==TEXPR && p->exprblock.opcode==OPCONCAT)
+       return( ncat(p->exprblock.leftp) + ncat(p->exprblock.rightp) );
+else   return(1);
+}
+
+
+
+
+ftnint lencat(p)
+register expptr p;
+{
+if(p->tag==TEXPR && p->exprblock.opcode==OPCONCAT)
+       return( lencat(p->exprblock.leftp) + lencat(p->exprblock.rightp) );
+else if( p->headblock.vleng!=NULL && ISICON(p->headblock.vleng) )
+       return(p->headblock.vleng->constblock.const.ci);
+else if((p->tag==TADDR || p->tag==TTEMP) && p->addrblock.varleng!=0)
+       return(p->addrblock.varleng);
+else
+       {
+       err("impossible element in concatenation");
+       return(0);
+       }
+}
+\f
+Addrp putconst(p)
+register Constp p;
+{
+register Addrp q;
+struct Literal *litp, *lastlit;
+int i, k, type;
+int litflavor;
+
+if( p->tag != TCONST )
+       badtag("putconst", p->tag);
+
+q = ALLOC(Addrblock);
+q->tag = TADDR;
+type = p->vtype;
+q->vtype = ( type==TYADDR ? TYINT : type );
+q->vleng = (expptr) cpexpr(p->vleng);
+q->vstg = STGCONST;
+q->memno = newlabel();
+q->memoffset = ICON(0);
+
+/* check for value in literal pool, and update pool if necessary */
+
+switch(type = p->vtype)
+       {
+       case TYCHAR:
+               if(p->vleng->constblock.const.ci > XL)
+                       break;  /* too long for literal table */
+               litflavor = 1;
+               goto loop;
+
+       case TYREAL:
+       case TYDREAL:
+               litflavor = 2;
+               goto loop;
+
+       case TYLOGICAL:
+               type = tylogical;
+       case TYSHORT:
+       case TYLONG:
+               litflavor = 3;
+
+       loop:
+               lastlit = litpool + nliterals;
+               for(litp = litpool ; litp<lastlit ; ++litp)
+                       if(type == litp->littype) switch(litflavor)
+                               {
+                       case 1:
+                               if(p->vleng->constblock.const.ci != litp->litval.litcval.litclen)
+                                       break;
+                               if(! eqn( (int) p->vleng->constblock.const.ci, p->const.ccp,
+                                       litp->litval.litcval.litcstr) )
+                                               break;
+
+                       ret:
+                               q->memno = litp->litnum;
+                               frexpr(p);
+                               return(q);
+
+                       case 2:
+                               if(p->const.cd[0] == litp->litval.litdval)
+                                       goto ret;
+                               break;
+
+                       case 3:
+                               if(p->const.ci == litp->litval.litival)
+                                       goto ret;
+                               break;
+                               }
+               if(nliterals < MAXLITERALS)
+                       {
+                       ++nliterals;
+                       litp->littype = type;
+                       litp->litnum = q->memno;
+                       switch(litflavor)
+                               {
+                               case 1:
+                                       litp->litval.litcval.litclen =
+                                               p->vleng->constblock.const.ci;
+                                       cpn( (int) litp->litval.litcval.litclen,
+                                               p->const.ccp,
+                                               litp->litval.litcval.litcstr);
+                                       break;
+
+                               case 2:
+                                       litp->litval.litdval = p->const.cd[0];
+                                       break;
+
+                               case 3:
+                                       litp->litval.litival = p->const.ci;
+                                       break;
+                               }
+                       }
+       default:
+               break;
+       }
+
+preven(typealign[ type==TYCHAR ? TYLONG : type ]);
+prlabel(asmfile, q->memno);
+
+k = 1;
+switch(type)
+       {
+       case TYLOGICAL:
+       case TYSHORT:
+       case TYLONG:
+               prconi(asmfile, type, p->const.ci);
+               break;
+
+       case TYCOMPLEX:
+               k = 2;
+       case TYREAL:
+               type = TYREAL;
+               goto flpt;
+
+       case TYDCOMPLEX:
+               k = 2;
+       case TYDREAL:
+               type = TYDREAL;
+
+       flpt:
+               for(i = 0 ; i < k ; ++i)
+                       prconr(asmfile, type, p->const.cd[i]);
+               break;
+
+       case TYCHAR:
+               putstr(asmfile, p->const.ccp,
+                       (int) (p->vleng->constblock.const.ci) );
+               break;
+
+       case TYADDR:
+               prcona(asmfile, p->const.ci);
+               break;
+
+       default:
+               badtype("putconst", p->vtype);
+       }
+
+frexpr(p);
+return( q );
+}
+\f
+/*
+ * put out a character string constant.  begin every one on
+ * a long integer boundary, and pad with nulls
+ */
+putstr(fp, s, n)
+FILEP fp;
+char *s;
+int n;
+{
+int b[SZSHORT];
+int i;
+
+i = 0;
+while(--n >= 0)
+       {
+       b[i++] = *s++;
+       if(i == SZSHORT)
+               {
+               prchars(fp, b);
+               i = 0;
+               }
+       }
+
+while(i < SZSHORT)
+       b[i++] = '\0';
+prchars(fp, b);
+}
diff --git a/usr/src/usr.bin/f77/src/f77pass1/vax.c b/usr/src/usr.bin/f77/src/f77pass1/vax.c
new file mode 100644 (file)
index 0000000..e47628e
--- /dev/null
@@ -0,0 +1,965 @@
+#include "defs.h"
+
+#ifdef SDB
+#      include <a.out.h>
+extern int types2[];
+#      ifndef N_SO
+#              include <stab.h>
+#      endif
+#endif
+
+#include "pccdefs.h"
+
+
+/*
+       VAX-11/780 - SPECIFIC ROUTINES
+*/
+
+
+int maxregvar = MAXREGVAR;
+int regnum[] =  { 10, 9, 8, 7, 6 } ;
+static int regmask[] = { 0x800, 0xc00, 0xe00, 0xf00, 0xf80, 0xfc0 };
+
+
+
+ftnint intcon[14] =
+       { 2, 2, 2, 2,
+         15, 31, 24, 56,
+         -128, -128, 127, 127,
+         32767, 2147483647 };
+
+#if HERE == VAX
+       /* then put in constants in octal */
+long realcon[6][2] =
+       {
+               { 0200, 0 },
+               { 0200, 0 },
+               { 037777677777, 0 },
+               { 037777677777, 037777777777 },
+               { 032200, 0 },
+               { 022200, 0 }
+       };
+#else
+double realcon[6] =
+       {
+       2.9387358771e-39,
+       2.938735877055718800e-39
+       1.7014117332e+38,
+       1.701411834604692250e+38
+       5.960464e-8,
+       1.38777878078144567e-17,
+       };
+#endif
+
+
+
+
+prsave(proflab)
+int proflab;
+{
+if(profileflag)
+       {
+       fprintf(asmfile, "L%d:\t.space\t4\n", proflab);
+       p2pi("\tmovab\tL%d,r0", proflab);
+       p2pass("\tjsb\tmcount");
+       }
+p2pi("\tsubl2\t$LF%d,sp", procno);
+}
+
+
+
+goret(type)
+int type;
+{
+p2pass("\tret");
+}
+
+
+
+
+/*
+ * move argument slot arg1 (relative to ap)
+ * to slot arg2 (relative to ARGREG)
+ */
+
+mvarg(type, arg1, arg2)
+int type, arg1, arg2;
+{
+p2pij("\tmovl\t%d(ap),%d(fp)", arg1+ARGOFFSET, arg2+argloc);
+}
+
+
+
+
+prlabel(fp, k)
+FILEP fp;
+int k;
+{
+fprintf(fp, "L%d:\n", k);
+}
+
+
+
+prconi(fp, type, n)
+FILEP fp;
+int type;
+ftnint n;
+{
+fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n);
+}
+
+
+
+prcona(fp, a)
+FILEP fp;
+ftnint a;
+{
+fprintf(fp, "\t.long\tL%ld\n", a);
+}
+
+
+
+#ifndef vax
+prconr(fp, type, x)
+FILEP fp;
+int type;
+float x;
+{
+fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x);
+}
+#endif
+
+#ifdef vax
+prconr(fp, type, x)
+FILEP fp;
+int type;
+double x;
+{
+/* non-portable cheat to preserve bit patterns */
+union { double xd; long int xl[2]; } cheat;
+cheat.xd = x;
+if(type == TYREAL)
+       {float y = x; fprintf(fp, "\t.long\t0x%X\n", *(long *) &y); }
+else
+       fprintf(fp, "\t.long\t0x%X,0x%X\n", cheat.xl[0], cheat.xl[1]);
+}
+#endif
+
+
+
+praddr(fp, stg, varno, offset)
+FILE *fp;
+int stg, varno;
+ftnint offset;
+{
+char *memname();
+
+if(stg == STGNULL)
+       fprintf(fp, "\t.long\t0\n");
+else
+       {
+       fprintf(fp, "\t.long\t%s", memname(stg,varno));
+       if(offset)
+               fprintf(fp, "+%ld", offset);
+       fprintf(fp, "\n");
+       }
+}
+
+
+
+
+preven(k)
+int k;
+{
+register int lg;
+
+if(k > 4)
+       lg = 3;
+else if(k > 2)
+       lg = 2;
+else if(k > 1)
+       lg = 1;
+else
+       return;
+fprintf(asmfile, "\t.align\t%d\n", lg);
+}
+
+
+
+
+pralign(k)
+int k;
+{
+  register int lg;
+
+  if (k > 4)
+    lg = 3;
+  else if (k > 2)
+    lg = 2;
+  else if (k > 1)
+    lg = 1;
+  else
+    return;
+
+  fprintf(initfile, "\t.align\t%d\n", lg);
+  return;
+}
+
+
+
+vaxgoto(index, nlab, labs)
+expptr index;
+register int nlab;
+struct Labelblock *labs[];
+{
+register int i;
+register int arrlab;
+
+putforce(TYINT, index);
+p2pi("\tcasel\tr0,$1,$%d", nlab-1);
+p2pi("L%d:", arrlab = newlabel() );
+for(i = 0; i< nlab ; ++i)
+       if( labs[i] )
+               p2pij("\t.word\tL%d-L%d", labs[i]->labelno, arrlab);
+}
+
+
+prarif(p, neg, zer, pos)
+expptr p;
+int neg, zer, pos;
+{
+int type;
+
+type = p->headblock.vtype;
+putforce(type, p);
+if(type == TYLONG)
+       p2pass("\ttstl\tr0");
+else if (type == TYSHORT)
+       p2pass("\ttstw\tr0");
+else
+       p2pass("\ttstd\tr0");
+p2pi("\tjlss\tL%d", neg);
+p2pi("\tjeql\tL%d", zer);
+p2pi("\tjbr\tL%d", pos);
+}
+
+
+
+
+char *memname(stg, mem)
+int stg, mem;
+{
+static char s[20];
+
+switch(stg)
+       {
+       case STGCOMMON:
+       case STGEXT:
+               sprintf(s, "_%s", varstr(XL, extsymtab[mem].extname) );
+               break;
+
+       case STGBSS:
+       case STGINIT:
+               sprintf(s, "v.%d", mem);
+               break;
+
+       case STGCONST:
+               sprintf(s, "L%d", mem);
+               break;
+
+       case STGEQUIV:
+               sprintf(s, "q.%d", mem+eqvstart);
+               break;
+
+       default:
+               badstg("memname", stg);
+       }
+return(s);
+}
+
+
+
+
+prlocvar(s, len)
+char *s;
+ftnint len;
+{
+fprintf(asmfile, "\t.lcomm\t%s,%ld\n", s, len);
+}
+
+
+
+
+char *
+packbytes(cp)
+register Constp cp;
+{
+  static char shrt[2];
+  static char lng[4];
+  static char quad[8];
+  static char oct[16];
+
+  register int type;
+  register int *ip, *jp;
+
+  switch (cp->vtype)
+    {
+    case TYSHORT:
+      *((short *) shrt) = (short) cp->const.ci;
+      return (shrt);
+
+    case TYLONG:
+    case TYLOGICAL:
+    case TYREAL:
+      *((int *) lng) = cp->const.ci;
+      return (lng);
+
+    case TYDREAL:
+      ip = (int *) quad;
+      jp = (int *) &(cp->const.cd[0]);
+      ip[0] = jp[0];
+      ip[1] = jp[1];
+      return (quad);
+
+    case TYCOMPLEX:
+      ip = (int *) quad;
+      jp = (int *) &(cp->const.cd[0]);
+      ip[0] = jp[0];
+      ip[1] = jp[2];
+      return (quad);
+
+    case TYDCOMPLEX:
+      ip = (int *) oct;
+      jp = (int *) &(cp->const.cd[0]);
+      *ip++ = *jp++;
+      *ip++ = *jp++;
+      *ip++ = *jp++;
+      *ip = *jp;
+      return (oct);
+
+    default:
+      badtype("packbytes", cp->vtype);
+    }
+}
+
+
+
+
+prsdata(s, len)
+register char *s;
+register int len;
+{
+  static char *longfmt = "\t.long\t0x%x\n";
+  static char *wordfmt = "\t.word\t0x%x\n";
+  static char *bytefmt = "\t.byte\t0x%x\n";
+
+  register int i;
+
+  i = 0;
+  if ((len - i) >= 4)
+    {
+      fprintf(initfile, longfmt, *((int *) s));
+      i += 4;
+    }
+  if ((len - i) >= 2)
+    {
+      fprintf(initfile, wordfmt, 0xffff & (*((short *) (s + i))));
+      i += 2;
+    }
+  if ((len - i) > 0)
+    fprintf(initfile,bytefmt, 0xff & s[i]);
+
+  return;
+}
+
+
+
+prquad(s)
+char *s;
+{
+  static char *quadfmt1 = "\t.quad\t0x%x\n";
+  static char *quadfmt2 = "\t.quad\t0x%x%08x\n";
+
+  if ( *((int *) (s + 4)) == 0 )
+    fprintf(initfile, quadfmt1, *((int *) s));
+  else
+    fprintf(initfile, quadfmt2, *((int *) (s + 4)), *((int *) s));
+
+  return;
+}
+
+
+
+#ifdef NOTDEF
+
+/*  The code for generating .fill directives has been      */
+/*  ifdefed out because of bugs in the UCB VAX assembler.  */
+/*  If those bugs are ever fixed (and it seems unlikely),  */
+/*  the NOTDEF's should be replaced by UCBVAXASM.          */
+
+
+prfill(n, s)
+int n;
+register char *s;
+{
+  static char *fillfmt1 = "\t.fill\t%d,8,0x%x\n";
+  static char *fillfmt2 = "\t.fill\t%d,8,0x%x%08x\n";
+
+  if (*((int *) (s + 4)) == 0)
+    fprintf(initfile, fillfmt1, n, *((int *) s));
+  else
+    fprintf(initfile, fillfmt2, n, *((int *) (s + 4)), *((int *) s));
+
+  return;
+}
+
+#endif
+
+
+
+prext(ep)
+register struct Extsym *ep;
+{
+  static char *globlfmt = "\t.globl\t_%s\n";
+  static char *commfmt = "\t.comm\t_%s,%ld\n";
+  static char *spacefmt = "\t.space\t%d\n";
+  static char *align2fmt = "\t.align\t2\n";
+  static char *labelfmt = "_%s:\n";
+
+  static char *seekerror = "seek error on tmp file";
+  static char *readerror = "read error on tmp file";
+
+  char *tag;
+  register int leng;
+  long pos;
+  register int i;
+  char oldvalue[8];
+  char newvalue[8];
+  register int n;
+  register int repl;
+
+  tag = varstr(XL, ep->extname);
+  leng = ep->maxleng;
+
+  if (leng == 0)
+    {
+      fprintf(asmfile, globlfmt, tag);
+      return;
+    }
+
+  if (ep->init == NO)
+    {
+      fprintf(asmfile, commfmt, tag, leng);
+      return;
+    }
+
+  fprintf(asmfile, globlfmt, tag);
+  fprintf(initfile, align2fmt);
+  fprintf(initfile, labelfmt, tag);
+
+  pos = lseek(cdatafile, ep->initoffset, 0);
+  if (pos == -1)
+    {
+      err(seekerror);
+      done(1);
+    }
+
+  *((int *) oldvalue) = 0;
+  *((int *) (oldvalue + 4)) = 0;
+  n = read(cdatafile, oldvalue, 8);
+  if (n < 0)
+    {
+      err(readerror);
+      done(1);
+    }
+
+  if (leng <= 8)
+    {
+      i = leng;
+      while (i > 0 && oldvalue[--i] == '\0') /* SKIP */;
+      if (oldvalue[i] == '\0')
+       fprintf(initfile, spacefmt, leng);
+      else if (leng == 8)
+       prquad(oldvalue);
+      else
+       prsdata(oldvalue, leng);
+
+      return;
+    }
+
+  repl = 1;
+  leng -= 8;
+
+  while (leng >= 8)
+    {
+      *((int *) newvalue) = 0;
+      *((int *) (newvalue + 4)) = 0;
+
+      n = read(cdatafile, newvalue, 8);
+      if (n < 0)
+       {
+         err(readerror);
+         done(1);
+       }
+
+      leng -= 8;
+
+      if (*((int *) oldvalue) == *((int *) newvalue)
+         && *((int *) (oldvalue + 4)) == *((int *) (newvalue + 4)))
+       repl++;
+      else
+       {
+         if (*((int *) oldvalue) == 0
+             && *((int *) (oldvalue + 4)) == 0)
+           fprintf(initfile, spacefmt, 8*repl);
+         else if (repl == 1)
+           prquad(oldvalue);
+         else
+#ifdef NOTDEF
+           prfill(repl, oldvalue);
+#else
+           {
+             while (repl-- > 0)
+               prquad(oldvalue);
+           }
+#endif
+         *((int *) oldvalue) = *((int *) newvalue);
+         *((int *) (oldvalue + 4)) = *((int *) (newvalue + 4));
+         repl = 1;
+       }
+    }
+
+  *((int *) newvalue) = 0;
+  *((int *) (newvalue + 4)) = 0;
+
+  if (leng > 0)
+    {
+      n = read(cdatafile, newvalue, leng);
+      if (n < 0)
+       {
+         err(readerror);
+         done(1);
+       }
+    }
+
+  if (*((int *) (oldvalue + 4)) == 0
+      && *((int *) oldvalue) == 0
+      && *((int *) (newvalue + 4)) == 0
+      && *((int *) newvalue) == 0)
+    {
+      fprintf(initfile, spacefmt, 8*repl + leng);
+      return;
+    }
+
+  if (*((int *) (oldvalue + 4)) == 0
+      && *((int *) oldvalue) == 0)
+    fprintf(initfile, spacefmt, 8*repl);
+  else if (repl == 1)
+    prquad(oldvalue);
+  else
+#ifdef NOTDEF
+    prfill(repl, oldvalue);
+#else
+    {
+      while (repl-- > 0)
+       prquad(oldvalue);
+    }
+#endif
+
+  prsdata(newvalue, leng);
+
+  return;
+}
+
+
+
+prlocdata(sname, leng, type, initoffset, inlcomm)
+char *sname;
+ftnint leng;
+int type;
+long initoffset;
+char *inlcomm;
+{
+  static char *seekerror = "seek error on tmp file";
+  static char *readerror = "read error on tmp file";
+
+  static char *labelfmt = "%s:\n";
+  static char *spacefmt = "\t.space\t%d\n";
+
+  register int k;
+  register int i;
+  register int repl;
+  register int first;
+  register long pos;
+  register long n;
+  char oldvalue[8];
+  char newvalue[8];
+
+  *inlcomm = NO;
+
+  k = leng;
+  first = YES;
+
+  pos = lseek(vdatafile, initoffset, 0);
+  if (pos == -1)
+    {
+      err(seekerror);
+      done(1);
+    }
+
+  *((int *) oldvalue) = 0;
+  *((int *) (oldvalue + 4)) = 0;
+  n = read(vdatafile, oldvalue, 8);
+  if (n < 0)
+    {
+      err(readerror);
+      done(1);
+    }
+
+  if (k <= 8)
+    {
+      i = k;
+      while (i > 0 && oldvalue[--i] == '\0')
+       /*  SKIP  */ ;
+      if (oldvalue[i] == '\0')
+       {
+         if (SMALLVAR(leng))
+           {
+             pralign(typealign[type]);
+             fprintf(initfile, labelfmt, sname);
+             fprintf(initfile, spacefmt, leng);
+           }
+         else
+           {
+             preven(ALIDOUBLE);
+             prlocvar(sname, leng);
+             *inlcomm = YES;
+           }
+       }
+      else
+       {
+         fprintf(initfile, labelfmt, sname);
+         if (leng == 8)
+           prquad(oldvalue);
+         else
+           prsdata(oldvalue, leng);
+       }
+      return;
+    }
+
+  repl = 1;
+  k -= 8;
+
+  while (k >=8)
+    {
+      *((int *) newvalue) = 0;
+      *((int *) (newvalue + 4)) = 0;
+
+      n = read(vdatafile, newvalue, 8);
+      if (n < 0)
+       {
+         err(readerror);
+         done(1);
+       }
+
+      k -= 8;
+
+      if (*((int *) oldvalue) == *((int *) newvalue)
+         && *((int *) (oldvalue + 4)) == *((int *) (newvalue + 4)))
+       repl++;
+      else
+       {
+         if (first == YES)
+           {
+             pralign(typealign[type]);
+             fprintf(initfile, labelfmt, sname);
+             first = NO;
+           }
+
+         if (*((int *) oldvalue) == 0
+             && *((int *) (oldvalue + 4)) == 0)
+           fprintf(initfile, spacefmt, 8*repl);
+         else
+           {
+             while (repl-- > 0)
+               prquad(oldvalue);
+           }
+         *((int *) oldvalue) = *((int *) newvalue);
+         *((int *) (oldvalue + 4)) = *((int *) (newvalue + 4));
+         repl = 1;
+       }
+    }
+
+  *((int *) newvalue) = 0;
+  *((int *) (newvalue + 4)) = 0;
+
+  if (k > 0)
+    {
+      n = read(vdatafile, newvalue, k);
+      if (n < 0)
+       {
+         err(readerror);
+         done(1);
+       }
+    }
+
+  if (*((int *) (oldvalue + 4)) == 0
+      && *((int *) oldvalue) == 0
+      && *((int *) (newvalue + 4)) == 0
+      && *((int *) newvalue) == 0)
+    {
+      if (first == YES && !SMALLVAR(leng))
+       {
+         prlocvar(sname, leng);
+         *inlcomm = YES;
+       }
+      else
+       {
+         if (first == YES)
+           {
+             pralign(typealign[type]);
+             fprintf(initfile, labelfmt, sname);
+           }
+         fprintf(initfile, spacefmt, 8*repl + k);
+       }
+      return;
+    }
+
+  if (first == YES)    
+    {
+      pralign(typealign[type]);
+      fprintf(initfile, labelfmt, sname);
+    }
+
+  if (*((int *) (oldvalue + 4)) == 0
+      && *((int *) oldvalue) == 0)
+    fprintf(initfile, spacefmt, 8*repl);
+  else
+    {
+      while (repl-- > 0)
+       prquad(oldvalue);
+    }
+
+  prsdata(newvalue, k);
+
+  return;
+}
+           
+
+
+
+prendproc()
+{
+}
+
+
+
+
+prtail()
+{
+}
+
+
+
+
+
+prolog(ep, argvec)
+struct Entrypoint *ep;
+Addrp  argvec;
+{
+int i, argslot, proflab;
+int size;
+register chainp p;
+register Namep q;
+register struct Dimblock *dp;
+expptr tp;
+
+p2pass("\t.align\t1");
+
+
+if(procclass == CLMAIN) {
+       if(fudgelabel)
+               {
+               if(ep->entryname) {
+                       p2ps("_%s:",  varstr(XL, ep->entryname->extname));
+                       p2pi("\t.word\tLWM%d", procno);
+               }
+               putlabel(fudgelabel);
+               fudgelabel = 0;
+               fixlwm();
+               }
+       else
+               {
+               p2pass( "_MAIN_:" );
+               if(ep->entryname == NULL)
+                       p2pi("\t.word\tLWM%d", procno);
+               }
+
+} else if(ep->entryname)
+       if(fudgelabel)
+               {
+               putlabel(fudgelabel);
+               fudgelabel = 0;
+               fixlwm();
+               }
+       else
+               {
+               p2ps("_%s:",  varstr(XL, ep->entryname->extname));
+               p2pi("\t.word\tLWM%d", procno);
+               prsave(newlabel());
+               }
+
+if(procclass == CLBLOCK)
+       return;
+if (anylocals == YES)
+       {
+       char buff[30];
+       sprintf(buff, "\tmovl\t$v.%d,r11", bsslabel);
+       p2pass(buff);
+       }
+if(argvec)
+       {
+       if (argvec->tag != TADDR) badtag ("prolog",argvec->tag);
+       argloc = argvec->memoffset->constblock.const.ci + SZINT;
+                       /* first slot holds count */
+       if(proctype == TYCHAR)
+               {
+               mvarg(TYADDR, 0, chslot);
+               mvarg(TYLENG, SZADDR, chlgslot);
+               argslot = SZADDR + SZLENG;
+               }
+       else if( ISCOMPLEX(proctype) )
+               {
+               mvarg(TYADDR, 0, cxslot);
+               argslot = SZADDR;
+               }
+       else
+               argslot = 0;
+
+       for(p = ep->arglist ; p ; p =p->nextp)
+               {
+               q = (Namep) (p->datap);
+               mvarg(TYADDR, argslot, q->vardesc.varno);
+               argslot += SZADDR;
+               }
+       for(p = ep->arglist ; p ; p = p->nextp)
+               {
+               q = (Namep) (p->datap);
+               if(q->vtype==TYCHAR && q->vclass!=CLPROC)
+                       {
+                       if(q->vleng && ! ISCONST(q->vleng) )
+                               mvarg(TYLENG, argslot,
+                                       q->vleng->addrblock.memno);
+                       argslot += SZLENG;
+                       }
+               }
+       p2pi("\taddl3\t$%d,fp,ap", argloc-ARGOFFSET);
+       p2pi("\tmovl\t$%d,(ap)\n", lastargslot/SZADDR);
+       }
+
+for(p = ep->arglist ; p ; p = p->nextp)
+       {
+       q = (Namep) (p->datap);
+       if(dp = q->vdim)
+               {
+               for(i = 0 ; i < dp->ndim ; ++i)
+                       if(dp->dims[i].dimexpr)
+                               puteq( fixtype(cpexpr(dp->dims[i].dimsize)),
+                                       fixtype(cpexpr(dp->dims[i].dimexpr)));
+#ifdef SDB
+                if(sdbflag) {
+               for(i = 0 ; i < dp->ndim ; ++i) {
+                       if(dp->dims[i].lbaddr)
+                               puteq( fixtype(cpexpr(dp->dims[i].lbaddr)),
+                                       fixtype(cpexpr(dp->dims[i].lb)));
+                       if(dp->dims[i].ubaddr)
+                               puteq( fixtype(cpexpr(dp->dims[i].ubaddr)),
+                                       fixtype(cpexpr(dp->dims[i].ub)));
+                   
+                                                }
+                            }
+#endif
+               size = typesize[ q->vtype ];
+               if(q->vtype == TYCHAR)
+                       if( ISICON(q->vleng) )
+                               size *= q->vleng->constblock.const.ci;
+                       else
+                               size = -1;
+
+               /* on VAX, get more efficient subscripting if subscripts
+                  have zero-base, so fudge the argument pointers for arrays.
+                  Not done if array bounds are being checked.
+               */
+               if(dp->basexpr)
+                       puteq(  cpexpr(fixtype(dp->baseoffset)),
+                               cpexpr(fixtype(dp->basexpr)));
+#ifdef SDB
+               if( (! checksubs) && (! sdbflag) )
+#else
+               if(! checksubs)
+#endif
+                       {
+                       if(dp->basexpr)
+                               {
+                               if(size > 0)
+                                       tp = (expptr) ICON(size);
+                               else
+                                       tp = (expptr) cpexpr(q->vleng);
+                               putforce(TYINT,
+                                       fixtype( mkexpr(OPSTAR, tp,
+                                               cpexpr(dp->baseoffset)) ));
+                               p2pi("\tsubl2\tr0,%d(ap)",
+                                       p->datap->nameblock.vardesc.varno +
+                                               ARGOFFSET);
+                               }
+                       else if(dp->baseoffset->constblock.const.ci != 0)
+                               {
+                               char buff[25];
+                               if(size > 0)
+                                       {
+                                       sprintf(buff, "\tsubl2\t$%ld,%d(ap)",
+                                               dp->baseoffset->constblock.const.ci * size,
+                                               p->datap->nameblock.vardesc.varno +
+                                                       ARGOFFSET);
+                                       }
+                               else    {
+                                       putforce(TYINT, mkexpr(OPSTAR, cpexpr(dp->baseoffset),
+                                               cpexpr(q->vleng) ));
+                                       sprintf(buff, "\tsubl2\tr0,%d(ap)",
+                                               p->datap->nameblock.vardesc.varno +
+                                                       ARGOFFSET);
+                                       }
+                               p2pass(buff);
+                               }
+                       }
+               }
+       }
+
+if(typeaddr)
+       puteq( cpexpr(typeaddr), mkaddcon(ep->typelabel) );
+/* replace to avoid long jump problem
+putgoto(ep->entrylabel);
+*/
+p2pi("\tjmp\tL%d", ep->entrylabel);
+}
+
+fixlwm()
+{
+       extern lwmno;
+       if (lwmno == procno)
+               return;
+       fprintf(asmfile, "\t.set\tLWM%d,0x%x\n",
+               procno, regmask[highregvar]);
+       lwmno = procno;
+}
+
+
+prhead(fp)
+FILEP fp;
+{
+#if FAMILY==PCC
+       p2triple(P2LBRACKET, ARGREG-highregvar, procno);
+       p2word( (long) (BITSPERCHAR*autoleng) );
+       p2flush();
+#endif
+}