* symbols.c (symbol_create): If bfd_make_empty_symbol fails, call
[binutils-gdb.git] / gas / symbols.c
1 /* symbols.c -symbol table-
2 Copyright (C) 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* #define DEBUG_SYMS / * to debug symbol list maintenance */
22
23 #include <ctype.h>
24
25 #include "as.h"
26
27 #include "obstack.h" /* For "symbols.h" */
28 #include "subsegs.h"
29
30 /* This is non-zero if symbols are case sensitive, which is the
31 default. */
32 int symbols_case_sensitive = 1;
33
34 #ifndef WORKING_DOT_WORD
35 extern int new_broken_words;
36 #endif
37
38 /* symbol-name => struct symbol pointer */
39 static struct hash_control *sy_hash;
40
41 /* Below are commented in "symbols.h". */
42 symbolS *symbol_rootP;
43 symbolS *symbol_lastP;
44 symbolS abs_symbol;
45
46 #ifdef DEBUG_SYMS
47 #define debug_verify_symchain verify_symbol_chain
48 #else
49 #define debug_verify_symchain (void)
50 #endif
51
52 struct obstack notes;
53
54 static void fb_label_init PARAMS ((void));
55
56 /* symbol_new()
57
58 Return a pointer to a new symbol. Die if we can't make a new
59 symbol. Fill in the symbol's values. Add symbol to end of symbol
60 chain.
61
62 This function should be called in the general case of creating a
63 symbol. However, if the output file symbol table has already been
64 set, and you are certain that this symbol won't be wanted in the
65 output file, you can call symbol_create. */
66
67 symbolS *
68 symbol_new (name, segment, valu, frag)
69 const char *name;
70 segT segment;
71 valueT valu;
72 fragS *frag;
73 {
74 symbolS *symbolP = symbol_create (name, segment, valu, frag);
75
76 /*
77 * Link to end of symbol chain.
78 */
79 #ifdef BFD_ASSEMBLER
80 {
81 extern int symbol_table_frozen;
82 if (symbol_table_frozen)
83 abort ();
84 }
85 #endif
86 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
87 debug_verify_symchain (symbol_rootP, symbol_lastP);
88
89 return symbolP;
90 }
91
92 symbolS *
93 symbol_create (name, segment, valu, frag)
94 const char *name; /* It is copied, the caller can destroy/modify */
95 segT segment; /* Segment identifier (SEG_<something>) */
96 valueT valu; /* Symbol value */
97 fragS *frag; /* Associated fragment */
98 {
99 unsigned int name_length;
100 char *preserved_copy_of_name;
101 symbolS *symbolP;
102
103 name_length = strlen (name) + 1; /* +1 for \0 */
104 obstack_grow (&notes, name, name_length);
105 preserved_copy_of_name = obstack_finish (&notes);
106 #ifdef STRIP_UNDERSCORE
107 if (preserved_copy_of_name[0] == '_')
108 preserved_copy_of_name++;
109 #endif
110
111 #ifdef tc_canonicalize_symbol_name
112 preserved_copy_of_name =
113 tc_canonicalize_symbol_name (preserved_copy_of_name);
114 #endif
115
116 if (! symbols_case_sensitive)
117 {
118 unsigned char *s;
119
120 for (s = (unsigned char *) preserved_copy_of_name; *s != '\0'; s++)
121 if (islower (*s))
122 *s = toupper (*s);
123 }
124
125 symbolP = (symbolS *) obstack_alloc (&notes, sizeof (symbolS));
126
127 /* symbol must be born in some fixed state. This seems as good as any. */
128 memset (symbolP, 0, sizeof (symbolS));
129
130 #ifdef BFD_ASSEMBLER
131 symbolP->bsym = bfd_make_empty_symbol (stdoutput);
132 if (symbolP->bsym == NULL)
133 as_perror ("%s", "bfd_make_empty_symbol");
134 symbolP->bsym->udata.p = (PTR) symbolP;
135 #endif
136 S_SET_NAME (symbolP, preserved_copy_of_name);
137
138 S_SET_SEGMENT (symbolP, segment);
139 S_SET_VALUE (symbolP, valu);
140 symbol_clear_list_pointers (symbolP);
141
142 symbolP->sy_frag = frag;
143 #ifndef BFD_ASSEMBLER
144 symbolP->sy_number = ~0;
145 symbolP->sy_name_offset = (unsigned int) ~0;
146 #endif
147
148 obj_symbol_new_hook (symbolP);
149
150 #ifdef tc_symbol_new_hook
151 tc_symbol_new_hook (symbolP);
152 #endif
153
154 return symbolP;
155 }
156 \f
157
158 /*
159 * colon()
160 *
161 * We have just seen "<name>:".
162 * Creates a struct symbol unless it already exists.
163 *
164 * Gripes if we are redefining a symbol incompatibly (and ignores it).
165 *
166 */
167 symbolS *
168 colon (sym_name) /* just seen "x:" - rattle symbols & frags */
169 const char *sym_name; /* symbol name, as a cannonical string */
170 /* We copy this string: OK to alter later. */
171 {
172 register symbolS *symbolP; /* symbol we are working with */
173
174 /* Sun local labels go out of scope whenever a non-local symbol is
175 defined. */
176 if (LOCAL_LABELS_DOLLAR && *sym_name != 'L')
177 dollar_label_clear ();
178
179 #ifndef WORKING_DOT_WORD
180 if (new_broken_words)
181 {
182 struct broken_word *a;
183 int possible_bytes;
184 fragS *frag_tmp;
185 char *frag_opcode;
186
187 extern const int md_short_jump_size;
188 extern const int md_long_jump_size;
189 possible_bytes = (md_short_jump_size
190 + new_broken_words * md_long_jump_size);
191
192 frag_tmp = frag_now;
193 frag_opcode = frag_var (rs_broken_word,
194 possible_bytes,
195 possible_bytes,
196 (relax_substateT) 0,
197 (symbolS *) broken_words,
198 0L,
199 NULL);
200
201 /* We want to store the pointer to where to insert the jump table in the
202 fr_opcode of the rs_broken_word frag. This requires a little
203 hackery. */
204 while (frag_tmp
205 && (frag_tmp->fr_type != rs_broken_word
206 || frag_tmp->fr_opcode))
207 frag_tmp = frag_tmp->fr_next;
208 know (frag_tmp);
209 frag_tmp->fr_opcode = frag_opcode;
210 new_broken_words = 0;
211
212 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word)
213 a->dispfrag = frag_tmp;
214 }
215 #endif /* WORKING_DOT_WORD */
216
217 if ((symbolP = symbol_find (sym_name)) != 0)
218 {
219 #ifdef RESOLVE_SYMBOL_REDEFINITION
220 if (RESOLVE_SYMBOL_REDEFINITION (symbolP))
221 return symbolP;
222 #endif
223 /*
224 * Now check for undefined symbols
225 */
226 if (!S_IS_DEFINED (symbolP))
227 {
228 if (S_GET_VALUE (symbolP) == 0)
229 {
230 symbolP->sy_frag = frag_now;
231 #ifdef OBJ_VMS
232 S_GET_OTHER(symbolP) = const_flag;
233 #endif
234 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
235 S_SET_SEGMENT (symbolP, now_seg);
236 #ifdef N_UNDF
237 know (N_UNDF == 0);
238 #endif /* if we have one, it better be zero. */
239
240 }
241 else
242 {
243 /*
244 * There are still several cases to check:
245 * A .comm/.lcomm symbol being redefined as
246 * initialized data is OK
247 * A .comm/.lcomm symbol being redefined with
248 * a larger size is also OK
249 *
250 * This only used to be allowed on VMS gas, but Sun cc
251 * on the sparc also depends on it.
252 */
253
254 if (((!S_IS_DEBUG (symbolP)
255 && !S_IS_DEFINED (symbolP)
256 && S_IS_EXTERNAL (symbolP))
257 || S_GET_SEGMENT (symbolP) == bss_section)
258 && (now_seg == data_section
259 || now_seg == S_GET_SEGMENT (symbolP)))
260 {
261 /*
262 * Select which of the 2 cases this is
263 */
264 if (now_seg != data_section)
265 {
266 /*
267 * New .comm for prev .comm symbol.
268 * If the new size is larger we just
269 * change its value. If the new size
270 * is smaller, we ignore this symbol
271 */
272 if (S_GET_VALUE (symbolP)
273 < ((unsigned) frag_now_fix ()))
274 {
275 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
276 }
277 }
278 else
279 {
280 /* It is a .comm/.lcomm being converted to initialized
281 data. */
282 symbolP->sy_frag = frag_now;
283 #ifdef OBJ_VMS
284 S_GET_OTHER(symbolP) = const_flag;
285 #endif /* OBJ_VMS */
286 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
287 S_SET_SEGMENT (symbolP, now_seg); /* keep N_EXT bit */
288 }
289 }
290 else
291 {
292 #if defined (S_GET_OTHER) && defined (S_GET_DESC)
293 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%ld.",
294 sym_name,
295 segment_name (S_GET_SEGMENT (symbolP)),
296 S_GET_OTHER (symbolP), S_GET_DESC (symbolP),
297 (long) S_GET_VALUE (symbolP));
298 #else
299 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%ld.",
300 sym_name,
301 segment_name (S_GET_SEGMENT (symbolP)),
302 (long) S_GET_VALUE (symbolP));
303 #endif
304 }
305 } /* if the undefined symbol has no value */
306 }
307 else
308 {
309 /* Don't blow up if the definition is the same */
310 if (!(frag_now == symbolP->sy_frag
311 && S_GET_VALUE (symbolP) == frag_now_fix ()
312 && S_GET_SEGMENT (symbolP) == now_seg))
313 as_fatal ("Symbol %s already defined.", sym_name);
314 } /* if this symbol is not yet defined */
315
316 }
317 else
318 {
319 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (),
320 frag_now);
321 #ifdef OBJ_VMS
322 S_SET_OTHER (symbolP, const_flag);
323 #endif /* OBJ_VMS */
324
325 symbol_table_insert (symbolP);
326 } /* if we have seen this symbol before */
327
328 if (mri_common_symbol != NULL)
329 {
330 /* This symbol is actually being defined within an MRI common
331 section. This requires special handling. */
332 symbolP->sy_value.X_op = O_symbol;
333 symbolP->sy_value.X_add_symbol = mri_common_symbol;
334 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol);
335 symbolP->sy_frag = &zero_address_frag;
336 S_SET_SEGMENT (symbolP, expr_section);
337 symbolP->sy_mri_common = 1;
338 }
339
340 #ifdef tc_frob_label
341 tc_frob_label (symbolP);
342 #endif
343
344 return symbolP;
345 }
346 \f
347
348 /*
349 * symbol_table_insert()
350 *
351 * Die if we can't insert the symbol.
352 *
353 */
354
355 void
356 symbol_table_insert (symbolP)
357 symbolS *symbolP;
358 {
359 register const char *error_string;
360
361 know (symbolP);
362 know (S_GET_NAME (symbolP));
363
364 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
365 {
366 as_fatal ("Inserting \"%s\" into symbol table failed: %s",
367 S_GET_NAME (symbolP), error_string);
368 } /* on error */
369 } /* symbol_table_insert() */
370 \f
371 /*
372 * symbol_find_or_make()
373 *
374 * If a symbol name does not exist, create it as undefined, and insert
375 * it into the symbol table. Return a pointer to it.
376 */
377 symbolS *
378 symbol_find_or_make (name)
379 const char *name;
380 {
381 register symbolS *symbolP;
382
383 symbolP = symbol_find (name);
384
385 if (symbolP == NULL)
386 {
387 symbolP = symbol_make (name);
388
389 symbol_table_insert (symbolP);
390 } /* if symbol wasn't found */
391
392 return (symbolP);
393 } /* symbol_find_or_make() */
394
395 symbolS *
396 symbol_make (name)
397 CONST char *name;
398 {
399 symbolS *symbolP;
400
401 /* Let the machine description default it, e.g. for register names. */
402 symbolP = md_undefined_symbol ((char *) name);
403
404 if (!symbolP)
405 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag);
406
407 return (symbolP);
408 } /* symbol_make() */
409
410 /*
411 * symbol_find()
412 *
413 * Implement symbol table lookup.
414 * In: A symbol's name as a string: '\0' can't be part of a symbol name.
415 * Out: NULL if the name was not in the symbol table, else the address
416 * of a struct symbol associated with that name.
417 */
418
419 symbolS *
420 symbol_find (name)
421 CONST char *name;
422 {
423 #ifdef STRIP_UNDERSCORE
424 return (symbol_find_base (name, 1));
425 #else /* STRIP_UNDERSCORE */
426 return (symbol_find_base (name, 0));
427 #endif /* STRIP_UNDERSCORE */
428 } /* symbol_find() */
429
430 symbolS *
431 symbol_find_base (name, strip_underscore)
432 CONST char *name;
433 int strip_underscore;
434 {
435 if (strip_underscore && *name == '_')
436 name++;
437
438 #ifdef tc_canonicalize_symbol_name
439 {
440 char *copy;
441
442 copy = (char *) alloca (strlen (name) + 1);
443 strcpy (copy, name);
444 name = tc_canonicalize_symbol_name (copy);
445 }
446 #endif
447
448 if (! symbols_case_sensitive)
449 {
450 unsigned char *copy;
451
452 copy = (unsigned char *) alloca (strlen (name) + 1);
453 name = (const char *) copy;
454 for (; *copy != '\0'; copy++)
455 if (islower (*copy))
456 *copy = toupper (*copy);
457 }
458
459 return ((symbolS *) hash_find (sy_hash, name));
460 }
461
462 /*
463 * Once upon a time, symbols were kept in a singly linked list. At
464 * least coff needs to be able to rearrange them from time to time, for
465 * which a doubly linked list is much more convenient. Loic did these
466 * as macros which seemed dangerous to me so they're now functions.
467 * xoxorich.
468 */
469
470 /* Link symbol ADDME after symbol TARGET in the chain. */
471 void
472 symbol_append (addme, target, rootPP, lastPP)
473 symbolS *addme;
474 symbolS *target;
475 symbolS **rootPP;
476 symbolS **lastPP;
477 {
478 if (target == NULL)
479 {
480 know (*rootPP == NULL);
481 know (*lastPP == NULL);
482 *rootPP = addme;
483 *lastPP = addme;
484 return;
485 } /* if the list is empty */
486
487 if (target->sy_next != NULL)
488 {
489 #ifdef SYMBOLS_NEED_BACKPOINTERS
490 target->sy_next->sy_previous = addme;
491 #endif /* SYMBOLS_NEED_BACKPOINTERS */
492 }
493 else
494 {
495 know (*lastPP == target);
496 *lastPP = addme;
497 } /* if we have a next */
498
499 addme->sy_next = target->sy_next;
500 target->sy_next = addme;
501
502 #ifdef SYMBOLS_NEED_BACKPOINTERS
503 addme->sy_previous = target;
504 #endif /* SYMBOLS_NEED_BACKPOINTERS */
505 }
506
507 /* Set the chain pointers of SYMBOL to null. */
508 void
509 symbol_clear_list_pointers (symbolP)
510 symbolS *symbolP;
511 {
512 symbolP->sy_next = NULL;
513 #ifdef SYMBOLS_NEED_BACKPOINTERS
514 symbolP->sy_previous = NULL;
515 #endif
516 }
517
518 #ifdef SYMBOLS_NEED_BACKPOINTERS
519 /* Remove SYMBOLP from the list. */
520 void
521 symbol_remove (symbolP, rootPP, lastPP)
522 symbolS *symbolP;
523 symbolS **rootPP;
524 symbolS **lastPP;
525 {
526 if (symbolP == *rootPP)
527 {
528 *rootPP = symbolP->sy_next;
529 } /* if it was the root */
530
531 if (symbolP == *lastPP)
532 {
533 *lastPP = symbolP->sy_previous;
534 } /* if it was the tail */
535
536 if (symbolP->sy_next != NULL)
537 {
538 symbolP->sy_next->sy_previous = symbolP->sy_previous;
539 } /* if not last */
540
541 if (symbolP->sy_previous != NULL)
542 {
543 symbolP->sy_previous->sy_next = symbolP->sy_next;
544 } /* if not first */
545
546 debug_verify_symchain (*rootPP, *lastPP);
547 }
548
549 /* Link symbol ADDME before symbol TARGET in the chain. */
550 void
551 symbol_insert (addme, target, rootPP, lastPP)
552 symbolS *addme;
553 symbolS *target;
554 symbolS **rootPP;
555 symbolS **lastPP;
556 {
557 if (target->sy_previous != NULL)
558 {
559 target->sy_previous->sy_next = addme;
560 }
561 else
562 {
563 know (*rootPP == target);
564 *rootPP = addme;
565 } /* if not first */
566
567 addme->sy_previous = target->sy_previous;
568 target->sy_previous = addme;
569 addme->sy_next = target;
570
571 debug_verify_symchain (*rootPP, *lastPP);
572 }
573
574 #endif /* SYMBOLS_NEED_BACKPOINTERS */
575
576 void
577 verify_symbol_chain (rootP, lastP)
578 symbolS *rootP;
579 symbolS *lastP;
580 {
581 symbolS *symbolP = rootP;
582
583 if (symbolP == NULL)
584 return;
585
586 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP))
587 {
588 #ifdef SYMBOLS_NEED_BACKPOINTERS
589 know (symbolP->sy_next->sy_previous == symbolP);
590 #else
591 /* Walk the list anyways, to make sure pointers are still good. */
592 ;
593 #endif /* SYMBOLS_NEED_BACKPOINTERS */
594 }
595
596 assert (lastP == symbolP);
597 }
598
599 void
600 verify_symbol_chain_2 (sym)
601 symbolS *sym;
602 {
603 symbolS *p = sym, *n = sym;
604 #ifdef SYMBOLS_NEED_BACKPOINTERS
605 while (symbol_previous (p))
606 p = symbol_previous (p);
607 #endif
608 while (symbol_next (n))
609 n = symbol_next (n);
610 verify_symbol_chain (p, n);
611 }
612
613 /* Resolve the value of a symbol. This is called during the final
614 pass over the symbol table to resolve any symbols with complex
615 values. */
616
617 void
618 resolve_symbol_value (symp)
619 symbolS *symp;
620 {
621 int resolved;
622
623 if (symp->sy_resolved)
624 return;
625
626 resolved = 0;
627
628 if (symp->sy_resolving)
629 {
630 as_bad ("Symbol definition loop encountered at %s",
631 S_GET_NAME (symp));
632 S_SET_VALUE (symp, (valueT) 0);
633 resolved = 1;
634 }
635 else
636 {
637 offsetT left, right, val;
638 segT seg_left, seg_right;
639
640 symp->sy_resolving = 1;
641
642 reduce:
643 switch (symp->sy_value.X_op)
644 {
645 case O_absent:
646 S_SET_VALUE (symp, 0);
647 /* Fall through. */
648 case O_constant:
649 S_SET_VALUE (symp, S_GET_VALUE (symp) + symp->sy_frag->fr_address);
650 if (S_GET_SEGMENT (symp) == expr_section)
651 S_SET_SEGMENT (symp, absolute_section);
652 resolved = 1;
653 break;
654
655 case O_symbol:
656 resolve_symbol_value (symp->sy_value.X_add_symbol);
657
658 if (symp->sy_mri_common)
659 {
660 /* This is a symbol inside an MRI common section. The
661 relocation routines are going to handle it specially.
662 Don't change the value. */
663 S_SET_VALUE (symp, symp->sy_value.X_add_number);
664 resolved = symp->sy_value.X_add_symbol->sy_resolved;
665 break;
666 }
667
668 if (symp->sy_value.X_add_number == 0)
669 copy_symbol_attributes (symp, symp->sy_value.X_add_symbol);
670
671 S_SET_VALUE (symp,
672 (symp->sy_value.X_add_number
673 + symp->sy_frag->fr_address
674 + S_GET_VALUE (symp->sy_value.X_add_symbol)));
675 if (S_GET_SEGMENT (symp) == expr_section
676 || S_GET_SEGMENT (symp) == undefined_section)
677 S_SET_SEGMENT (symp,
678 S_GET_SEGMENT (symp->sy_value.X_add_symbol));
679
680 /* If we have equated this symbol to an undefined symbol, we
681 keep X_op set to O_symbol. This permits the routine
682 which writes out relocation to detect this case, and
683 convert the relocation to be against the symbol to which
684 this symbol is equated. */
685 if (! S_IS_DEFINED (symp) || S_IS_COMMON (symp))
686 symp->sy_value.X_op = O_symbol;
687
688 resolved = symp->sy_value.X_add_symbol->sy_resolved;
689 break;
690
691 case O_uminus:
692 case O_bit_not:
693 case O_logical_not:
694 resolve_symbol_value (symp->sy_value.X_add_symbol);
695 if (symp->sy_value.X_op == O_uminus)
696 val = - S_GET_VALUE (symp->sy_value.X_add_symbol);
697 else if (symp->sy_value.X_op == O_logical_not)
698 val = ! S_GET_VALUE (symp->sy_value.X_add_symbol);
699 else
700 val = ~ S_GET_VALUE (symp->sy_value.X_add_symbol);
701 S_SET_VALUE (symp,
702 (val
703 + symp->sy_value.X_add_number
704 + symp->sy_frag->fr_address));
705 if (S_GET_SEGMENT (symp) == expr_section
706 || S_GET_SEGMENT (symp) == undefined_section)
707 S_SET_SEGMENT (symp, absolute_section);
708 resolved = symp->sy_value.X_add_symbol->sy_resolved;
709 break;
710
711 case O_add:
712 resolve_symbol_value (symp->sy_value.X_add_symbol);
713 resolve_symbol_value (symp->sy_value.X_op_symbol);
714 seg_left = S_GET_SEGMENT (symp->sy_value.X_add_symbol);
715 seg_right = S_GET_SEGMENT (symp->sy_value.X_op_symbol);
716 /* This case comes up with PIC support. */
717 {
718 symbolS *s_left = symp->sy_value.X_add_symbol;
719 symbolS *s_right = symp->sy_value.X_op_symbol;
720
721 if (seg_left == absolute_section)
722 {
723 symbolS *t;
724 segT ts;
725 t = s_left;
726 s_left = s_right;
727 s_right = t;
728 ts = seg_left;
729 seg_left = seg_right;
730 seg_right = ts;
731 }
732 if (seg_right == absolute_section
733 && s_right->sy_resolved)
734 {
735 symp->sy_value.X_add_number += S_GET_VALUE (s_right);
736 symp->sy_value.X_op_symbol = 0;
737 symp->sy_value.X_add_symbol = s_left;
738 symp->sy_value.X_op = O_symbol;
739 goto reduce;
740 }
741 }
742 /* fall through */
743
744 case O_multiply:
745 case O_divide:
746 case O_modulus:
747 case O_left_shift:
748 case O_right_shift:
749 case O_bit_inclusive_or:
750 case O_bit_or_not:
751 case O_bit_exclusive_or:
752 case O_bit_and:
753 case O_subtract:
754 case O_eq:
755 case O_ne:
756 case O_lt:
757 case O_le:
758 case O_ge:
759 case O_gt:
760 case O_logical_and:
761 case O_logical_or:
762 resolve_symbol_value (symp->sy_value.X_add_symbol);
763 resolve_symbol_value (symp->sy_value.X_op_symbol);
764 seg_left = S_GET_SEGMENT (symp->sy_value.X_add_symbol);
765 seg_right = S_GET_SEGMENT (symp->sy_value.X_op_symbol);
766 if (seg_left != seg_right
767 && seg_left != undefined_section
768 && seg_right != undefined_section)
769 as_bad ("%s is operation on symbols in different sections",
770 S_GET_NAME (symp));
771 if ((S_GET_SEGMENT (symp->sy_value.X_add_symbol)
772 != absolute_section)
773 && symp->sy_value.X_op != O_subtract)
774 as_bad ("%s is illegal operation on non-absolute symbols",
775 S_GET_NAME (symp));
776 left = S_GET_VALUE (symp->sy_value.X_add_symbol);
777 right = S_GET_VALUE (symp->sy_value.X_op_symbol);
778 switch (symp->sy_value.X_op)
779 {
780 case O_multiply: val = left * right; break;
781 case O_divide: val = left / right; break;
782 case O_modulus: val = left % right; break;
783 case O_left_shift: val = left << right; break;
784 case O_right_shift: val = left >> right; break;
785 case O_bit_inclusive_or: val = left | right; break;
786 case O_bit_or_not: val = left |~ right; break;
787 case O_bit_exclusive_or: val = left ^ right; break;
788 case O_bit_and: val = left & right; break;
789 case O_add: val = left + right; break;
790 case O_subtract: val = left - right; break;
791 case O_eq: val = left == right ? ~ (offsetT) 0 : 0;
792 case O_ne: val = left != right ? ~ (offsetT) 0 : 0;
793 case O_lt: val = left < right ? ~ (offsetT) 0 : 0;
794 case O_le: val = left <= right ? ~ (offsetT) 0 : 0;
795 case O_ge: val = left >= right ? ~ (offsetT) 0 : 0;
796 case O_gt: val = left > right ? ~ (offsetT) 0 : 0;
797 case O_logical_and: val = left && right; break;
798 case O_logical_or: val = left || right; break;
799 default: abort ();
800 }
801 S_SET_VALUE (symp,
802 (symp->sy_value.X_add_number
803 + symp->sy_frag->fr_address
804 + val));
805 if (S_GET_SEGMENT (symp) == expr_section
806 || S_GET_SEGMENT (symp) == undefined_section)
807 S_SET_SEGMENT (symp, absolute_section);
808 resolved = (symp->sy_value.X_add_symbol->sy_resolved
809 && symp->sy_value.X_op_symbol->sy_resolved);
810 break;
811
812 case O_register:
813 case O_big:
814 case O_illegal:
815 /* Give an error (below) if not in expr_section. We don't
816 want to worry about expr_section symbols, because they
817 are fictional (they are created as part of expression
818 resolution), and any problems may not actually mean
819 anything. */
820 break;
821 }
822 }
823
824 /* Don't worry if we can't resolve an expr_section symbol. */
825 if (resolved)
826 symp->sy_resolved = 1;
827 else if (S_GET_SEGMENT (symp) != expr_section)
828 {
829 as_bad ("can't resolve value for symbol \"%s\"", S_GET_NAME (symp));
830 symp->sy_resolved = 1;
831 }
832 }
833
834 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
835 They are *really* local. That is, they go out of scope whenever we see a
836 label that isn't local. Also, like fb labels, there can be multiple
837 instances of a dollar label. Therefor, we name encode each instance with
838 the instance number, keep a list of defined symbols separate from the real
839 symbol table, and we treat these buggers as a sparse array. */
840
841 static long *dollar_labels;
842 static long *dollar_label_instances;
843 static char *dollar_label_defines;
844 static long dollar_label_count;
845 static unsigned long dollar_label_max;
846
847 int
848 dollar_label_defined (label)
849 long label;
850 {
851 long *i;
852
853 know ((dollar_labels != NULL) || (dollar_label_count == 0));
854
855 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
856 if (*i == label)
857 return dollar_label_defines[i - dollar_labels];
858
859 /* if we get here, label isn't defined */
860 return 0;
861 } /* dollar_label_defined() */
862
863 static int
864 dollar_label_instance (label)
865 long label;
866 {
867 long *i;
868
869 know ((dollar_labels != NULL) || (dollar_label_count == 0));
870
871 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
872 if (*i == label)
873 return (dollar_label_instances[i - dollar_labels]);
874
875 /* If we get here, we haven't seen the label before, therefore its instance
876 count is zero. */
877 return 0;
878 }
879
880 void
881 dollar_label_clear ()
882 {
883 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count);
884 }
885
886 #define DOLLAR_LABEL_BUMP_BY 10
887
888 void
889 define_dollar_label (label)
890 long label;
891 {
892 long *i;
893
894 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i)
895 if (*i == label)
896 {
897 ++dollar_label_instances[i - dollar_labels];
898 dollar_label_defines[i - dollar_labels] = 1;
899 return;
900 }
901
902 /* if we get to here, we don't have label listed yet. */
903
904 if (dollar_labels == NULL)
905 {
906 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
907 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long));
908 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY);
909 dollar_label_max = DOLLAR_LABEL_BUMP_BY;
910 dollar_label_count = 0;
911 }
912 else if (dollar_label_count == dollar_label_max)
913 {
914 dollar_label_max += DOLLAR_LABEL_BUMP_BY;
915 dollar_labels = (long *) xrealloc ((char *) dollar_labels,
916 dollar_label_max * sizeof (long));
917 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances,
918 dollar_label_max * sizeof (long));
919 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max);
920 } /* if we needed to grow */
921
922 dollar_labels[dollar_label_count] = label;
923 dollar_label_instances[dollar_label_count] = 1;
924 dollar_label_defines[dollar_label_count] = 1;
925 ++dollar_label_count;
926 }
927
928 /*
929 * dollar_label_name()
930 *
931 * Caller must copy returned name: we re-use the area for the next name.
932 *
933 * The mth occurence of label n: is turned into the symbol "Ln^Am"
934 * where n is the label number and m is the instance number. "L" makes
935 * it a label discarded unless debugging and "^A"('\1') ensures no
936 * ordinary symbol SHOULD get the same name as a local label
937 * symbol. The first "4:" is "L4^A1" - the m numbers begin at 1.
938 *
939 * fb labels get the same treatment, except that ^B is used in place of ^A.
940 */
941
942 char * /* Return local label name. */
943 dollar_label_name (n, augend)
944 register long n; /* we just saw "n$:" : n a number */
945 register int augend; /* 0 for current instance, 1 for new instance */
946 {
947 long i;
948 /* Returned to caller, then copied. used for created names ("4f") */
949 static char symbol_name_build[24];
950 register char *p;
951 register char *q;
952 char symbol_name_temporary[20]; /* build up a number, BACKWARDS */
953
954 know (n >= 0);
955 know (augend == 0 || augend == 1);
956 p = symbol_name_build;
957 *p++ = 'L';
958
959 /* Next code just does sprintf( {}, "%d", n); */
960 /* label number */
961 q = symbol_name_temporary;
962 for (*q++ = 0, i = n; i; ++q)
963 {
964 *q = i % 10 + '0';
965 i /= 10;
966 }
967 while ((*p = *--q) != '\0')
968 ++p;
969
970 *p++ = 1; /* ^A */
971
972 /* instance number */
973 q = symbol_name_temporary;
974 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q)
975 {
976 *q = i % 10 + '0';
977 i /= 10;
978 }
979 while ((*p++ = *--q) != '\0');;
980
981 /* The label, as a '\0' ended string, starts at symbol_name_build. */
982 return symbol_name_build;
983 }
984
985 /*
986 * Sombody else's idea of local labels. They are made by "n:" where n
987 * is any decimal digit. Refer to them with
988 * "nb" for previous (backward) n:
989 * or "nf" for next (forward) n:.
990 *
991 * We do a little better and let n be any number, not just a single digit, but
992 * since the other guy's assembler only does ten, we treat the first ten
993 * specially.
994 *
995 * Like someone else's assembler, we have one set of local label counters for
996 * entire assembly, not one set per (sub)segment like in most assemblers. This
997 * implies that one can refer to a label in another segment, and indeed some
998 * crufty compilers have done just that.
999 *
1000 * Since there could be a LOT of these things, treat them as a sparse array.
1001 */
1002
1003 #define FB_LABEL_SPECIAL (10)
1004
1005 static long fb_low_counter[FB_LABEL_SPECIAL];
1006 static long *fb_labels;
1007 static long *fb_label_instances;
1008 static long fb_label_count;
1009 static long fb_label_max;
1010
1011 /* this must be more than FB_LABEL_SPECIAL */
1012 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
1013
1014 static void
1015 fb_label_init ()
1016 {
1017 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter));
1018 } /* fb_label_init() */
1019
1020 /* add one to the instance number of this fb label */
1021 void
1022 fb_label_instance_inc (label)
1023 long label;
1024 {
1025 long *i;
1026
1027 if (label < FB_LABEL_SPECIAL)
1028 {
1029 ++fb_low_counter[label];
1030 return;
1031 }
1032
1033 if (fb_labels != NULL)
1034 {
1035 for (i = fb_labels + FB_LABEL_SPECIAL;
1036 i < fb_labels + fb_label_count; ++i)
1037 {
1038 if (*i == label)
1039 {
1040 ++fb_label_instances[i - fb_labels];
1041 return;
1042 } /* if we find it */
1043 } /* for each existing label */
1044 }
1045
1046 /* if we get to here, we don't have label listed yet. */
1047
1048 if (fb_labels == NULL)
1049 {
1050 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1051 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long));
1052 fb_label_max = FB_LABEL_BUMP_BY;
1053 fb_label_count = FB_LABEL_SPECIAL;
1054
1055 }
1056 else if (fb_label_count == fb_label_max)
1057 {
1058 fb_label_max += FB_LABEL_BUMP_BY;
1059 fb_labels = (long *) xrealloc ((char *) fb_labels,
1060 fb_label_max * sizeof (long));
1061 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances,
1062 fb_label_max * sizeof (long));
1063 } /* if we needed to grow */
1064
1065 fb_labels[fb_label_count] = label;
1066 fb_label_instances[fb_label_count] = 1;
1067 ++fb_label_count;
1068 }
1069
1070 static long
1071 fb_label_instance (label)
1072 long label;
1073 {
1074 long *i;
1075
1076 if (label < FB_LABEL_SPECIAL)
1077 {
1078 return (fb_low_counter[label]);
1079 }
1080
1081 if (fb_labels != NULL)
1082 {
1083 for (i = fb_labels + FB_LABEL_SPECIAL;
1084 i < fb_labels + fb_label_count; ++i)
1085 {
1086 if (*i == label)
1087 {
1088 return (fb_label_instances[i - fb_labels]);
1089 } /* if we find it */
1090 } /* for each existing label */
1091 }
1092
1093 /* We didn't find the label, so this must be a reference to the
1094 first instance. */
1095 return 0;
1096 }
1097
1098 /*
1099 * fb_label_name()
1100 *
1101 * Caller must copy returned name: we re-use the area for the next name.
1102 *
1103 * The mth occurence of label n: is turned into the symbol "Ln^Bm"
1104 * where n is the label number and m is the instance number. "L" makes
1105 * it a label discarded unless debugging and "^B"('\2') ensures no
1106 * ordinary symbol SHOULD get the same name as a local label
1107 * symbol. The first "4:" is "L4^B1" - the m numbers begin at 1.
1108 *
1109 * dollar labels get the same treatment, except that ^A is used in place of ^B. */
1110
1111 char * /* Return local label name. */
1112 fb_label_name (n, augend)
1113 long n; /* we just saw "n:", "nf" or "nb" : n a number */
1114 long augend; /* 0 for nb, 1 for n:, nf */
1115 {
1116 long i;
1117 /* Returned to caller, then copied. used for created names ("4f") */
1118 static char symbol_name_build[24];
1119 register char *p;
1120 register char *q;
1121 char symbol_name_temporary[20]; /* build up a number, BACKWARDS */
1122
1123 know (n >= 0);
1124 know (augend == 0 || augend == 1);
1125 p = symbol_name_build;
1126 *p++ = 'L';
1127
1128 /* Next code just does sprintf( {}, "%d", n); */
1129 /* label number */
1130 q = symbol_name_temporary;
1131 for (*q++ = 0, i = n; i; ++q)
1132 {
1133 *q = i % 10 + '0';
1134 i /= 10;
1135 }
1136 while ((*p = *--q) != '\0')
1137 ++p;
1138
1139 *p++ = 2; /* ^B */
1140
1141 /* instance number */
1142 q = symbol_name_temporary;
1143 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q)
1144 {
1145 *q = i % 10 + '0';
1146 i /= 10;
1147 }
1148 while ((*p++ = *--q) != '\0');;
1149
1150 /* The label, as a '\0' ended string, starts at symbol_name_build. */
1151 return (symbol_name_build);
1152 } /* fb_label_name() */
1153
1154 /*
1155 * decode name that may have been generated by foo_label_name() above. If
1156 * the name wasn't generated by foo_label_name(), then return it unaltered.
1157 * This is used for error messages.
1158 */
1159
1160 char *
1161 decode_local_label_name (s)
1162 char *s;
1163 {
1164 char *p;
1165 char *symbol_decode;
1166 int label_number;
1167 int instance_number;
1168 char *type;
1169 const char *message_format = "\"%d\" (instance number %d of a %s label)";
1170
1171 if (s[0] != 'L')
1172 return s;
1173
1174 for (label_number = 0, p = s + 1; isdigit (*p); ++p)
1175 label_number = (10 * label_number) + *p - '0';
1176
1177 if (*p == 1)
1178 type = "dollar";
1179 else if (*p == 2)
1180 type = "fb";
1181 else
1182 return s;
1183
1184 for (instance_number = 0, p++; isdigit (*p); ++p)
1185 instance_number = (10 * instance_number) + *p - '0';
1186
1187 symbol_decode = obstack_alloc (&notes, strlen (message_format) + 30);
1188 sprintf (symbol_decode, message_format, label_number, instance_number, type);
1189
1190 return symbol_decode;
1191 }
1192
1193 /* Get the value of a symbol. */
1194
1195 valueT
1196 S_GET_VALUE (s)
1197 symbolS *s;
1198 {
1199 if (!s->sy_resolved && !s->sy_resolving && s->sy_value.X_op != O_constant)
1200 resolve_symbol_value (s);
1201 if (s->sy_value.X_op != O_constant)
1202 {
1203 static symbolS *recur;
1204
1205 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
1206 may call S_GET_VALUE. We use a static symbol to avoid the
1207 immediate recursion. */
1208 if (recur == s)
1209 return (valueT) s->sy_value.X_add_number;
1210 recur = s;
1211 if (! s->sy_resolved
1212 || s->sy_value.X_op != O_symbol
1213 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
1214 as_bad ("Attempt to get value of unresolved symbol %s",
1215 S_GET_NAME (s));
1216 recur = NULL;
1217 }
1218 return (valueT) s->sy_value.X_add_number;
1219 }
1220
1221 /* Set the value of a symbol. */
1222
1223 void
1224 S_SET_VALUE (s, val)
1225 symbolS *s;
1226 valueT val;
1227 {
1228 s->sy_value.X_op = O_constant;
1229 s->sy_value.X_add_number = (offsetT) val;
1230 s->sy_value.X_unsigned = 0;
1231 }
1232
1233 void
1234 copy_symbol_attributes (dest, src)
1235 symbolS *dest, *src;
1236 {
1237 #ifdef BFD_ASSEMBLER
1238 /* In an expression, transfer the settings of these flags.
1239 The user can override later, of course. */
1240 #define COPIED_SYMFLAGS (BSF_FUNCTION)
1241 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS;
1242 #endif
1243
1244 #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES
1245 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
1246 #endif
1247 }
1248
1249 #ifdef BFD_ASSEMBLER
1250
1251 int
1252 S_IS_EXTERNAL (s)
1253 symbolS *s;
1254 {
1255 flagword flags = s->bsym->flags;
1256
1257 /* sanity check */
1258 if (flags & BSF_LOCAL && flags & BSF_GLOBAL)
1259 abort ();
1260
1261 return (flags & BSF_GLOBAL) != 0;
1262 }
1263
1264 int
1265 S_IS_WEAK (s)
1266 symbolS *s;
1267 {
1268 return (s->bsym->flags & BSF_WEAK) != 0;
1269 }
1270
1271 int
1272 S_IS_COMMON (s)
1273 symbolS *s;
1274 {
1275 return bfd_is_com_section (s->bsym->section);
1276 }
1277
1278 int
1279 S_IS_DEFINED (s)
1280 symbolS *s;
1281 {
1282 return s->bsym->section != undefined_section;
1283 }
1284
1285 int
1286 S_IS_DEBUG (s)
1287 symbolS *s;
1288 {
1289 if (s->bsym->flags & BSF_DEBUGGING)
1290 return 1;
1291 return 0;
1292 }
1293
1294 int
1295 S_IS_LOCAL (s)
1296 symbolS *s;
1297 {
1298 flagword flags = s->bsym->flags;
1299 const char *name;
1300
1301 /* sanity check */
1302 if (flags & BSF_LOCAL && flags & BSF_GLOBAL)
1303 abort ();
1304
1305 if (bfd_get_section (s->bsym) == reg_section)
1306 return 1;
1307
1308 name = S_GET_NAME (s);
1309 return (name != NULL
1310 && ! S_IS_DEBUG (s)
1311 && (strchr (name, '\001')
1312 || strchr (name, '\002')
1313 || (! flag_keep_locals
1314 && (LOCAL_LABEL (name)
1315 || (flag_mri
1316 && name[0] == '?'
1317 && name[1] == '?')))));
1318 }
1319
1320 int
1321 S_IS_EXTERN (s)
1322 symbolS *s;
1323 {
1324 return S_IS_EXTERNAL (s);
1325 }
1326
1327 int
1328 S_IS_STABD (s)
1329 symbolS *s;
1330 {
1331 return S_GET_NAME (s) == 0;
1332 }
1333
1334 CONST char *
1335 S_GET_NAME (s)
1336 symbolS *s;
1337 {
1338 return s->bsym->name;
1339 }
1340
1341 segT
1342 S_GET_SEGMENT (s)
1343 symbolS *s;
1344 {
1345 return s->bsym->section;
1346 }
1347
1348 void
1349 S_SET_SEGMENT (s, seg)
1350 symbolS *s;
1351 segT seg;
1352 {
1353 s->bsym->section = seg;
1354 }
1355
1356 void
1357 S_SET_EXTERNAL (s)
1358 symbolS *s;
1359 {
1360 if ((s->bsym->flags & BSF_WEAK) != 0)
1361 as_warn ("%s already declared as weak", S_GET_NAME (s));
1362 s->bsym->flags |= BSF_GLOBAL;
1363 s->bsym->flags &= ~(BSF_LOCAL|BSF_WEAK);
1364 }
1365
1366 void
1367 S_CLEAR_EXTERNAL (s)
1368 symbolS *s;
1369 {
1370 if ((s->bsym->flags & BSF_WEAK) != 0)
1371 as_warn ("%s already declared as weak", S_GET_NAME (s));
1372 s->bsym->flags |= BSF_LOCAL;
1373 s->bsym->flags &= ~(BSF_GLOBAL|BSF_WEAK);
1374 }
1375
1376 void
1377 S_SET_WEAK (s)
1378 symbolS *s;
1379 {
1380 if ((s->bsym->flags & BSF_GLOBAL) != 0)
1381 as_warn ("%s already declared as global", S_GET_NAME (s));
1382 s->bsym->flags |= BSF_WEAK;
1383 s->bsym->flags &= ~(BSF_GLOBAL|BSF_LOCAL);
1384 }
1385
1386 void
1387 S_SET_NAME (s, name)
1388 symbolS *s;
1389 char *name;
1390 {
1391 s->bsym->name = name;
1392 }
1393 #endif /* BFD_ASSEMBLER */
1394
1395 void
1396 symbol_begin ()
1397 {
1398 symbol_lastP = NULL;
1399 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */
1400 sy_hash = hash_new ();
1401
1402 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol));
1403 #ifdef BFD_ASSEMBLER
1404 #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL)
1405 abs_symbol.bsym = bfd_abs_section.symbol;
1406 #endif
1407 #else
1408 /* Can't initialise a union. Sigh. */
1409 S_SET_SEGMENT (&abs_symbol, absolute_section);
1410 #endif
1411 abs_symbol.sy_value.X_op = O_constant;
1412 abs_symbol.sy_frag = &zero_address_frag;
1413
1414 if (LOCAL_LABELS_FB)
1415 fb_label_init ();
1416 }
1417
1418 \f
1419 int indent_level;
1420
1421 #if 0
1422
1423 static void
1424 indent ()
1425 {
1426 printf ("%*s", indent_level * 4, "");
1427 }
1428
1429 #endif
1430
1431 void print_expr_1 PARAMS ((FILE *, expressionS *));
1432 void print_symbol_value_1 PARAMS ((FILE *, symbolS *));
1433
1434 void
1435 print_symbol_value_1 (file, sym)
1436 FILE *file;
1437 symbolS *sym;
1438 {
1439 const char *name = S_GET_NAME (sym);
1440 if (!name || !name[0])
1441 name = "(unnamed)";
1442 fprintf (file, "sym %lx %s", (unsigned long) sym, name);
1443 if (sym->sy_frag != &zero_address_frag)
1444 fprintf (file, " frag %lx", (long) sym->sy_frag);
1445 if (sym->written)
1446 fprintf (file, " written");
1447 if (sym->sy_resolved)
1448 fprintf (file, " resolved");
1449 else if (sym->sy_resolving)
1450 fprintf (file, " resolving");
1451 if (sym->sy_used_in_reloc)
1452 fprintf (file, " used-in-reloc");
1453 if (sym->sy_used)
1454 fprintf (file, " used");
1455 if (S_IS_LOCAL (sym))
1456 fprintf (file, " local");
1457 if (S_IS_EXTERN (sym))
1458 fprintf (file, " extern");
1459 if (S_IS_DEBUG (sym))
1460 fprintf (file, " debug");
1461 if (S_IS_DEFINED (sym))
1462 fprintf (file, " defined");
1463 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym)));
1464 if (sym->sy_resolved)
1465 {
1466 segT s = S_GET_SEGMENT (sym);
1467
1468 if (s != undefined_section
1469 && s != expr_section)
1470 fprintf (file, " %lx", (long) S_GET_VALUE (sym));
1471 }
1472 else if (indent_level < 8 && S_GET_SEGMENT (sym) != undefined_section)
1473 {
1474 indent_level++;
1475 fprintf (file, "\n%*s<", indent_level * 4, "");
1476 print_expr_1 (file, &sym->sy_value);
1477 fprintf (file, ">");
1478 indent_level--;
1479 }
1480 fflush (file);
1481 }
1482
1483 void
1484 print_symbol_value (sym)
1485 symbolS *sym;
1486 {
1487 indent_level = 0;
1488 print_symbol_value_1 (stderr, sym);
1489 fprintf (stderr, "\n");
1490 }
1491
1492 void
1493 print_expr_1 (file, exp)
1494 FILE *file;
1495 expressionS *exp;
1496 {
1497 fprintf (file, "expr %lx ", (long) exp);
1498 switch (exp->X_op)
1499 {
1500 case O_illegal:
1501 fprintf (file, "illegal");
1502 break;
1503 case O_absent:
1504 fprintf (file, "absent");
1505 break;
1506 case O_constant:
1507 fprintf (file, "constant %lx", (long) exp->X_add_number);
1508 break;
1509 case O_symbol:
1510 indent_level++;
1511 fprintf (file, "symbol\n%*s<", indent_level * 4, "");
1512 print_symbol_value_1 (file, exp->X_add_symbol);
1513 fprintf (file, ">");
1514 maybe_print_addnum:
1515 if (exp->X_add_number)
1516 fprintf (file, "\n%*s%lx", indent_level * 4, "",
1517 (long) exp->X_add_number);
1518 indent_level--;
1519 break;
1520 case O_register:
1521 fprintf (file, "register #%d", (int) exp->X_add_number);
1522 break;
1523 case O_big:
1524 fprintf (file, "big");
1525 break;
1526 case O_uminus:
1527 fprintf (file, "uminus -<");
1528 indent_level++;
1529 print_symbol_value_1 (file, exp->X_add_symbol);
1530 fprintf (file, ">");
1531 goto maybe_print_addnum;
1532 case O_bit_not:
1533 fprintf (file, "bit_not");
1534 break;
1535 case O_multiply:
1536 fprintf (file, "multiply");
1537 break;
1538 case O_divide:
1539 fprintf (file, "divide");
1540 break;
1541 case O_modulus:
1542 fprintf (file, "modulus");
1543 break;
1544 case O_left_shift:
1545 fprintf (file, "lshift");
1546 break;
1547 case O_right_shift:
1548 fprintf (file, "rshift");
1549 break;
1550 case O_bit_inclusive_or:
1551 fprintf (file, "bit_ior");
1552 break;
1553 case O_bit_exclusive_or:
1554 fprintf (file, "bit_xor");
1555 break;
1556 case O_bit_and:
1557 fprintf (file, "bit_and");
1558 break;
1559 case O_eq:
1560 fprintf (file, "eq");
1561 break;
1562 case O_ne:
1563 fprintf (file, "ne");
1564 break;
1565 case O_lt:
1566 fprintf (file, "lt");
1567 break;
1568 case O_le:
1569 fprintf (file, "le");
1570 break;
1571 case O_ge:
1572 fprintf (file, "ge");
1573 break;
1574 case O_gt:
1575 fprintf (file, "gt");
1576 break;
1577 case O_logical_and:
1578 fprintf (file, "logical_and");
1579 break;
1580 case O_logical_or:
1581 fprintf (file, "logical_or");
1582 break;
1583 case O_add:
1584 indent_level++;
1585 fprintf (file, "add\n%*s<", indent_level * 4, "");
1586 print_symbol_value_1 (file, exp->X_add_symbol);
1587 fprintf (file, ">\n%*s<", indent_level * 4, "");
1588 print_symbol_value_1 (file, exp->X_op_symbol);
1589 fprintf (file, ">");
1590 goto maybe_print_addnum;
1591 case O_subtract:
1592 indent_level++;
1593 fprintf (file, "subtract\n%*s<", indent_level * 4, "");
1594 print_symbol_value_1 (file, exp->X_add_symbol);
1595 fprintf (file, ">\n%*s<", indent_level * 4, "");
1596 print_symbol_value_1 (file, exp->X_op_symbol);
1597 fprintf (file, ">");
1598 goto maybe_print_addnum;
1599 default:
1600 fprintf (file, "{unknown opcode %d}", (int) exp->X_op);
1601 break;
1602 }
1603 fflush (stdout);
1604 }
1605
1606 void
1607 print_expr (exp)
1608 expressionS *exp;
1609 {
1610 print_expr_1 (stderr, exp);
1611 fprintf (stderr, "\n");
1612 }
1613
1614 void
1615 symbol_print_statistics (file)
1616 FILE *file;
1617 {
1618 hash_print_statistics (file, "symbol table", sy_hash);
1619 }
1620
1621 /* end of symbols.c */