4 * (C) Copyright 1989-1995
15 #if defined(__APPLE__) && defined(__MACH__)
16 #include <sys/types.h>
17 #include <sys/malloc.h>
25 * The module assym.c contains the functions that operate
26 * on the mnemonic/directive and symbol structures.
28 * assym.c contains the following functions:
39 * assym.c contains no local/static variables.
42 /*)Function VOID syminit()
44 * The function syminit() is called early in the game
45 * to set up the hashtables. First all buckets in a
46 * table are cleared. Then a pass is made through
47 * the respective symbol lists, linking them into
48 * their hash buckets. Finally the base area pointer
52 * int h computed hash value
53 * mne * mp pointer to a mne structure
54 * mne ** mpp pointer to an array of
55 * mne structure pointers
56 * sym * sp pointer to a sym structure
57 * sym ** spp pointer to an array of
58 * sym structure pointers
61 * area area[] single elememt area array
62 * area dca defined as area[0]
63 * mne * mnehash[] array of pointers to NHASH
64 * linked mnemonic/directive lists
65 * sym * symhash[] array of pointers to NHASH
72 * (1) The symbol hash tables are initialized,
73 * the only defined symbol is '.'.
74 * (2) The mnemonic/directive hash tables are
75 * initialized with the assembler directives
76 * and mnemonics found in the machine dependent
78 * (3) The area pointer is initialized to dca (area[0]).
84 register struct mne *mp;
86 register struct sym *sp;
91 while (mpp < &mnehash[NHASH])
96 mp->m_mp = mnehash[h];
104 while (spp < &symhash[NHASH])
109 sp->s_sp = symhash[h];
111 if (sp->s_flag&S_END)
119 /*)Function area * alookup(id)
121 * char * id area name string
123 * The function alookup() searches the area list for a
124 * match with id. If the area is defined then a pointer
125 * to this area is returned else a NULL is returned.
128 * area * ap pointer to area structure
131 * area * areap pointer to an area structure
134 * int symeq() assym.c
144 register struct area *ap;
148 if (symeq(id, ap->a_id)) {
156 /*)Function mne * mlookup(id)
158 * char * id mnemonic/directive name string
160 * The function mlookup() searches the mnemonic/directive
161 * hash tables for a match returning a pointer to the
162 * mne structure else it returns a NULL.
165 * mne * mp pointer to mne structure
166 * int h calculated hash value
169 * mne * mnehash[] array of pointers to NHASH
170 * linked mnemonic/directive lists
183 register struct mne *mp;
189 if (symeq(id, mp->m_id))
196 /*)Function sym * lookup(id)
198 * char * id symbol name string
200 * The function lookup() searches the symbol hash tables for
201 * a symbol name match returning a pointer to the sym structure.
202 * If the symbol is not found then a sym structure is created,
203 * initialized, and linked to the appropriate hash table.
204 * A pointer to this new sym structure is returned.
207 * int h computed hash value
208 * sym * sp pointer to a sym structure
211 * sym * symhash[] array of pointers to NHASH
212 * linked symbol lists
216 * VOID * new() assym.c
217 * int symeq() assym.c
220 * If the function new() fails to allocate space
221 * for the new sym structure the assembly terminates.
228 register struct sym *sp;
234 if (symeq(id, sp->s_id))
238 sp = (struct sym *) new (sizeof(struct sym));
239 sp->s_sp = symhash[h];
242 strncpy(sp->s_id, id, NCPS);
251 /*)Function VOID symglob()
253 * The function symglob() will mark all symbols of
254 * type S_NEW as global. Called at the beginning of pass 1
255 * if the assembly option -g was specified.
258 * sym * sp pointer to a sym structure
262 * sym * symhash[] array of pointers to NHASH
263 * linked symbol lists
269 * Symbol types changed.
275 register struct sym *sp;
278 for (i=0; i<NHASH; ++i) {
281 if (sp->s_type == S_NEW)
288 /*)Function VOID allglob()
290 * The function allglob() will mark all symbols of
291 * type S_USER as global. Called at the beginning of pass 1
292 * if the assembly option -a was specified.
295 * sym * sp pointer to a sym structure
299 * sym * symhash[] array of pointers to NHASH
300 * linked symbol lists
306 * Symbol types changed.
312 register struct sym *sp;
315 for (i=0; i<NHASH; ++i) {
318 if (sp != &dot && sp->s_type == S_USER)
325 /*)Function int symeq(p1, p2)
327 * char * p1 name string
328 * char * p2 name string
330 * The function symeq() compares the two name strings for a match.
331 * The return value is 1 for a match and 0 for no match.
337 * char ccase[] an array of characters which
338 * perform the case translation function
350 register char *p1, *p2;
361 if (ccase[(unsigned char)(*p1++)] != ccase[(unsigned char)(*p2++)])
369 /*)Function int hash(p)
371 * char * p pointer to string to hash
373 * The function hash() computes a hash code using the sum
374 * of all characters mod table size algorithm.
377 * int h accumulated character sum
381 * char ccase[] an array of characters which
382 * perform the case translation function
404 h += ccase[(unsigned char)(*p++)];
411 /*)Function VOID * new(n)
413 * unsigned int n allocation size in bytes
415 * The function new() allocates n bytes of space and returns
416 * a pointer to this memory. If no space is available the
417 * assembly is terminated.
420 * VOID * p a general pointer
426 * VOID asexit() asmain.c
427 * int fprintf() c_library
428 * VOID * malloc() c_library
431 * Memory is allocated, if allocation fails
432 * the assembly is terminated.
441 if ((p = (VOID *) malloc(n)) == NULL) {
442 fprintf(stderr, "Out of space!\n");