4 * (C) Copyright 1989-1995
21 * The module assym.c contains the functions that operate
22 * on the mnemonic/directive and symbol structures.
24 * assym.c contains the following functions:
35 * assym.c contains no local/static variables.
38 /*)Function VOID syminit()
40 * The function syminit() is called early in the game
41 * to set up the hashtables. First all buckets in a
42 * table are cleared. Then a pass is made through
43 * the respective symbol lists, linking them into
44 * their hash buckets. Finally the base area pointer
48 * int h computed hash value
49 * mne * mp pointer to a mne structure
50 * mne ** mpp pointer to an array of
51 * mne structure pointers
52 * sym * sp pointer to a sym structure
53 * sym ** spp pointer to an array of
54 * sym structure pointers
57 * area area[] single elememt area array
58 * area dca defined as area[0]
59 * mne * mnehash[] array of pointers to NHASH
60 * linked mnemonic/directive lists
61 * sym * symhash[] array of pointers to NHASH
68 * (1) The symbol hash tables are initialized,
69 * the only defined symbol is '.'.
70 * (2) The mnemonic/directive hash tables are
71 * initialized with the assembler directives
72 * and mnemonics found in the machine dependent
74 * (3) The area pointer is initialized to dca (area[0]).
80 register struct mne *mp;
82 register struct sym *sp;
87 while (mpp < &mnehash[NHASH])
92 mp->m_mp = mnehash[h];
100 while (spp < &symhash[NHASH])
105 sp->s_sp = symhash[h];
107 if (sp->s_flag&S_END)
115 /*)Function area * alookup(id)
117 * char * id area name string
119 * The function alookup() searches the area list for a
120 * match with id. If the area is defined then a pointer
121 * to this area is returned else a NULL is returned.
124 * area * ap pointer to area structure
127 * area * areap pointer to an area structure
130 * int symeq() assym.c
140 register struct area *ap;
144 if (symeq(id, ap->a_id)) {
152 /*)Function mne * mlookup(id)
154 * char * id mnemonic/directive name string
156 * The function mlookup() searches the mnemonic/directive
157 * hash tables for a match returning a pointer to the
158 * mne structure else it returns a NULL.
161 * mne * mp pointer to mne structure
162 * int h calculated hash value
165 * mne * mnehash[] array of pointers to NHASH
166 * linked mnemonic/directive lists
179 register struct mne *mp;
185 if (as_strcmpi(id, mp->m_id) == 0) /* JLH: case insensitive */
192 /*)Function sym * lookup(id)
194 * char * id symbol name string
196 * The function lookup() searches the symbol hash tables for
197 * a symbol name match returning a pointer to the sym structure.
198 * If the symbol is not found then a sym structure is created,
199 * initialized, and linked to the appropriate hash table.
200 * A pointer to this new sym structure is returned.
203 * int h computed hash value
204 * sym * sp pointer to a sym structure
207 * sym * symhash[] array of pointers to NHASH
208 * linked symbol lists
212 * VOID * new() assym.c
213 * int symeq() assym.c
216 * If the function new() fails to allocate space
217 * for the new sym structure the assembly terminates.
224 register struct sym *sp;
230 if (symeq(id, sp->s_id))
234 sp = (struct sym *) new (sizeof(struct sym));
235 sp->s_sp = symhash[h];
238 strncpy(sp->s_id, id, NCPS);
247 /*)Function VOID symglob()
249 * The function symglob() will mark all symbols of
250 * type S_NEW as global. Called at the beginning of pass 1
251 * if the assembly option -g was specified.
254 * sym * sp pointer to a sym structure
258 * sym * symhash[] array of pointers to NHASH
259 * linked symbol lists
265 * Symbol types changed.
271 register struct sym *sp;
274 for (i=0; i<NHASH; ++i) {
277 if (sp->s_type == S_NEW)
284 /*)Function VOID allglob()
286 * The function allglob() will mark all symbols of
287 * type S_USER as global. Called at the beginning of pass 1
288 * if the assembly option -a was specified.
291 * sym * sp pointer to a sym structure
295 * sym * symhash[] array of pointers to NHASH
296 * linked symbol lists
302 * Symbol types changed.
308 register struct sym *sp;
311 for (i=0; i<NHASH; ++i) {
314 if (sp != &dot && sp->s_type == S_USER)
321 /*)Function int symeq(p1, p2)
323 * char * p1 name string
324 * char * p2 name string
326 * The function symeq() compares the two name strings for a match.
327 * The return value is 1 for a match and 0 for no match.
333 * char ccase[] an array of characters which
334 * perform the case translation function
346 register char *p1, *p2;
357 if (ccase[(unsigned char)(*p1++)] != ccase[(unsigned char)(*p2++)])
365 /*)Function int hash(p)
367 * char * p pointer to string to hash
369 * The function hash() computes a hash code using the sum
370 * of all characters mod table size algorithm.
373 * int h accumulated character sum
377 * char ccase[] an array of characters which
378 * perform the case translation function
400 h += ccase[(unsigned char)(*p++)];
407 /*)Function VOID * new(n)
409 * unsigned int n allocation size in bytes
411 * The function new() allocates n bytes of space and returns
412 * a pointer to this memory. If no space is available the
413 * assembly is terminated.
416 * VOID * p a general pointer
422 * VOID asexit() asmain.c
423 * int fprintf() c_library
424 * VOID * malloc() c_library
427 * Memory is allocated, if allocation fails
428 * the assembly is terminated.
437 if ((p = (VOID *) malloc(n)) == NULL) {
438 fprintf(stderr, "Out of space!\n");