4 * (C) Copyright 1989-1995
16 #if defined(__APPLE__) && defined(__MACH__)
17 #include <sys/types.h>
18 #include <sys/malloc.h>
26 * The module assym.c contains the functions that operate
27 * on the mnemonic/directive and symbol structures.
29 * assym.c contains the following functions:
40 * assym.c contains no local/static variables.
43 /*)Function VOID syminit()
45 * The function syminit() is called early in the game
46 * to set up the hashtables. First all buckets in a
47 * table are cleared. Then a pass is made through
48 * the respective symbol lists, linking them into
49 * their hash buckets. Finally the base area pointer
53 * int h computed hash value
54 * mne * mp pointer to a mne structure
55 * mne ** mpp pointer to an array of
56 * mne structure pointers
57 * sym * sp pointer to a sym structure
58 * sym ** spp pointer to an array of
59 * sym structure pointers
62 * area area[] single elememt area array
63 * area dca defined as area[0]
64 * mne * mnehash[] array of pointers to NHASH
65 * linked mnemonic/directive lists
66 * sym * symhash[] array of pointers to NHASH
73 * (1) The symbol hash tables are initialized,
74 * the only defined symbol is '.'.
75 * (2) The mnemonic/directive hash tables are
76 * initialized with the assembler directives
77 * and mnemonics found in the machine dependent
79 * (3) The area pointer is initialized to dca (area[0]).
85 register struct mne *mp;
87 register struct sym *sp;
92 while (mpp < &mnehash[NHASH])
97 mp->m_mp = mnehash[h];
105 while (spp < &symhash[NHASH])
110 sp->s_sp = symhash[h];
112 if (sp->s_flag&S_END)
120 /*)Function area * alookup(id)
122 * char * id area name string
124 * The function alookup() searches the area list for a
125 * match with id. If the area is defined then a pointer
126 * to this area is returned else a NULL is returned.
129 * area * ap pointer to area structure
132 * area * areap pointer to an area structure
135 * int symeq() assym.c
145 register struct area *ap;
149 if (symeq(id, ap->a_id)) {
157 /*)Function mne * mlookup(id)
159 * char * id mnemonic/directive name string
161 * The function mlookup() searches the mnemonic/directive
162 * hash tables for a match returning a pointer to the
163 * mne structure else it returns a NULL.
166 * mne * mp pointer to mne structure
167 * int h calculated hash value
170 * mne * mnehash[] array of pointers to NHASH
171 * linked mnemonic/directive lists
184 register struct mne *mp;
190 if (symeq(id, mp->m_id))
197 /*)Function sym * lookup(id)
199 * char * id symbol name string
201 * The function lookup() searches the symbol hash tables for
202 * a symbol name match returning a pointer to the sym structure.
203 * If the symbol is not found then a sym structure is created,
204 * initialized, and linked to the appropriate hash table.
205 * A pointer to this new sym structure is returned.
208 * int h computed hash value
209 * sym * sp pointer to a sym structure
212 * sym * symhash[] array of pointers to NHASH
213 * linked symbol lists
217 * VOID * new() assym.c
218 * int symeq() assym.c
221 * If the function new() fails to allocate space
222 * for the new sym structure the assembly terminates.
229 register struct sym *sp;
235 if (symeq(id, sp->s_id))
239 sp = (struct sym *) new (sizeof(struct sym));
240 sp->s_sp = symhash[h];
243 strncpy(sp->s_id, id, NCPS);
252 /*)Function VOID symglob()
254 * The function symglob() will mark all symbols of
255 * type S_NEW as global. Called at the beginning of pass 1
256 * if the assembly option -g was specified.
259 * sym * sp pointer to a sym structure
263 * sym * symhash[] array of pointers to NHASH
264 * linked symbol lists
270 * Symbol types changed.
276 register struct sym *sp;
279 for (i=0; i<NHASH; ++i) {
282 if (sp->s_type == S_NEW)
289 /*)Function VOID allglob()
291 * The function allglob() will mark all symbols of
292 * type S_USER as global. Called at the beginning of pass 1
293 * if the assembly option -a was specified.
296 * sym * sp pointer to a sym structure
300 * sym * symhash[] array of pointers to NHASH
301 * linked symbol lists
307 * Symbol types changed.
313 register struct sym *sp;
316 for (i=0; i<NHASH; ++i) {
319 if (sp != &dot && sp->s_type == S_USER)
326 /*)Function int symeq(p1, p2)
328 * char * p1 name string
329 * char * p2 name string
331 * The function symeq() compares the two name strings for a match.
332 * The return value is 1 for a match and 0 for no match.
338 * char ccase[] an array of characters which
339 * perform the case translation function
351 register char *p1, *p2;
362 if (ccase[(unsigned char)(*p1++)] != ccase[(unsigned char)(*p2++)])
370 /*)Function int hash(p)
372 * char * p pointer to string to hash
374 * The function hash() computes a hash code using the sum
375 * of all characters mod table size algorithm.
378 * int h accumulated character sum
382 * char ccase[] an array of characters which
383 * perform the case translation function
405 h += ccase[(unsigned char)(*p++)];
412 /*)Function VOID * new(n)
414 * unsigned int n allocation size in bytes
416 * The function new() allocates n bytes of space and returns
417 * a pointer to this memory. If no space is available the
418 * assembly is terminated.
421 * VOID * p a general pointer
427 * VOID asexit() asmain.c
428 * int fprintf() c_library
429 * VOID * malloc() c_library
432 * Memory is allocated, if allocation fails
433 * the assembly is terminated.
442 if ((p = (VOID *) malloc(n)) == NULL) {
443 fprintf(stderr, "Out of space!\n");