]>
Commit | Line | Data |
---|---|---|
fecd2382 RP |
1 | /* symbols.c -symbol table- |
2 | Copyright (C) 1987, 1990, 1991 Free Software Foundation, Inc. | |
a39116f1 RP |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 RP |
19 | |
20 | #include "as.h" | |
21 | ||
22 | #include "obstack.h" /* For "symbols.h" */ | |
23 | #include "subsegs.h" | |
24 | ||
25 | #ifndef WORKING_DOT_WORD | |
26 | extern int new_broken_words; | |
27 | #endif | |
28 | #ifdef VMS | |
29 | extern char const_flag; | |
30 | #endif | |
31 | ||
32 | static | |
a39116f1 RP |
33 | struct hash_control * |
34 | sy_hash; /* symbol-name => struct symbol pointer */ | |
fecd2382 | 35 | |
a39116f1 | 36 | /* Below are commented in "symbols.h". */ |
fecd2382 RP |
37 | unsigned int local_bss_counter; |
38 | symbolS * symbol_rootP; | |
39 | symbolS * symbol_lastP; | |
40 | symbolS abs_symbol; | |
41 | ||
42 | symbolS* dot_text_symbol; | |
43 | symbolS* dot_data_symbol; | |
44 | symbolS* dot_bss_symbol; | |
45 | ||
46 | struct obstack notes; | |
47 | ||
48 | /* | |
49 | * Un*x idea of local labels. They are made by "n:" where n | |
50 | * is any decimal digit. Refer to them with | |
51 | * "nb" for previous (backward) n: | |
52 | * or "nf" for next (forward) n:. | |
53 | * | |
54 | * Like Un*x AS, we have one set of local label counters for entire assembly, | |
55 | * not one set per (sub)segment like in most assemblers. This implies that | |
56 | * one can refer to a label in another segment, and indeed some crufty | |
57 | * compilers have done just that. | |
58 | * | |
59 | * I document the symbol names here to save duplicating words elsewhere. | |
60 | * The mth occurence of label n: is turned into the symbol "Ln^Am" where | |
61 | * n is a digit and m is a decimal number. "L" makes it a label discarded | |
62 | * unless debugging and "^A"('\1') ensures no ordinary symbol SHOULD get the | |
63 | * same name as a local label symbol. The first "4:" is "L4^A1" - the m | |
64 | * numbers begin at 1. | |
65 | */ | |
66 | ||
67 | typedef short unsigned int | |
a39116f1 | 68 | local_label_countT; |
fecd2382 RP |
69 | |
70 | static local_label_countT | |
a39116f1 | 71 | local_label_counter[10]; |
fecd2382 RP |
72 | |
73 | static /* Returned to caller, then copied. */ | |
a39116f1 | 74 | char symbol_name_build[12]; /* used for created names ("4f") */ |
fecd2382 RP |
75 | |
76 | #ifdef LOCAL_LABELS_DOLLAR | |
77 | int local_label_defined[10]; | |
78 | #endif | |
79 | ||
80 | \f | |
81 | void | |
a39116f1 | 82 | symbol_begin() |
fecd2382 | 83 | { |
a39116f1 RP |
84 | symbol_lastP = NULL; |
85 | symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ | |
86 | sy_hash = hash_new(); | |
87 | bzero ((char *)(& abs_symbol), sizeof(abs_symbol)); | |
88 | S_SET_SEGMENT(&abs_symbol, SEG_ABSOLUTE); /* Can't initialise a union. Sigh. */ | |
89 | bzero ((char *)(local_label_counter), sizeof(local_label_counter) ); | |
90 | local_bss_counter = 0; | |
fecd2382 RP |
91 | } |
92 | \f | |
93 | /* | |
94 | * local_label_name() | |
95 | * | |
96 | * Caller must copy returned name: we re-use the area for the next name. | |
97 | */ | |
98 | ||
99 | char * /* Return local label name. */ | |
a39116f1 RP |
100 | local_label_name(n, augend) |
101 | register int n; /* we just saw "n:", "nf" or "nb" : n a digit */ | |
102 | register int augend; /* 0 for nb, 1 for n:, nf */ | |
fecd2382 | 103 | { |
a39116f1 RP |
104 | register char * p; |
105 | register char * q; | |
106 | char symbol_name_temporary[10]; /* build up a number, BACKWARDS */ | |
107 | ||
108 | know( n >= 0 ); | |
109 | know( augend == 0 || augend == 1 ); | |
110 | p = symbol_name_build; | |
111 | * p ++ = 'L'; | |
112 | * p ++ = n + '0'; /* Make into ASCII */ | |
113 | * p ++ = 1; /* ^A */ | |
114 | n = local_label_counter [ n ] + augend; | |
115 | /* version number of this local label */ | |
116 | /* | |
117 | * Next code just does sprintf( {}, "%d", n); | |
118 | * It is more elegant to do the next part recursively, but a procedure | |
119 | * call for each digit emitted is considered too costly. | |
120 | */ | |
121 | q = symbol_name_temporary; | |
122 | for (*q++=0; n; q++) /* emits NOTHING if n starts as 0 */ | |
123 | { | |
124 | know(n>0); /* We expect n > 0 always */ | |
125 | *q = n % 10 + '0'; | |
126 | n /= 10; | |
127 | } | |
128 | while (( * p ++ = * -- q ) != '\0') ;; | |
129 | ||
130 | /* The label, as a '\0' ended string, starts at symbol_name_build. */ | |
131 | return(symbol_name_build); | |
fecd2382 RP |
132 | } /* local_label_name() */ |
133 | ||
134 | ||
135 | void local_colon (n) | |
136 | int n; /* just saw "n:" */ | |
137 | { | |
a39116f1 | 138 | local_label_counter [n] ++; |
fecd2382 | 139 | #ifdef LOCAL_LABELS_DOLLAR |
a39116f1 | 140 | local_label_defined[n]=1; |
fecd2382 | 141 | #endif |
a39116f1 | 142 | colon (local_label_name (n, 0)); |
fecd2382 RP |
143 | } |
144 | \f | |
145 | /* | |
146 | * symbol_new() | |
147 | * | |
148 | * Return a pointer to a new symbol. | |
149 | * Die if we can't make a new symbol. | |
150 | * Fill in the symbol's values. | |
151 | * Add symbol to end of symbol chain. | |
152 | * | |
153 | * | |
154 | * Please always call this to create a new symbol. | |
155 | * | |
156 | * Changes since 1985: Symbol names may not contain '\0'. Sigh. | |
157 | * 2nd argument is now a SEG rather than a TYPE. The mapping between | |
158 | * segments and types is mostly encapsulated herein (actually, we inherit it | |
159 | * from macros in struc-symbol.h). | |
160 | */ | |
161 | ||
162 | symbolS *symbol_new(name, segment, value, frag) | |
163 | char *name; /* It is copied, the caller can destroy/modify */ | |
164 | segT segment; /* Segment identifier (SEG_<something>) */ | |
165 | long value; /* Symbol value */ | |
166 | fragS *frag; /* Associated fragment */ | |
167 | { | |
168 | unsigned int name_length; | |
169 | char *preserved_copy_of_name; | |
170 | symbolS *symbolP; | |
171 | ||
172 | name_length = strlen(name) + 1; /* +1 for \0 */ | |
173 | obstack_grow(¬es, name, name_length); | |
174 | preserved_copy_of_name = obstack_finish(¬es); | |
175 | symbolP = (symbolS *)obstack_alloc(¬es, sizeof(symbolS)); | |
a39116f1 RP |
176 | |
177 | /* symbol must be born in some fixed state. This seems as good as any. */ | |
dae50edd | 178 | memset(symbolP, 0, sizeof(symbolS)); |
a39116f1 | 179 | |
a6c6eaf8 | 180 | #ifdef STRIP_UNDERSCORE |
fecd2382 | 181 | S_SET_NAME(symbolP, (*preserved_copy_of_name == '_' |
a39116f1 RP |
182 | ? preserved_copy_of_name + 1 |
183 | : preserved_copy_of_name)); | |
fecd2382 RP |
184 | #else /* STRIP_UNDERSCORE */ |
185 | S_SET_NAME(symbolP, preserved_copy_of_name); | |
186 | #endif /* STRIP_UNDERSCORE */ | |
a39116f1 | 187 | |
fecd2382 RP |
188 | S_SET_SEGMENT(symbolP, segment); |
189 | S_SET_VALUE(symbolP, value); | |
a39116f1 RP |
190 | /* symbol_clear_list_pointers(symbolP); uneeded if symbol is born zeroed. */ |
191 | ||
fecd2382 | 192 | symbolP->sy_frag = frag; |
dae50edd RP |
193 | /* krm: uneeded if symbol is born zeroed. |
194 | symbolP->sy_forward = NULL; */ /* JF */ | |
fecd2382 RP |
195 | symbolP->sy_number = ~0; |
196 | symbolP->sy_name_offset = ~0; | |
a39116f1 | 197 | |
fecd2382 RP |
198 | /* |
199 | * Link to end of symbol chain. | |
200 | */ | |
201 | symbol_append(symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
a39116f1 | 202 | |
fecd2382 RP |
203 | obj_symbol_new_hook(symbolP); |
204 | ||
205 | #ifdef DEBUG | |
a39116f1 | 206 | /* verify_symbol_chain(symbol_rootP, symbol_lastP); */ |
fecd2382 | 207 | #endif /* DEBUG */ |
a39116f1 | 208 | |
fecd2382 RP |
209 | return(symbolP); |
210 | } /* symbol_new() */ | |
211 | ||
212 | \f | |
213 | /* | |
214 | * colon() | |
215 | * | |
216 | * We have just seen "<name>:". | |
217 | * Creates a struct symbol unless it already exists. | |
218 | * | |
219 | * Gripes if we are redefining a symbol incompatibly (and ignores it). | |
220 | * | |
221 | */ | |
222 | void colon(sym_name) /* just seen "x:" - rattle symbols & frags */ | |
a39116f1 RP |
223 | register char * sym_name; /* symbol name, as a cannonical string */ |
224 | /* We copy this string: OK to alter later. */ | |
fecd2382 | 225 | { |
a39116f1 RP |
226 | register symbolS * symbolP; /* symbol we are working with */ |
227 | ||
fecd2382 | 228 | #ifdef LOCAL_LABELS_DOLLAR |
a39116f1 RP |
229 | /* Sun local labels go out of scope whenever a non-local symbol is defined. */ |
230 | ||
231 | if(*sym_name !='L') | |
232 | bzero((void *) local_label_defined, sizeof(local_label_defined)); | |
fecd2382 | 233 | #endif |
a39116f1 | 234 | |
fecd2382 | 235 | #ifndef WORKING_DOT_WORD |
a39116f1 RP |
236 | if(new_broken_words) { |
237 | struct broken_word *a; | |
238 | int possible_bytes; | |
239 | fragS *frag_tmp; | |
240 | char *frag_opcode; | |
241 | ||
242 | extern md_short_jump_size; | |
243 | extern md_long_jump_size; | |
244 | possible_bytes=md_short_jump_size + new_broken_words * md_long_jump_size; | |
245 | ||
246 | frag_tmp=frag_now; | |
247 | frag_opcode=frag_var(rs_broken_word, | |
248 | possible_bytes, | |
249 | possible_bytes, | |
250 | (relax_substateT) 0, | |
251 | (symbolS *) broken_words, | |
252 | 0L, | |
253 | NULL); | |
254 | ||
255 | /* We want to store the pointer to where to insert the jump table in the | |
256 | fr_opcode of the rs_broken_word frag. This requires a little hackery */ | |
257 | while(frag_tmp && (frag_tmp->fr_type!=rs_broken_word || frag_tmp->fr_opcode)) | |
258 | frag_tmp=frag_tmp->fr_next; | |
259 | know(frag_tmp); | |
260 | frag_tmp->fr_opcode=frag_opcode; | |
261 | new_broken_words = 0; | |
262 | ||
263 | for(a=broken_words;a && a->dispfrag==0;a=a->next_broken_word) | |
264 | a->dispfrag=frag_tmp; | |
265 | } | |
fecd2382 | 266 | #endif |
a39116f1 | 267 | if ((symbolP = symbol_find(sym_name)) != 0) { |
fecd2382 | 268 | #ifdef VMS |
a39116f1 RP |
269 | /* |
270 | * If the new symbol is .comm AND it has a size of zero, | |
271 | * we ignore it (i.e. the old symbol overrides it) | |
272 | */ | |
273 | if ((SEGMENT_TO_SYMBOL_TYPE((int) now_seg) == (N_UNDF | N_EXT)) && | |
274 | ((obstack_next_free(& frags) - frag_now->fr_literal) == 0)) | |
275 | return; | |
276 | /* | |
277 | * If the old symbol is .comm and it has a size of zero, | |
278 | * we override it with the new symbol value. | |
279 | */ | |
280 | if ((symbolP->sy_type == (N_UNDF | N_EXT)) | |
281 | && (S_GET_VALUE(symbolP) == 0)) { | |
282 | symbolP->sy_frag = frag_now; | |
283 | symbolP->sy_other = const_flag; | |
284 | S_SET_VALUE(symbolP, obstack_next_free(& frags) - frag_now->fr_literal); | |
285 | symbolP->sy_type |= SEGMENT_TO_SYMBOL_TYPE((int) now_seg); /* keep N_EXT bit */ | |
286 | return; | |
287 | } | |
fecd2382 | 288 | #endif /* VMS */ |
a39116f1 RP |
289 | /* |
290 | * Now check for undefined symbols | |
291 | */ | |
292 | if (!S_IS_DEFINED(symbolP)) { | |
293 | if (S_GET_VALUE(symbolP) == 0) { | |
294 | symbolP->sy_frag = frag_now; | |
fecd2382 | 295 | #ifdef VMS |
a39116f1 | 296 | symbolP->sy_other = const_flag; |
fecd2382 | 297 | #endif |
a39116f1 RP |
298 | S_SET_VALUE(symbolP, obstack_next_free(&frags) - frag_now->fr_literal); |
299 | S_SET_SEGMENT(symbolP, now_seg); | |
fecd2382 | 300 | #ifdef N_UNDF |
a39116f1 | 301 | know(N_UNDF == 0); |
fecd2382 | 302 | #endif /* if we have one, it better be zero. */ |
a39116f1 RP |
303 | |
304 | } else { | |
305 | /* | |
306 | * There are still several cases to check: | |
307 | * A .comm/.lcomm symbol being redefined as | |
308 | * initialized data is OK | |
309 | * A .comm/.lcomm symbol being redefined with | |
310 | * a larger size is also OK | |
311 | * | |
312 | * This only used to be allowed on VMS gas, but Sun cc | |
313 | * on the sparc also depends on it. | |
314 | */ | |
315 | /* char New_Type = SEGMENT_TO_SYMBOL_TYPE((int) now_seg); */ | |
a6c6eaf8 RP |
316 | #ifdef MANY_SEGMENTS |
317 | #define SEG_BSS SEG_E2 | |
318 | #define SEG_DATA SEG_E1 | |
319 | #endif | |
a39116f1 RP |
320 | |
321 | if (((!S_IS_DEBUG(symbolP) && !S_IS_DEFINED(symbolP) && S_IS_EXTERNAL(symbolP)) | |
322 | || (S_GET_SEGMENT(symbolP) == SEG_BSS)) | |
323 | && ((now_seg == SEG_DATA) | |
324 | || (now_seg == S_GET_SEGMENT(symbolP)))) { | |
325 | /* | |
326 | * Select which of the 2 cases this is | |
327 | */ | |
328 | if (now_seg != SEG_DATA) { | |
329 | /* | |
330 | * New .comm for prev .comm symbol. | |
331 | * If the new size is larger we just | |
332 | * change its value. If the new size | |
333 | * is smaller, we ignore this symbol | |
334 | */ | |
335 | if (S_GET_VALUE(symbolP) | |
336 | < ((unsigned) (obstack_next_free(& frags) - frag_now->fr_literal))) { | |
337 | S_SET_VALUE(symbolP, | |
338 | obstack_next_free(& frags) - | |
339 | frag_now->fr_literal); | |
340 | } | |
341 | } else { | |
342 | /* | |
343 | * It is a .comm/.lcomm being converted | |
344 | * to initialized data. | |
345 | */ | |
346 | symbolP->sy_frag = frag_now; | |
fecd2382 | 347 | #ifdef VMS |
a39116f1 | 348 | symbolP->sy_other = const_flag; |
fecd2382 | 349 | #endif /* VMS */ |
a39116f1 RP |
350 | S_SET_VALUE(symbolP, obstack_next_free(& frags) - frag_now->fr_literal); |
351 | S_SET_SEGMENT(symbolP, now_seg); /* keep N_EXT bit */ | |
352 | } | |
353 | } else { | |
fecd2382 | 354 | #ifdef OBJ_COFF |
a39116f1 RP |
355 | as_fatal("Symbol \"%s\" is already defined as \"%s\"/%d.", |
356 | sym_name, | |
357 | segment_name(S_GET_SEGMENT(symbolP)), | |
358 | S_GET_VALUE(symbolP)); | |
fecd2382 | 359 | #else /* OBJ_COFF */ |
a39116f1 RP |
360 | as_fatal("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%d.", |
361 | sym_name, | |
362 | segment_name(S_GET_SEGMENT(symbolP)), | |
363 | S_GET_OTHER(symbolP), S_GET_DESC(symbolP), | |
364 | S_GET_VALUE(symbolP)); | |
fecd2382 | 365 | #endif /* OBJ_COFF */ |
a39116f1 RP |
366 | } |
367 | } /* if the undefined symbol has no value */ | |
368 | } else | |
369 | { | |
370 | /* Don't blow up if the definition is the same */ | |
371 | if (!(frag_now == symbolP->sy_frag | |
372 | && S_GET_VALUE(symbolP) == obstack_next_free(&frags) - frag_now->fr_literal | |
373 | && S_GET_SEGMENT(symbolP) == now_seg) ) | |
374 | as_fatal("Symbol %s already defined.", sym_name); | |
375 | } /* if this symbol is not yet defined */ | |
376 | ||
377 | } else { | |
378 | symbolP = symbol_new(sym_name, | |
379 | now_seg, | |
380 | (valueT)(obstack_next_free(&frags)-frag_now->fr_literal), | |
381 | frag_now); | |
fecd2382 | 382 | #ifdef VMS |
a39116f1 | 383 | S_SET_OTHER(symbolP, const_flag); |
fecd2382 | 384 | #endif /* VMS */ |
a39116f1 RP |
385 | |
386 | symbol_table_insert(symbolP); | |
387 | } /* if we have seen this symbol before */ | |
388 | ||
389 | return; | |
fecd2382 RP |
390 | } /* colon() */ |
391 | ||
392 | \f | |
393 | /* | |
394 | * symbol_table_insert() | |
395 | * | |
396 | * Die if we can't insert the symbol. | |
397 | * | |
398 | */ | |
399 | ||
400 | void symbol_table_insert(symbolP) | |
401 | symbolS *symbolP; | |
402 | { | |
403 | register char *error_string; | |
404 | ||
405 | know(symbolP); | |
406 | know(S_GET_NAME(symbolP)); | |
407 | ||
408 | if (*(error_string = hash_jam(sy_hash, S_GET_NAME(symbolP), (char *)symbolP))) { | |
409 | as_fatal("Inserting \"%s\" into symbol table failed: %s", | |
410 | S_GET_NAME(symbolP), error_string); | |
411 | } /* on error */ | |
412 | } /* symbol_table_insert() */ | |
413 | \f | |
414 | /* | |
415 | * symbol_find_or_make() | |
416 | * | |
417 | * If a symbol name does not exist, create it as undefined, and insert | |
418 | * it into the symbol table. Return a pointer to it. | |
419 | */ | |
420 | symbolS *symbol_find_or_make(name) | |
421 | char *name; | |
422 | { | |
423 | register symbolS *symbolP; | |
424 | ||
425 | symbolP = symbol_find(name); | |
426 | ||
427 | if (symbolP == NULL) { | |
428 | symbolP = symbol_make(name); | |
a39116f1 | 429 | |
fecd2382 RP |
430 | symbol_table_insert(symbolP); |
431 | } /* if symbol wasn't found */ | |
a39116f1 | 432 | |
fecd2382 RP |
433 | return(symbolP); |
434 | } /* symbol_find_or_make() */ | |
435 | ||
436 | symbolS *symbol_make(name) | |
437 | char *name; | |
438 | { | |
439 | symbolS *symbolP; | |
a39116f1 | 440 | |
fecd2382 RP |
441 | /* Let the machine description default it, e.g. for register names. */ |
442 | symbolP = md_undefined_symbol(name); | |
443 | ||
444 | if (!symbolP) { | |
445 | symbolP = symbol_new(name, | |
446 | SEG_UNKNOWN, | |
447 | 0, | |
448 | &zero_address_frag); | |
449 | } /* if md didn't build us a symbol */ | |
a39116f1 | 450 | |
fecd2382 RP |
451 | return(symbolP); |
452 | } /* symbol_make() */ | |
453 | ||
454 | /* | |
455 | * symbol_find() | |
456 | * | |
457 | * Implement symbol table lookup. | |
458 | * In: A symbol's name as a string: '\0' can't be part of a symbol name. | |
459 | * Out: NULL if the name was not in the symbol table, else the address | |
460 | * of a struct symbol associated with that name. | |
461 | */ | |
462 | ||
463 | symbolS *symbol_find(name) | |
464 | char *name; | |
465 | { | |
a6c6eaf8 RP |
466 | #ifdef STRIP_UNDERSCORE |
467 | return(symbol_find_base(name, 1)); | |
468 | #else /* STRIP_UNDERSCORE */ | |
7d890909 | 469 | return(symbol_find_base(name, 0)); |
fecd2382 | 470 | #endif /* STRIP_UNDERSCORE */ |
a6c6eaf8 | 471 | } /* symbol_find() */ |
fecd2382 RP |
472 | |
473 | symbolS *symbol_find_base(name, strip_underscore) | |
474 | char *name; | |
475 | int strip_underscore; | |
476 | { | |
a39116f1 RP |
477 | if(strip_underscore && *name == '_') name++; |
478 | return ( (symbolS *) hash_find( sy_hash, name )); | |
fecd2382 RP |
479 | } |
480 | ||
481 | /* | |
482 | * Once upon a time, symbols were kept in a singly linked list. At | |
483 | * least coff needs to be able to rearrange them from time to time, for | |
484 | * which a doubly linked list is much more convenient. Loic did these | |
485 | * as macros which seemed dangerous to me so they're now functions. | |
486 | * xoxorich. | |
487 | */ | |
488 | ||
489 | /* Link symbol ADDME after symbol TARGET in the chain. */ | |
490 | void symbol_append(addme, target, rootPP, lastPP) | |
491 | symbolS *addme; | |
492 | symbolS *target; | |
493 | symbolS **rootPP; | |
494 | symbolS **lastPP; | |
495 | { | |
496 | if (target == NULL) { | |
497 | know(*rootPP == NULL); | |
498 | know(*lastPP == NULL); | |
499 | *rootPP = addme; | |
500 | *lastPP = addme; | |
501 | return; | |
502 | } /* if the list is empty */ | |
a39116f1 | 503 | |
fecd2382 RP |
504 | if (target->sy_next != NULL) { |
505 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
506 | target->sy_next->sy_previous = addme; | |
507 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
508 | } else { | |
509 | know(*lastPP == target); | |
510 | *lastPP = addme; | |
511 | } /* if we have a next */ | |
512 | ||
513 | addme->sy_next = target->sy_next; | |
514 | target->sy_next = addme; | |
a39116f1 | 515 | |
fecd2382 RP |
516 | #ifdef SYMBOLS_NEED_BACKPOINTERS |
517 | addme->sy_previous = target; | |
518 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
a39116f1 | 519 | |
fecd2382 | 520 | #ifdef DEBUG |
a39116f1 | 521 | /* verify_symbol_chain(*rootPP, *lastPP); */ |
fecd2382 | 522 | #endif /* DEBUG */ |
a39116f1 | 523 | |
fecd2382 RP |
524 | return; |
525 | } /* symbol_append() */ | |
526 | ||
527 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
528 | /* Remove SYMBOLP from the list. */ | |
529 | void symbol_remove(symbolP, rootPP, lastPP) | |
530 | symbolS *symbolP; | |
531 | symbolS **rootPP; | |
532 | symbolS **lastPP; | |
533 | { | |
534 | if (symbolP == *rootPP) { | |
535 | *rootPP = symbolP->sy_next; | |
536 | } /* if it was the root */ | |
a39116f1 | 537 | |
fecd2382 RP |
538 | if (symbolP == *lastPP) { |
539 | *lastPP = symbolP->sy_previous; | |
540 | } /* if it was the tail */ | |
a39116f1 | 541 | |
fecd2382 RP |
542 | if (symbolP->sy_next != NULL) { |
543 | symbolP->sy_next->sy_previous = symbolP->sy_previous; | |
544 | } /* if not last */ | |
545 | ||
546 | if (symbolP->sy_previous != NULL) { | |
547 | symbolP->sy_previous->sy_next = symbolP->sy_next; | |
548 | } /* if not first */ | |
549 | ||
550 | #ifdef DEBUG | |
551 | verify_symbol_chain(*rootPP, *lastPP); | |
552 | #endif /* DEBUG */ | |
a39116f1 | 553 | |
fecd2382 RP |
554 | return; |
555 | } /* symbol_remove() */ | |
556 | ||
557 | /* Set the chain pointers of SYMBOL to null. */ | |
558 | void symbol_clear_list_pointers(symbolP) | |
559 | symbolS *symbolP; | |
560 | { | |
a39116f1 RP |
561 | symbolP->sy_next = NULL; |
562 | symbolP->sy_previous = NULL; | |
fecd2382 RP |
563 | } /* symbol_clear_list_pointers() */ |
564 | ||
565 | /* Link symbol ADDME before symbol TARGET in the chain. */ | |
566 | void symbol_insert(addme, target, rootPP, lastPP) | |
567 | symbolS *addme; | |
568 | symbolS *target; | |
569 | symbolS **rootPP; | |
570 | symbolS **lastPP; | |
571 | { | |
a39116f1 RP |
572 | if (target->sy_previous != NULL) { |
573 | target->sy_previous->sy_next = addme; | |
574 | } else { | |
575 | know(*rootPP == target); | |
576 | *rootPP = addme; | |
577 | } /* if not first */ | |
578 | ||
579 | addme->sy_previous = target->sy_previous; | |
580 | target->sy_previous = addme; | |
581 | addme->sy_next = target; | |
582 | ||
fecd2382 | 583 | #ifdef DEBUG |
a39116f1 | 584 | verify_symbol_chain(*rootPP, *lastPP); |
fecd2382 | 585 | #endif /* DEBUG */ |
a39116f1 RP |
586 | |
587 | return; | |
fecd2382 RP |
588 | } /* symbol_insert() */ |
589 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
590 | ||
591 | void verify_symbol_chain(rootP, lastP) | |
592 | symbolS *rootP; | |
593 | symbolS *lastP; | |
594 | { | |
595 | symbolS *symbolP = rootP; | |
a39116f1 | 596 | |
fecd2382 RP |
597 | if (symbolP == NULL) { |
598 | return; | |
599 | } /* empty chain */ | |
a39116f1 | 600 | |
fecd2382 RP |
601 | for ( ; symbol_next(symbolP) != NULL; symbolP = symbol_next(symbolP)) { |
602 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
603 | /*$if (symbolP->sy_previous) { | |
a39116f1 RP |
604 | know(symbolP->sy_previous->sy_next == symbolP); |
605 | } else { | |
606 | know(symbolP == rootP); | |
607 | }$*/ /* both directions */ | |
fecd2382 RP |
608 | know(symbolP->sy_next->sy_previous == symbolP); |
609 | #else /* SYMBOLS_NEED_BACKPOINTERS */ | |
610 | ; | |
611 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
612 | } /* verify pointers */ | |
a39116f1 | 613 | |
fecd2382 | 614 | know(lastP == symbolP); |
a39116f1 | 615 | |
fecd2382 RP |
616 | return; |
617 | } /* verify_symbol_chain() */ | |
618 | ||
619 | ||
a6c6eaf8 RP |
620 | /* |
621 | * decode name that may have been generated by local_label_name() above. If | |
622 | * the name wasn't generated by local_label_name(), then return it unaltered. | |
623 | * This is used for error messages. | |
624 | */ | |
a39116f1 | 625 | |
a6c6eaf8 RP |
626 | char *decode_local_label_name(s) |
627 | char *s; | |
628 | { | |
629 | char *symbol_decode; | |
630 | int label_number; | |
a39116f1 | 631 | /* int label_version; */ |
a6c6eaf8 | 632 | char *message_format = "\"%d\" (instance number %s of a local label)"; |
a39116f1 | 633 | |
a6c6eaf8 RP |
634 | if (s[0] != 'L' |
635 | || s[2] != 1) { | |
636 | return(s); | |
637 | } /* not a local_label_name() generated name. */ | |
a39116f1 | 638 | |
a6c6eaf8 | 639 | label_number = s[1] - '0'; |
a39116f1 | 640 | |
a6c6eaf8 | 641 | (void) sprintf(symbol_decode = obstack_alloc(¬es, strlen(s + 3) + strlen(message_format) + 10), |
a39116f1 RP |
642 | message_format, label_number, s + 3); |
643 | ||
a6c6eaf8 RP |
644 | return(symbol_decode); |
645 | } /* decode_local_label_name() */ | |
646 | ||
647 | ||
fecd2382 RP |
648 | /* |
649 | * Local Variables: | |
650 | * comment-column: 0 | |
651 | * fill-column: 131 | |
652 | * End: | |
653 | */ | |
654 | ||
8b228fe9 | 655 | /* end of symbols.c */ |