gas: maintain O_constant signedness in more cases
[binutils-gdb.git] / gas / expr.c
blobb83296cc10dcac4450a6891f8d0bee8da58124d7
1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2023 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 /* This is really a branch office of as-read.c. I split it out to clearly
22 distinguish the world of expressions from the world of statements.
23 (It also gives smaller files to re-compile.)
24 Here, "operand"s are of expressions, not instructions. */
26 #define min(a, b) ((a) < (b) ? (a) : (b))
28 #include "as.h"
29 #include "safe-ctype.h"
31 #include <limits.h>
32 #ifndef CHAR_BIT
33 #define CHAR_BIT 8
34 #endif
36 bool literal_prefix_dollar_hex = false;
38 static void clean_up_expression (expressionS * expressionP);
40 /* We keep a mapping of expression symbols to file positions, so that
41 we can provide better error messages. */
43 struct expr_symbol_line {
44 struct expr_symbol_line *next;
45 symbolS *sym;
46 const char *file;
47 unsigned int line;
50 static struct expr_symbol_line *expr_symbol_lines;
52 static const expressionS zero = { .X_op = O_constant };
54 /* Build a dummy symbol to hold a complex expression. This is how we
55 build expressions up out of other expressions. The symbol is put
56 into the fake section expr_section. */
58 symbolS *
59 make_expr_symbol (const expressionS *expressionP)
61 symbolS *symbolP;
62 struct expr_symbol_line *n;
64 if (expressionP->X_op == O_symbol
65 && expressionP->X_add_number == 0)
66 return expressionP->X_add_symbol;
68 if (expressionP->X_op == O_big)
70 /* This won't work, because the actual value is stored in
71 generic_floating_point_number or generic_bignum, and we are
72 going to lose it if we haven't already. */
73 if (expressionP->X_add_number > 0)
74 as_bad (_("bignum invalid"));
75 else
76 as_bad (_("floating point number invalid"));
77 expressionP = &zero;
80 /* Putting constant symbols in absolute_section rather than
81 expr_section is convenient for the old a.out code, for which
82 S_GET_SEGMENT does not always retrieve the value put in by
83 S_SET_SEGMENT. */
84 symbolP = symbol_create (FAKE_LABEL_NAME,
85 (expressionP->X_op == O_constant
86 ? absolute_section
87 : expressionP->X_op == O_register
88 ? reg_section
89 : expr_section),
90 &zero_address_frag, 0);
91 symbol_set_value_expression (symbolP, expressionP);
93 if (expressionP->X_op == O_constant)
94 resolve_symbol_value (symbolP);
96 n = notes_alloc (sizeof (*n));
97 n->sym = symbolP;
98 n->file = as_where (&n->line);
99 n->next = expr_symbol_lines;
100 expr_symbol_lines = n;
102 return symbolP;
105 /* Return the file and line number for an expr symbol. Return
106 non-zero if something was found, 0 if no information is known for
107 the symbol. */
110 expr_symbol_where (symbolS *sym, const char **pfile, unsigned int *pline)
112 struct expr_symbol_line *l;
114 for (l = expr_symbol_lines; l != NULL; l = l->next)
116 if (l->sym == sym)
118 *pfile = l->file;
119 *pline = l->line;
120 return 1;
124 return 0;
127 /* Look up a previously used .startof. / .sizeof. symbol, or make a fresh
128 one. */
129 static symbolS **seen[2];
130 static unsigned int nr_seen[2];
132 static symbolS *
133 symbol_lookup_or_make (const char *name, bool start)
135 char *buf = concat (start ? ".startof." : ".sizeof.", name, NULL);
136 symbolS *symbolP;
137 unsigned int i;
139 for (i = 0; i < nr_seen[start]; ++i)
141 symbolP = seen[start][i];
143 if (! symbolP)
144 break;
146 name = S_GET_NAME (symbolP);
147 if ((symbols_case_sensitive
148 ? strcmp (buf, name)
149 : strcasecmp (buf, name)) == 0)
151 free (buf);
152 return symbolP;
156 symbolP = symbol_make (buf);
157 free (buf);
159 if (i >= nr_seen[start])
161 unsigned int nr = (i + 1) * 2;
163 seen[start] = XRESIZEVEC (symbolS *, seen[start], nr);
164 nr_seen[start] = nr;
165 memset (&seen[start][i + 1], 0, (nr - i - 1) * sizeof(seen[0][0]));
168 seen[start][i] = symbolP;
170 return symbolP;
173 /* Utilities for building expressions.
174 Since complex expressions are recorded as symbols for use in other
175 expressions these return a symbolS * and not an expressionS *.
176 These explicitly do not take an "add_number" argument. */
177 /* ??? For completeness' sake one might want expr_build_symbol.
178 It would just return its argument. */
180 /* Build an expression for an unsigned constant.
181 The corresponding one for signed constants is missing because
182 there's currently no need for it. One could add an unsigned_p flag
183 but that seems more clumsy. */
185 symbolS *
186 expr_build_uconstant (offsetT value)
188 expressionS e;
190 e.X_op = O_constant;
191 e.X_add_number = value;
192 e.X_unsigned = 1;
193 e.X_extrabit = 0;
194 return make_expr_symbol (&e);
197 /* Build an expression for the current location ('.'). */
199 symbolS *
200 expr_build_dot (void)
202 expressionS e;
204 current_location (&e);
205 return symbol_clone_if_forward_ref (make_expr_symbol (&e));
208 /* Build any floating-point literal here.
209 Also build any bignum literal here. */
211 /* Seems atof_machine can backscan through generic_bignum and hit whatever
212 happens to be loaded before it in memory. And its way too complicated
213 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
214 and never write into the early words, thus they'll always be zero.
215 I hate Dean's floating-point code. Bleh. */
216 LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
218 FLONUM_TYPE generic_floating_point_number = {
219 &generic_bignum[6], /* low. (JF: Was 0) */
220 &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high. JF: (added +6) */
221 0, /* leader. */
222 0, /* exponent. */
223 0 /* sign. */
227 static void
228 floating_constant (expressionS *expressionP)
230 /* input_line_pointer -> floating-point constant. */
231 int error_code;
233 error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
234 &generic_floating_point_number);
236 if (error_code)
238 if (error_code == ERROR_EXPONENT_OVERFLOW)
240 as_bad (_("bad floating-point constant: exponent overflow"));
242 else
244 as_bad (_("bad floating-point constant: unknown error code=%d"),
245 error_code);
248 expressionP->X_op = O_big;
249 /* input_line_pointer -> just after constant, which may point to
250 whitespace. */
251 expressionP->X_add_number = -1;
254 uint32_t
255 generic_bignum_to_int32 (void)
257 return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
258 << LITTLENUM_NUMBER_OF_BITS)
259 | ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
262 uint64_t
263 generic_bignum_to_int64 (void)
265 return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
266 << LITTLENUM_NUMBER_OF_BITS)
267 | ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
268 << LITTLENUM_NUMBER_OF_BITS)
269 | ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
270 << LITTLENUM_NUMBER_OF_BITS)
271 | ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
274 static void
275 integer_constant (int radix, expressionS *expressionP)
277 char *start; /* Start of number. */
278 char *suffix = NULL;
279 char c;
280 valueT number; /* Offset or (absolute) value. */
281 short int digit; /* Value of next digit in current radix. */
282 short int maxdig = 0; /* Highest permitted digit value. */
283 int too_many_digits = 0; /* If we see >= this number of. */
284 char *name; /* Points to name of symbol. */
285 symbolS *symbolP; /* Points to symbol. */
287 int small; /* True if fits in 32 bits. */
289 /* May be bignum, or may fit in 32 bits. */
290 /* Most numbers fit into 32 bits, and we want this case to be fast.
291 so we pretend it will fit into 32 bits. If, after making up a 32
292 bit number, we realise that we have scanned more digits than
293 comfortably fit into 32 bits, we re-scan the digits coding them
294 into a bignum. For decimal and octal numbers we are
295 conservative: Some numbers may be assumed bignums when in fact
296 they do fit into 32 bits. Numbers of any radix can have excess
297 leading zeros: We strive to recognise this and cast them back
298 into 32 bits. We must check that the bignum really is more than
299 32 bits, and change it back to a 32-bit number if it fits. The
300 number we are looking for is expected to be positive, but if it
301 fits into 32 bits as an unsigned number, we let it be a 32-bit
302 number. The cavalier approach is for speed in ordinary cases. */
303 /* This has been extended for 64 bits. We blindly assume that if
304 you're compiling in 64-bit mode, the target is a 64-bit machine.
305 This should be cleaned up. */
307 #ifdef BFD64
308 #define valuesize 64
309 #else /* includes non-bfd case, mostly */
310 #define valuesize 32
311 #endif
313 if (is_end_of_line[(unsigned char) *input_line_pointer])
315 expressionP->X_op = O_absent;
316 return;
319 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
321 int flt = 0;
323 /* In MRI mode, the number may have a suffix indicating the
324 radix. For that matter, it might actually be a floating
325 point constant. */
326 for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
328 if (*suffix == 'e' || *suffix == 'E')
329 flt = 1;
332 if (suffix == input_line_pointer)
334 radix = 10;
335 suffix = NULL;
337 else
339 c = *--suffix;
340 c = TOUPPER (c);
341 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
342 we distinguish between 'B' and 'b'. This is the case for
343 Z80. */
344 if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B')
345 radix = 2;
346 else if (c == 'D')
347 radix = 10;
348 else if (c == 'O' || c == 'Q')
349 radix = 8;
350 else if (c == 'H')
351 radix = 16;
352 else if (suffix[1] == '.' || c == 'E' || flt)
354 floating_constant (expressionP);
355 return;
357 else
359 radix = 10;
360 suffix = NULL;
365 switch (radix)
367 case 2:
368 maxdig = 2;
369 too_many_digits = valuesize + 1;
370 break;
371 case 8:
372 maxdig = radix = 8;
373 too_many_digits = (valuesize + 2) / 3 + 1;
374 break;
375 case 16:
376 maxdig = radix = 16;
377 too_many_digits = (valuesize + 3) / 4 + 1;
378 break;
379 case 10:
380 maxdig = radix = 10;
381 too_many_digits = (valuesize + 11) / 4; /* Very rough. */
383 #undef valuesize
384 start = input_line_pointer;
385 c = *input_line_pointer++;
386 for (number = 0;
387 (digit = hex_value (c)) < maxdig;
388 c = *input_line_pointer++)
390 number = number * radix + digit;
392 /* c contains character after number. */
393 /* input_line_pointer->char after c. */
394 small = (input_line_pointer - start - 1) < too_many_digits;
396 if (radix == 16 && c == '_')
398 /* This is literal of the form 0x333_0_12345678_1.
399 This example is equivalent to 0x00000333000000001234567800000001. */
401 int num_little_digits = 0;
402 int i;
403 input_line_pointer = start; /* -> 1st digit. */
405 know (LITTLENUM_NUMBER_OF_BITS == 16);
407 for (c = '_'; c == '_'; num_little_digits += 2)
410 /* Convert one 64-bit word. */
411 int ndigit = 0;
412 number = 0;
413 for (c = *input_line_pointer++;
414 (digit = hex_value (c)) < maxdig;
415 c = *(input_line_pointer++))
417 number = number * radix + digit;
418 ndigit++;
421 /* Check for 8 digit per word max. */
422 if (ndigit > 8)
423 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
425 /* Add this chunk to the bignum.
426 Shift things down 2 little digits. */
427 know (LITTLENUM_NUMBER_OF_BITS == 16);
428 for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
429 i >= 2;
430 i--)
431 generic_bignum[i] = generic_bignum[i - 2];
433 /* Add the new digits as the least significant new ones. */
434 generic_bignum[0] = number & 0xffffffff;
435 generic_bignum[1] = number >> 16;
438 /* Again, c is char after number, input_line_pointer->after c. */
440 if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
441 num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
443 gas_assert (num_little_digits >= 4);
445 if (num_little_digits != 8)
446 as_bad (_("a bignum with underscores must have exactly 4 words"));
448 /* We might have some leading zeros. These can be trimmed to give
449 us a change to fit this constant into a small number. */
450 while (generic_bignum[num_little_digits - 1] == 0
451 && num_little_digits > 1)
452 num_little_digits--;
454 if (num_little_digits <= 2)
456 /* will fit into 32 bits. */
457 number = generic_bignum_to_int32 ();
458 small = 1;
460 #ifdef BFD64
461 else if (num_little_digits <= 4)
463 /* Will fit into 64 bits. */
464 number = generic_bignum_to_int64 ();
465 small = 1;
467 #endif
468 else
470 small = 0;
472 /* Number of littlenums in the bignum. */
473 number = num_little_digits;
476 else if (!small)
478 /* We saw a lot of digits. manufacture a bignum the hard way. */
479 LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum. */
480 LITTLENUM_TYPE *pointer; /* -> littlenum we are frobbing now. */
481 long carry;
483 leader = generic_bignum;
484 generic_bignum[0] = 0;
485 generic_bignum[1] = 0;
486 generic_bignum[2] = 0;
487 generic_bignum[3] = 0;
488 input_line_pointer = start; /* -> 1st digit. */
489 c = *input_line_pointer++;
490 for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++)
492 for (pointer = generic_bignum; pointer <= leader; pointer++)
494 long work;
496 work = carry + radix * *pointer;
497 *pointer = work & LITTLENUM_MASK;
498 carry = work >> LITTLENUM_NUMBER_OF_BITS;
500 if (carry)
502 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
504 /* Room to grow a longer bignum. */
505 *++leader = carry;
509 /* Again, c is char after number. */
510 /* input_line_pointer -> after c. */
511 know (LITTLENUM_NUMBER_OF_BITS == 16);
512 if (leader < generic_bignum + 2)
514 /* Will fit into 32 bits. */
515 number = generic_bignum_to_int32 ();
516 small = 1;
518 #ifdef BFD64
519 else if (leader < generic_bignum + 4)
521 /* Will fit into 64 bits. */
522 number = generic_bignum_to_int64 ();
523 small = 1;
525 #endif
526 else
528 /* Number of littlenums in the bignum. */
529 number = leader - generic_bignum + 1;
533 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
534 && suffix != NULL
535 && input_line_pointer - 1 == suffix)
536 c = *input_line_pointer++;
538 #ifndef tc_allow_U_suffix
539 #define tc_allow_U_suffix 1
540 #endif
541 /* PR 19910: Look for, and ignore, a U suffix to the number. */
542 if (tc_allow_U_suffix && (c == 'U' || c == 'u'))
543 c = * input_line_pointer++;
545 #ifndef tc_allow_L_suffix
546 #define tc_allow_L_suffix 1
547 #endif
548 /* PR 20732: Look for, and ignore, a L or LL suffix to the number. */
549 if (tc_allow_L_suffix)
550 while (c == 'L' || c == 'l')
551 c = * input_line_pointer++;
553 if (small)
555 /* Here with number, in correct radix. c is the next char.
556 Note that unlike un*x, we allow "011f" "0x9f" to both mean
557 the same as the (conventional) "9f".
558 This is simply easier than checking for strict canonical
559 form. Syntax sux! */
561 if (LOCAL_LABELS_FB && c == 'b')
563 /* Backward ref to local label.
564 Because it is backward, expect it to be defined. */
565 /* Construct a local label. */
566 name = fb_label_name (number, 0);
568 /* Seen before, or symbol is defined: OK. */
569 symbolP = symbol_find (name);
570 if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
572 expressionP->X_op = O_symbol;
573 expressionP->X_add_symbol = symbolP;
575 else
577 /* Either not seen or not defined. */
578 /* @@ Should print out the original string instead of
579 the parsed number. */
580 as_bad (_("backward ref to unknown label \"%d:\""),
581 (int) number);
582 expressionP->X_op = O_constant;
585 expressionP->X_add_number = 0;
586 } /* case 'b' */
587 else if (LOCAL_LABELS_FB && c == 'f')
589 /* Forward reference. Expect symbol to be undefined or
590 unknown. undefined: seen it before. unknown: never seen
591 it before.
593 Construct a local label name, then an undefined symbol.
594 Don't create a xseg frag for it: caller may do that.
595 Just return it as never seen before. */
596 name = fb_label_name (number, 1);
597 symbolP = symbol_find_or_make (name);
598 /* We have no need to check symbol properties. */
599 expressionP->X_op = O_symbol;
600 expressionP->X_add_symbol = symbolP;
601 expressionP->X_add_number = 0;
602 } /* case 'f' */
603 else if (LOCAL_LABELS_DOLLAR && c == '$')
605 /* If the dollar label is *currently* defined, then this is just
606 another reference to it. If it is not *currently* defined,
607 then this is a fresh instantiation of that number, so create
608 it. */
610 if (dollar_label_defined (number))
612 name = dollar_label_name (number, 0);
613 symbolP = symbol_find (name);
614 know (symbolP != NULL);
616 else
618 name = dollar_label_name (number, 1);
619 symbolP = symbol_find_or_make (name);
622 expressionP->X_op = O_symbol;
623 expressionP->X_add_symbol = symbolP;
624 expressionP->X_add_number = 0;
625 } /* case '$' */
626 else
628 expressionP->X_op = O_constant;
629 expressionP->X_add_number = number;
630 input_line_pointer--; /* Restore following character. */
631 } /* Really just a number. */
633 else
635 /* Not a small number. */
636 expressionP->X_op = O_big;
637 expressionP->X_add_number = number; /* Number of littlenums. */
638 input_line_pointer--; /* -> char following number. */
642 /* Parse an MRI multi character constant. */
644 static void
645 mri_char_constant (expressionS *expressionP)
647 int i;
649 if (*input_line_pointer == '\''
650 && input_line_pointer[1] != '\'')
652 expressionP->X_op = O_constant;
653 expressionP->X_add_number = 0;
654 return;
657 /* In order to get the correct byte ordering, we must build the
658 number in reverse. */
659 for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
661 int j;
663 generic_bignum[i] = 0;
664 for (j = 0; j < CHARS_PER_LITTLENUM; j++)
666 if (*input_line_pointer == '\'')
668 if (input_line_pointer[1] != '\'')
669 break;
670 ++input_line_pointer;
672 generic_bignum[i] <<= 8;
673 generic_bignum[i] += *input_line_pointer;
674 ++input_line_pointer;
677 if (i < SIZE_OF_LARGE_NUMBER - 1)
679 /* If there is more than one littlenum, left justify the
680 last one to make it match the earlier ones. If there is
681 only one, we can just use the value directly. */
682 for (; j < CHARS_PER_LITTLENUM; j++)
683 generic_bignum[i] <<= 8;
686 if (*input_line_pointer == '\''
687 && input_line_pointer[1] != '\'')
688 break;
691 if (i < 0)
693 as_bad (_("character constant too large"));
694 i = 0;
697 if (i > 0)
699 int c;
700 int j;
702 c = SIZE_OF_LARGE_NUMBER - i;
703 for (j = 0; j < c; j++)
704 generic_bignum[j] = generic_bignum[i + j];
705 i = c;
708 know (LITTLENUM_NUMBER_OF_BITS == 16);
709 if (i > 2)
711 expressionP->X_op = O_big;
712 expressionP->X_add_number = i;
714 else
716 expressionP->X_op = O_constant;
717 if (i < 2)
718 expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
719 else
720 expressionP->X_add_number =
721 (((generic_bignum[1] & LITTLENUM_MASK)
722 << LITTLENUM_NUMBER_OF_BITS)
723 | (generic_bignum[0] & LITTLENUM_MASK));
726 /* Skip the final closing quote. */
727 ++input_line_pointer;
730 /* Return an expression representing the current location. This
731 handles the magic symbol `.'. */
733 void
734 current_location (expressionS *expressionp)
736 if (now_seg == absolute_section)
738 expressionp->X_op = O_constant;
739 expressionp->X_add_number = abs_section_offset;
741 else
743 expressionp->X_op = O_symbol;
744 expressionp->X_add_symbol = &dot_symbol;
745 expressionp->X_add_number = 0;
749 #ifndef md_register_arithmetic
750 # define md_register_arithmetic 1
751 #endif
753 /* In: Input_line_pointer points to 1st char of operand, which may
754 be a space.
756 Out: An expressionS.
757 The operand may have been empty: in this case X_op == O_absent.
758 Input_line_pointer->(next non-blank) char after operand. */
760 static segT
761 operand (expressionS *expressionP, enum expr_mode mode)
763 char c;
764 symbolS *symbolP; /* Points to symbol. */
765 char *name; /* Points to name of symbol. */
766 segT segment;
768 /* All integers are regarded as unsigned unless they are negated.
769 This is because the only thing which cares whether a number is
770 unsigned is the code in emit_expr which extends constants into
771 bignums. It should only sign extend negative numbers, so that
772 something like ``.quad 0x80000000'' is not sign extended even
773 though it appears negative if valueT is 32 bits. */
774 expressionP->X_unsigned = 1;
775 expressionP->X_extrabit = 0;
777 /* Digits, assume it is a bignum. */
779 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
780 c = *input_line_pointer++; /* input_line_pointer -> past char in c. */
782 if (is_end_of_line[(unsigned char) c])
783 goto eol;
785 switch (c)
787 case '1':
788 case '2':
789 case '3':
790 case '4':
791 case '5':
792 case '6':
793 case '7':
794 case '8':
795 case '9':
796 input_line_pointer--;
798 integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
799 ? 0 : 10,
800 expressionP);
801 break;
803 #ifdef LITERAL_PREFIXPERCENT_BIN
804 case '%':
805 integer_constant (2, expressionP);
806 break;
807 #endif
809 case '0':
810 /* Non-decimal radix. */
812 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
814 char *s;
816 /* Check for a hex or float constant. */
817 for (s = input_line_pointer; hex_p (*s); s++)
819 if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
821 --input_line_pointer;
822 integer_constant (0, expressionP);
823 break;
826 c = *input_line_pointer;
827 switch (c)
829 case 'o':
830 case 'O':
831 case 'q':
832 case 'Q':
833 case '8':
834 case '9':
835 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
837 integer_constant (0, expressionP);
838 break;
840 /* Fall through. */
841 default:
842 default_case:
843 if (c && strchr (FLT_CHARS, c))
845 input_line_pointer++;
846 floating_constant (expressionP);
847 expressionP->X_add_number = - TOLOWER (c);
849 else
851 /* The string was only zero. */
852 expressionP->X_op = O_constant;
853 expressionP->X_add_number = 0;
856 break;
858 case 'x':
859 case 'X':
860 if (flag_m68k_mri)
861 goto default_case;
862 input_line_pointer++;
863 integer_constant (16, expressionP);
864 break;
866 case 'b':
867 if (LOCAL_LABELS_FB && !flag_m68k_mri
868 && input_line_pointer[1] != '0'
869 && input_line_pointer[1] != '1')
871 /* Parse this as a back reference to label 0. */
872 input_line_pointer--;
873 integer_constant (10, expressionP);
874 break;
876 /* Otherwise, parse this as a binary number. */
877 /* Fall through. */
878 case 'B':
879 if (input_line_pointer[1] == '0'
880 || input_line_pointer[1] == '1')
882 input_line_pointer++;
883 integer_constant (2, expressionP);
884 break;
886 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
887 input_line_pointer++;
888 goto default_case;
890 case '0':
891 case '1':
892 case '2':
893 case '3':
894 case '4':
895 case '5':
896 case '6':
897 case '7':
898 integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
899 ? 0 : 8,
900 expressionP);
901 break;
903 case 'f':
904 if (LOCAL_LABELS_FB)
906 int is_label = 1;
908 /* If it says "0f" and it could possibly be a floating point
909 number, make it one. Otherwise, make it a local label,
910 and try to deal with parsing the rest later. */
911 if (!is_end_of_line[(unsigned char) input_line_pointer[1]]
912 && strchr (FLT_CHARS, 'f') != NULL)
914 char *cp = input_line_pointer + 1;
916 atof_generic (&cp, ".", EXP_CHARS,
917 &generic_floating_point_number);
919 /* Was nothing parsed, or does it look like an
920 expression? */
921 is_label = (cp == input_line_pointer + 1
922 || (cp == input_line_pointer + 2
923 && (cp[-1] == '-' || cp[-1] == '+'))
924 || *cp == 'f'
925 || *cp == 'b');
927 if (is_label)
929 input_line_pointer--;
930 integer_constant (10, expressionP);
931 break;
934 /* Fall through. */
936 case 'd':
937 case 'D':
938 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
940 integer_constant (0, expressionP);
941 break;
943 /* Fall through. */
944 case 'F':
945 case 'r':
946 case 'e':
947 case 'E':
948 case 'g':
949 case 'G':
950 input_line_pointer++;
951 floating_constant (expressionP);
952 expressionP->X_add_number = - TOLOWER (c);
953 break;
955 case '$':
956 if (LOCAL_LABELS_DOLLAR)
958 integer_constant (10, expressionP);
959 break;
961 else
962 goto default_case;
965 break;
967 #ifndef NEED_INDEX_OPERATOR
968 case '[':
969 # ifdef md_need_index_operator
970 if (md_need_index_operator())
971 goto de_fault;
972 # endif
973 #endif
974 /* Fall through. */
975 case '(':
976 /* Didn't begin with digit & not a name. */
977 segment = expr (0, expressionP, mode);
978 /* expression () will pass trailing whitespace. */
979 if ((c == '(' && *input_line_pointer != ')')
980 || (c == '[' && *input_line_pointer != ']'))
982 if (* input_line_pointer)
983 as_bad (_("found '%c', expected: '%c'"),
984 * input_line_pointer, c == '(' ? ')' : ']');
985 else
986 as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
988 else
989 input_line_pointer++;
990 SKIP_ALL_WHITESPACE ();
991 /* Here with input_line_pointer -> char after "(...)". */
992 return segment;
994 #ifdef TC_M68K
995 case 'E':
996 if (! flag_m68k_mri || *input_line_pointer != '\'')
997 goto de_fault;
998 as_bad (_("EBCDIC constants are not supported"));
999 /* Fall through. */
1000 case 'A':
1001 if (! flag_m68k_mri || *input_line_pointer != '\'')
1002 goto de_fault;
1003 ++input_line_pointer;
1004 #endif
1005 /* Fall through. */
1006 case '\'':
1007 if (! flag_m68k_mri)
1009 /* Warning: to conform to other people's assemblers NO
1010 ESCAPEMENT is permitted for a single quote. The next
1011 character, parity errors and all, is taken as the value
1012 of the operand. VERY KINKY. */
1013 expressionP->X_op = O_constant;
1014 expressionP->X_add_number = *input_line_pointer++;
1015 break;
1018 mri_char_constant (expressionP);
1019 break;
1021 #ifdef TC_M68K
1022 case '"':
1023 /* Double quote is the bitwise not operator in MRI mode. */
1024 if (! flag_m68k_mri)
1025 goto de_fault;
1026 #endif
1027 /* Fall through. */
1028 case '~':
1029 /* '~' is permitted to start a label on the Delta. */
1030 if (is_name_beginner (c))
1031 goto isname;
1032 /* Fall through. */
1033 case '!':
1034 case '-':
1035 case '+':
1037 #ifdef md_operator
1038 unary:
1039 #endif
1040 operand (expressionP, mode);
1041 if (expressionP->X_op == O_constant)
1043 /* input_line_pointer -> char after operand. */
1044 if (c == '-')
1046 expressionP->X_add_number
1047 = - (addressT) expressionP->X_add_number;
1048 /* Notice: '-' may overflow: no warning is given.
1049 This is compatible with other people's
1050 assemblers. Sigh. */
1051 expressionP->X_unsigned = 0;
1052 if (expressionP->X_add_number)
1053 expressionP->X_extrabit ^= 1;
1055 else if (c == '~' || c == '"')
1057 expressionP->X_add_number = ~ expressionP->X_add_number;
1058 expressionP->X_extrabit ^= 1;
1059 expressionP->X_unsigned = 0;
1061 else if (c == '!')
1063 expressionP->X_add_number = ! expressionP->X_add_number;
1064 expressionP->X_unsigned = 1;
1065 expressionP->X_extrabit = 0;
1068 else if (expressionP->X_op == O_big
1069 && expressionP->X_add_number <= 0
1070 && c == '-'
1071 && (generic_floating_point_number.sign == '+'
1072 || generic_floating_point_number.sign == 'P'))
1074 /* Negative flonum (eg, -1.000e0). */
1075 if (generic_floating_point_number.sign == '+')
1076 generic_floating_point_number.sign = '-';
1077 else
1078 generic_floating_point_number.sign = 'N';
1080 else if (expressionP->X_op == O_big
1081 && expressionP->X_add_number > 0)
1083 int i;
1085 if (c == '~' || c == '-')
1087 for (i = 0; i < expressionP->X_add_number; ++i)
1088 generic_bignum[i] = ~generic_bignum[i];
1090 /* Extend the bignum to at least the size of .octa. */
1091 if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1093 expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1094 for (; i < expressionP->X_add_number; ++i)
1095 generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1098 if (c == '-')
1099 for (i = 0; i < expressionP->X_add_number; ++i)
1101 generic_bignum[i] += 1;
1102 if (generic_bignum[i])
1103 break;
1106 else if (c == '!')
1108 for (i = 0; i < expressionP->X_add_number; ++i)
1109 if (generic_bignum[i] != 0)
1110 break;
1111 expressionP->X_add_number = i >= expressionP->X_add_number;
1112 expressionP->X_op = O_constant;
1113 expressionP->X_unsigned = 1;
1114 expressionP->X_extrabit = 0;
1117 else if (expressionP->X_op != O_illegal
1118 && expressionP->X_op != O_absent)
1120 if (c != '+')
1122 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1123 if (c == '-')
1124 expressionP->X_op = O_uminus;
1125 else if (c == '~' || c == '"')
1126 expressionP->X_op = O_bit_not;
1127 else
1128 expressionP->X_op = O_logical_not;
1129 expressionP->X_add_number = 0;
1131 else if (!md_register_arithmetic && expressionP->X_op == O_register)
1133 /* Convert to binary '+'. */
1134 expressionP->X_op_symbol = make_expr_symbol (expressionP);
1135 expressionP->X_add_symbol = make_expr_symbol (&zero);
1136 expressionP->X_add_number = 0;
1137 expressionP->X_op = O_add;
1140 else
1141 as_warn (_("Unary operator %c ignored because bad operand follows"),
1144 break;
1146 #if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1147 case '$':
1148 if (literal_prefix_dollar_hex)
1150 /* $L is the start of a local label, not a hex constant. */
1151 if (* input_line_pointer == 'L')
1152 goto isname;
1153 integer_constant (16, expressionP);
1155 else
1157 goto isname;
1159 break;
1160 #else
1161 case '$':
1162 /* '$' is the program counter when in MRI mode, or when
1163 DOLLAR_DOT is defined. */
1164 #ifndef DOLLAR_DOT
1165 if (! flag_m68k_mri)
1166 goto de_fault;
1167 #endif
1168 if (DOLLAR_AMBIGU && hex_p (*input_line_pointer))
1170 /* In MRI mode and on Z80, '$' is also used as the prefix
1171 for a hexadecimal constant. */
1172 integer_constant (16, expressionP);
1173 break;
1176 if (is_part_of_name (*input_line_pointer))
1177 goto isname;
1179 current_location (expressionP);
1180 break;
1181 #endif
1183 case '.':
1184 if (!is_part_of_name (*input_line_pointer))
1186 current_location (expressionP);
1187 break;
1189 else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1190 && ! is_part_of_name (input_line_pointer[8]))
1191 || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1192 && ! is_part_of_name (input_line_pointer[7])))
1194 int start;
1196 start = (input_line_pointer[1] == 't'
1197 || input_line_pointer[1] == 'T');
1198 input_line_pointer += start ? 8 : 7;
1199 SKIP_WHITESPACE ();
1201 /* Cover for the as_bad () invocations below. */
1202 expressionP->X_op = O_absent;
1204 if (*input_line_pointer != '(')
1205 as_bad (_("syntax error in .startof. or .sizeof."));
1206 else
1208 ++input_line_pointer;
1209 SKIP_WHITESPACE ();
1210 c = get_symbol_name (& name);
1211 if (! *name)
1213 as_bad (_("expected symbol name"));
1214 (void) restore_line_pointer (c);
1215 if (c == ')')
1216 ++input_line_pointer;
1217 break;
1220 expressionP->X_op = O_symbol;
1221 expressionP->X_add_symbol = symbol_lookup_or_make (name, start);
1222 expressionP->X_add_number = 0;
1224 *input_line_pointer = c;
1225 SKIP_WHITESPACE_AFTER_NAME ();
1226 if (*input_line_pointer != ')')
1227 as_bad (_("syntax error in .startof. or .sizeof."));
1228 else
1229 ++input_line_pointer;
1231 break;
1233 else
1235 goto isname;
1238 case ',':
1239 eol:
1240 /* Can't imagine any other kind of operand. */
1241 expressionP->X_op = O_absent;
1242 input_line_pointer--;
1243 break;
1245 #ifdef TC_M68K
1246 case '%':
1247 if (! flag_m68k_mri)
1248 goto de_fault;
1249 integer_constant (2, expressionP);
1250 break;
1252 case '@':
1253 if (! flag_m68k_mri)
1254 goto de_fault;
1255 integer_constant (8, expressionP);
1256 break;
1258 case ':':
1259 if (! flag_m68k_mri)
1260 goto de_fault;
1262 /* In MRI mode, this is a floating point constant represented
1263 using hexadecimal digits. */
1265 ++input_line_pointer;
1266 integer_constant (16, expressionP);
1267 break;
1269 case '*':
1270 if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
1271 goto de_fault;
1273 current_location (expressionP);
1274 break;
1275 #endif
1277 default:
1278 #if defined(md_need_index_operator) || defined(TC_M68K)
1279 de_fault:
1280 #endif
1281 if (is_name_beginner (c) || c == '"') /* Here if did not begin with a digit. */
1283 /* Identifier begins here.
1284 This is kludged for speed, so code is repeated. */
1285 isname:
1286 -- input_line_pointer;
1287 c = get_symbol_name (&name);
1289 #ifdef md_operator
1291 operatorT op = md_operator (name, 1, &c);
1293 switch (op)
1295 case O_uminus:
1296 restore_line_pointer (c);
1297 c = '-';
1298 goto unary;
1299 case O_bit_not:
1300 restore_line_pointer (c);
1301 c = '~';
1302 goto unary;
1303 case O_logical_not:
1304 restore_line_pointer (c);
1305 c = '!';
1306 goto unary;
1307 case O_illegal:
1308 as_bad (_("invalid use of operator \"%s\""), name);
1309 break;
1310 default:
1311 break;
1314 if (op != O_absent && op != O_illegal)
1316 restore_line_pointer (c);
1317 expr (9, expressionP, mode);
1318 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1319 expressionP->X_op_symbol = NULL;
1320 expressionP->X_add_number = 0;
1321 expressionP->X_op = op;
1322 break;
1325 #endif
1327 #ifdef md_parse_name
1328 /* This is a hook for the backend to parse certain names
1329 specially in certain contexts. If a name always has a
1330 specific value, it can often be handled by simply
1331 entering it in the symbol table. */
1332 if (md_parse_name (name, expressionP, mode, &c))
1334 restore_line_pointer (c);
1335 break;
1337 #endif
1339 symbolP = symbol_find_or_make (name);
1341 /* If we have an absolute symbol or a reg, then we know its
1342 value now. */
1343 segment = S_GET_SEGMENT (symbolP);
1344 if (mode != expr_defer
1345 && segment == absolute_section
1346 && !S_FORCE_RELOC (symbolP, 0))
1348 expressionP->X_op = O_constant;
1349 expressionP->X_add_number = S_GET_VALUE (symbolP);
1351 else if (mode != expr_defer && segment == reg_section)
1353 expressionP->X_op = O_register;
1354 expressionP->X_add_number = S_GET_VALUE (symbolP);
1356 else
1358 expressionP->X_op = O_symbol;
1359 expressionP->X_add_symbol = symbolP;
1360 expressionP->X_add_number = 0;
1363 restore_line_pointer (c);
1365 else
1367 /* Let the target try to parse it. Success is indicated by changing
1368 the X_op field to something other than O_absent and pointing
1369 input_line_pointer past the expression. If it can't parse the
1370 expression, X_op and input_line_pointer should be unchanged. */
1371 expressionP->X_op = O_absent;
1372 --input_line_pointer;
1373 md_operand (expressionP);
1374 if (expressionP->X_op == O_absent)
1376 ++input_line_pointer;
1377 as_bad (_("bad expression"));
1378 expressionP->X_op = O_constant;
1379 expressionP->X_add_number = 0;
1382 break;
1385 /* It is more 'efficient' to clean up the expressionS when they are
1386 created. Doing it here saves lines of code. */
1387 clean_up_expression (expressionP);
1388 SKIP_ALL_WHITESPACE (); /* -> 1st char after operand. */
1389 know (*input_line_pointer != ' ');
1391 /* The PA port needs this information. */
1392 if (expressionP->X_add_symbol)
1393 symbol_mark_used (expressionP->X_add_symbol);
1395 if (mode != expr_defer)
1397 expressionP->X_add_symbol
1398 = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1399 expressionP->X_op_symbol
1400 = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1403 switch (expressionP->X_op)
1405 default:
1406 return absolute_section;
1407 case O_symbol:
1408 return S_GET_SEGMENT (expressionP->X_add_symbol);
1409 case O_register:
1410 return reg_section;
1414 /* Internal. Simplify a struct expression for use by expr (). */
1416 /* In: address of an expressionS.
1417 The X_op field of the expressionS may only take certain values.
1418 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1420 Out: expressionS may have been modified:
1421 Unused fields zeroed to help expr (). */
1423 static void
1424 clean_up_expression (expressionS *expressionP)
1426 switch (expressionP->X_op)
1428 case O_illegal:
1429 case O_absent:
1430 expressionP->X_add_number = 0;
1431 /* Fall through. */
1432 case O_big:
1433 case O_constant:
1434 case O_register:
1435 expressionP->X_add_symbol = NULL;
1436 /* Fall through. */
1437 case O_symbol:
1438 case O_uminus:
1439 case O_bit_not:
1440 expressionP->X_op_symbol = NULL;
1441 break;
1442 default:
1443 break;
1447 /* Expression parser. */
1449 /* We allow an empty expression, and just assume (absolute,0) silently.
1450 Unary operators and parenthetical expressions are treated as operands.
1451 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1453 We used to do an aho/ullman shift-reduce parser, but the logic got so
1454 warped that I flushed it and wrote a recursive-descent parser instead.
1455 Now things are stable, would anybody like to write a fast parser?
1456 Most expressions are either register (which does not even reach here)
1457 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1458 So I guess it doesn't really matter how inefficient more complex expressions
1459 are parsed.
1461 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1462 Also, we have consumed any leading or trailing spaces (operand does that)
1463 and done all intervening operators.
1465 This returns the segment of the result, which will be
1466 absolute_section or the segment of a symbol. */
1468 #undef __
1469 #define __ O_illegal
1470 #ifndef O_SINGLE_EQ
1471 #define O_SINGLE_EQ O_illegal
1472 #endif
1474 /* Maps ASCII -> operators. */
1475 static const operatorT op_encoding[256] = {
1476 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1477 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1479 __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
1480 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1481 __, __, __, __, __, __, __, __,
1482 __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __,
1483 __, __, __, __, __, __, __, __,
1484 __, __, __, __, __, __, __, __,
1485 __, __, __, __, __, __, __, __,
1486 __, __, __,
1487 #ifdef NEED_INDEX_OPERATOR
1488 O_index,
1489 #else
1491 #endif
1492 __, __, O_bit_exclusive_or, __,
1493 __, __, __, __, __, __, __, __,
1494 __, __, __, __, __, __, __, __,
1495 __, __, __, __, __, __, __, __,
1496 __, __, __, __, O_bit_inclusive_or, __, __, __,
1498 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1499 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1500 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1501 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1502 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1503 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1504 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1505 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1508 /* Rank Examples
1509 0 operand, (expression)
1510 1 ||
1511 2 &&
1512 3 == <> < <= >= >
1513 4 + -
1514 5 used for * / % in MRI mode
1515 6 & ^ ! |
1516 7 * / % << >>
1517 8 unary - unary ~
1519 static operator_rankT op_rank[O_max] = {
1520 0, /* O_illegal */
1521 0, /* O_absent */
1522 0, /* O_constant */
1523 0, /* O_symbol */
1524 0, /* O_symbol_rva */
1525 0, /* O_secidx */
1526 0, /* O_register */
1527 0, /* O_big */
1528 9, /* O_uminus */
1529 9, /* O_bit_not */
1530 9, /* O_logical_not */
1531 8, /* O_multiply */
1532 8, /* O_divide */
1533 8, /* O_modulus */
1534 8, /* O_left_shift */
1535 8, /* O_right_shift */
1536 7, /* O_bit_inclusive_or */
1537 7, /* O_bit_or_not */
1538 7, /* O_bit_exclusive_or */
1539 7, /* O_bit_and */
1540 5, /* O_add */
1541 5, /* O_subtract */
1542 4, /* O_eq */
1543 4, /* O_ne */
1544 4, /* O_lt */
1545 4, /* O_le */
1546 4, /* O_ge */
1547 4, /* O_gt */
1548 3, /* O_logical_and */
1549 2, /* O_logical_or */
1550 1, /* O_index */
1553 /* Unfortunately, in MRI mode for the m68k, multiplication and
1554 division have lower precedence than the bit wise operators. This
1555 function sets the operator precedences correctly for the current
1556 mode. Also, MRI uses a different bit_not operator, and this fixes
1557 that as well. */
1559 #define STANDARD_MUL_PRECEDENCE 8
1560 #define MRI_MUL_PRECEDENCE 6
1562 void
1563 expr_set_precedence (void)
1565 if (flag_m68k_mri)
1567 op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
1568 op_rank[O_divide] = MRI_MUL_PRECEDENCE;
1569 op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
1571 else
1573 op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1574 op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1575 op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1579 void
1580 expr_set_rank (operatorT op, operator_rankT rank)
1582 gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank));
1583 op_rank[op] = rank;
1586 /* Initialize the expression parser. */
1588 void
1589 expr_begin (void)
1591 expr_set_precedence ();
1593 /* Verify that X_op field is wide enough. */
1595 expressionS e;
1596 e.X_op = O_max;
1597 gas_assert (e.X_op == O_max);
1600 memset (seen, 0, sizeof seen);
1601 memset (nr_seen, 0, sizeof nr_seen);
1602 expr_symbol_lines = NULL;
1605 void
1606 expr_end (void)
1608 for (size_t i = 0; i < ARRAY_SIZE (seen); i++)
1609 free (seen[i]);
1612 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1613 sets NUM_CHARS to the number of characters in the operator.
1614 Does not advance INPUT_LINE_POINTER. */
1616 static inline operatorT
1617 operatorf (int *num_chars)
1619 int c;
1620 operatorT ret;
1622 c = *input_line_pointer & 0xff;
1623 *num_chars = 1;
1625 if (is_end_of_line[c])
1626 return O_illegal;
1628 #ifdef md_operator
1629 if (is_name_beginner (c))
1631 char *name;
1632 char ec = get_symbol_name (& name);
1634 ret = md_operator (name, 2, &ec);
1635 switch (ret)
1637 case O_absent:
1638 *input_line_pointer = ec;
1639 input_line_pointer = name;
1640 break;
1641 case O_uminus:
1642 case O_bit_not:
1643 case O_logical_not:
1644 as_bad (_("invalid use of operator \"%s\""), name);
1645 ret = O_illegal;
1646 /* FALLTHROUGH */
1647 default:
1648 *input_line_pointer = ec;
1649 *num_chars = input_line_pointer - name;
1650 input_line_pointer = name;
1651 return ret;
1654 #endif
1656 switch (c)
1658 default:
1659 ret = op_encoding[c];
1660 #ifdef md_operator
1661 if (ret == O_illegal)
1663 char *start = input_line_pointer;
1665 ret = md_operator (NULL, 2, NULL);
1666 if (ret != O_illegal)
1667 *num_chars = input_line_pointer - start;
1668 input_line_pointer = start;
1670 #endif
1671 return ret;
1673 case '+':
1674 case '-':
1675 return op_encoding[c];
1677 case '<':
1678 switch (input_line_pointer[1])
1680 default:
1681 return op_encoding[c];
1682 case '<':
1683 ret = O_left_shift;
1684 break;
1685 case '>':
1686 ret = O_ne;
1687 break;
1688 case '=':
1689 ret = O_le;
1690 break;
1692 *num_chars = 2;
1693 return ret;
1695 case '=':
1696 if (input_line_pointer[1] != '=')
1697 return op_encoding[c];
1699 *num_chars = 2;
1700 return O_eq;
1702 case '>':
1703 switch (input_line_pointer[1])
1705 default:
1706 return op_encoding[c];
1707 case '>':
1708 ret = O_right_shift;
1709 break;
1710 case '=':
1711 ret = O_ge;
1712 break;
1714 *num_chars = 2;
1715 return ret;
1717 case '!':
1718 switch (input_line_pointer[1])
1720 case '!':
1721 /* We accept !! as equivalent to ^ for MRI compatibility. */
1722 *num_chars = 2;
1723 return O_bit_exclusive_or;
1724 case '=':
1725 /* We accept != as equivalent to <>. */
1726 *num_chars = 2;
1727 return O_ne;
1728 default:
1729 if (flag_m68k_mri)
1730 return O_bit_inclusive_or;
1731 return op_encoding[c];
1734 case '|':
1735 if (input_line_pointer[1] != '|')
1736 return op_encoding[c];
1738 *num_chars = 2;
1739 return O_logical_or;
1741 case '&':
1742 if (input_line_pointer[1] != '&')
1743 return op_encoding[c];
1745 *num_chars = 2;
1746 return O_logical_and;
1749 /* NOTREACHED */
1752 /* Implement "word-size + 1 bit" addition for
1753 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1754 is used so that the full range of unsigned word values and the full range of
1755 signed word values can be represented in an O_constant expression, which is
1756 useful e.g. for .sleb128 directives. */
1758 void
1759 add_to_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1761 valueT ures = resultP->X_add_number;
1762 valueT uamount = amount;
1764 resultP->X_add_number += uamount;
1766 resultP->X_extrabit ^= rhs_highbit;
1768 if (ures + uamount < ures)
1769 resultP->X_extrabit ^= 1;
1772 /* Similarly, for subtraction. */
1774 void
1775 subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1777 valueT ures = resultP->X_add_number;
1778 valueT uamount = amount;
1780 resultP->X_add_number -= uamount;
1782 resultP->X_extrabit ^= rhs_highbit;
1784 if (ures < uamount)
1785 resultP->X_extrabit ^= 1;
1788 /* Parse an expression. */
1790 segT
1791 expr (int rankarg, /* Larger # is higher rank. */
1792 expressionS *resultP, /* Deliver result here. */
1793 enum expr_mode mode /* Controls behavior. */)
1795 operator_rankT rank = (operator_rankT) rankarg;
1796 segT retval;
1797 expressionS right;
1798 operatorT op_left;
1799 operatorT op_right;
1800 int op_chars;
1802 know (rankarg >= 0);
1804 /* Save the value of dot for the fixup code. */
1805 if (rank == 0)
1807 dot_value = frag_now_fix ();
1808 dot_frag = frag_now;
1811 retval = operand (resultP, mode);
1813 /* operand () gobbles spaces. */
1814 know (*input_line_pointer != ' ');
1816 op_left = operatorf (&op_chars);
1817 while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1819 segT rightseg;
1820 bool is_unsigned;
1821 offsetT frag_off;
1823 input_line_pointer += op_chars; /* -> after operator. */
1825 right.X_md = 0;
1826 rightseg = expr (op_rank[(int) op_left], &right, mode);
1827 if (right.X_op == O_absent)
1829 as_warn (_("missing operand; zero assumed"));
1830 right.X_op = O_constant;
1831 right.X_add_number = 0;
1832 right.X_add_symbol = NULL;
1833 right.X_op_symbol = NULL;
1836 know (*input_line_pointer != ' ');
1838 if (op_left == O_index)
1840 if (*input_line_pointer != ']')
1841 as_bad ("missing right bracket");
1842 else
1844 ++input_line_pointer;
1845 SKIP_WHITESPACE ();
1849 op_right = operatorf (&op_chars);
1851 know (op_right == O_illegal || op_left == O_index
1852 || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1853 know ((int) op_left >= (int) O_multiply);
1854 #ifndef md_operator
1855 know ((int) op_left <= (int) O_index);
1856 #else
1857 know ((int) op_left < (int) O_max);
1858 #endif
1860 /* input_line_pointer->after right-hand quantity. */
1861 /* left-hand quantity in resultP. */
1862 /* right-hand quantity in right. */
1863 /* operator in op_left. */
1865 if (resultP->X_op == O_big)
1867 if (resultP->X_add_number > 0)
1868 as_warn (_("left operand is a bignum; integer 0 assumed"));
1869 else
1870 as_warn (_("left operand is a float; integer 0 assumed"));
1871 resultP->X_op = O_constant;
1872 resultP->X_add_number = 0;
1873 resultP->X_add_symbol = NULL;
1874 resultP->X_op_symbol = NULL;
1876 if (right.X_op == O_big)
1878 if (right.X_add_number > 0)
1879 as_warn (_("right operand is a bignum; integer 0 assumed"));
1880 else
1881 as_warn (_("right operand is a float; integer 0 assumed"));
1882 right.X_op = O_constant;
1883 right.X_add_number = 0;
1884 right.X_add_symbol = NULL;
1885 right.X_op_symbol = NULL;
1888 is_unsigned = resultP->X_unsigned && right.X_unsigned;
1890 if (mode == expr_defer
1891 && ((resultP->X_add_symbol != NULL
1892 && S_IS_FORWARD_REF (resultP->X_add_symbol))
1893 || (right.X_add_symbol != NULL
1894 && S_IS_FORWARD_REF (right.X_add_symbol))))
1895 goto general;
1897 /* Optimize common cases. */
1898 #ifdef md_optimize_expr
1899 if (md_optimize_expr (resultP, op_left, &right))
1901 /* Skip. */
1902 is_unsigned = resultP->X_unsigned;
1904 else
1905 #endif
1906 if (op_left == O_add && right.X_op == O_constant
1907 && (md_register_arithmetic || resultP->X_op != O_register))
1909 /* X + constant. */
1910 add_to_result (resultP, right.X_add_number, right.X_extrabit);
1912 /* This case comes up in PIC code. */
1913 else if (op_left == O_subtract
1914 && right.X_op == O_symbol
1915 && resultP->X_op == O_symbol
1916 && retval == rightseg
1917 #ifdef md_allow_local_subtract
1918 && md_allow_local_subtract (resultP, & right, rightseg)
1919 #endif
1920 && ((SEG_NORMAL (rightseg)
1921 && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
1922 && !S_FORCE_RELOC (right.X_add_symbol, 0))
1923 || right.X_add_symbol == resultP->X_add_symbol)
1924 && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1925 symbol_get_frag (right.X_add_symbol),
1926 &frag_off))
1928 offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
1929 - S_GET_VALUE (right.X_add_symbol);
1930 subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1931 subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
1932 add_to_result (resultP, symval_diff, symval_diff < 0);
1933 resultP->X_op = O_constant;
1934 resultP->X_add_symbol = 0;
1935 is_unsigned = false;
1937 else if (op_left == O_subtract && right.X_op == O_constant
1938 && (md_register_arithmetic || resultP->X_op != O_register))
1940 /* X - constant. */
1941 subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1942 is_unsigned = false;
1944 else if (op_left == O_add && resultP->X_op == O_constant
1945 && (md_register_arithmetic || right.X_op != O_register))
1947 /* Constant + X. */
1948 resultP->X_op = right.X_op;
1949 resultP->X_add_symbol = right.X_add_symbol;
1950 resultP->X_op_symbol = right.X_op_symbol;
1951 add_to_result (resultP, right.X_add_number, right.X_extrabit);
1952 retval = rightseg;
1954 else if (resultP->X_op == O_constant && right.X_op == O_constant)
1956 /* Constant OP constant. */
1957 offsetT v = right.X_add_number;
1958 if (v == 0 && (op_left == O_divide || op_left == O_modulus))
1960 as_warn (_("division by zero"));
1961 v = 1;
1963 switch (op_left)
1965 default: goto general;
1966 case O_multiply:
1967 /* Do the multiply as unsigned to silence ubsan. The
1968 result is of course the same when we throw away high
1969 bits of the result. */
1970 resultP->X_add_number *= (valueT) v;
1971 break;
1972 case O_divide: resultP->X_add_number /= v; break;
1973 case O_modulus: resultP->X_add_number %= v; break;
1974 case O_left_shift:
1975 case O_right_shift:
1976 /* We always use unsigned shifts. According to the ISO
1977 C standard, left shift of a signed type having a
1978 negative value is undefined behaviour, and right
1979 shift of a signed type having negative value is
1980 implementation defined. Left shift of a signed type
1981 when the result overflows is also undefined
1982 behaviour. So don't trigger ubsan warnings or rely
1983 on characteristics of the compiler. */
1984 if ((valueT) v >= sizeof (valueT) * CHAR_BIT)
1986 as_warn_value_out_of_range (_("shift count"), v, 0,
1987 sizeof (valueT) * CHAR_BIT - 1,
1988 NULL, 0);
1989 resultP->X_add_number = 0;
1991 else if (op_left == O_left_shift)
1992 resultP->X_add_number
1993 = (valueT) resultP->X_add_number << (valueT) v;
1994 else
1995 resultP->X_add_number
1996 = (valueT) resultP->X_add_number >> (valueT) v;
1997 is_unsigned = resultP->X_unsigned;
1998 break;
1999 case O_bit_inclusive_or: resultP->X_add_number |= v; break;
2000 case O_bit_or_not: resultP->X_add_number |= ~v; break;
2001 case O_bit_exclusive_or: resultP->X_add_number ^= v; break;
2002 case O_bit_and: resultP->X_add_number &= v; break;
2003 /* Constant + constant (O_add) is handled by the
2004 previous if statement for constant + X, so is omitted
2005 here. */
2006 case O_subtract:
2007 subtract_from_result (resultP, v, 0);
2008 is_unsigned = false;
2009 break;
2010 case O_eq:
2011 resultP->X_add_number =
2012 resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
2013 is_unsigned = false;
2014 break;
2015 case O_ne:
2016 resultP->X_add_number =
2017 resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
2018 is_unsigned = false;
2019 break;
2020 case O_lt:
2021 resultP->X_add_number =
2022 resultP->X_add_number < v ? ~ (offsetT) 0 : 0;
2023 is_unsigned = false;
2024 break;
2025 case O_le:
2026 resultP->X_add_number =
2027 resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
2028 is_unsigned = false;
2029 break;
2030 case O_ge:
2031 resultP->X_add_number =
2032 resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
2033 is_unsigned = false;
2034 break;
2035 case O_gt:
2036 resultP->X_add_number =
2037 resultP->X_add_number > v ? ~ (offsetT) 0 : 0;
2038 is_unsigned = false;
2039 break;
2040 case O_logical_and:
2041 resultP->X_add_number = resultP->X_add_number && v;
2042 is_unsigned = true;
2043 break;
2044 case O_logical_or:
2045 resultP->X_add_number = resultP->X_add_number || v;
2046 is_unsigned = true;
2047 break;
2050 else if (resultP->X_op == O_symbol
2051 && right.X_op == O_symbol
2052 && (op_left == O_add
2053 || op_left == O_subtract
2054 || (resultP->X_add_number == 0
2055 && right.X_add_number == 0)))
2057 /* Symbol OP symbol. */
2058 resultP->X_op = op_left;
2059 resultP->X_op_symbol = right.X_add_symbol;
2060 if (op_left == O_add)
2061 add_to_result (resultP, right.X_add_number, right.X_extrabit);
2062 else if (op_left == O_subtract)
2064 subtract_from_result (resultP, right.X_add_number,
2065 right.X_extrabit);
2066 if (retval == rightseg
2067 && SEG_NORMAL (retval)
2068 && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
2069 && !S_FORCE_RELOC (right.X_add_symbol, 0))
2071 retval = absolute_section;
2072 rightseg = absolute_section;
2076 else
2078 general:
2079 /* The general case. */
2080 resultP->X_add_symbol = make_expr_symbol (resultP);
2081 resultP->X_op_symbol = make_expr_symbol (&right);
2082 resultP->X_op = op_left;
2083 resultP->X_add_number = 0;
2084 resultP->X_extrabit = 0;
2087 resultP->X_unsigned = is_unsigned;
2089 if (retval != rightseg)
2091 if (retval == undefined_section)
2093 else if (rightseg == undefined_section)
2094 retval = rightseg;
2095 else if (retval == expr_section)
2097 else if (rightseg == expr_section)
2098 retval = rightseg;
2099 else if (retval == reg_section)
2101 else if (rightseg == reg_section)
2102 retval = rightseg;
2103 else if (rightseg == absolute_section)
2105 else if (retval == absolute_section)
2106 retval = rightseg;
2107 #ifdef DIFF_EXPR_OK
2108 else if (op_left == O_subtract)
2110 #endif
2111 else
2112 as_bad (_("operation combines symbols in different segments"));
2115 op_left = op_right;
2116 } /* While next operator is >= this rank. */
2118 /* The PA port needs this information. */
2119 if (resultP->X_add_symbol)
2120 symbol_mark_used (resultP->X_add_symbol);
2122 if (rank == 0 && mode == expr_evaluate)
2123 resolve_expression (resultP);
2125 return resultP->X_op == O_constant ? absolute_section : retval;
2128 /* Resolve an expression without changing any symbols/sub-expressions
2129 used. */
2132 resolve_expression (expressionS *expressionP)
2134 /* Help out with CSE. */
2135 valueT final_val = expressionP->X_add_number;
2136 symbolS *add_symbol = expressionP->X_add_symbol;
2137 symbolS *orig_add_symbol = add_symbol;
2138 symbolS *op_symbol = expressionP->X_op_symbol;
2139 operatorT op = expressionP->X_op;
2140 valueT left, right;
2141 segT seg_left, seg_right;
2142 fragS *frag_left, *frag_right;
2143 offsetT frag_off;
2145 switch (op)
2147 default:
2148 return 0;
2150 case O_constant:
2151 case O_register:
2152 left = 0;
2153 break;
2155 case O_symbol:
2156 case O_symbol_rva:
2157 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2158 return 0;
2160 break;
2162 case O_uminus:
2163 case O_bit_not:
2164 case O_logical_not:
2165 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2166 return 0;
2168 if (seg_left != absolute_section)
2169 return 0;
2171 if (op == O_logical_not)
2172 left = !left;
2173 else if (op == O_uminus)
2174 left = -left;
2175 else
2176 left = ~left;
2177 op = O_constant;
2178 break;
2180 case O_multiply:
2181 case O_divide:
2182 case O_modulus:
2183 case O_left_shift:
2184 case O_right_shift:
2185 case O_bit_inclusive_or:
2186 case O_bit_or_not:
2187 case O_bit_exclusive_or:
2188 case O_bit_and:
2189 case O_add:
2190 case O_subtract:
2191 case O_eq:
2192 case O_ne:
2193 case O_lt:
2194 case O_le:
2195 case O_ge:
2196 case O_gt:
2197 case O_logical_and:
2198 case O_logical_or:
2199 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
2200 || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
2201 return 0;
2203 /* Simplify addition or subtraction of a constant by folding the
2204 constant into X_add_number. */
2205 if (op == O_add)
2207 if (seg_right == absolute_section)
2209 final_val += right;
2210 op = O_symbol;
2211 break;
2213 else if (seg_left == absolute_section)
2215 final_val += left;
2216 left = right;
2217 seg_left = seg_right;
2218 add_symbol = op_symbol;
2219 orig_add_symbol = expressionP->X_op_symbol;
2220 op = O_symbol;
2221 break;
2224 else if (op == O_subtract)
2226 if (seg_right == absolute_section)
2228 final_val -= right;
2229 op = O_symbol;
2230 break;
2234 /* Equality and non-equality tests are permitted on anything.
2235 Subtraction, and other comparison operators are permitted if
2236 both operands are in the same section.
2237 Shifts by constant zero are permitted on anything.
2238 Multiplies, bit-ors, and bit-ands with constant zero are
2239 permitted on anything.
2240 Multiplies and divides by constant one are permitted on
2241 anything.
2242 Binary operations with both operands being the same register
2243 or undefined symbol are permitted if the result doesn't depend
2244 on the input value.
2245 Otherwise, both operands must be absolute. We already handled
2246 the case of addition or subtraction of a constant above. */
2247 frag_off = 0;
2248 if (!(seg_left == absolute_section
2249 && seg_right == absolute_section)
2250 && !(op == O_eq || op == O_ne)
2251 && !((op == O_subtract
2252 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2253 && seg_left == seg_right
2254 && (finalize_syms
2255 || frag_offset_fixed_p (frag_left, frag_right, &frag_off)
2256 || (op == O_gt
2257 && frag_gtoffset_p (left, frag_left,
2258 right, frag_right, &frag_off)))
2259 && (seg_left != reg_section || left == right)
2260 && (seg_left != undefined_section || add_symbol == op_symbol)))
2262 if ((seg_left == absolute_section && left == 0)
2263 || (seg_right == absolute_section && right == 0))
2265 if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2267 if (!(seg_right == absolute_section && right == 0))
2269 seg_left = seg_right;
2270 left = right;
2271 add_symbol = op_symbol;
2272 orig_add_symbol = expressionP->X_op_symbol;
2274 op = O_symbol;
2275 break;
2277 else if (op == O_left_shift || op == O_right_shift)
2279 if (!(seg_left == absolute_section && left == 0))
2281 op = O_symbol;
2282 break;
2285 else if (op != O_multiply
2286 && op != O_bit_or_not && op != O_bit_and)
2287 return 0;
2289 else if (op == O_multiply
2290 && seg_left == absolute_section && left == 1)
2292 seg_left = seg_right;
2293 left = right;
2294 add_symbol = op_symbol;
2295 orig_add_symbol = expressionP->X_op_symbol;
2296 op = O_symbol;
2297 break;
2299 else if ((op == O_multiply || op == O_divide)
2300 && seg_right == absolute_section && right == 1)
2302 op = O_symbol;
2303 break;
2305 else if (!(left == right
2306 && ((seg_left == reg_section && seg_right == reg_section)
2307 || (seg_left == undefined_section
2308 && seg_right == undefined_section
2309 && add_symbol == op_symbol))))
2310 return 0;
2311 else if (op == O_bit_and || op == O_bit_inclusive_or)
2313 op = O_symbol;
2314 break;
2316 else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2317 return 0;
2320 right += frag_off / OCTETS_PER_BYTE;
2321 switch (op)
2323 case O_add: left += right; break;
2324 case O_subtract: left -= right; break;
2325 case O_multiply: left *= right; break;
2326 case O_divide:
2327 if (right == 0)
2328 return 0;
2329 left = (offsetT) left / (offsetT) right;
2330 break;
2331 case O_modulus:
2332 if (right == 0)
2333 return 0;
2334 left = (offsetT) left % (offsetT) right;
2335 break;
2336 case O_left_shift:
2337 if (right >= sizeof (left) * CHAR_BIT)
2338 left = 0;
2339 else
2340 left <<= right;
2341 break;
2342 case O_right_shift:
2343 if (right >= sizeof (left) * CHAR_BIT)
2344 left = 0;
2345 else
2346 left >>= right;
2347 break;
2348 case O_bit_inclusive_or: left |= right; break;
2349 case O_bit_or_not: left |= ~right; break;
2350 case O_bit_exclusive_or: left ^= right; break;
2351 case O_bit_and: left &= right; break;
2352 case O_eq:
2353 case O_ne:
2354 left = (left == right
2355 && seg_left == seg_right
2356 && (finalize_syms || frag_left == frag_right)
2357 && (seg_left != undefined_section
2358 || add_symbol == op_symbol)
2359 ? ~ (valueT) 0 : 0);
2360 if (op == O_ne)
2361 left = ~left;
2362 break;
2363 case O_lt:
2364 left = (offsetT) left < (offsetT) right ? ~ (valueT) 0 : 0;
2365 break;
2366 case O_le:
2367 left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2368 break;
2369 case O_ge:
2370 left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2371 break;
2372 case O_gt:
2373 left = (offsetT) left > (offsetT) right ? ~ (valueT) 0 : 0;
2374 break;
2375 case O_logical_and: left = left && right; break;
2376 case O_logical_or: left = left || right; break;
2377 default: abort ();
2380 op = O_constant;
2381 break;
2384 if (op == O_symbol)
2386 if (seg_left == absolute_section)
2387 op = O_constant;
2388 else if (seg_left == reg_section && final_val == 0)
2389 op = O_register;
2390 else if (!symbol_same_p (add_symbol, orig_add_symbol))
2391 final_val += left;
2392 expressionP->X_add_symbol = add_symbol;
2394 expressionP->X_op = op;
2396 if (op == O_constant || op == O_register)
2397 final_val += left;
2398 expressionP->X_add_number = final_val;
2400 return 1;
2403 /* "Look through" register equates. */
2404 void resolve_register (expressionS *expP)
2406 symbolS *sym;
2407 offsetT acc = 0;
2408 const expressionS *e = expP;
2410 if (expP->X_op != O_symbol)
2411 return;
2415 sym = e->X_add_symbol;
2416 acc += e->X_add_number;
2417 e = symbol_get_value_expression (sym);
2419 while (symbol_equated_p (sym));
2421 if (e->X_op == O_register)
2423 *expP = *e;
2424 expP->X_add_number += acc;
2428 /* This lives here because it belongs equally in expr.c & read.c.
2429 expr.c is just a branch office read.c anyway, and putting it
2430 here lessens the crowd at read.c.
2432 Assume input_line_pointer is at start of symbol name, or the
2433 start of a double quote enclosed symbol name. Advance
2434 input_line_pointer past symbol name. Turn that character into a '\0',
2435 returning its former value, which may be the closing double quote.
2437 This allows a string compare (RMS wants symbol names to be strings)
2438 of the symbol name.
2440 NOTE: The input buffer is further altered when adjacent strings are
2441 concatenated by the function. Callers caring about the original buffer
2442 contents will need to make a copy before calling here.
2444 There will always be a char following symbol name, because all good
2445 lines end in end-of-line. */
2447 char
2448 get_symbol_name (char ** ilp_return)
2450 char c;
2452 * ilp_return = input_line_pointer;
2453 /* We accept FAKE_LABEL_CHAR in a name in case this is being called with a
2454 constructed string. */
2455 if (is_name_beginner (c = *input_line_pointer++)
2456 || (input_from_string && c == FAKE_LABEL_CHAR))
2458 while (is_part_of_name (c = *input_line_pointer++)
2459 || (input_from_string && c == FAKE_LABEL_CHAR))
2461 if (is_name_ender (c))
2462 c = *input_line_pointer++;
2464 else if (c == '"')
2466 char *dst = input_line_pointer;
2468 * ilp_return = input_line_pointer;
2469 for (;;)
2471 c = *input_line_pointer++;
2473 if (c == 0)
2475 as_warn (_("missing closing '\"'"));
2476 break;
2479 if (c == '"')
2481 char *ilp_save = input_line_pointer;
2483 SKIP_WHITESPACE ();
2484 if (*input_line_pointer == '"')
2486 ++input_line_pointer;
2487 continue;
2489 input_line_pointer = ilp_save;
2490 break;
2493 if (c == '\\')
2494 switch (*input_line_pointer)
2496 case '"':
2497 case '\\':
2498 c = *input_line_pointer++;
2499 break;
2501 default:
2502 if (c != 0)
2503 as_warn (_("'\\%c' in quoted symbol name; "
2504 "behavior may change in the future"),
2505 *input_line_pointer);
2506 break;
2509 *dst++ = c;
2511 *dst = 0;
2513 *--input_line_pointer = 0;
2514 return c;
2517 /* Replace the NUL character pointed to by input_line_pointer
2518 with C. If C is \" then advance past it. Return the character
2519 now pointed to by input_line_pointer. */
2521 char
2522 restore_line_pointer (char c)
2524 * input_line_pointer = c;
2525 if (c == '"')
2526 c = * ++ input_line_pointer;
2527 return c;
2530 unsigned int
2531 get_single_number (void)
2533 expressionS exp;
2534 operand (&exp, expr_normal);
2535 return exp.X_add_number;