don't throw away float <-> double conversions for FORTRAN.
[unix-history] / usr / src / old / as.vax / assyms.c
index d45cf70..52cd5c7 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[] = "@(#)assyms.c 4.10 %G%";
+static char sccsid[] = "@(#)assyms.c 4.14 %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -69,12 +69,8 @@ syminstall()
        for (i = 0; i < NINST; i++)
                itab[i] = (Iptr*)BADPOINT;
 
        for (i = 0; i < NINST; i++)
                itab[i] = (Iptr*)BADPOINT;
 
-#ifdef FLEXNAMES
-       for (ip = (Iptr)instab; ip->s_name != 0; ip++) {
-#else not FLEXNAMES
-       for (ip = (Iptr)instab; ip->s_name[0] != '\0'; ip++){
-#endif not FLEXNAMES
-               p1 = ip->s_name;
+       for (ip = (Iptr)instab; FETCHNAME(ip)[0]; ip++) {
+               p1 = FETCHNAME(ip);
                p2 = yytext;
                while (*p2++ = *p1++);
                hp = lookup(0);         /* 0 => don't install this*/
                p2 = yytext;
                while (*p2++ = *p1++);
                hp = lookup(0);         /* 0 => don't install this*/
@@ -96,7 +92,11 @@ syminstall()
        }
 }      /*end of syminstall*/
 
        }
 }      /*end of syminstall*/
 
-
+#define ISLABEL(sp) \
+       (   (!savelabels) \
+        && (sp->s_tag == LABELID) \
+        && (STRPLACE(sp) & STR_CORE) \
+        && (FETCHNAME(sp)[0] == 'L'))
 /*
  *     Assign final values to symbols,
  *     and overwrite the index field with its relative position in
 /*
  *     Assign final values to symbols,
  *     and overwrite the index field with its relative position in
@@ -133,16 +133,11 @@ freezesymtab()
                        hdr.a_bss += bs;
                }
           assignindex:
                        hdr.a_bss += bs;
                }
           assignindex:
-               if (    (sp->s_name[0] != 'L')
-                    || (sp->s_tag != LABELID)
-                    || savelabels
-                    )                  /*then, we will write it later on*/
-                               sp->s_index = relpos++;
+               if (!ISLABEL(sp))
+                       sp->s_index = relpos++;
        }
 }
 
        }
 }
 
