date and time created 88/07/22 16:08:01 by bostic
[unix-history] / usr / src / old / as.vax / asparse.c
index 7ad5b1b..5ebcefd 100644 (file)
@@ -1,8 +1,11 @@
 /*
 /*
- *     Copyright (c) 1982 Regents of the University of California
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
  */
  */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)asparse.c 4.13 %G%";
+static char sccsid[] = "@(#)asparse.c  5.3 (Berkeley) %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -44,7 +47,7 @@ struct        arg     arglist[NARG];  /*building up operands in instructions*/
  */
 char   tokensets[(LASTTOKEN) - (FIRSTTOKEN) + 1];
 
  */
 char   tokensets[(LASTTOKEN) - (FIRSTTOKEN) + 1];
 
-static char    UDotsname[32];  /*name of the assembly source*/
+static char    UDotsname[64];  /*name of the assembly source*/
 
 yyparse()
 {
 
 yyparse()
 {
@@ -68,7 +71,7 @@ yyparse()
        reg     struct  symtab  *p;
        reg     struct  symtab  *stpt;
 
        reg     struct  symtab  *p;
        reg     struct  symtab  *stpt;
 
-               char    *stringp;       /*handles string lists*/
+               struct  strdesc *stringp;       /*handles string lists*/
 
                int     regno;          /*handles arguments*/
                int     *ptrregno = &regno;
 
                int     regno;          /*handles arguments*/
                int     *ptrregno = &regno;
@@ -131,48 +134,26 @@ yyparse()
                        np = (struct symtab *)yylval;
                        shiftover(NAME);
                        if (val != COLON) {
                        np = (struct symtab *)yylval;
                        shiftover(NAME);
                        if (val != COLON) {
-#ifdef FLEXNAMES
                                yyerror("\"%s\" is not followed by a ':' for a label definition",
                                yyerror("\"%s\" is not followed by a ':' for a label definition",
-#else not FLEXNAMES
-                               yyerror("\"%.*s\" is not followed by a ':' for a label definition",
-                                       NCPName,
-#endif not FLEXNAMES
-                                       np->s_name);
+                                       FETCHNAME(np));
                                goto  errorfix;
                        }
 restlab:
                        shift;
                                goto  errorfix;
                        }
 restlab:
                        shift;
-                       flushfield(NBPW/4);
+                       flushfield(NBWD/4);
                        if ((np->s_type&XTYPE)!=XUNDEF) {
                        if ((np->s_type&XTYPE)!=XUNDEF) {
-                               if(  (np->s_type&XTYPE)!=dotp->e_xtype 
-                                  || np->s_value!=dotp->e_xvalue
-                                  || (  (passno==1)
-                                      &&(np->s_index != dotp->e_xloc)
-                                     )
-                                 ){
-#ifndef DEBUG
-                                       if (np->s_name[0] != 'L')
-#endif not DEBUG
-                                       {
-                                               if (passno == 1)
-#ifdef FLEXNAMES
-                                                 yyerror("%s redefined",
-#else not FLEXNAMES
-                                                 yyerror("%.*s redefined",
-                                                       NCPName,
-#endif not FLEXNAMES 
-                                                       np->s_name);
-                                               else
-#ifdef FLEXNAMES
-                                                 yyerror("%s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
-#else not FLEXNAMES
-                                                 yyerror("%.*s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
-                                                       NCPName,
-#endif not FLEXNAMES
-                                                       np->s_name,
+                               if (  (np->s_type&XTYPE) != dotp->e_xtype 
+                                  || np->s_value != dotp->e_xvalue
+                                  || (   passno == 1
+                                      && np->s_index != dotp->e_xloc) ) {
+                                       if (passno == 1)
+                                               yyerror("%s redefined",
+                                                       FETCHNAME(np));
+                                       else
+                                               yyerror("%s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
+                                                       FETCHNAME(np),
                                                        np->s_value,
                                                        dotp->e_xvalue);
                                                        np->s_value,
                                                        dotp->e_xvalue);
-                                       }
                                }
                        }
                        np->s_type &= ~(XTYPE|XFORW);
                                }
                        }
                        np->s_type &= ~(XTYPE|XFORW);
@@ -180,13 +161,13 @@ restlab:
                        np->s_value = dotp->e_xvalue;
                        if (passno == 1){
                                np->s_index = dotp-usedot;
                        np->s_value = dotp->e_xvalue;
                        if (passno == 1){
                                np->s_index = dotp-usedot;
-                               if (np->s_name[0] == 'L'){
+                               if (FETCHNAME(np)[0] == 'L'){
                                        nlabels++;
                                }
                                np->s_tag = LABELID;
                        }
                }       /*end of this being a label*/
                                        nlabels++;
                                }
                                np->s_tag = LABELID;
                        }
                }       /*end of this being a label*/
-       }       /*end of to consuming all labels, NLs and SEMIS */ 
+       }       /*end of consuming all labels, NLs and SEMIS */ 
 
        xp = explist;
        ap = arglist;
 
        xp = explist;
        ap = arglist;
@@ -214,10 +195,11 @@ restlab:
 
    case IFILE:
        shift;
 
    case IFILE:
        shift;
-       stringp = (char *)yylval;
+       stringp = (struct strdesc *)yylval;
        shiftover(STRING);
        dotsname = &UDotsname[0];
        shiftover(STRING);
        dotsname = &UDotsname[0];
-       movestr(dotsname, stringp, min(STRLEN(stringp), sizeof(dotsname)));
+       movestr(dotsname, stringp->sd_string,
+               min(stringp->sd_strlen, sizeof(UDotsname)));
        break;
 
    case ILINENO:
        break;
 
    case ILINENO:
@@ -256,11 +238,7 @@ restlab:
         */
        if (passno == 1){
                stpt = (struct symtab *)symalloc();
         */
        if (passno == 1){
                stpt = (struct symtab *)symalloc();
-#ifdef FLEXNAMES
                stpt->s_name = np->s_name;
                stpt->s_name = np->s_name;
-#else
-               movestr(stpt->s_name, np->s_name, NCPName);
-#endif
                np->s_tag = OBSOLETE;   /*invalidate original */
                nforgotten++;
                np = stpt;
                np->s_tag = OBSOLETE;   /*invalidate original */
                nforgotten++;
                np = stpt;
@@ -300,26 +278,12 @@ restlab:
        }
        if (seg_type == IDATA)
                seg_number += NLOC;
        }
        if (seg_type == IDATA)
                seg_number += NLOC;
-       flushfield(NBPW/4);
+       flushfield(NBWD/4);
        dotp = &usedot[seg_number];
        dotp = &usedot[seg_number];
-#ifdef UNIX
        if (passno==2) {        /* go salt away in pass 2*/
                txtfil = usefile[seg_number];
                relfil = rusefile[seg_number];
        }
        if (passno==2) {        /* go salt away in pass 2*/
                txtfil = usefile[seg_number];
                relfil = rusefile[seg_number];
        }
-#endif UNIX
-#ifdef VMS
-       if (passno==2) {
-               puchar(vms_obj_ptr,6);          /*  setpl  */
-               puchar(vms_obj_ptr,seg_number); /* psect # */
-               plong(vms_obj_ptr,dotp->e_xvalue);/*  offset */
-               puchar(vms_obj_ptr,80);         /*  setrb  */
-               if((vms_obj_ptr-sobuf) > 400){
-                       write(objfil,sobuf,vms_obj_ptr-sobuf);
-                       vms_obj_ptr=sobuf+1;    /*flush buf*/
-               }
-       }
-#endif VMS
        break;
 
        /*
        break;
 
        /*
@@ -330,10 +294,10 @@ restlab:
         *      exprlist:  empty | exprlist outexpr
         *      outexpr:   <expr> | <expr> : <expr>
         */
         *      exprlist:  empty | exprlist outexpr
         *      outexpr:   <expr> | <expr> : <expr>
         */
-   case IBYTE: curlen = NBPW/4; goto elist;
-   case IWORD: curlen = NBPW/2; goto elist;
-   case IINT:  curlen = NBPW;   goto elist;
-   case ILONG: curlen = NBPW;   goto elist;
+   case IBYTE: curlen = NBWD/4; goto elist;
+   case IWORD: curlen = NBWD/2; goto elist;
+   case IINT:  curlen = NBWD;   goto elist;
+   case ILONG: curlen = NBWD;   goto elist;
 
    elist:
        seg_type = val;
 
    elist:
        seg_type = val;
@@ -374,9 +338,9 @@ restlab:
                        if (bitoff)
                                yyerror("Illegal relocation in field");
                        switch(curlen){
                        if (bitoff)
                                yyerror("Illegal relocation in field");
                        switch(curlen){
-                               case NBPW/4:    reloc_how = TYPB; break;
-                               case NBPW/2:    reloc_how = TYPW; break;
-                               case NBPW:      reloc_how = TYPL; break;
+                               case NBWD/4:    reloc_how = TYPB; break;
+                               case NBWD/2:    reloc_how = TYPW; break;
+                               case NBWD:      reloc_how = TYPL; break;
                        }
                        if (passno == 1){
                                dotp->e_xvalue += ty_nbyte[reloc_how];
                        }
                        if (passno == 1){
                                dotp->e_xvalue += ty_nbyte[reloc_how];
@@ -408,7 +372,7 @@ restlab:
        }       /* there existed an expression at all */
 
        flushfield(curlen);
        }       /* there existed an expression at all */
 
        flushfield(curlen);
-       if ( ( curlen == NBPW/4) && bitoff)
+       if ( ( curlen == NBWD/4) && bitoff)
                dotp->e_xvalue ++;
        break;
        /*end of case IBYTE, IWORD, ILONG, IINT*/
                dotp->e_xvalue ++;
        break;
        /*end of case IBYTE, IWORD, ILONG, IINT*/
@@ -420,8 +384,7 @@ restlab:
                yyerror("Space size not absolute");
        space_value = locxp->e_xvalue;
   ospace:
                yyerror("Space size not absolute");
        space_value = locxp->e_xvalue;
   ospace:
-       flushfield(NBPW/4);
-#ifdef UNIX
+       flushfield(NBWD/4);
        {
                static char spacebuf[128];
                while (space_value > sizeof(spacebuf)){
        {
                static char spacebuf[128];
                while (space_value > sizeof(spacebuf)){
@@ -430,21 +393,8 @@ restlab:
                }
                outs(spacebuf, space_value);
        }
                }
                outs(spacebuf, space_value);
        }
-#endif UNIX
-#ifdef VMS
-       dotp->e_xvalue += space_value;          /*bump pc*/
-       if (passno==2){
-         puchar(vms_obj_ptr,81);               /* AUGR  */
-         pulong(vms_obj_ptr,space_value);/* incr  */
-         if ((vms_obj_ptr-sobuf) > 400) {
-               write(objfil,sobuf,vms_obj_ptr-sobuf);
-               vms_obj_ptr=sobuf+1;            /*pur buf*/
-         }
-       }
-#endif VMS
        break;
 
        break;
 
-#ifdef UNIX
        /*
         *      .fill rep, size, value
         *      repeat rep times: fill size bytes with (truncated) value
        /*
         *      .fill rep, size, value
         *      repeat rep times: fill size bytes with (truncated) value
@@ -467,15 +417,13 @@ restlab:
        expr(locxp, val);
        if (passno == 2 && (locxp->e_xtype & XTYPE) != XABS)    /* tekmdp */
                yyerror("Fill value not absolute");
        expr(locxp, val);
        if (passno == 2 && (locxp->e_xtype & XTYPE) != XABS)    /* tekmdp */
                yyerror("Fill value not absolute");
-       flushfield(NBPW/4);
-       if (passno == 1) {
-               dotp->e_xvalue += fill_rep * fill_size;
-       } else {
+       flushfield(NBWD/4);
+       dotp->e_xvalue += fill_rep * fill_size;
+       if (passno == 2) {
                while(fill_rep-- > 0)
                        bwrite((char *)&locxp->e_xvalue, fill_size, txtfil);
        }
        break;
                while(fill_rep-- > 0)
                        bwrite((char *)&locxp->e_xvalue, fill_size, txtfil);
        }
        break;
-#endif UNIX
 
    case IASCII:                /* .ascii [ <stringlist> ] */
    case IASCIZ:        /* .asciz [ <stringlist> ] */
 
    case IASCII:                /* .ascii [ <stringlist> ] */
    case IASCIZ:        /* .asciz [ <stringlist> ] */
@@ -487,35 +435,35 @@ restlab:
         *      stringlist: empty | STRING | stringlist STRING
         */
        while (val == STRING){
         *      stringlist: empty | STRING | stringlist STRING
         */
        while (val == STRING){
-               flushfield(NBPW/4);
+               int     mystrlen;
+               flushfield(NBWD/4);
                if (bitoff)
                        dotp->e_xvalue++;
                if (bitoff)
                        dotp->e_xvalue++;
-               stringp = (char *)yylval;
+               stringp = (struct strdesc *)yylval;
                /*
                /*
-                *      utilize the string scanner cheat,
-                *      where it appended a null byte on the string,
-                *      but didn't charge it to STRLEN
+                *      utilize the string scanner cheat;
+                *      the scanner appended a null byte on the string,
+                *      but didn't charge it to sd_strlen
                 */
                 */
-               STRLEN(stringp) += (auxval == IASCIZ) ? 1 : 0;
-#ifdef UNIX
-               outs(stringp, STRLEN(stringp));
-#endif UNIX
-#ifdef VMS
-               {
-                       reg int i;
-                       for (i=0; i < stringp->str_lg; i++){
-                         dotp->e_xvalue += 1;
-                           if (passno==2){
-                               puchar(vms_obj_ptr,-1);
-                               puchar(vms_obj_ptr,stringp->str[i]);
-                               if (vms_obj_ptr-sobuf > 400) {
-                                 write(objfil,sobuf,vms_obj_ptr-sobuf);
-                                 vms_obj_ptr = sobuf + 1;
-                               }
-                           }
+               mystrlen = stringp->sd_strlen;
+               mystrlen += (auxval == IASCIZ) ? 1 : 0;
+               if (passno == 2){
+                       if (stringp->sd_place & STR_CORE){
+                               outs(stringp->sd_string, mystrlen);
+                       } else {
+                               int     i, nread;
+                               fseek(strfile, stringp->sd_stroff, 0);
+                               for (i = 0; i < mystrlen;/*VOID*/){
+                                       nread = fread(yytext, 1,
+                                               min(mystrlen - i,
+                                                 sizeof(yytext)), strfile);
+                                       outs(yytext, nread);
+                                       i += nread;
+                               }
                        }
                        }
+               } else {
+                       dotp->e_xvalue += mystrlen;
                }
                }
-#endif VMS
                shift;          /*over the STRING*/
                if (val == CM)  /*could be a split string*/
                        shift;
                shift;          /*over the STRING*/
                if (val == CM)  /*could be a split string*/
                        shift;
@@ -566,30 +514,8 @@ restlab:
  *     .stabd           <expr>, <expr>, <expr> # . 
  */
    case ISTAB: 
  *     .stabd           <expr>, <expr>, <expr> # . 
  */
    case ISTAB: 
-#ifndef FLEXNAMES
-       stabname = ".stab";
-       if (passno == 2)        goto errorfix;
-       stpt = (struct symtab *)yylval;
-       /*
-        *      Make a pointer to the .stab slot.
-        *      There is a pointer in the way (stpt), and
-        *      tokptr points to the next token.
-        */
-       stabstart = tokptr;
-       (char *)stabstart -= sizeof(struct symtab *);
-       (char *)stabstart -= sizeof(bytetoktype);
-       shift;
-       for (argcnt = 0; argcnt < NCPName; argcnt++){
-               expr(locxp, val);
-               stpt->s_name[argcnt] = locxp->e_xvalue;
-               xp = explist;
-               shiftover(CM);
-       }
-       goto tailstab;
-#else  FLEXNAMES
-       yyerror(".stab directive not supported in; report this compiler bug to system administrator");
+       yyerror(".stab directive no longer supported");
        goto errorfix;
        goto errorfix;
-#endif FLEXNAMES
 
   tailstab:
        expr(locxp, val);
 
   tailstab:
        expr(locxp, val);
@@ -612,7 +538,11 @@ restlab:
                stpt->s_value = locxp->e_xvalue;
                stpt->s_index = dotp - usedot;
                if (exprisname){
                stpt->s_value = locxp->e_xvalue;
                stpt->s_index = dotp - usedot;
                if (exprisname){
+                       stpt->s_type = locxp->e_xtype;
                        switch(stpt->s_ptype){
                        switch(stpt->s_ptype){
+                               case N_LCSYM:
+                                       stpt->s_dest = (struct symtab *)exprisname;
+                                       stpt->s_type |= STABFLAG;
                                case N_GSYM:
                                case N_FNAME:
                                case N_RSYM:
                                case N_GSYM:
                                case N_FNAME:
                                case N_RSYM:
@@ -724,28 +654,18 @@ restlab:
        (bytetoktype *)stabstart -= sizeof(bytetoktype);
        shift;
        if (auxval == ISTABSTR){
        (bytetoktype *)stabstart -= sizeof(bytetoktype);
        shift;
        if (auxval == ISTABSTR){
-               stringp = (char *)yylval;
+               stringp = (struct strdesc *)yylval;
                shiftover(STRING);
                shiftover(STRING);
-#ifndef FLEXNAMES
-               movestr(stpt->s_name, stringp, min(STRLEN(stringp), NCPName));
-#else
-               stpt->s_name = stringp;
+               stpt->s_name = (char *)stringp;
                /*
                 *      We want the trailing null included in this string.
                 *      We utilize the cheat the string scanner used,
                 *      and merely increment the string length
                 */
                /*
                 *      We want the trailing null included in this string.
                 *      We utilize the cheat the string scanner used,
                 *      and merely increment the string length
                 */
-               STRLEN(stringp) += 1;
-#endif
+               stringp->sd_strlen += 1;
                shiftover(CM);
        } else {
                shiftover(CM);
        } else {
-#ifndef FLEXNAMES
-               static char nullstr[NCPName];
-               movestr(stpt->s_name, nullstr, NCPName);
-#else
-               static char nullstr[1];
-               stpt->s_name = savestr(nullstr, 1);
-#endif
+               stpt->s_name = (char *)savestr("\0", 0, STR_BOTH);
        }
        goto tailstab;
        break;
        }
        goto tailstab;
        break;
@@ -762,13 +682,7 @@ restlab:
        if ( (locxp->e_xtype & XTYPE) != XABS)  /* tekmdp */
                yyerror("comm size not absolute");
        if (passno == 1 && (np->s_type&XTYPE) != XUNDEF)
        if ( (locxp->e_xtype & XTYPE) != XABS)  /* tekmdp */
                yyerror("comm size not absolute");
        if (passno == 1 && (np->s_type&XTYPE) != XUNDEF)
-#ifdef FLEXNAMES
-               yyerror("Redefinition of %s",
-#else not FLEXNAMES
-               yyerror("Redefinition of %.*s",
-                       NCPName,
-#endif not FLEXNAMES
-                       np->s_name);
+               yyerror("Redefinition of %s", FETCHNAME(np));
        if (passno==1) {
                np->s_value = locxp->e_xvalue;
                if (auxval == ICOMM)
        if (passno==1) {
                np->s_value = locxp->e_xvalue;
                if (auxval == ICOMM)