4 * (C) Copyright 1989-1995
12 * - lookup: Use StoreString for sym construction
13 * - change symeq() to do length-independent string compare
14 * - change hash() to do length-independent hash calculation
16 * - make mnemonics case insensitive ALWAYS
17 * - make hash() case-insensitive always
18 * - replace symeq() call in mlookup with strcmpi
34 * The module assym.c contains the functions that operate
35 * on the mnemonic/directive and symbol structures.
37 * assym.c contains the following functions:
48 * assym.c contains no local/static variables.
51 /*)Function VOID syminit()
53 * The function syminit() is called early in the game
54 * to set up the hashtables. First all buckets in a
55 * table are cleared. Then a pass is made through
56 * the respective symbol lists, linking them into
57 * their hash buckets. Finally the base area pointer
61 * int h computed hash value
62 * mne * mp pointer to a mne structure
63 * mne ** mpp pointer to an array of
64 * mne structure pointers
65 * sym * sp pointer to a sym structure
66 * sym ** spp pointer to an array of
67 * sym structure pointers
70 * area area[] single elememt area array
71 * area dca defined as area[0]
72 * mne * mnehash[] array of pointers to NHASH
73 * linked mnemonic/directive lists
74 * sym * symhash[] array of pointers to NHASH
81 * (1) The symbol hash tables are initialized,
82 * the only defined symbol is '.'.
83 * (2) The mnemonic/directive hash tables are
84 * initialized with the assembler directives
85 * and mnemonics found in the machine dependent
87 * (3) The area pointer is initialized to dca (area[0]).
93 register struct mne *mp;
95 register struct sym *sp;
100 while (mpp < &mnehash[NHASH])
105 mp->m_mp = mnehash[h];
107 if (mp->m_flag&S_END)
113 while (spp < &symhash[NHASH])
118 sp->s_sp = symhash[h];
120 if (sp->s_flag&S_END)
128 /*)Function area * alookup(id)
130 * char * id area name string
132 * The function alookup() searches the area list for a
133 * match with id. If the area is defined then a pointer
134 * to this area is returned else a NULL is returned.
137 * area * ap pointer to area structure
140 * area * areap pointer to an area structure
143 * int symeq() assym.c
153 register struct area *ap;
157 if (symeq(id, ap->a_id)) {
165 /*)Function mne * mlookup(id)
167 * char * id mnemonic/directive name string
169 * The function mlookup() searches the mnemonic/directive
170 * hash tables for a match returning a pointer to the
171 * mne structure else it returns a NULL.
174 * mne * mp pointer to mne structure
175 * int h calculated hash value
178 * mne * mnehash[] array of pointers to NHASH
179 * linked mnemonic/directive lists
192 register struct mne *mp;
198 if (as_strcmpi(id, mp->m_id) == 0) /* JLH: case insensitive */
205 /*)Function sym * lookup(id)
207 * char * id symbol name string
209 * The function lookup() searches the symbol hash tables for
210 * a symbol name match returning a pointer to the sym structure.
211 * If the symbol is not found then a sym structure is created,
212 * initialized, and linked to the appropriate hash table.
213 * A pointer to this new sym structure is returned.
216 * int h computed hash value
217 * sym * sp pointer to a sym structure
220 * sym * symhash[] array of pointers to NHASH
221 * linked symbol lists
225 * VOID * new() assym.c
226 * int symeq() assym.c
229 * If the function new() fails to allocate space
230 * for the new sym structure the assembly terminates.
237 register struct sym *sp;
243 if (symeq(id, sp->s_id))
247 sp = (struct sym *) new (sizeof(struct sym));
248 sp->s_sp = symhash[h];
251 sp->s_id = StoreString( id ); /* JLH */
260 /*)Function VOID symglob()
262 * The function symglob() will mark all symbols of
263 * type S_NEW as global. Called at the beginning of pass 1
264 * if the assembly option -g was specified.
267 * sym * sp pointer to a sym structure
271 * sym * symhash[] array of pointers to NHASH
272 * linked symbol lists
278 * Symbol types changed.
284 register struct sym *sp;
287 for (i=0; i<NHASH; ++i) {
290 if (sp->s_type == S_NEW)
297 /*)Function VOID allglob()
299 * The function allglob() will mark all symbols of
300 * type S_USER as global. Called at the beginning of pass 1
301 * if the assembly option -a was specified.
304 * sym * sp pointer to a sym structure
308 * sym * symhash[] array of pointers to NHASH
309 * linked symbol lists
315 * Symbol types changed.
321 register struct sym *sp;
324 for (i=0; i<NHASH; ++i) {
327 if (sp != &dot && sp->s_type == S_USER)
334 /*)Function int symeq(p1, p2)
336 * char * p1 name string
337 * char * p2 name string
339 * The function symeq() compares the two name strings for a match.
340 * The return value is 1 for a match and 0 for no match.
346 * char ccase[] an array of characters which
347 * perform the case translation function
359 register char *p1, *p2;
362 return (strcmp( p1, p2 ) == 0);
364 return (as_strcmpi( p1, p2 ) == 0);
368 /*)Function int hash(p)
370 * char * p pointer to string to hash
372 * The function hash() computes a hash code using the sum
373 * of all characters mod table size algorithm.
376 * int h accumulated character sum
380 * char ccase[] an array of characters which
381 * perform the case translation function
398 /* JLH: case insensitive hash: Doesn't much affect
399 * hashing, and allows same function for mnemonics and symbols
401 h += ccase[(int)*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");