4 * (C) Copyright 1989-1995
20 * The module assym.c contains the functions that operate
21 * on the mnemonic/directive and symbol structures.
23 * assym.c contains the following functions:
34 * assym.c contains no local/static variables.
37 /*)Function VOID syminit()
39 * The function syminit() is called early in the game
40 * to set up the hashtables. First all buckets in a
41 * table are cleared. Then a pass is made through
42 * the respective symbol lists, linking them into
43 * their hash buckets. Finally the base area pointer
47 * int h computed hash value
48 * mne * mp pointer to a mne structure
49 * mne ** mpp pointer to an array of
50 * mne structure pointers
51 * sym * sp pointer to a sym structure
52 * sym ** spp pointer to an array of
53 * sym structure pointers
56 * area area[] single elememt area array
57 * area dca defined as area[0]
58 * mne * mnehash[] array of pointers to NHASH
59 * linked mnemonic/directive lists
60 * sym * symhash[] array of pointers to NHASH
67 * (1) The symbol hash tables are initialized,
68 * the only defined symbol is '.'.
69 * (2) The mnemonic/directive hash tables are
70 * initialized with the assembler directives
71 * and mnemonics found in the machine dependent
73 * (3) The area pointer is initialized to dca (area[0]).
79 register struct mne *mp;
81 register struct sym *sp;
86 while (mpp < &mnehash[NHASH])
91 mp->m_mp = mnehash[h];
99 while (spp < &symhash[NHASH])
104 sp->s_sp = symhash[h];
106 if (sp->s_flag&S_END)
114 /*)Function area * alookup(id)
116 * char * id area name string
118 * The function alookup() searches the area list for a
119 * match with id. If the area is defined then a pointer
120 * to this area is returned else a NULL is returned.
123 * area * ap pointer to area structure
126 * area * areap pointer to an area structure
129 * int symeq() assym.c
139 register struct area *ap;
143 if (symeq(id, ap->a_id)) {
151 /*)Function mne * mlookup(id)
153 * char * id mnemonic/directive name string
155 * The function mlookup() searches the mnemonic/directive
156 * hash tables for a match returning a pointer to the
157 * mne structure else it returns a NULL.
160 * mne * mp pointer to mne structure
161 * int h calculated hash value
164 * mne * mnehash[] array of pointers to NHASH
165 * linked mnemonic/directive lists
178 register struct mne *mp;
184 if (symeq(id, mp->m_id))
191 /*)Function sym * lookup(id)
193 * char * id symbol name string
195 * The function lookup() searches the symbol hash tables for
196 * a symbol name match returning a pointer to the sym structure.
197 * If the symbol is not found then a sym structure is created,
198 * initialized, and linked to the appropriate hash table.
199 * A pointer to this new sym structure is returned.
202 * int h computed hash value
203 * sym * sp pointer to a sym structure
206 * sym * symhash[] array of pointers to NHASH
207 * linked symbol lists
211 * VOID * new() assym.c
212 * int symeq() assym.c
215 * If the function new() fails to allocate space
216 * for the new sym structure the assembly terminates.
223 register struct sym *sp;
229 if (symeq(id, sp->s_id))
233 sp = (struct sym *) new (sizeof(struct sym));
234 sp->s_sp = symhash[h];
237 strncpy(sp->s_id, id, NCPS);
246 /*)Function VOID symglob()
248 * The function symglob() will mark all symbols of
249 * type S_NEW as global. Called at the beginning of pass 1
250 * if the assembly option -g was specified.
253 * sym * sp pointer to a sym structure
257 * sym * symhash[] array of pointers to NHASH
258 * linked symbol lists
264 * Symbol types changed.
270 register struct sym *sp;
273 for (i=0; i<NHASH; ++i) {
276 if (sp->s_type == S_NEW)
283 /*)Function VOID allglob()
285 * The function allglob() will mark all symbols of
286 * type S_USER as global. Called at the beginning of pass 1
287 * if the assembly option -a was specified.
290 * sym * sp pointer to a sym structure
294 * sym * symhash[] array of pointers to NHASH
295 * linked symbol lists
301 * Symbol types changed.
307 register struct sym *sp;
310 for (i=0; i<NHASH; ++i) {
313 if (sp != &dot && sp->s_type == S_USER)
320 /*)Function int symeq(p1, p2)
322 * char * p1 name string
323 * char * p2 name string
325 * The function symeq() compares the two name strings for a match.
326 * The return value is 1 for a match and 0 for no match.
332 * char ccase[] an array of characters which
333 * perform the case translation function
345 register char *p1, *p2;
356 if (ccase[(unsigned char)(*p1++)] != ccase[(unsigned char)(*p2++)])
364 /*)Function int hash(p)
366 * char * p pointer to string to hash
368 * The function hash() computes a hash code using the sum
369 * of all characters mod table size algorithm.
372 * int h accumulated character sum
376 * char ccase[] an array of characters which
377 * perform the case translation function
399 h += ccase[(unsigned char)(*p++)];
406 /*)Function VOID * new(n)
408 * unsigned int n allocation size in bytes
410 * The function new() allocates n bytes of space and returns
411 * a pointer to this memory. If no space is available the
412 * assembly is terminated.
415 * VOID * p a general pointer
421 * VOID asexit() asmain.c
422 * int fprintf() c_library
423 * VOID * malloc() c_library
426 * Memory is allocated, if allocation fails
427 * the assembly is terminated.
436 if ((p = (VOID *) malloc(n)) == NULL) {
437 fprintf(stderr, "Out of space!\n");