bye bye fixed names (eg, FLEXNAMES is not set)
[unix-history] / usr / src / old / as.vax / asparse.c
index abdbfe7..a9d57ef 100644 (file)
@@ -2,7 +2,7 @@
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)asparse.c 4.9 %G%";
+static char sccsid[] = "@(#)asparse.c 4.16 %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -29,7 +29,7 @@ int   droppedLP;              /*one is analyzing an expression beginning with*/
                                /*a left parenthesis, which has already been*/
                                /*shifted. (Used to parse (<expr>)(rn)*/
 
                                /*a left parenthesis, which has already been*/
                                /*shifted. (Used to parse (<expr>)(rn)*/
 
-char   yytext[NCPS+2];         /*the lexical image*/
+char   yytext[NCPName+2];      /*the lexical image*/
 int    yylval;                 /*the lexical value; sloppy typing*/
 struct Opcode          yyopcode;       /* lexical value for an opcode */
 Bignum yybignum;               /* lexical value for a big number */
 int    yylval;                 /*the lexical value; sloppy typing*/
 struct Opcode          yyopcode;       /* lexical value for an opcode */
 Bignum yybignum;               /* lexical value for a big number */
@@ -44,7 +44,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 +68,7 @@ yyparse()
        reg     struct  symtab  *p;
        reg     struct  symtab  *stpt;
 
        reg     struct  symtab  *p;
        reg     struct  symtab  *stpt;
 
-               struct  strdesc *stringp;       /*handles string lists*/
+               struct  strdesc *stringp;       /*handles string lists*/
 
                int     regno;          /*handles arguments*/
                int     *ptrregno = &regno;
 
                int     regno;          /*handles arguments*/
                int     *ptrregno = &regno;
@@ -87,7 +87,9 @@ yyparse()
                ptrall  stabstart;      /*where the stab starts in the buffer*/
                int     reloc_how;      /* how to relocate expressions */
                int     toconv;         /* how to convert bignums */
                ptrall  stabstart;      /*where the stab starts in the buffer*/
                int     reloc_how;      /* how to relocate expressions */
                int     toconv;         /* how to convert bignums */
+               int     incasetable;    /* set if in a case table */
 
 
+       incasetable = 0;
        xp = explist;
        ap = arglist;
 
        xp = explist;
        ap = arglist;
 
@@ -129,13 +131,8 @@ 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",
-                                       NCPS,
-#endif not FLEXNAMES
-                                       np->s_name);
+                                       FETCHNAME(np));
                                goto  errorfix;
                        }
 restlab:
                                goto  errorfix;
                        }
 restlab:
