a140046e6827f0eb7ae3d6d2ee61debb4e46046d
1 /* symbols.c -symbol table-
3 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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)
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.
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "obstack.h" /* For "symbols.h" */
28 #ifndef WORKING_DOT_WORD
29 extern int new_broken_words
;
32 extern char const_flag
;
37 sy_hash
; /* symbol-name => struct symbol pointer */
39 /* Below are commented in "symbols.h". */
40 unsigned int local_bss_counter
;
41 symbolS
*symbol_rootP
;
42 symbolS
*symbol_lastP
;
45 symbolS
*dot_text_symbol
;
46 symbolS
*dot_data_symbol
;
47 symbolS
*dot_bss_symbol
;
52 static void fb_label_init (void);
53 #else /* not __STDC__ */
54 static void fb_label_init ();
55 #endif /* not __STDC__ */
61 symbol_rootP
= NULL
; /* In case we have 0 symbols (!!) */
62 sy_hash
= hash_new ();
63 memset ((char *) (&abs_symbol
), '\0', sizeof (abs_symbol
));
64 S_SET_SEGMENT (&abs_symbol
, SEG_ABSOLUTE
); /* Can't initialise a union. Sigh. */
65 local_bss_counter
= 0;
66 #ifdef LOCAL_LABELS_FB
68 #endif /* LOCAL_LABELS_FB */
74 * Return a pointer to a new symbol.
75 * Die if we can't make a new symbol.
76 * Fill in the symbol's values.
77 * Add symbol to end of symbol chain.
80 * Please always call this to create a new symbol.
82 * Changes since 1985: Symbol names may not contain '\0'. Sigh.
83 * 2nd argument is now a SEG rather than a TYPE. The mapping between
84 * segments and types is mostly encapsulated herein (actually, we inherit it
85 * from macros in struc-symbol.h).
89 symbol_new (name
, segment
, value
, frag
)
90 char *name
; /* It is copied, the caller can destroy/modify */
91 segT segment
; /* Segment identifier (SEG_<something>) */
92 long value
; /* Symbol value */
93 fragS
*frag
; /* Associated fragment */
95 unsigned int name_length
;
96 char *preserved_copy_of_name
;
99 name_length
= strlen (name
) + 1; /* +1 for \0 */
100 obstack_grow (¬es
, name
, name_length
);
101 preserved_copy_of_name
= obstack_finish (¬es
);
102 symbolP
= (symbolS
*) obstack_alloc (¬es
, sizeof (symbolS
));
104 /* symbol must be born in some fixed state. This seems as good as any. */
105 memset (symbolP
, 0, sizeof (symbolS
));
107 #ifdef STRIP_UNDERSCORE
108 S_SET_NAME (symbolP
, (*preserved_copy_of_name
== '_'
109 ? preserved_copy_of_name
+ 1
110 : preserved_copy_of_name
));
111 #else /* STRIP_UNDERSCORE */
112 S_SET_NAME (symbolP
, preserved_copy_of_name
);
113 #endif /* STRIP_UNDERSCORE */
115 S_SET_SEGMENT (symbolP
, segment
);
116 S_SET_VALUE (symbolP
, value
);
117 /* symbol_clear_list_pointers(symbolP); uneeded if symbol is born zeroed. */
119 symbolP
->sy_frag
= frag
;
120 /* krm: uneeded if symbol is born zeroed.
121 symbolP->sy_forward = NULL; *//* JF */
122 symbolP
->sy_number
= ~0;
123 symbolP
->sy_name_offset
= ~0;
126 * Link to end of symbol chain.
128 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
130 obj_symbol_new_hook (symbolP
);
133 /* verify_symbol_chain(symbol_rootP, symbol_lastP); */
143 * We have just seen "<name>:".
144 * Creates a struct symbol unless it already exists.
146 * Gripes if we are redefining a symbol incompatibly (and ignores it).
150 colon (sym_name
) /* just seen "x:" - rattle symbols & frags */
151 register char *sym_name
; /* symbol name, as a cannonical string */
152 /* We copy this string: OK to alter later. */
154 register symbolS
*symbolP
; /* symbol we are working with */
156 #ifdef LOCAL_LABELS_DOLLAR
157 /* Sun local labels go out of scope whenever a non-local symbol is defined. */
159 if (*sym_name
!= 'L')
160 dollar_label_clear ();
161 #endif /* LOCAL_LABELS_DOLLAR */
163 #ifndef WORKING_DOT_WORD
164 if (new_broken_words
)
166 struct broken_word
*a
;
171 extern md_short_jump_size
;
172 extern md_long_jump_size
;
173 possible_bytes
= md_short_jump_size
+ new_broken_words
* md_long_jump_size
;
176 frag_opcode
= frag_var (rs_broken_word
,
180 (symbolS
*) broken_words
,
184 /* We want to store the pointer to where to insert the jump table in the
185 fr_opcode of the rs_broken_word frag. This requires a little hackery */
186 while (frag_tmp
&& (frag_tmp
->fr_type
!= rs_broken_word
|| frag_tmp
->fr_opcode
))
187 frag_tmp
= frag_tmp
->fr_next
;
189 frag_tmp
->fr_opcode
= frag_opcode
;
190 new_broken_words
= 0;
192 for (a
= broken_words
; a
&& a
->dispfrag
== 0; a
= a
->next_broken_word
)
193 a
->dispfrag
= frag_tmp
;
195 #endif /* WORKING_DOT_WORD */
197 if ((symbolP
= symbol_find (sym_name
)) != 0)
201 * If the new symbol is .comm AND it has a size of zero,
202 * we ignore it (i.e. the old symbol overrides it)
204 if ((SEGMENT_TO_SYMBOL_TYPE ((int) now_seg
) == (N_UNDF
| N_EXT
)) &&
205 ((obstack_next_free (&frags
) - frag_now
->fr_literal
) == 0))
208 * If the old symbol is .comm and it has a size of zero,
209 * we override it with the new symbol value.
211 if ((symbolP
->sy_type
== (N_UNDF
| N_EXT
))
212 && (S_GET_VALUE (symbolP
) == 0))
214 symbolP
->sy_frag
= frag_now
;
215 symbolP
->sy_other
= const_flag
;
216 S_SET_VALUE (symbolP
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
217 symbolP
->sy_type
|= SEGMENT_TO_SYMBOL_TYPE ((int) now_seg
); /* keep N_EXT bit */
222 * Now check for undefined symbols
224 if (!S_IS_DEFINED (symbolP
))
226 if (S_GET_VALUE (symbolP
) == 0)
228 symbolP
->sy_frag
= frag_now
;
230 symbolP
->sy_other
= const_flag
;
232 S_SET_VALUE (symbolP
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
233 S_SET_SEGMENT (symbolP
, now_seg
);
236 #endif /* if we have one, it better be zero. */
242 * There are still several cases to check:
243 * A .comm/.lcomm symbol being redefined as
244 * initialized data is OK
245 * A .comm/.lcomm symbol being redefined with
246 * a larger size is also OK
248 * This only used to be allowed on VMS gas, but Sun cc
249 * on the sparc also depends on it.
251 /* char New_Type = SEGMENT_TO_SYMBOL_TYPE((int) now_seg); */
253 #define SEG_BSS SEG_E2
254 #define SEG_DATA SEG_E1
257 if (((!S_IS_DEBUG (symbolP
) && !S_IS_DEFINED (symbolP
) && S_IS_EXTERNAL (symbolP
))
258 || (S_GET_SEGMENT (symbolP
) == SEG_BSS
))
259 && ((now_seg
== SEG_DATA
)
260 || (now_seg
== S_GET_SEGMENT (symbolP
))))
263 * Select which of the 2 cases this is
265 if (now_seg
!= SEG_DATA
)
268 * New .comm for prev .comm symbol.
269 * If the new size is larger we just
270 * change its value. If the new size
271 * is smaller, we ignore this symbol
273 if (S_GET_VALUE (symbolP
)
274 < ((unsigned) (obstack_next_free (&frags
) - frag_now
->fr_literal
)))
276 S_SET_VALUE (symbolP
,
277 obstack_next_free (&frags
) -
278 frag_now
->fr_literal
);
284 * It is a .comm/.lcomm being converted
285 * to initialized data.
287 symbolP
->sy_frag
= frag_now
;
289 symbolP
->sy_other
= const_flag
;
291 S_SET_VALUE (symbolP
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
292 S_SET_SEGMENT (symbolP
, now_seg
); /* keep N_EXT bit */
298 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%d.",
300 segment_name (S_GET_SEGMENT (symbolP
)),
301 S_GET_VALUE (symbolP
));
303 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%d.",
305 segment_name (S_GET_SEGMENT (symbolP
)),
306 S_GET_OTHER (symbolP
), S_GET_DESC (symbolP
),
307 S_GET_VALUE (symbolP
));
308 #endif /* OBJ_COFF */
310 } /* if the undefined symbol has no value */
314 /* Don't blow up if the definition is the same */
315 if (!(frag_now
== symbolP
->sy_frag
316 && S_GET_VALUE (symbolP
) == obstack_next_free (&frags
) - frag_now
->fr_literal
317 && S_GET_SEGMENT (symbolP
) == now_seg
))
318 as_fatal ("Symbol %s already defined.", sym_name
);
319 } /* if this symbol is not yet defined */
324 symbolP
= symbol_new (sym_name
,
326 (valueT
) (obstack_next_free (&frags
) - frag_now
->fr_literal
),
329 S_SET_OTHER (symbolP
, const_flag
);
332 symbol_table_insert (symbolP
);
333 } /* if we have seen this symbol before */
340 * symbol_table_insert()
342 * Die if we can't insert the symbol.
347 symbol_table_insert (symbolP
)
350 register char *error_string
;
353 know (S_GET_NAME (symbolP
));
355 if (*(error_string
= hash_jam (sy_hash
, S_GET_NAME (symbolP
), (char *) symbolP
)))
357 as_fatal ("Inserting \"%s\" into symbol table failed: %s",
358 S_GET_NAME (symbolP
), error_string
);
360 } /* symbol_table_insert() */
363 * symbol_find_or_make()
365 * If a symbol name does not exist, create it as undefined, and insert
366 * it into the symbol table. Return a pointer to it.
369 symbol_find_or_make (name
)
372 register symbolS
*symbolP
;
374 symbolP
= symbol_find (name
);
378 symbolP
= symbol_make (name
);
380 symbol_table_insert (symbolP
);
381 } /* if symbol wasn't found */
384 } /* symbol_find_or_make() */
392 /* Let the machine description default it, e.g. for register names. */
393 symbolP
= md_undefined_symbol (name
);
397 symbolP
= symbol_new (name
,
401 } /* if md didn't build us a symbol */
404 } /* symbol_make() */
409 * Implement symbol table lookup.
410 * In: A symbol's name as a string: '\0' can't be part of a symbol name.
411 * Out: NULL if the name was not in the symbol table, else the address
412 * of a struct symbol associated with that name.
419 #ifdef STRIP_UNDERSCORE
420 return (symbol_find_base (name
, 1));
421 #else /* STRIP_UNDERSCORE */
422 return (symbol_find_base (name
, 0));
423 #endif /* STRIP_UNDERSCORE */
424 } /* symbol_find() */
427 symbol_find_base (name
, strip_underscore
)
429 int strip_underscore
;
431 if (strip_underscore
&& *name
== '_')
433 return ((symbolS
*) hash_find (sy_hash
, name
));
437 * Once upon a time, symbols were kept in a singly linked list. At
438 * least coff needs to be able to rearrange them from time to time, for
439 * which a doubly linked list is much more convenient. Loic did these
440 * as macros which seemed dangerous to me so they're now functions.
444 /* Link symbol ADDME after symbol TARGET in the chain. */
446 symbol_append (addme
, target
, rootPP
, lastPP
)
454 know (*rootPP
== NULL
);
455 know (*lastPP
== NULL
);
459 } /* if the list is empty */
461 if (target
->sy_next
!= NULL
)
463 #ifdef SYMBOLS_NEED_BACKPOINTERS
464 target
->sy_next
->sy_previous
= addme
;
465 #endif /* SYMBOLS_NEED_BACKPOINTERS */
469 know (*lastPP
== target
);
471 } /* if we have a next */
473 addme
->sy_next
= target
->sy_next
;
474 target
->sy_next
= addme
;
476 #ifdef SYMBOLS_NEED_BACKPOINTERS
477 addme
->sy_previous
= target
;
478 #endif /* SYMBOLS_NEED_BACKPOINTERS */
481 /* verify_symbol_chain(*rootPP, *lastPP); */
485 } /* symbol_append() */
487 #ifdef SYMBOLS_NEED_BACKPOINTERS
488 /* Remove SYMBOLP from the list. */
490 symbol_remove (symbolP
, rootPP
, lastPP
)
495 if (symbolP
== *rootPP
)
497 *rootPP
= symbolP
->sy_next
;
498 } /* if it was the root */
500 if (symbolP
== *lastPP
)
502 *lastPP
= symbolP
->sy_previous
;
503 } /* if it was the tail */
505 if (symbolP
->sy_next
!= NULL
)
507 symbolP
->sy_next
->sy_previous
= symbolP
->sy_previous
;
510 if (symbolP
->sy_previous
!= NULL
)
512 symbolP
->sy_previous
->sy_next
= symbolP
->sy_next
;
516 verify_symbol_chain (*rootPP
, *lastPP
);
520 } /* symbol_remove() */
522 /* Set the chain pointers of SYMBOL to null. */
524 symbol_clear_list_pointers (symbolP
)
527 symbolP
->sy_next
= NULL
;
528 symbolP
->sy_previous
= NULL
;
529 } /* symbol_clear_list_pointers() */
531 /* Link symbol ADDME before symbol TARGET in the chain. */
533 symbol_insert (addme
, target
, rootPP
, lastPP
)
539 if (target
->sy_previous
!= NULL
)
541 target
->sy_previous
->sy_next
= addme
;
545 know (*rootPP
== target
);
549 addme
->sy_previous
= target
->sy_previous
;
550 target
->sy_previous
= addme
;
551 addme
->sy_next
= target
;
554 verify_symbol_chain (*rootPP
, *lastPP
);
558 } /* symbol_insert() */
560 #endif /* SYMBOLS_NEED_BACKPOINTERS */
563 verify_symbol_chain (rootP
, lastP
)
567 symbolS
*symbolP
= rootP
;
574 for (; symbol_next (symbolP
) != NULL
; symbolP
= symbol_next (symbolP
))
576 #ifdef SYMBOLS_NEED_BACKPOINTERS
577 /*$if (symbolP->sy_previous) {
578 know(symbolP->sy_previous->sy_next == symbolP);
580 know(symbolP == rootP);
581 }$*//* both directions */
582 know (symbolP
->sy_next
->sy_previous
== symbolP
);
583 #else /* SYMBOLS_NEED_BACKPOINTERS */
585 #endif /* SYMBOLS_NEED_BACKPOINTERS */
586 } /* verify pointers */
588 know (lastP
== symbolP
);
591 } /* verify_symbol_chain() */
594 #ifdef LOCAL_LABELS_DOLLAR
596 /* Dollar labels look like a number followed by a dollar sign. Eg, "42$".
597 They are *really* local. That is, they go out of scope whenever we see a
598 label that isn't local. Also, like fb labels, there can be multiple
599 instances of a dollar label. Therefor, we name encode each instance with
600 the instance number, keep a list of defined symbols separate from the real
601 symbol table, and we treat these buggers as a sparse array. */
603 static long *dollar_labels
= NULL
;
604 static long *dollar_label_instances
= NULL
;
605 static char *dollar_label_defines
= NULL
;
606 static long dollar_label_count
= 0;
607 static long dollar_label_max
= 0;
610 dollar_label_defined (label
)
615 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
617 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
621 return (dollar_label_defines
[i
- dollar_labels
]);
623 } /* look for label */
625 /* if we get here, label isn't defined */
627 } /* dollar_label_defined() */
630 dollar_label_instance (label
)
635 know ((dollar_labels
!= NULL
) || (dollar_label_count
== 0));
637 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
641 return (dollar_label_instances
[i
- dollar_labels
]);
643 } /* look for (the union :-) label */
645 /* if we get here, we haven't seen the label before, therefor it's instance
648 } /* dollar_label_instance() */
651 dollar_label_clear ()
653 memset (dollar_label_defines
, '\0', dollar_label_count
);
655 } /* clear_dollar_labels() */
657 #define DOLLAR_LABEL_BUMP_BY 10
660 define_dollar_label (label
)
665 for (i
= dollar_labels
; i
< dollar_labels
+ dollar_label_count
; ++i
)
669 ++dollar_label_instances
[i
- dollar_labels
];
670 dollar_label_defines
[i
- dollar_labels
] = 1;
672 } /* if we find it */
673 } /* for each existing label */
675 /* if we get to here, we don't have label listed yet. */
677 if (dollar_labels
== NULL
)
679 dollar_labels
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
680 dollar_label_instances
= (long *) xmalloc (DOLLAR_LABEL_BUMP_BY
* sizeof (long));
681 dollar_label_defines
= xmalloc (DOLLAR_LABEL_BUMP_BY
);
682 dollar_label_max
= DOLLAR_LABEL_BUMP_BY
;
683 dollar_label_count
= 0;
686 else if (dollar_label_count
== dollar_label_max
)
688 dollar_label_max
+= DOLLAR_LABEL_BUMP_BY
;
689 dollar_labels
= (long *) xrealloc ((char *) dollar_labels
,
690 dollar_label_max
* sizeof (long));
691 dollar_label_instances
= (long *) xrealloc ((char *) dollar_label_instances
,
692 dollar_label_max
* sizeof (long));
693 dollar_label_defines
= xrealloc (dollar_label_defines
, dollar_label_max
);
694 } /* if we needed to grow */
696 dollar_labels
[dollar_label_count
] = label
;
697 dollar_label_instances
[dollar_label_count
] = 1;
698 dollar_label_defines
[dollar_label_count
] = 1;
699 ++dollar_label_count
;
701 } /* define_dollar_label() */
704 * dollar_label_name()
706 * Caller must copy returned name: we re-use the area for the next name.
708 * The mth occurence of label n: is turned into the symbol "Ln^Am" where
709 * n is the label number and m is the instance number. "L" makes it a label discarded
710 * unless debugging and "^A"('\1') ensures no ordinary symbol SHOULD get the
711 * same name as a local label symbol. The first "4:" is "L4^A1" - the m
712 * numbers begin at 1.
714 * fb labels get the same treatment, except that ^B is used in place of ^A.
717 char * /* Return local label name. */
718 dollar_label_name (n
, augend
)
719 register long n
; /* we just saw "n$:" : n a number */
720 register int augend
; /* 0 for current instance, 1 for new instance */
723 /* Returned to caller, then copied. used for created names ("4f") */
724 static char symbol_name_build
[24];
727 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
730 know (augend
== 0 || augend
== 1);
731 p
= symbol_name_build
;
734 /* Next code just does sprintf( {}, "%d", n); */
736 q
= symbol_name_temporary
;
737 for (*q
++ = 0, i
= n
; i
; ++q
)
742 while ((*p
= *--q
) != '\0')
747 /* instance number */
748 q
= symbol_name_temporary
;
749 for (*q
++ = 0, i
= dollar_label_instance (n
) + augend
; i
; ++q
)
754 while ((*p
++ = *--q
) != '\0');;
756 /* The label, as a '\0' ended string, starts at symbol_name_build. */
757 return (symbol_name_build
);
758 } /* dollar_label_name() */
760 #endif /* LOCAL_LABELS_DOLLAR */
762 #ifdef LOCAL_LABELS_FB
765 * Sombody else's idea of local labels. They are made by "n:" where n
766 * is any decimal digit. Refer to them with
767 * "nb" for previous (backward) n:
768 * or "nf" for next (forward) n:.
770 * We do a little better and let n be any number, not just a single digit, but
771 * since the other guy's assembler only does ten, we treat the first ten
774 * Like someone else's assembler, we have one set of local label counters for
775 * entire assembly, not one set per (sub)segment like in most assemblers. This
776 * implies that one can refer to a label in another segment, and indeed some
777 * crufty compilers have done just that.
779 * Since there could be a LOT of these things, treat them as a sparse array.
782 #define FB_LABEL_SPECIAL (10)
784 static long fb_low_counter
[FB_LABEL_SPECIAL
];
785 static long *fb_labels
;
786 static long *fb_label_instances
;
787 static long fb_label_count
= 0;
788 static long fb_label_max
= 0;
790 /* this must be more than FB_LABEL_SPECIAL */
791 #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6)
796 memset ((void *) fb_low_counter
, '\0', sizeof (fb_low_counter
));
798 } /* fb_label_init() */
800 /* add one to the instance number of this fb label */
802 fb_label_instance_inc (label
)
807 if (label
< FB_LABEL_SPECIAL
)
809 ++fb_low_counter
[label
];
813 for (i
= fb_labels
+ FB_LABEL_SPECIAL
; i
< fb_labels
+ fb_label_count
; ++i
)
817 ++fb_label_instances
[i
- fb_labels
];
819 } /* if we find it */
820 } /* for each existing label */
822 /* if we get to here, we don't have label listed yet. */
824 if (fb_labels
== NULL
)
826 fb_labels
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
827 fb_label_instances
= (long *) xmalloc (FB_LABEL_BUMP_BY
* sizeof (long));
828 fb_label_max
= FB_LABEL_BUMP_BY
;
829 fb_label_count
= FB_LABEL_SPECIAL
;
832 else if (fb_label_count
== fb_label_max
)
834 fb_label_max
+= FB_LABEL_BUMP_BY
;
835 fb_labels
= (long *) xrealloc ((char *) fb_labels
,
836 fb_label_max
* sizeof (long));
837 fb_label_instances
= (long *) xrealloc ((char *) fb_label_instances
,
838 fb_label_max
* sizeof (long));
839 } /* if we needed to grow */
841 fb_labels
[fb_label_count
] = label
;
842 fb_label_instances
[fb_label_count
] = 1;
845 } /* fb_label_instance_inc() */
848 fb_label_instance (label
)
853 if (label
< FB_LABEL_SPECIAL
)
855 return (fb_low_counter
[label
]);
858 for (i
= fb_labels
+ FB_LABEL_SPECIAL
; i
< fb_labels
+ fb_label_count
; ++i
)
862 return (fb_label_instances
[i
- fb_labels
]);
863 } /* if we find it */
864 } /* for each existing label */
868 } /* fb_label_instance() */
873 * Caller must copy returned name: we re-use the area for the next name.
875 * The mth occurence of label n: is turned into the symbol "Ln^Bm" where
876 * n is the label number and m is the instance number. "L" makes it a label discarded
877 * unless debugging and "^B"('\2') ensures no ordinary symbol SHOULD get the
878 * same name as a local label symbol. The first "4:" is "L4^B1" - the m
879 * numbers begin at 1.
881 * dollar labels get the same treatment, except that ^A is used in place of ^B.
884 char * /* Return local label name. */
885 fb_label_name (n
, augend
)
886 long n
; /* we just saw "n:", "nf" or "nb" : n a number */
887 long augend
; /* 0 for nb, 1 for n:, nf */
890 /* Returned to caller, then copied. used for created names ("4f") */
891 static char symbol_name_build
[24];
894 char symbol_name_temporary
[20]; /* build up a number, BACKWARDS */
897 know (augend
== 0 || augend
== 1);
898 p
= symbol_name_build
;
901 /* Next code just does sprintf( {}, "%d", n); */
903 q
= symbol_name_temporary
;
904 for (*q
++ = 0, i
= n
; i
; ++q
)
909 while ((*p
= *--q
) != '\0')
914 /* instance number */
915 q
= symbol_name_temporary
;
916 for (*q
++ = 0, i
= fb_label_instance (n
) + augend
; i
; ++q
)
921 while ((*p
++ = *--q
) != '\0');;
923 /* The label, as a '\0' ended string, starts at symbol_name_build. */
924 return (symbol_name_build
);
925 } /* fb_label_name() */
927 #endif /* LOCAL_LABELS_FB */
931 * decode name that may have been generated by foo_label_name() above. If
932 * the name wasn't generated by foo_label_name(), then return it unaltered.
933 * This is used for error messages.
937 decode_local_label_name (s
)
945 const char *message_format
= "\"%d\" (instance number %d of a %s label)";
950 for (label_number
= 0, p
= s
+ 1; isdigit (*p
); ++p
)
952 label_number
= (10 * label_number
) + *p
- '0';
968 for (instance_number
= 0, p
= s
+ 1; isdigit (*p
); ++p
)
970 instance_number
= (10 * instance_number
) + *p
- '0';
973 symbol_decode
= obstack_alloc (¬es
, strlen (message_format
) + 30);
974 (void) sprintf (symbol_decode
, message_format
, label_number
,
975 instance_number
, type
);
977 return (symbol_decode
);
978 } /* decode_local_label_name() */
988 /* end of symbols.c */