-
-
 /*
  *     For all of the stabs that had their final value undefined during pass 1
  *     and during pass 2 assign a final value.
 /*
  *     For all of the stabs that had their final value undefined during pass 1
  *     and during pass 2 assign a final value.
@@ -322,17 +317,10 @@ dumpsymtab()
        for (segno = 0; segno < NLOC + NLOC; segno++){
                printf("Segment number: %d\n", segno);
                SEGITERATE(segno, 0, 0, cosp, sp, ub, ++){
        for (segno = 0; segno < NLOC + NLOC; segno++){
                printf("Segment number: %d\n", segno);
                SEGITERATE(segno, 0, 0, cosp, sp, ub, ++){
-#ifdef FLEXNAMES
                        printf("\tSeg: %d \"%s\" value: %d index: %d tag %s\n",
                        printf("\tSeg: %d \"%s\" value: %d index: %d tag %s\n",
-                               segno, sp->s_name,
+                               segno, FETCHNAME(sp),
                                sp->s_value, sp->s_index,
                                tagstring(sp->s_tag));
                                sp->s_value, sp->s_index,
                                tagstring(sp->s_tag));
-#else not FLEXNAMES
-                       printf("\tSeg: %d \"%*.*s\" value: %d index: %d tag %s\n",
-                               segno, NCPName, NCPName, sp->s_name,
-                               sp->s_value, sp->s_index,
-                               tagstring(sp->s_tag));
-#endif not FLEXNAMES
                        printf("\t\ttype: %d jxbump %d jxfear: %d\n",
                                sp->s_type, sp->s_jxbump, sp->s_jxfear);
                }
                        printf("\t\ttype: %d jxbump %d jxfear: %d\n",
                                sp->s_type, sp->s_jxbump, sp->s_jxfear);
                }
@@ -400,10 +388,10 @@ struct symtab **lookup(instflg)
        register char           *to;
        register        int     len;
        register        int     nprobes;
        register char           *to;
        register        int     len;
        register        int     nprobes;
-       static   struct hashdallop *hdallop;
-       static   struct symtab  **emptyslot;
-       static   struct hashdallop *emptyhd;
-       static   struct symtab  **hp_ub;
+       static  struct  hashdallop *hdallop;
+       static  struct  symtab  **emptyslot;
+       static  struct  hashdallop *emptyhd;
+       static  struct  symtab  **hp_ub;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
 
        emptyslot = 0;
        for (nprobes = 0, from = yytext;
@@ -426,24 +414,13 @@ struct symtab **lookup(instflg)
                                nprobes += 2)
                {
                        from = yytext;
                                nprobes += 2)
                {
                        from = yytext;
-                       to = (*hp)->s_name;
-#ifndef FLEXNAMES
-                       for (len = 0; (len<NCPName) && *from; len++)
-                               if (*from++ != *to++)
-                                       goto nextprobe;
-                       if (len >= NCPName)     /*both are maximal length*/
-                               return(hp);
-                       if (*to == 0)           /*assert *from == 0*/
-                               return(hp);
-#else FLEXNAMES
+                       to = FETCHNAME(*hp);
                        while (*from && *to)
                                if (*from++ != *to++)
                                        goto nextprobe;
                        if (*to == *from)       /*assert both are == 0*/
                                return(hp);
                        while (*from && *to)
                                if (*from++ != *to++)
                                        goto nextprobe;
                        if (*to == *from)       /*assert both are == 0*/
                                return(hp);
