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