|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)sym.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:
10: #include "as.h"
11:
12: /* Allocation increments for symbol buckets and character blocks */
13: #define SYM_INCR 50
14: #define CBLOCK_INCR 512
15:
16: extern struct stab_sym_bkt *stabkt_head;
17:
18: struct sym_bkt *last_symbol; /* last symbol defined */
19: struct sym_bkt *sym_hash_tab[HASH_MAX]; /* Symbol hash table */
20: struct sym_bkt *sym_free = NULL; /* head of free list */
21: char *cblock = NULL; /* storage for symbol names */
22: int ccnt = 0; /* number of chars left in c block */
23:
24: /* grab a new symbol bucket off of the free list; allocate space
25: * for a new free list if necessary
26: */
27: struct sym_bkt *
28: gsbkt()
29: { register struct sym_bkt *sbp;
30: register int i;
31:
32: if ((sbp = sym_free) != NULL) sym_free = sbp->next_s;
33: else {
34: sbp = (struct sym_bkt *)calloc(SYM_INCR,sizeof(struct sym_bkt));
35: if (sbp == NULL) sys_error("Symbol storage exceeded\n",0);
36: for (i = SYM_INCR-1; i--;) {
37: sbp->next_s = sym_free;
38: sym_free = sbp++;
39: }
40: }
41:
42: return(sbp);
43: }
44:
45: /* initialize hash table */
46: sym_init()
47: {
48: register int i;
49: for (i=0; i<HASH_MAX; i++) sym_hash_tab[i] = NULL;
50: } /* end Sym_Init */
51:
52: char *
53: sstring(string)
54: register char *string;
55: {
56: register char *p,*q; /* working char string */
57: register int i;
58:
59: i = strlen(string); /* get length of string */
60:
61: if (++i > ccnt) { /* if not enough room get more */
62: if ((cblock = (char *)calloc(CBLOCK_INCR,1)) == NULL)
63: sys_error("Symbol storage exceeded\n",0);
64: ccnt = CBLOCK_INCR;
65: }
66:
67: p = q = cblock; /* copy string into permanent storage */
68: while (*p++ = *string++);
69: cblock = p;
70: ccnt -= i;
71: return(q);
72: } /* end sstring */
73:
74: /* lookup symbol in symbol table */
75: struct sym_bkt *
76: lookup(s)
77: register char *s;
78: {
79: register struct sym_bkt *sbp; /* general purpose ptr */
80: register int Save; /* save subscript in sym_hash_tab */
81: register char *p;
82: static char local[250]; /* used for constructing local sym */
83: extern char *ll_format;
84:
85: if (*s>='0' && *s<='9') { /* local symbol hackery */
86: /* we hope no-one uses really long local symbols */
87: p = local;
88: while ((*p++ = *s++) && (p < &local[sizeof local-1]));/* copy local symbol */
89: p--;
90: s = last_symbol->name_s; /* add last symbol defined as suffix */
91: while ((*p++ = *s++) && (p < &local[sizeof local-1]));
92: s = local; /* this becomes name to deal with */
93: }
94:
95: /* if the symbol is already in here, return a ptr to it */
96: for (sbp = sym_hash_tab[Save=hash(s)]; sbp != NULL ; sbp = sbp->next_s)
97: if (strcmp(sbp->name_s,s) == 0) return(sbp);
98:
99: /* Since it's not, make a bucket for it, and put the bucket in the symbol table */
100: sbp = gsbkt(); /* get the bucket */
101: sbp->name_s = sstring(s); /* Store it's name */
102: sbp->value_s = sbp->attr_s = 0;
103: #if AS
104: sbp->id_s = 0;
105: #endif
106: sbp->csect_s = C_UNDEF;
107: sbp->next_s = sym_hash_tab[Save]; /* and insert on top of list */
108: if (s == local || *s == *ll_format) sbp->attr_s |= S_LOCAL;
109: return(sym_hash_tab[Save] = sbp);
110: }
111:
112:
113: /*
114: * Perm Flags all currently defined symbols as permanent (and therefore
115: * ineligible for redefinition. Also prevents them from being output
116: * in the object file).
117: */
118: perm()
119: { register struct sym_bkt **sbp1, *sbp2;
120:
121: for (sbp1 = sym_hash_tab; sbp1 < &sym_hash_tab[HASH_MAX]; sbp1++)
122: for (sbp2 = *sbp1; sbp2; sbp2 = sbp2->next_s)
123: sbp2->attr_s |= S_PERM;
124: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.