-#endif FLEXNAMES
-
-       nextprobe: ;
+               nextprobe: ;
                }
                if (*hp == 0 && emptyslot == 0 &&
                    hdallop->h_nused < HASHCLOGGED) {
                }
                if (*hp == 0 && emptyslot == 0 &&
                    hdallop->h_nused < HASHCLOGGED) {
@@ -462,41 +439,59 @@ struct symtab **lookup(instflg)
        if (instflg) {
                *hp = symalloc();
                hdallop->h_nused++;
        if (instflg) {
                *hp = symalloc();
                hdallop->h_nused++;
-#ifndef FLEXNAMES
-               strncpy((*hp)->s_name, yytext, NCPName);
-#else FLEXNAMES
                for (from = yytext, len = 0; *from++; len++)
                        continue;
                for (from = yytext, len = 0; *from++; len++)
                        continue;
-               /*
-                *      save string and trailing null
-                */
-               (*hp)->s_name = savestr(yytext, len + 1);
-#endif FLEXNAMES
+               (*hp)->s_name = (char *)savestr(yytext, len + 1, STR_BOTH);
        }
        return(hp);
 }      /*end of lookup*/
 /*
        }
        return(hp);
 }      /*end of lookup*/
 /*
- *     save a string str, length len in the string pool.
- *     string known just by its length; can have or not have trailing nulls.
- *
- *     The length of the string occurs as a short just before
- *     the character pointer returned.
+ *     save a string str with len in the places indicated by place
  */
  */
-char *savestr(str, len)
+struct strdesc *savestr(str, len, place)
        char    *str;
        int     len;
        char    *str;
        int     len;
+       int     place;
 {
 {
-       char    *res;
-
-       if (len + sizeof(lgtype) >= (STRPOOLDALLOP - strplhead->str_nalloc))
+       reg     struct  strdesc *res;
+               int     tlen;
+       /*
+        *      Compute the total length of the record to live in core
+        */
+       tlen = sizeof(struct strdesc) - sizeof(res->sd_string);
+       if (place & STR_CORE)
+               tlen += len;
+       /*
+        *      See if there is enough space for the record,
+        *      and allocate the record.
+        */
+       if (tlen >= (STRPOOLDALLOP - strplhead->str_nalloc))
                strpoolalloc();
                strpoolalloc();
-       res = strplhead->str_names + strplhead->str_nalloc;
-       plgtype(res, len);
-       movestr(res, str, len);
-       strplhead->str_nalloc += sizeof(lgtype) + len;
+       res = (struct strdesc *)(strplhead->str_names + strplhead->str_nalloc);
+       /*
+        *      Save the string information that is always present
+        */
+       res->sd_stroff = strfilepos;
+       res->sd_strlen = len;
+       res->sd_place = place;
+       /*
+        *      Now, save the string itself.  If str is null, then
+        *      the characters have already been dumped to the file
+        */
+       if ((place & STR_CORE) && str)
+               movestr(res[0].sd_string, str, len);
+       if (place & STR_FILE){
+               if (str){
+                       fwrite(str, 1, len, strfile);
+               }
+               strfilepos += len;
+       }
+       /*
+        *      Adjust the in core string pool size
+        */
+       strplhead->str_nalloc += tlen;
        return(res);
 }
        return(res);
 }
-
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are
 /*
  *     The relocation information is saved internally in an array of
  *     lists of relocation buffers.  The relocation buffers are
@@ -644,95 +639,88 @@ int sizesymtab()
 {
        return (sizeof (struct nlist) * NOUTSYMS);
 }
 {
        return (sizeof (struct nlist) * NOUTSYMS);
 }
-
-#ifdef FLEXNAMES
-/*
- *     We write out the flexible length character strings for  names
- *     in two stages.
- *     1)      We always! maintain a fixed sized name list entry;
- *     the string is indexed by a four byte quantity from the beginning
- *     of the string pool area.  Index 0 is reserved, and indicates
- *     that there is no associated string. The first valid index is 4.
- *     2)       We concatenate together and write all of the strings
- *     in the string pool at the end of the name list. The first 
- *     four bytes in the string pool are indexed only by 0 (see above);
- *     they contain the total number of bytes in the string pool.
- */
-#endif FLEXNAMES
-
 /*
  *     Write out n symbols to file f, beginning at p
  *     ignoring symbols that are obsolete, jxxx instructions, and
  *     possibly, labels
  */
 /*
  *     Write out n symbols to file f, beginning at p
  *     ignoring symbols that are obsolete, jxxx instructions, and
  *     possibly, labels
  */
-
 int symwrite(symfile)
        BFILE *symfile;
 {
 int symwrite(symfile)
        BFILE *symfile;
 {
-       int     symsout;                        /*those actually written*/
-       int     symsdesired = NOUTSYMS;
-       register        struct  symtab *sp, *ub;
-#ifdef FLEXNAMES
-       char            *name;                  /* temp to save the name */
-       long            stroff  = sizeof (stroff);
+               int     symsout;                /*those actually written*/
+               int     symsdesired = NOUTSYMS;
+       reg     struct  symtab *sp, *ub;
+               char    *name;                  /* temp to save the name */
+               int     totalstr;
        /*
         *      We use sp->s_index to hold the length of the
         *      name; it isn't used for anything else
         */
        /*
         *      We use sp->s_index to hold the length of the
         *      name; it isn't used for anything else
         */
-#endif FLEXNAMES
-
        register        struct  allocbox        *allocwalk;
 
        symsout = 0;
        register        struct  allocbox        *allocwalk;
 
        symsout = 0;
-       DECLITERATE(allocwalk, sp, ub)
-       {
+       totalstr = sizeof(totalstr);
+       DECLITERATE(allocwalk, sp, ub) {
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
-               if ((sp->s_name[0] == 'L') && (sp->s_tag == LABELID) && !savelabels)
+               if (ISLABEL(sp))
                        continue;
                symsout++;
                        continue;
                symsout++;
-
-#ifdef FLEXNAMES
                name = sp->s_name;              /* save pointer */
                /*
                 *      the length of the symbol table string
                name = sp->s_name;              /* save pointer */
                /*
                 *      the length of the symbol table string
-                *      always includes the trailing null
+                *      always includes the trailing null;
+                *      blast the pointer to its a.out value.
                 */
                 */
-               if (sp->s_name && (sp->s_index = STRLEN(sp->s_name))){
-                       sp->s_nmx = stroff;     /* clobber pointer */
-                       stroff += sp->s_index;
+               if (sp->s_name && (sp->s_index = STRLEN(sp))){
+                       sp->s_nmx = totalstr;
+                       totalstr += sp->s_index;
                } else {
                        sp->s_nmx = 0;
                }
                } else {
                        sp->s_nmx = 0;
                }
-#endif
-               sp->s_type = (sp->s_ptype != 0) ? sp->s_ptype : (sp->s_type & (~XFORW));
+               if (sp->s_ptype != 0)
+                       sp->s_type = sp->s_ptype;
+               else
+                       sp->s_type = (sp->s_type & (~XFORW));
                if (readonlydata && (sp->s_type&~N_EXT) == N_DATA)
                        sp->s_type = N_TEXT | (sp->s_type & N_EXT);
                bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile);
                if (readonlydata && (sp->s_type&~N_EXT) == N_DATA)
                        sp->s_type = N_TEXT | (sp->s_type & N_EXT);
                bwrite((char *)&sp->s_nm, sizeof (struct nlist), symfile);
-#ifdef FLEXNAMES
                sp->s_name = name;              /* restore pointer */
                sp->s_name = name;              /* restore pointer */
-#endif FLEXNAMES
        }
        if (symsout != symsdesired)
                yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n",
                        symsout, symsdesired);
        }
        if (symsout != symsdesired)
                yyerror("INTERNAL ERROR: Wrote %d symbols, wanted to write %d symbols\n",
                        symsout, symsdesired);
-#ifdef FLEXNAMES
        /*
        /*
-        *      Pass 2 through the string pool
+        *      Construct the string pool from the symbols that were written,
+        *      possibly fetching from the string file if the string
+        *      is not core resident.
         */
         */
+       bwrite(&totalstr, sizeof(totalstr), symfile);
        symsout = 0;
        symsout = 0;
-       bwrite((char *)&stroff, sizeof (stroff), symfile);
-       stroff = sizeof (stroff);
-       symsout = 0;
-       DECLITERATE(allocwalk, sp, ub)
-       {
+       DECLITERATE(allocwalk, sp, ub) {
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
                if (sp->s_tag >= IGNOREBOUND) 
                        continue;
-               if ((sp->s_name[0] == 'L') && (sp->s_tag == LABELID) && !savelabels)
+               if (ISLABEL(sp))
                        continue;
                        continue;
-               if (sp->s_name && (sp->s_index = STRLEN(sp->s_name))){
-                       bwrite(sp->s_name, sp->s_index, symfile);
+               symsout++;
+               if (STRLEN(sp) > 0){
+                if (STRPLACE(sp) & STR_CORE){
+                       bwrite(FETCHNAME(sp), STRLEN(sp), symfile);
+                } else if (STRPLACE(sp) & STR_FILE){
+                       char    rbuf[2048];
+                       int     left, nread;
+                       fseek(strfile, STROFF(sp), 0);
+                       for (left = STRLEN(sp); left > 0; left -= nread){
+                               nread = fread(rbuf, sizeof(char),
+                                       min(sizeof(rbuf), left), strfile);
+                               if (nread == 0)
+                                       break;
+                               bwrite(rbuf, nread, symfile);
+                       }
+                }
                }
        }
                }
        }
-#endif FLEXNAMES
+       if (symsout != symsdesired)
+               yyerror("INTERNAL ERROR: Wrote %d strings, wanted %d\n",
+                       symsout, symsdesired);
 }
 }