Annotation of researchv9/cmd/sun/as/stab.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)stab.c 1.1 86/02/03 Copyr 1983 Sun Micro";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Copyright (c) 1983 by Sun Microsystems, Inc.
                      7:  */
                      8: 
                      9: #include "scan.h" 
                     10: #include "as.h"
                     11: 
                     12: extern struct sym_bkt *sym_hash_tab[];
                     13: extern long dot;                       /* current offset in csect (i.e. addr)*/
                     14: 
                     15: 
                     16: struct stab_sym_bkt *stab_free = NULL;
                     17: #define STAB_INCR 50
                     18: 
                     19: #ifdef EBUG
                     20: #      define DEBUG( X ) printf(X)
                     21: #else
                     22: #      define DEBUG( X )
                     23: #endif
                     24: 
                     25: struct stab_sym_bkt *
                     26: gstab()
                     27: {
                     28:     /* get a stab symbol bucket -- analogous with gsbkt()/sym.c */
                     29:     register struct stab_sym_bkt *sbp;
                     30:     register int i;
                     31: 
                     32:     if ((sbp = stab_free) != NULL) {
                     33:        stab_free = sbp->next_stab;
                     34:     } else {
                     35:        sbp = (struct stab_sym_bkt *) calloc( STAB_INCR, sizeof(struct stab_sym_bkt));
                     36:        if (sbp == NULL) sys_error("Stab storage exceeded\n", 0);
                     37:        for (i=STAB_INCR-1;i--;) {
                     38:            sbp->next_stab = stab_free;
                     39:            stab_free = sbp++;
                     40:        }
                     41:     }
                     42:     return sbp;
                     43: }
                     44: 
                     45: stab_op( ip )
                     46:     struct ins_bkt *ip;
                     47: {
                     48:     /* 
                     49:       allocate a new stab bucket, and process the stabs/d/n
                     50:       arguments which have already been parsed for us.
                     51:     */
                     52:     struct stab_sym_bkt *s;
                     53:     register int opno;
                     54:     opcode_t opcode = ip->op_i;
                     55: 
                     56:     if (pass != 2) return;
                     57:     s = gstab();
                     58:     if (opcode==OP_STABS){
                     59:        /* have a string operand -- parse it a la Ascii(), and save it off */
                     60:        register char *cp;
                     61:        register nchars;
                     62:        char *sp;
                     63:        if (numops != 5 ){
                     64:            PROG_ERROR( E_NUMOPS); return;
                     65:        }
                     66:        if (operands[0].type_o != T_STRING ) {
                     67:            DEBUG("first stabs operand not a string\n");
                     68:            PROG_ERROR( E_OPERAND); return;
                     69:        }
                     70:        nchars = 0;
                     71:        cp = operands[0].stringval_o;
                     72:        while (*cp++)++nchars;
                     73:        cp = operands[0].stringval_o;
                     74:        s->ch = sp = (char *) calloc( nchars +1, sizeof(char));
                     75:        if (sp==NULL) sys_error( "Out of string space\n", 0);
                     76:        /* nchars is only an approximate character count -- recount for real */
                     77:        nchars = 0;
                     78:        while (*cp){
                     79:            nchars++;
                     80:            if ((*sp = *cp++)!= '\\'){
                     81:                sp++;
                     82:            } 
                     83:            else switch (*cp) {
                     84:                int i;
                     85:                int c;
                     86:                /* bet none of this is ever executed */
                     87:                case '\\':
                     88:                case '"':
                     89:                    *sp++ = *cp++;
                     90:                    break;
                     91:                default:
                     92:                    /* \ octal */
                     93:                    for(i=0,c=0; i<3; i++) {
                     94:                        if((*cp >= '0') && (*cp <= '7'))
                     95:                            c = (c<<3) + *cp-- - '0';
                     96:                        else 
                     97:                            break;
                     98:                    }
                     99:                    *sp++ = c;
                    100:            }
                    101:        }
                    102:        s->id = nchars;
                    103:        opno = 1;
                    104:     } else if ( opcode == OP_STABD ) {
                    105:        if (numops != 3 ) { 
                    106:            DEBUG("stabd has the wrong number of operands\n");
                    107:            PROG_ERROR(E_NUMOPS);
                    108:            return;
                    109:        }
                    110:        opno = 0;
                    111:        s->id = 0;
                    112:     } else { /* opcode == OP_STABN */
                    113:        if (numops != 4 ) {
                    114:            DEBUG("stabn has the wrong number of operands\n");
                    115:            PROG_ERROR(E_NUMOPS);
                    116:            return;
                    117:        }
                    118:        opno = 0;
                    119:        s->id = 0;
                    120:     }
                    121:     /* stuff the next three numbers without too much thought */
                    122:     if (operands[opno].sym_o != NULL || operands[opno].type_o != T_NORMAL){
                    123:        DEBUG("stab first numeric operand bad\n");
                    124:        PROG_ERROR( E_OPERAND); return;
                    125:     }
                    126:     s->type = operands[opno++].value_o;
                    127:     if (operands[opno].sym_o != NULL || operands[opno].type_o != T_NORMAL){
                    128:        DEBUG("stab second numeric operand bad\n");
                    129:        PROG_ERROR( E_OPERAND); return;
                    130:     }
                    131:     s->other = operands[opno++].value_o;
                    132:     if (operands[opno].sym_o != NULL || operands[opno].type_o != T_NORMAL){
                    133:        DEBUG("stab third numeric operand bad\n");
                    134:        PROG_ERROR( E_OPERAND); return;
                    135:     }
                    136:     s->desc = operands[opno++].value_o;
                    137: 
                    138:     if (opcode == OP_STABD) {
                    139:        /* value is dot */
                    140:        s->value = dot;
                    141:     } else {
                    142:        /* value is either a label or its a number */
                    143:        if (operands[opno].type_o != T_NORMAL){
                    144:            DEBUG("stab last operand isn't `normal'\n");
                    145:            PROG_ERROR(E_OPERAND); return;
                    146:        }
                    147:        switch (s->type) {
                    148:        case N_FUN:
                    149:        case N_STSYM:
                    150:        case N_LCSYM:
                    151:        case N_SLINE:
                    152:        case N_SO:
                    153:        case N_SOL:
                    154:        case N_ENTRY:
                    155:        case N_LBRAC:
                    156:        case N_RBRAC:
                    157:        case N_ECOML:
                    158:                /* it a label */
                    159:                if (!operands[opno].sym_o) {
                    160:                    DEBUG("stab last operand isn't a label\n");
                    161:                    PROG_ERROR(E_OPERAND); return;
                    162:                }
                    163:                break;
                    164:        default:
                    165:                /* its a number */
                    166:                if ( operands[opno].sym_o) {
                    167:                    DEBUG("stab last operand isn't just a number\n");
                    168:                    PROG_ERROR(E_OPERAND); return;
                    169:                }
                    170:                break;
                    171:        }
                    172:        s->value = operands[opno].value_o;
                    173:     }
                    174:     link_stab_tab( s );
                    175: }
                    176: /* ************************************************************************* */
                    177: 
                    178:   /* Link the incoming stab bucket to the stab symbol table.       */
                    179:   /* The addition of the incoming stab is linked to the end of the */
                    180:   /* current linked list.                                          */
                    181: 
                    182: 
                    183: link_stab_tab(s)
                    184: struct stab_sym_bkt *s;
                    185: 
                    186: 
                    187: { if (stabkt_head == NULL)                 /* if no entry on linked list */
                    188:      { stabkt_head = s;                         /* let both head and tail     */
                    189:        stabkt_tail = s;                         /* pointing to this entry s   */
                    190:        stabkt_head->next_stab = NULL;      /* and make the next one null */
                    191:      }
                    192:      else { stabkt_tail->next_stab = s;          /* otherwise make this entry */
                    193:             stabkt_tail = stabkt_tail->next_stab; /* the next entry and move  */
                    194:             stabkt_tail->next_stab = NULL;  /* tail pointing to this one */
                    195:           }
                    196: } /* end Link_Stab_Tab */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.