@@ -149,25 +146,15 @@ restlab:
                                      )
                                  ){
 #ifndef DEBUG
                                      )
                                  ){
 #ifndef DEBUG
-                                       if (np->s_name[0] != 'L')
+                                       if (FETCHNAME(np)[0] != 'L')
 #endif not DEBUG
                                        {
                                                if (passno == 1)
 #endif not DEBUG
                                        {
                                                if (passno == 1)
-#ifdef FLEXNAMES
                                                  yyerror("%s redefined",
                                                  yyerror("%s redefined",
-#else not FLEXNAMES
-                                                 yyerror("%.*s redefined",
-                                                       NCPS,
-#endif not FLEXNAMES 
-                                                       np->s_name);
+                                                       FETCHNAME(np));
                                                else
                                                else
-#ifdef FLEXNAMES
                                                  yyerror("%s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
                                                  yyerror("%s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
-#else not FLEXNAMES
-                                                 yyerror("%.*s redefined: PHASE ERROR, 1st: %d, 2nd: %d",
-                                                       NCPS,
-#endif not FLEXNAMES
-                                                       np->s_name,
+                                                       FETCHNAME(np),
                                                        np->s_value,
                                                        dotp->e_xvalue);
                                        }
                                                        np->s_value,
                                                        dotp->e_xvalue);
                                        }
@@ -178,7 +165,7 @@ 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;
                                        nlabels++;
                                }
                                np->s_tag = LABELID;
@@ -215,9 +202,8 @@ restlab:
        stringp = (struct strdesc *)yylval;
        shiftover(STRING);
        dotsname = &UDotsname[0];
        stringp = (struct strdesc *)yylval;
        shiftover(STRING);
        dotsname = &UDotsname[0];
-       movestr(dotsname, stringp->str,
-               stringp->str_lg >= 32? 32 :stringp->str_lg);
-       dotsname[stringp->str_lg] = '\0';
+       movestr(dotsname, stringp->sd_string,
+               min(stringp->sd_strlen, sizeof(UDotsname)));
        break;
 
    case ILINENO:
        break;
 
    case ILINENO:
@@ -256,11 +242,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, NCPS);
-#endif
                np->s_tag = OBSOLETE;   /*invalidate original */
                nforgotten++;
                np = stpt;
                np->s_tag = OBSOLETE;   /*invalidate original */
                nforgotten++;
                np = stpt;
@@ -302,24 +284,10 @@ restlab:
                seg_number += NLOC;
        flushfield(NBPW/4);
        dotp = &usedot[seg_number];
                seg_number += NLOC;
        flushfield(NBPW/4);
        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;
 
        /*
@@ -384,6 +352,19 @@ restlab:
                                outrel(locxp, reloc_how);
                        }
                } else {
                                outrel(locxp, reloc_how);
                        }
                } else {
+                       /*
+                        *      
+                        *      See if we are doing a case instruction.
+                        *      If so, then see if the branch distance,
+                        *      stored as a word,
+                        *      is going to loose sig bits.
+                        */
+                       if (passno == 2 && incasetable){
+                               if (  (locxp->e_xvalue < -32768)
+                                   ||(locxp->e_xvalue > 32767)){
+                                       yyerror("Case will branch too far");
+                               }
+                       }
                        field_value = locxp->e_xvalue & ( (1L << field_width)-1);
                        bitfield |= field_value << bitoff;
                        bitoff += field_width;
                        field_value = locxp->e_xvalue & ( (1L << field_width)-1);
                        bitfield |= field_value << bitoff;
                        bitoff += field_width;
@@ -408,29 +389,16 @@ restlab:
        space_value = locxp->e_xvalue;
   ospace:
        flushfield(NBPW/4);
        space_value = locxp->e_xvalue;
   ospace:
        flushfield(NBPW/4);
-#ifdef UNIX
-       while (space_value > 96){
-               outs(strbuf[2].str, 96);
-               space_value -= 96;
-       }
-       outs(strbuf[2].str, space_value);
-#endif UNIX
-#ifdef VMS
-       dotp->e_xvalue += space_value;          /*bump pc*/
-       if (passno==2){
-         if(*(strbuf[2].str)==0) {
-               puchar(vms_obj_ptr,81);         /* AUGR  */
-               pulong(vms_obj_ptr,space_value);/* incr  */
-         } else yyerror("VMS, encountered non-0 .space");
-         if ((vms_obj_ptr-sobuf) > 400) {
-               write(objfil,sobuf,vms_obj_ptr-sobuf);
-               vms_obj_ptr=sobuf+1;            /*pur buf*/
-         }
+       {
+               static char spacebuf[128];
+               while (space_value > sizeof(spacebuf)){
+                       outs(spacebuf, sizeof(spacebuf));
+                       space_value -= sizeof(spacebuf);
+               }
+               outs(spacebuf, space_value);
        }
        }
-#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
@@ -461,60 +429,50 @@ restlab:
                        bwrite((char *)&locxp->e_xvalue, fill_size, txtfil);
        }
        break;
                        bwrite((char *)&locxp->e_xvalue, fill_size, txtfil);
        }
        break;
-#endif UNIX
 
 
-   case IASCII:        /* .ascii [ <stringlist> ] */
+   case IASCII:                /* .ascii [ <stringlist> ] */
    case IASCIZ:        /* .asciz [ <stringlist> ] */
        auxval = val;
        shift;
    case IASCIZ:        /* .asciz [ <stringlist> ] */
        auxval = val;
        shift;
-
        /*
         *      Code to consume a string list
         *
         *      stringlist: empty | STRING | stringlist STRING
         */
        /*
         *      Code to consume a string list
         *
         *      stringlist: empty | STRING | stringlist STRING
         */
-       while (val ==  STRING){
+       while (val == STRING){
+               int     mystrlen;
                flushfield(NBPW/4);
                if (bitoff)
                flushfield(NBPW/4);
                if (bitoff)
-                 dotp->e_xvalue++;
+                       dotp->e_xvalue++;
                stringp = (struct strdesc *)yylval;
                stringp = (struct strdesc *)yylval;
-#ifdef UNIX
-               outs(stringp->str, stringp->str_lg);
-#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;
-                               }
-                           }
+               /*
+                *      utilize the string scanner cheat;
+                *      the scanner appended a null byte on the string,
+                *      but didn't charge it to sd_strlen
+                */
+               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;
        }
