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
33 * The module assym.c contains the functions that operate
34 * on the mnemonic/directive and symbol structures.
36 * assym.c contains the following functions:
47 * assym.c contains no local/static variables.
50 /*)Function VOID syminit()
52 * The function syminit() is called early in the game
53 * to set up the hashtables. First all buckets in a
54 * table are cleared. Then a pass is made through
55 * the respective symbol lists, linking them into
56 * their hash buckets. Finally the base area pointer
60 * int h computed hash value
61 * mne * mp pointer to a mne structure
62 * mne ** mpp pointer to an array of
63 * mne structure pointers
64 * sym * sp pointer to a sym structure
65 * sym ** spp pointer to an array of
66 * sym structure pointers
69 * area area[] single elememt area array
70 * area dca defined as area[0]
71 * mne * mnehash[] array of pointers to NHASH
72 * linked mnemonic/directive lists
73 * sym * symhash[] array of pointers to NHASH
80 * (1) The symbol hash tables are initialized,
81 * the only defined symbol is '.'.
82 * (2) The mnemonic/directive hash tables are
83 * initialized with the assembler directives
84 * and mnemonics found in the machine dependent
86 * (3) The area pointer is initialized to dca (area[0]).
92 register struct mne *mp;
94 register struct sym *sp;
99 while (mpp < &mnehash[NHASH])
104 mp->m_mp = mnehash[h];
106 if (mp->m_flag&S_END)
112 while (spp < &symhash[NHASH])
117 sp->s_sp = symhash[h];
119 if (sp->s_flag&S_END)
127 /*)Function area * alookup(id)
129 * char * id area name string
131 * The function alookup() searches the area list for a
132 * match with id. If the area is defined then a pointer
133 * to this area is returned else a NULL is returned.
136 * area * ap pointer to area structure
139 * area * areap pointer to an area structure
142 * int symeq() assym.c
152 register struct area *ap;
156 if (symeq(id, ap->a_id)) {
164 /*)Function mne * mlookup(id)
166 * char * id mnemonic/directive name string
168 * The function mlookup() searches the mnemonic/directive
169 * hash tables for a match returning a pointer to the
170 * mne structure else it returns a NULL.
173 * mne * mp pointer to mne structure
174 * int h calculated hash value
177 * mne * mnehash[] array of pointers to NHASH
178 * linked mnemonic/directive lists
191 register struct mne *mp;
197 if (strcmpi(id, mp->m_id) == 0) /* JLH: case insensitive */
204 /*)Function sym * lookup(id)
206 * char * id symbol name string
208 * The function lookup() searches the symbol hash tables for
209 * a symbol name match returning a pointer to the sym structure.
210 * If the symbol is not found then a sym structure is created,
211 * initialized, and linked to the appropriate hash table.
212 * A pointer to this new sym structure is returned.
215 * int h computed hash value
216 * sym * sp pointer to a sym structure
219 * sym * symhash[] array of pointers to NHASH
220 * linked symbol lists
224 * VOID * new() assym.c
225 * int symeq() assym.c
228 * If the function new() fails to allocate space
229 * for the new sym structure the assembly terminates.
236 register struct sym *sp;
242 if (symeq(id, sp->s_id))
246 sp = (struct sym *) new (sizeof(struct sym));
247 sp->s_sp = symhash[h];
250 sp->s_id = StoreString( id ); /* JLH */
259 /*)Function VOID symglob()
261 * The function symglob() will mark all symbols of
262 * type S_NEW as global. Called at the beginning of pass 1
263 * if the assembly option -g was specified.
266 * sym * sp pointer to a sym structure
270 * sym * symhash[] array of pointers to NHASH
271 * linked symbol lists
277 * Symbol types changed.
283 register struct sym *sp;
286 for (i=0; i<NHASH; ++i) {
289 if (sp->s_type == S_NEW)
296 /*)Function VOID allglob()
298 * The function allglob() will mark all symbols of
299 * type S_USER as global. Called at the beginning of pass 1
300 * if the assembly option -a was specified.
303 * sym * sp pointer to a sym structure
307 * sym * symhash[] array of pointers to NHASH
308 * linked symbol lists
314 * Symbol types changed.
320 register struct sym *sp;
323 for (i=0; i<NHASH; ++i) {
326 if (sp != &dot && sp->s_type == S_USER)
333 /*)Function int symeq(p1, p2)
335 * char * p1 name string
336 * char * p2 name string
338 * The function symeq() compares the two name strings for a match.
339 * The return value is 1 for a match and 0 for no match.
345 * char ccase[] an array of characters which
346 * perform the case translation function
358 register char *p1, *p2;
361 return (strcmp( p1, p2 ) == 0);
363 return (strcmpi( p1, p2 ) == 0);
367 /*)Function int hash(p)
369 * char * p pointer to string to hash
371 * The function hash() computes a hash code using the sum
372 * of all characters mod table size algorithm.
375 * int h accumulated character sum
379 * char ccase[] an array of characters which
380 * perform the case translation function
397 /* JLH: case insensitive hash: Doesn't much affect
398 * hashing, and allows same function for mnemonics and symbols
400 h += ccase[(int)*p++];
405 /*)Function VOID * new(n)
407 * unsigned int n allocation size in bytes
409 * The function new() allocates n bytes of space and returns
410 * a pointer to this memory. If no space is available the
411 * assembly is terminated.
414 * VOID * p a general pointer
420 * VOID asexit() asmain.c
421 * int fprintf() c_library
422 * VOID * malloc() c_library
425 * Memory is allocated, if allocation fails
426 * the assembly is terminated.
435 if ((p = (VOID *) malloc(n)) == NULL) {
436 fprintf(stderr, "Out of space!\n");