4 * (C) Copyright 1989-1995
17 //#if defined(_MSC_VER)
27 * The module assym.c contains the functions that operate
28 * on the mnemonic/directive and symbol structures.
30 * assym.c contains the following functions:
41 * assym.c contains no local/static variables.
44 /*)Function VOID syminit()
46 * The function syminit() is called early in the game
47 * to set up the hashtables. First all buckets in a
48 * table are cleared. Then a pass is made through
49 * the respective symbol lists, linking them into
50 * their hash buckets. Finally the base area pointer
54 * int h computed hash value
55 * mne * mp pointer to a mne structure
56 * mne ** mpp pointer to an array of
57 * mne structure pointers
58 * sym * sp pointer to a sym structure
59 * sym ** spp pointer to an array of
60 * sym structure pointers
63 * area area[] single elememt area array
64 * area dca defined as area[0]
65 * mne * mnehash[] array of pointers to NHASH
66 * linked mnemonic/directive lists
67 * sym * symhash[] array of pointers to NHASH
74 * (1) The symbol hash tables are initialized,
75 * the only defined symbol is '.'.
76 * (2) The mnemonic/directive hash tables are
77 * initialized with the assembler directives
78 * and mnemonics found in the machine dependent
80 * (3) The area pointer is initialized to dca (area[0]).
86 register struct mne *mp;
88 register struct sym *sp;
93 while (mpp < &mnehash[NHASH])
98 mp->m_mp = mnehash[h];
100 if (mp->m_flag&S_END)
106 while (spp < &symhash[NHASH])
111 sp->s_sp = symhash[h];
113 if (sp->s_flag&S_END)
121 /*)Function area * alookup(id)
123 * char * id area name string
125 * The function alookup() searches the area list for a
126 * match with id. If the area is defined then a pointer
127 * to this area is returned else a NULL is returned.
130 * area * ap pointer to area structure
133 * area * areap pointer to an area structure
136 * int symeq() assym.c
146 register struct area *ap;
150 if (symeq(id, ap->a_id)) {
158 /*)Function mne * mlookup(id)
160 * char * id mnemonic/directive name string
162 * The function mlookup() searches the mnemonic/directive
163 * hash tables for a match returning a pointer to the
164 * mne structure else it returns a NULL.
167 * mne * mp pointer to mne structure
168 * int h calculated hash value
171 * mne * mnehash[] array of pointers to NHASH
172 * linked mnemonic/directive lists
185 register struct mne *mp;
191 if (symeq(id, mp->m_id))
198 /*)Function sym * lookup(id)
200 * char * id symbol name string
202 * The function lookup() searches the symbol hash tables for
203 * a symbol name match returning a pointer to the sym structure.
204 * If the symbol is not found then a sym structure is created,
205 * initialized, and linked to the appropriate hash table.
206 * A pointer to this new sym structure is returned.
209 * int h computed hash value
210 * sym * sp pointer to a sym structure
213 * sym * symhash[] array of pointers to NHASH
214 * linked symbol lists
218 * VOID * new() assym.c
219 * int symeq() assym.c
222 * If the function new() fails to allocate space
223 * for the new sym structure the assembly terminates.
230 register struct sym *sp;
236 if (symeq(id, sp->s_id))
240 sp = (struct sym *) new (sizeof(struct sym));
241 sp->s_sp = symhash[h];
244 strncpy(sp->s_id, id, NCPS);
253 /*)Function VOID symglob()
255 * The function symglob() will mark all symbols of
256 * type S_NEW as global. Called at the beginning of pass 1
257 * if the assembly option -g was specified.
260 * sym * sp pointer to a sym structure
264 * sym * symhash[] array of pointers to NHASH
265 * linked symbol lists
271 * Symbol types changed.
277 register struct sym *sp;
280 for (i=0; i<NHASH; ++i) {
283 if (sp->s_type == S_NEW)
290 /*)Function VOID allglob()
292 * The function allglob() will mark all symbols of
293 * type S_USER as global. Called at the beginning of pass 1
294 * if the assembly option -a was specified.
297 * sym * sp pointer to a sym structure
301 * sym * symhash[] array of pointers to NHASH
302 * linked symbol lists
308 * Symbol types changed.
314 register struct sym *sp;
317 for (i=0; i<NHASH; ++i) {
320 if (sp != &dot && sp->s_type == S_USER)
327 /*)Function int symeq(p1, p2)
329 * char * p1 name string
330 * char * p2 name string
332 * The function symeq() compares the two name strings for a match.
333 * The return value is 1 for a match and 0 for no match.
339 * char ccase[] an array of characters which
340 * perform the case translation function
352 register char *p1, *p2;
363 if (ccase[*p1++] != ccase[*p2++])
371 /*)Function int hash(p)
373 * char * p pointer to string to hash
375 * The function hash() computes a hash code using the sum
376 * of all characters mod table size algorithm.
379 * int h accumulated character sum
383 * char ccase[] an array of characters which
384 * perform the case translation function
413 /*)Function VOID * new(n)
415 * unsigned int n allocation size in bytes
417 * The function new() allocates n bytes of space and returns
418 * a pointer to this memory. If no space is available the
419 * assembly is terminated.
422 * VOID * p a general pointer
428 * VOID asexit() asmain.c
429 * int fprintf() c_library
430 * VOID * malloc() c_library
433 * Memory is allocated, if allocation fails
434 * the assembly is terminated.
443 if ((p = (VOID *) malloc(n)) == NULL) {
444 fprintf(stderr, "Out of space!\n");