-
-       if (auxval == IASCIZ){
-               flushfield(NBPW/4);
-#ifdef UNIX
-               outb(0);
-#endif UNIX
-#ifdef VMS
-               if (passno == 2) {
-                       puchar(vms_obj_ptr,-1);
-                       puchar(vms_obj_ptr,0);
-               }
-               dotp->e_xvalue += 1;
-#endif VMS
-       }
        break;
        
    case IORG:  /* .org <expr> */
        break;
        
    case IORG:  /* .org <expr> */
@@ -555,36 +513,14 @@ restlab:
  *             final expression is taken to be  the current
  *             location counter, and is patched by the 2nd pass
  *
  *             final expression is taken to be  the current
  *             location counter, and is patched by the 2nd pass
  *
- *     .stab{<expr>,}*NCPS,<expr>, <expr>, <expr>, <expr>
+ *     .stab{<expr>,}*NCPName,<expr>, <expr>, <expr>, <expr>
  *     .stabn           <expr>, <expr>, <expr>, <expr>
  *     .stabs   STRING, <expr>, <expr>, <expr>, <expr>
  *     .stabd           <expr>, <expr>, <expr> # . 
  */
    case ISTAB: 
  *     .stabn           <expr>, <expr>, <expr>, <expr>
  *     .stabs   STRING, <expr>, <expr>, <expr>, <expr>
  *     .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 < NCPS; 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);
@@ -721,23 +657,22 @@ restlab:
        if (auxval == ISTABSTR){
                stringp = (struct strdesc *)yylval;
                shiftover(STRING);
        if (auxval == ISTABSTR){
                stringp = (struct strdesc *)yylval;
                shiftover(STRING);
-#ifndef FLEXNAMES
-               auxval = stringp->str_lg > NCPS ? NCPS : stringp->str_lg;
-#else
-               stringp->str[stringp->str_lg] = 0;
-#endif
+               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
+                */
+               stringp->sd_strlen += 1;
                shiftover(CM);
        } else {
                shiftover(CM);
        } else {
-               stringp = &(strbuf[2]);
-#ifndef FLEXNAMES
-               auxval = NCPS;
-#endif
+               static char nullstr[1];
+               static  struct  strdesc strdp;
+               strdp.sd_stroff = strfilepos;
+               strdp.sd_strlen = 0;
+               strdp.sd_place = STR_BOTH;
+               stpt->s_name = (char *)savestr(nullstr, &strdp);
        }
        }
-#ifndef FLEXNAMES
-       movestr(stpt->s_name, stringp->str, auxval);
-#else
-       stpt->s_name = savestr(stringp->str);
-#endif
        goto tailstab;
        break;
 
        goto tailstab;
        break;
 
@@ -753,13 +688,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",
-                       NCPS,
-#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)
@@ -779,6 +708,7 @@ restlab:
        break;
 
    case INST0:                 /* instructions w/o arguments*/
        break;
 
    case INST0:                 /* instructions w/o arguments*/
+       incasetable = 0;
        insout(yyopcode, (struct arg *)0, 0);
        shift;  
        break;
        insout(yyopcode, (struct arg *)0, 0);
        shift;  
        break;
@@ -936,6 +866,24 @@ restlab:
                goto errorfix;
        }
 
                goto errorfix;
        }
 
+       /*
+        *      See if this is a case instruction,
+        *      so we can set up tests on the following
+        *      vector of branch displacements
+        */
+       if (yyopcode.Op_eopcode == CORE){
+               switch(yyopcode.Op_popcode){
+               case 0x8f:      /* caseb */
+               case 0xaf:      /* casew */
+               case 0xcf:      /* casel */
+                       incasetable++;
+                       break;
+               default:
+                       incasetable = 0;
+                       break;
+               }
+       }
+
        insout(yyopcode, arglist,
                auxval == INSTn ? argcnt : - argcnt);
        break;
        insout(yyopcode, arglist,
                auxval == INSTn ? argcnt : - argcnt);
        break;
@@ -1034,6 +982,15 @@ inttoktype funnyreg(val, regnoback)       /*what the read head will sit on*/
        *regnoback = locxp->e_xvalue;
        return(val);
 } 
        *regnoback = locxp->e_xvalue;
        return(val);
 } 
+/*
+ *     Shift over error
+ */
+shiftoerror(token)
+       int     token;
+{
+       char    *tok_to_name();
+       yyerror("%s expected", tok_to_name(token));
+}
 
 /*VARARGS1*/
 yyerror(s, a1, a2,a3,a4,a5)
 
 /*VARARGS1*/
 yyerror(s, a1, a2,a3,a4,a5)