arm: avoid "shadowing" of glibc function name
[binutils-gdb.git] / gas / expr.c
1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2021 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
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. */
25
26 #define min(a, b) ((a) < (b) ? (a) : (b))
27
28 #include "as.h"
29 #include "safe-ctype.h"
30
31 #include <limits.h>
32 #ifndef CHAR_BIT
33 #define CHAR_BIT 8
34 #endif
35
36 bool literal_prefix_dollar_hex = false;
37
38 static void clean_up_expression (expressionS * expressionP);
39
40 /* We keep a mapping of expression symbols to file positions, so that
41 we can provide better error messages. */
42
43 struct expr_symbol_line {
44 struct expr_symbol_line *next;
45 symbolS *sym;
46 const char *file;
47 unsigned int line;
48 };
49
50 static struct expr_symbol_line *expr_symbol_lines;
51 \f
52 /* Build a dummy symbol to hold a complex expression. This is how we
53 build expressions up out of other expressions. The symbol is put
54 into the fake section expr_section. */
55
56 symbolS *
57 make_expr_symbol (expressionS *expressionP)
58 {
59 expressionS zero;
60 symbolS *symbolP;
61 struct expr_symbol_line *n;
62
63 if (expressionP->X_op == O_symbol
64 && expressionP->X_add_number == 0)
65 return expressionP->X_add_symbol;
66
67 if (expressionP->X_op == O_big)
68 {
69 /* This won't work, because the actual value is stored in
70 generic_floating_point_number or generic_bignum, and we are
71 going to lose it if we haven't already. */
72 if (expressionP->X_add_number > 0)
73 as_bad (_("bignum invalid"));
74 else
75 as_bad (_("floating point number invalid"));
76 zero.X_op = O_constant;
77 zero.X_add_number = 0;
78 zero.X_unsigned = 0;
79 zero.X_extrabit = 0;
80 clean_up_expression (&zero);
81 expressionP = &zero;
82 }
83
84 /* Putting constant symbols in absolute_section rather than
85 expr_section is convenient for the old a.out code, for which
86 S_GET_SEGMENT does not always retrieve the value put in by
87 S_SET_SEGMENT. */
88 symbolP = symbol_create (FAKE_LABEL_NAME,
89 (expressionP->X_op == O_constant
90 ? absolute_section
91 : expressionP->X_op == O_register
92 ? reg_section
93 : expr_section),
94 &zero_address_frag, 0);
95 symbol_set_value_expression (symbolP, expressionP);
96
97 if (expressionP->X_op == O_constant)
98 resolve_symbol_value (symbolP);
99
100 n = XNEW (struct expr_symbol_line);
101 n->sym = symbolP;
102 n->file = as_where (&n->line);
103 n->next = expr_symbol_lines;
104 expr_symbol_lines = n;
105
106 return symbolP;
107 }
108
109 /* Return the file and line number for an expr symbol. Return
110 non-zero if something was found, 0 if no information is known for
111 the symbol. */
112
113 int
114 expr_symbol_where (symbolS *sym, const char **pfile, unsigned int *pline)
115 {
116 struct expr_symbol_line *l;
117
118 for (l = expr_symbol_lines; l != NULL; l = l->next)
119 {
120 if (l->sym == sym)
121 {
122 *pfile = l->file;
123 *pline = l->line;
124 return 1;
125 }
126 }
127
128 return 0;
129 }
130 \f
131 /* Utilities for building expressions.
132 Since complex expressions are recorded as symbols for use in other
133 expressions these return a symbolS * and not an expressionS *.
134 These explicitly do not take an "add_number" argument. */
135 /* ??? For completeness' sake one might want expr_build_symbol.
136 It would just return its argument. */
137
138 /* Build an expression for an unsigned constant.
139 The corresponding one for signed constants is missing because
140 there's currently no need for it. One could add an unsigned_p flag
141 but that seems more clumsy. */
142
143 symbolS *
144 expr_build_uconstant (offsetT value)
145 {
146 expressionS e;
147
148 e.X_op = O_constant;
149 e.X_add_number = value;
150 e.X_unsigned = 1;
151 e.X_extrabit = 0;
152 return make_expr_symbol (&e);
153 }
154
155 /* Build an expression for the current location ('.'). */
156
157 symbolS *
158 expr_build_dot (void)
159 {
160 expressionS e;
161
162 current_location (&e);
163 return symbol_clone_if_forward_ref (make_expr_symbol (&e));
164 }
165 \f
166 /* Build any floating-point literal here.
167 Also build any bignum literal here. */
168
169 /* Seems atof_machine can backscan through generic_bignum and hit whatever
170 happens to be loaded before it in memory. And its way too complicated
171 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
172 and never write into the early words, thus they'll always be zero.
173 I hate Dean's floating-point code. Bleh. */
174 LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
175
176 FLONUM_TYPE generic_floating_point_number = {
177 &generic_bignum[6], /* low. (JF: Was 0) */
178 &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high. JF: (added +6) */
179 0, /* leader. */
180 0, /* exponent. */
181 0 /* sign. */
182 };
183
184 \f
185 static void
186 floating_constant (expressionS *expressionP)
187 {
188 /* input_line_pointer -> floating-point constant. */
189 int error_code;
190
191 error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
192 &generic_floating_point_number);
193
194 if (error_code)
195 {
196 if (error_code == ERROR_EXPONENT_OVERFLOW)
197 {
198 as_bad (_("bad floating-point constant: exponent overflow"));
199 }
200 else
201 {
202 as_bad (_("bad floating-point constant: unknown error code=%d"),
203 error_code);
204 }
205 }
206 expressionP->X_op = O_big;
207 /* input_line_pointer -> just after constant, which may point to
208 whitespace. */
209 expressionP->X_add_number = -1;
210 }
211
212 uint32_t
213 generic_bignum_to_int32 (void)
214 {
215 return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
216 << LITTLENUM_NUMBER_OF_BITS)
217 | ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
218 }
219
220 uint64_t
221 generic_bignum_to_int64 (void)
222 {
223 return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
224 << LITTLENUM_NUMBER_OF_BITS)
225 | ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
226 << LITTLENUM_NUMBER_OF_BITS)
227 | ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
228 << LITTLENUM_NUMBER_OF_BITS)
229 | ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
230 }
231
232 static void
233 integer_constant (int radix, expressionS *expressionP)
234 {
235 char *start; /* Start of number. */
236 char *suffix = NULL;
237 char c;
238 valueT number; /* Offset or (absolute) value. */
239 short int digit; /* Value of next digit in current radix. */
240 short int maxdig = 0; /* Highest permitted digit value. */
241 int too_many_digits = 0; /* If we see >= this number of. */
242 char *name; /* Points to name of symbol. */
243 symbolS *symbolP; /* Points to symbol. */
244
245 int small; /* True if fits in 32 bits. */
246
247 /* May be bignum, or may fit in 32 bits. */
248 /* Most numbers fit into 32 bits, and we want this case to be fast.
249 so we pretend it will fit into 32 bits. If, after making up a 32
250 bit number, we realise that we have scanned more digits than
251 comfortably fit into 32 bits, we re-scan the digits coding them
252 into a bignum. For decimal and octal numbers we are
253 conservative: Some numbers may be assumed bignums when in fact
254 they do fit into 32 bits. Numbers of any radix can have excess
255 leading zeros: We strive to recognise this and cast them back
256 into 32 bits. We must check that the bignum really is more than
257 32 bits, and change it back to a 32-bit number if it fits. The
258 number we are looking for is expected to be positive, but if it
259 fits into 32 bits as an unsigned number, we let it be a 32-bit
260 number. The cavalier approach is for speed in ordinary cases. */
261 /* This has been extended for 64 bits. We blindly assume that if
262 you're compiling in 64-bit mode, the target is a 64-bit machine.
263 This should be cleaned up. */
264
265 #ifdef BFD64
266 #define valuesize 64
267 #else /* includes non-bfd case, mostly */
268 #define valuesize 32
269 #endif
270
271 if (is_end_of_line[(unsigned char) *input_line_pointer])
272 {
273 expressionP->X_op = O_absent;
274 return;
275 }
276
277 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
278 {
279 int flt = 0;
280
281 /* In MRI mode, the number may have a suffix indicating the
282 radix. For that matter, it might actually be a floating
283 point constant. */
284 for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
285 {
286 if (*suffix == 'e' || *suffix == 'E')
287 flt = 1;
288 }
289
290 if (suffix == input_line_pointer)
291 {
292 radix = 10;
293 suffix = NULL;
294 }
295 else
296 {
297 c = *--suffix;
298 c = TOUPPER (c);
299 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
300 we distinguish between 'B' and 'b'. This is the case for
301 Z80. */
302 if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B')
303 radix = 2;
304 else if (c == 'D')
305 radix = 10;
306 else if (c == 'O' || c == 'Q')
307 radix = 8;
308 else if (c == 'H')
309 radix = 16;
310 else if (suffix[1] == '.' || c == 'E' || flt)
311 {
312 floating_constant (expressionP);
313 return;
314 }
315 else
316 {
317 radix = 10;
318 suffix = NULL;
319 }
320 }
321 }
322
323 switch (radix)
324 {
325 case 2:
326 maxdig = 2;
327 too_many_digits = valuesize + 1;
328 break;
329 case 8:
330 maxdig = radix = 8;
331 too_many_digits = (valuesize + 2) / 3 + 1;
332 break;
333 case 16:
334 maxdig = radix = 16;
335 too_many_digits = (valuesize + 3) / 4 + 1;
336 break;
337 case 10:
338 maxdig = radix = 10;
339 too_many_digits = (valuesize + 11) / 4; /* Very rough. */
340 }
341 #undef valuesize
342 start = input_line_pointer;
343 c = *input_line_pointer++;
344 for (number = 0;
345 (digit = hex_value (c)) < maxdig;
346 c = *input_line_pointer++)
347 {
348 number = number * radix + digit;
349 }
350 /* c contains character after number. */
351 /* input_line_pointer->char after c. */
352 small = (input_line_pointer - start - 1) < too_many_digits;
353
354 if (radix == 16 && c == '_')
355 {
356 /* This is literal of the form 0x333_0_12345678_1.
357 This example is equivalent to 0x00000333000000001234567800000001. */
358
359 int num_little_digits = 0;
360 int i;
361 input_line_pointer = start; /* -> 1st digit. */
362
363 know (LITTLENUM_NUMBER_OF_BITS == 16);
364
365 for (c = '_'; c == '_'; num_little_digits += 2)
366 {
367
368 /* Convert one 64-bit word. */
369 int ndigit = 0;
370 number = 0;
371 for (c = *input_line_pointer++;
372 (digit = hex_value (c)) < maxdig;
373 c = *(input_line_pointer++))
374 {
375 number = number * radix + digit;
376 ndigit++;
377 }
378
379 /* Check for 8 digit per word max. */
380 if (ndigit > 8)
381 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
382
383 /* Add this chunk to the bignum.
384 Shift things down 2 little digits. */
385 know (LITTLENUM_NUMBER_OF_BITS == 16);
386 for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
387 i >= 2;
388 i--)
389 generic_bignum[i] = generic_bignum[i - 2];
390
391 /* Add the new digits as the least significant new ones. */
392 generic_bignum[0] = number & 0xffffffff;
393 generic_bignum[1] = number >> 16;
394 }
395
396 /* Again, c is char after number, input_line_pointer->after c. */
397
398 if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
399 num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
400
401 gas_assert (num_little_digits >= 4);
402
403 if (num_little_digits != 8)
404 as_bad (_("a bignum with underscores must have exactly 4 words"));
405
406 /* We might have some leading zeros. These can be trimmed to give
407 us a change to fit this constant into a small number. */
408 while (generic_bignum[num_little_digits - 1] == 0
409 && num_little_digits > 1)
410 num_little_digits--;
411
412 if (num_little_digits <= 2)
413 {
414 /* will fit into 32 bits. */
415 number = generic_bignum_to_int32 ();
416 small = 1;
417 }
418 #ifdef BFD64
419 else if (num_little_digits <= 4)
420 {
421 /* Will fit into 64 bits. */
422 number = generic_bignum_to_int64 ();
423 small = 1;
424 }
425 #endif
426 else
427 {
428 small = 0;
429
430 /* Number of littlenums in the bignum. */
431 number = num_little_digits;
432 }
433 }
434 else if (!small)
435 {
436 /* We saw a lot of digits. manufacture a bignum the hard way. */
437 LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum. */
438 LITTLENUM_TYPE *pointer; /* -> littlenum we are frobbing now. */
439 long carry;
440
441 leader = generic_bignum;
442 generic_bignum[0] = 0;
443 generic_bignum[1] = 0;
444 generic_bignum[2] = 0;
445 generic_bignum[3] = 0;
446 input_line_pointer = start; /* -> 1st digit. */
447 c = *input_line_pointer++;
448 for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++)
449 {
450 for (pointer = generic_bignum; pointer <= leader; pointer++)
451 {
452 long work;
453
454 work = carry + radix * *pointer;
455 *pointer = work & LITTLENUM_MASK;
456 carry = work >> LITTLENUM_NUMBER_OF_BITS;
457 }
458 if (carry)
459 {
460 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
461 {
462 /* Room to grow a longer bignum. */
463 *++leader = carry;
464 }
465 }
466 }
467 /* Again, c is char after number. */
468 /* input_line_pointer -> after c. */
469 know (LITTLENUM_NUMBER_OF_BITS == 16);
470 if (leader < generic_bignum + 2)
471 {
472 /* Will fit into 32 bits. */
473 number = generic_bignum_to_int32 ();
474 small = 1;
475 }
476 #ifdef BFD64
477 else if (leader < generic_bignum + 4)
478 {
479 /* Will fit into 64 bits. */
480 number = generic_bignum_to_int64 ();
481 small = 1;
482 }
483 #endif
484 else
485 {
486 /* Number of littlenums in the bignum. */
487 number = leader - generic_bignum + 1;
488 }
489 }
490
491 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
492 && suffix != NULL
493 && input_line_pointer - 1 == suffix)
494 c = *input_line_pointer++;
495
496 #ifndef tc_allow_U_suffix
497 #define tc_allow_U_suffix 1
498 #endif
499 /* PR 19910: Look for, and ignore, a U suffix to the number. */
500 if (tc_allow_U_suffix && (c == 'U' || c == 'u'))
501 c = * input_line_pointer++;
502
503 #ifndef tc_allow_L_suffix
504 #define tc_allow_L_suffix 1
505 #endif
506 /* PR 20732: Look for, and ignore, a L or LL suffix to the number. */
507 if (tc_allow_L_suffix)
508 while (c == 'L' || c == 'l')
509 c = * input_line_pointer++;
510
511 if (small)
512 {
513 /* Here with number, in correct radix. c is the next char.
514 Note that unlike un*x, we allow "011f" "0x9f" to both mean
515 the same as the (conventional) "9f".
516 This is simply easier than checking for strict canonical
517 form. Syntax sux! */
518
519 if (LOCAL_LABELS_FB && c == 'b')
520 {
521 /* Backward ref to local label.
522 Because it is backward, expect it to be defined. */
523 /* Construct a local label. */
524 name = fb_label_name ((int) number, 0);
525
526 /* Seen before, or symbol is defined: OK. */
527 symbolP = symbol_find (name);
528 if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
529 {
530 /* Local labels are never absolute. Don't waste time
531 checking absoluteness. */
532 know (SEG_NORMAL (S_GET_SEGMENT (symbolP)));
533
534 expressionP->X_op = O_symbol;
535 expressionP->X_add_symbol = symbolP;
536 }
537 else
538 {
539 /* Either not seen or not defined. */
540 /* @@ Should print out the original string instead of
541 the parsed number. */
542 as_bad (_("backward ref to unknown label \"%d:\""),
543 (int) number);
544 expressionP->X_op = O_constant;
545 }
546
547 expressionP->X_add_number = 0;
548 } /* case 'b' */
549 else if (LOCAL_LABELS_FB && c == 'f')
550 {
551 /* Forward reference. Expect symbol to be undefined or
552 unknown. undefined: seen it before. unknown: never seen
553 it before.
554
555 Construct a local label name, then an undefined symbol.
556 Don't create a xseg frag for it: caller may do that.
557 Just return it as never seen before. */
558 name = fb_label_name ((int) number, 1);
559 symbolP = symbol_find_or_make (name);
560 /* We have no need to check symbol properties. */
561 #ifndef many_segments
562 /* Since "know" puts its arg into a "string", we
563 can't have newlines in the argument. */
564 know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section);
565 #endif
566 expressionP->X_op = O_symbol;
567 expressionP->X_add_symbol = symbolP;
568 expressionP->X_add_number = 0;
569 } /* case 'f' */
570 else if (LOCAL_LABELS_DOLLAR && c == '$')
571 {
572 /* If the dollar label is *currently* defined, then this is just
573 another reference to it. If it is not *currently* defined,
574 then this is a fresh instantiation of that number, so create
575 it. */
576
577 if (dollar_label_defined ((long) number))
578 {
579 name = dollar_label_name ((long) number, 0);
580 symbolP = symbol_find (name);
581 know (symbolP != NULL);
582 }
583 else
584 {
585 name = dollar_label_name ((long) number, 1);
586 symbolP = symbol_find_or_make (name);
587 }
588
589 expressionP->X_op = O_symbol;
590 expressionP->X_add_symbol = symbolP;
591 expressionP->X_add_number = 0;
592 } /* case '$' */
593 else
594 {
595 expressionP->X_op = O_constant;
596 expressionP->X_add_number = number;
597 input_line_pointer--; /* Restore following character. */
598 } /* Really just a number. */
599 }
600 else
601 {
602 /* Not a small number. */
603 expressionP->X_op = O_big;
604 expressionP->X_add_number = number; /* Number of littlenums. */
605 input_line_pointer--; /* -> char following number. */
606 }
607 }
608
609 /* Parse an MRI multi character constant. */
610
611 static void
612 mri_char_constant (expressionS *expressionP)
613 {
614 int i;
615
616 if (*input_line_pointer == '\''
617 && input_line_pointer[1] != '\'')
618 {
619 expressionP->X_op = O_constant;
620 expressionP->X_add_number = 0;
621 return;
622 }
623
624 /* In order to get the correct byte ordering, we must build the
625 number in reverse. */
626 for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
627 {
628 int j;
629
630 generic_bignum[i] = 0;
631 for (j = 0; j < CHARS_PER_LITTLENUM; j++)
632 {
633 if (*input_line_pointer == '\'')
634 {
635 if (input_line_pointer[1] != '\'')
636 break;
637 ++input_line_pointer;
638 }
639 generic_bignum[i] <<= 8;
640 generic_bignum[i] += *input_line_pointer;
641 ++input_line_pointer;
642 }
643
644 if (i < SIZE_OF_LARGE_NUMBER - 1)
645 {
646 /* If there is more than one littlenum, left justify the
647 last one to make it match the earlier ones. If there is
648 only one, we can just use the value directly. */
649 for (; j < CHARS_PER_LITTLENUM; j++)
650 generic_bignum[i] <<= 8;
651 }
652
653 if (*input_line_pointer == '\''
654 && input_line_pointer[1] != '\'')
655 break;
656 }
657
658 if (i < 0)
659 {
660 as_bad (_("character constant too large"));
661 i = 0;
662 }
663
664 if (i > 0)
665 {
666 int c;
667 int j;
668
669 c = SIZE_OF_LARGE_NUMBER - i;
670 for (j = 0; j < c; j++)
671 generic_bignum[j] = generic_bignum[i + j];
672 i = c;
673 }
674
675 know (LITTLENUM_NUMBER_OF_BITS == 16);
676 if (i > 2)
677 {
678 expressionP->X_op = O_big;
679 expressionP->X_add_number = i;
680 }
681 else
682 {
683 expressionP->X_op = O_constant;
684 if (i < 2)
685 expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
686 else
687 expressionP->X_add_number =
688 (((generic_bignum[1] & LITTLENUM_MASK)
689 << LITTLENUM_NUMBER_OF_BITS)
690 | (generic_bignum[0] & LITTLENUM_MASK));
691 }
692
693 /* Skip the final closing quote. */
694 ++input_line_pointer;
695 }
696
697 /* Return an expression representing the current location. This
698 handles the magic symbol `.'. */
699
700 void
701 current_location (expressionS *expressionp)
702 {
703 if (now_seg == absolute_section)
704 {
705 expressionp->X_op = O_constant;
706 expressionp->X_add_number = abs_section_offset;
707 }
708 else
709 {
710 expressionp->X_op = O_symbol;
711 expressionp->X_add_symbol = &dot_symbol;
712 expressionp->X_add_number = 0;
713 }
714 }
715
716 /* In: Input_line_pointer points to 1st char of operand, which may
717 be a space.
718
719 Out: An expressionS.
720 The operand may have been empty: in this case X_op == O_absent.
721 Input_line_pointer->(next non-blank) char after operand. */
722
723 static segT
724 operand (expressionS *expressionP, enum expr_mode mode)
725 {
726 char c;
727 symbolS *symbolP; /* Points to symbol. */
728 char *name; /* Points to name of symbol. */
729 segT segment;
730
731 /* All integers are regarded as unsigned unless they are negated.
732 This is because the only thing which cares whether a number is
733 unsigned is the code in emit_expr which extends constants into
734 bignums. It should only sign extend negative numbers, so that
735 something like ``.quad 0x80000000'' is not sign extended even
736 though it appears negative if valueT is 32 bits. */
737 expressionP->X_unsigned = 1;
738 expressionP->X_extrabit = 0;
739
740 /* Digits, assume it is a bignum. */
741
742 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
743 c = *input_line_pointer++; /* input_line_pointer -> past char in c. */
744
745 if (is_end_of_line[(unsigned char) c])
746 goto eol;
747
748 switch (c)
749 {
750 case '1':
751 case '2':
752 case '3':
753 case '4':
754 case '5':
755 case '6':
756 case '7':
757 case '8':
758 case '9':
759 input_line_pointer--;
760
761 integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
762 ? 0 : 10,
763 expressionP);
764 break;
765
766 #ifdef LITERAL_PREFIXPERCENT_BIN
767 case '%':
768 integer_constant (2, expressionP);
769 break;
770 #endif
771
772 case '0':
773 /* Non-decimal radix. */
774
775 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
776 {
777 char *s;
778
779 /* Check for a hex or float constant. */
780 for (s = input_line_pointer; hex_p (*s); s++)
781 ;
782 if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
783 {
784 --input_line_pointer;
785 integer_constant (0, expressionP);
786 break;
787 }
788 }
789 c = *input_line_pointer;
790 switch (c)
791 {
792 case 'o':
793 case 'O':
794 case 'q':
795 case 'Q':
796 case '8':
797 case '9':
798 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
799 {
800 integer_constant (0, expressionP);
801 break;
802 }
803 /* Fall through. */
804 default:
805 default_case:
806 if (c && strchr (FLT_CHARS, c))
807 {
808 input_line_pointer++;
809 floating_constant (expressionP);
810 expressionP->X_add_number = - TOLOWER (c);
811 }
812 else
813 {
814 /* The string was only zero. */
815 expressionP->X_op = O_constant;
816 expressionP->X_add_number = 0;
817 }
818
819 break;
820
821 case 'x':
822 case 'X':
823 if (flag_m68k_mri)
824 goto default_case;
825 input_line_pointer++;
826 integer_constant (16, expressionP);
827 break;
828
829 case 'b':
830 if (LOCAL_LABELS_FB && !flag_m68k_mri
831 && input_line_pointer[1] != '0'
832 && input_line_pointer[1] != '1')
833 {
834 /* Parse this as a back reference to label 0. */
835 input_line_pointer--;
836 integer_constant (10, expressionP);
837 break;
838 }
839 /* Otherwise, parse this as a binary number. */
840 /* Fall through. */
841 case 'B':
842 if (input_line_pointer[1] == '0'
843 || input_line_pointer[1] == '1')
844 {
845 input_line_pointer++;
846 integer_constant (2, expressionP);
847 break;
848 }
849 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
850 input_line_pointer++;
851 goto default_case;
852
853 case '0':
854 case '1':
855 case '2':
856 case '3':
857 case '4':
858 case '5':
859 case '6':
860 case '7':
861 integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
862 ? 0 : 8,
863 expressionP);
864 break;
865
866 case 'f':
867 if (LOCAL_LABELS_FB)
868 {
869 int is_label = 1;
870
871 /* If it says "0f" and it could possibly be a floating point
872 number, make it one. Otherwise, make it a local label,
873 and try to deal with parsing the rest later. */
874 if (!is_end_of_line[(unsigned char) input_line_pointer[1]]
875 && strchr (FLT_CHARS, 'f') != NULL)
876 {
877 char *cp = input_line_pointer + 1;
878
879 atof_generic (&cp, ".", EXP_CHARS,
880 &generic_floating_point_number);
881
882 /* Was nothing parsed, or does it look like an
883 expression? */
884 is_label = (cp == input_line_pointer + 1
885 || (cp == input_line_pointer + 2
886 && (cp[-1] == '-' || cp[-1] == '+'))
887 || *cp == 'f'
888 || *cp == 'b');
889 }
890 if (is_label)
891 {
892 input_line_pointer--;
893 integer_constant (10, expressionP);
894 break;
895 }
896 }
897 /* Fall through. */
898
899 case 'd':
900 case 'D':
901 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
902 {
903 integer_constant (0, expressionP);
904 break;
905 }
906 /* Fall through. */
907 case 'F':
908 case 'r':
909 case 'e':
910 case 'E':
911 case 'g':
912 case 'G':
913 input_line_pointer++;
914 floating_constant (expressionP);
915 expressionP->X_add_number = - TOLOWER (c);
916 break;
917
918 case '$':
919 if (LOCAL_LABELS_DOLLAR)
920 {
921 integer_constant (10, expressionP);
922 break;
923 }
924 else
925 goto default_case;
926 }
927
928 break;
929
930 #ifndef NEED_INDEX_OPERATOR
931 case '[':
932 # ifdef md_need_index_operator
933 if (md_need_index_operator())
934 goto de_fault;
935 # endif
936 #endif
937 /* Fall through. */
938 case '(':
939 /* Didn't begin with digit & not a name. */
940 segment = expr (0, expressionP, mode);
941 /* expression () will pass trailing whitespace. */
942 if ((c == '(' && *input_line_pointer != ')')
943 || (c == '[' && *input_line_pointer != ']'))
944 {
945 if (* input_line_pointer)
946 as_bad (_("found '%c', expected: '%c'"),
947 * input_line_pointer, c == '(' ? ')' : ']');
948 else
949 as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
950 }
951 else
952 input_line_pointer++;
953 SKIP_WHITESPACE ();
954 /* Here with input_line_pointer -> char after "(...)". */
955 return segment;
956
957 #ifdef TC_M68K
958 case 'E':
959 if (! flag_m68k_mri || *input_line_pointer != '\'')
960 goto de_fault;
961 as_bad (_("EBCDIC constants are not supported"));
962 /* Fall through. */
963 case 'A':
964 if (! flag_m68k_mri || *input_line_pointer != '\'')
965 goto de_fault;
966 ++input_line_pointer;
967 #endif
968 /* Fall through. */
969 case '\'':
970 if (! flag_m68k_mri)
971 {
972 /* Warning: to conform to other people's assemblers NO
973 ESCAPEMENT is permitted for a single quote. The next
974 character, parity errors and all, is taken as the value
975 of the operand. VERY KINKY. */
976 expressionP->X_op = O_constant;
977 expressionP->X_add_number = *input_line_pointer++;
978 break;
979 }
980
981 mri_char_constant (expressionP);
982 break;
983
984 #ifdef TC_M68K
985 case '"':
986 /* Double quote is the bitwise not operator in MRI mode. */
987 if (! flag_m68k_mri)
988 goto de_fault;
989 #endif
990 /* Fall through. */
991 case '~':
992 /* '~' is permitted to start a label on the Delta. */
993 if (is_name_beginner (c))
994 goto isname;
995 /* Fall through. */
996 case '!':
997 case '-':
998 case '+':
999 {
1000 #ifdef md_operator
1001 unary:
1002 #endif
1003 operand (expressionP, mode);
1004 if (expressionP->X_op == O_constant)
1005 {
1006 /* input_line_pointer -> char after operand. */
1007 if (c == '-')
1008 {
1009 expressionP->X_add_number
1010 = - (addressT) expressionP->X_add_number;
1011 /* Notice: '-' may overflow: no warning is given.
1012 This is compatible with other people's
1013 assemblers. Sigh. */
1014 expressionP->X_unsigned = 0;
1015 if (expressionP->X_add_number)
1016 expressionP->X_extrabit ^= 1;
1017 }
1018 else if (c == '~' || c == '"')
1019 {
1020 expressionP->X_add_number = ~ expressionP->X_add_number;
1021 expressionP->X_extrabit ^= 1;
1022 }
1023 else if (c == '!')
1024 {
1025 expressionP->X_add_number = ! expressionP->X_add_number;
1026 expressionP->X_unsigned = 1;
1027 expressionP->X_extrabit = 0;
1028 }
1029 }
1030 else if (expressionP->X_op == O_big
1031 && expressionP->X_add_number <= 0
1032 && c == '-'
1033 && (generic_floating_point_number.sign == '+'
1034 || generic_floating_point_number.sign == 'P'))
1035 {
1036 /* Negative flonum (eg, -1.000e0). */
1037 if (generic_floating_point_number.sign == '+')
1038 generic_floating_point_number.sign = '-';
1039 else
1040 generic_floating_point_number.sign = 'N';
1041 }
1042 else if (expressionP->X_op == O_big
1043 && expressionP->X_add_number > 0)
1044 {
1045 int i;
1046
1047 if (c == '~' || c == '-')
1048 {
1049 for (i = 0; i < expressionP->X_add_number; ++i)
1050 generic_bignum[i] = ~generic_bignum[i];
1051
1052 /* Extend the bignum to at least the size of .octa. */
1053 if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1054 {
1055 expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1056 for (; i < expressionP->X_add_number; ++i)
1057 generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1058 }
1059
1060 if (c == '-')
1061 for (i = 0; i < expressionP->X_add_number; ++i)
1062 {
1063 generic_bignum[i] += 1;
1064 if (generic_bignum[i])
1065 break;
1066 }
1067 }
1068 else if (c == '!')
1069 {
1070 for (i = 0; i < expressionP->X_add_number; ++i)
1071 if (generic_bignum[i] != 0)
1072 break;
1073 expressionP->X_add_number = i >= expressionP->X_add_number;
1074 expressionP->X_op = O_constant;
1075 expressionP->X_unsigned = 1;
1076 expressionP->X_extrabit = 0;
1077 }
1078 }
1079 else if (expressionP->X_op != O_illegal
1080 && expressionP->X_op != O_absent)
1081 {
1082 if (c != '+')
1083 {
1084 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1085 if (c == '-')
1086 expressionP->X_op = O_uminus;
1087 else if (c == '~' || c == '"')
1088 expressionP->X_op = O_bit_not;
1089 else
1090 expressionP->X_op = O_logical_not;
1091 expressionP->X_add_number = 0;
1092 }
1093 }
1094 else
1095 as_warn (_("Unary operator %c ignored because bad operand follows"),
1096 c);
1097 }
1098 break;
1099
1100 #if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1101 case '$':
1102 if (literal_prefix_dollar_hex)
1103 {
1104 /* $L is the start of a local label, not a hex constant. */
1105 if (* input_line_pointer == 'L')
1106 goto isname;
1107 integer_constant (16, expressionP);
1108 }
1109 else
1110 {
1111 goto isname;
1112 }
1113 break;
1114 #else
1115 case '$':
1116 /* '$' is the program counter when in MRI mode, or when
1117 DOLLAR_DOT is defined. */
1118 #ifndef DOLLAR_DOT
1119 if (! flag_m68k_mri)
1120 goto de_fault;
1121 #endif
1122 if (DOLLAR_AMBIGU && hex_p (*input_line_pointer))
1123 {
1124 /* In MRI mode and on Z80, '$' is also used as the prefix
1125 for a hexadecimal constant. */
1126 integer_constant (16, expressionP);
1127 break;
1128 }
1129
1130 if (is_part_of_name (*input_line_pointer))
1131 goto isname;
1132
1133 current_location (expressionP);
1134 break;
1135 #endif
1136
1137 case '.':
1138 if (!is_part_of_name (*input_line_pointer))
1139 {
1140 current_location (expressionP);
1141 break;
1142 }
1143 else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1144 && ! is_part_of_name (input_line_pointer[8]))
1145 || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1146 && ! is_part_of_name (input_line_pointer[7])))
1147 {
1148 int start;
1149
1150 start = (input_line_pointer[1] == 't'
1151 || input_line_pointer[1] == 'T');
1152 input_line_pointer += start ? 8 : 7;
1153 SKIP_WHITESPACE ();
1154
1155 /* Cover for the as_bad () invocations below. */
1156 expressionP->X_op = O_absent;
1157
1158 if (*input_line_pointer != '(')
1159 as_bad (_("syntax error in .startof. or .sizeof."));
1160 else
1161 {
1162 char *buf;
1163
1164 ++input_line_pointer;
1165 SKIP_WHITESPACE ();
1166 c = get_symbol_name (& name);
1167 if (! *name)
1168 {
1169 as_bad (_("expected symbol name"));
1170 (void) restore_line_pointer (c);
1171 if (c != ')')
1172 ignore_rest_of_line ();
1173 else
1174 ++input_line_pointer;
1175 break;
1176 }
1177
1178 buf = concat (start ? ".startof." : ".sizeof.", name,
1179 (char *) NULL);
1180 symbolP = symbol_make (buf);
1181 free (buf);
1182
1183 expressionP->X_op = O_symbol;
1184 expressionP->X_add_symbol = symbolP;
1185 expressionP->X_add_number = 0;
1186
1187 *input_line_pointer = c;
1188 SKIP_WHITESPACE_AFTER_NAME ();
1189 if (*input_line_pointer != ')')
1190 as_bad (_("syntax error in .startof. or .sizeof."));
1191 else
1192 ++input_line_pointer;
1193 }
1194 break;
1195 }
1196 else
1197 {
1198 goto isname;
1199 }
1200
1201 case ',':
1202 eol:
1203 /* Can't imagine any other kind of operand. */
1204 expressionP->X_op = O_absent;
1205 input_line_pointer--;
1206 break;
1207
1208 #ifdef TC_M68K
1209 case '%':
1210 if (! flag_m68k_mri)
1211 goto de_fault;
1212 integer_constant (2, expressionP);
1213 break;
1214
1215 case '@':
1216 if (! flag_m68k_mri)
1217 goto de_fault;
1218 integer_constant (8, expressionP);
1219 break;
1220
1221 case ':':
1222 if (! flag_m68k_mri)
1223 goto de_fault;
1224
1225 /* In MRI mode, this is a floating point constant represented
1226 using hexadecimal digits. */
1227
1228 ++input_line_pointer;
1229 integer_constant (16, expressionP);
1230 break;
1231
1232 case '*':
1233 if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
1234 goto de_fault;
1235
1236 current_location (expressionP);
1237 break;
1238 #endif
1239
1240 default:
1241 #if defined(md_need_index_operator) || defined(TC_M68K)
1242 de_fault:
1243 #endif
1244 if (is_name_beginner (c) || c == '"') /* Here if did not begin with a digit. */
1245 {
1246 /* Identifier begins here.
1247 This is kludged for speed, so code is repeated. */
1248 isname:
1249 -- input_line_pointer;
1250 c = get_symbol_name (&name);
1251
1252 #ifdef md_operator
1253 {
1254 operatorT op = md_operator (name, 1, &c);
1255
1256 switch (op)
1257 {
1258 case O_uminus:
1259 restore_line_pointer (c);
1260 c = '-';
1261 goto unary;
1262 case O_bit_not:
1263 restore_line_pointer (c);
1264 c = '~';
1265 goto unary;
1266 case O_logical_not:
1267 restore_line_pointer (c);
1268 c = '!';
1269 goto unary;
1270 case O_illegal:
1271 as_bad (_("invalid use of operator \"%s\""), name);
1272 break;
1273 default:
1274 break;
1275 }
1276
1277 if (op != O_absent && op != O_illegal)
1278 {
1279 restore_line_pointer (c);
1280 expr (9, expressionP, mode);
1281 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1282 expressionP->X_op_symbol = NULL;
1283 expressionP->X_add_number = 0;
1284 expressionP->X_op = op;
1285 break;
1286 }
1287 }
1288 #endif
1289
1290 #ifdef md_parse_name
1291 /* This is a hook for the backend to parse certain names
1292 specially in certain contexts. If a name always has a
1293 specific value, it can often be handled by simply
1294 entering it in the symbol table. */
1295 if (md_parse_name (name, expressionP, mode, &c))
1296 {
1297 restore_line_pointer (c);
1298 break;
1299 }
1300 #endif
1301
1302 symbolP = symbol_find_or_make (name);
1303
1304 /* If we have an absolute symbol or a reg, then we know its
1305 value now. */
1306 segment = S_GET_SEGMENT (symbolP);
1307 if (mode != expr_defer
1308 && segment == absolute_section
1309 && !S_FORCE_RELOC (symbolP, 0))
1310 {
1311 expressionP->X_op = O_constant;
1312 expressionP->X_add_number = S_GET_VALUE (symbolP);
1313 }
1314 else if (mode != expr_defer && segment == reg_section)
1315 {
1316 expressionP->X_op = O_register;
1317 expressionP->X_add_number = S_GET_VALUE (symbolP);
1318 }
1319 else
1320 {
1321 expressionP->X_op = O_symbol;
1322 expressionP->X_add_symbol = symbolP;
1323 expressionP->X_add_number = 0;
1324 }
1325
1326 restore_line_pointer (c);
1327 }
1328 else
1329 {
1330 /* Let the target try to parse it. Success is indicated by changing
1331 the X_op field to something other than O_absent and pointing
1332 input_line_pointer past the expression. If it can't parse the
1333 expression, X_op and input_line_pointer should be unchanged. */
1334 expressionP->X_op = O_absent;
1335 --input_line_pointer;
1336 md_operand (expressionP);
1337 if (expressionP->X_op == O_absent)
1338 {
1339 ++input_line_pointer;
1340 as_bad (_("bad expression"));
1341 expressionP->X_op = O_constant;
1342 expressionP->X_add_number = 0;
1343 }
1344 }
1345 break;
1346 }
1347
1348 /* It is more 'efficient' to clean up the expressionS when they are
1349 created. Doing it here saves lines of code. */
1350 clean_up_expression (expressionP);
1351 SKIP_ALL_WHITESPACE (); /* -> 1st char after operand. */
1352 know (*input_line_pointer != ' ');
1353
1354 /* The PA port needs this information. */
1355 if (expressionP->X_add_symbol)
1356 symbol_mark_used (expressionP->X_add_symbol);
1357
1358 if (mode != expr_defer)
1359 {
1360 expressionP->X_add_symbol
1361 = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1362 expressionP->X_op_symbol
1363 = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1364 }
1365
1366 switch (expressionP->X_op)
1367 {
1368 default:
1369 return absolute_section;
1370 case O_symbol:
1371 return S_GET_SEGMENT (expressionP->X_add_symbol);
1372 case O_register:
1373 return reg_section;
1374 }
1375 }
1376 \f
1377 /* Internal. Simplify a struct expression for use by expr (). */
1378
1379 /* In: address of an expressionS.
1380 The X_op field of the expressionS may only take certain values.
1381 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1382
1383 Out: expressionS may have been modified:
1384 Unused fields zeroed to help expr (). */
1385
1386 static void
1387 clean_up_expression (expressionS *expressionP)
1388 {
1389 switch (expressionP->X_op)
1390 {
1391 case O_illegal:
1392 case O_absent:
1393 expressionP->X_add_number = 0;
1394 /* Fall through. */
1395 case O_big:
1396 case O_constant:
1397 case O_register:
1398 expressionP->X_add_symbol = NULL;
1399 /* Fall through. */
1400 case O_symbol:
1401 case O_uminus:
1402 case O_bit_not:
1403 expressionP->X_op_symbol = NULL;
1404 break;
1405 default:
1406 break;
1407 }
1408 }
1409 \f
1410 /* Expression parser. */
1411
1412 /* We allow an empty expression, and just assume (absolute,0) silently.
1413 Unary operators and parenthetical expressions are treated as operands.
1414 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1415
1416 We used to do an aho/ullman shift-reduce parser, but the logic got so
1417 warped that I flushed it and wrote a recursive-descent parser instead.
1418 Now things are stable, would anybody like to write a fast parser?
1419 Most expressions are either register (which does not even reach here)
1420 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1421 So I guess it doesn't really matter how inefficient more complex expressions
1422 are parsed.
1423
1424 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1425 Also, we have consumed any leading or trailing spaces (operand does that)
1426 and done all intervening operators.
1427
1428 This returns the segment of the result, which will be
1429 absolute_section or the segment of a symbol. */
1430
1431 #undef __
1432 #define __ O_illegal
1433 #ifndef O_SINGLE_EQ
1434 #define O_SINGLE_EQ O_illegal
1435 #endif
1436
1437 /* Maps ASCII -> operators. */
1438 static const operatorT op_encoding[256] = {
1439 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1440 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1441
1442 __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
1443 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1444 __, __, __, __, __, __, __, __,
1445 __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __,
1446 __, __, __, __, __, __, __, __,
1447 __, __, __, __, __, __, __, __,
1448 __, __, __, __, __, __, __, __,
1449 __, __, __,
1450 #ifdef NEED_INDEX_OPERATOR
1451 O_index,
1452 #else
1453 __,
1454 #endif
1455 __, __, O_bit_exclusive_or, __,
1456 __, __, __, __, __, __, __, __,
1457 __, __, __, __, __, __, __, __,
1458 __, __, __, __, __, __, __, __,
1459 __, __, __, __, O_bit_inclusive_or, __, __, __,
1460
1461 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1462 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1463 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1464 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1465 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1466 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1467 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1468 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1469 };
1470
1471 /* Rank Examples
1472 0 operand, (expression)
1473 1 ||
1474 2 &&
1475 3 == <> < <= >= >
1476 4 + -
1477 5 used for * / % in MRI mode
1478 6 & ^ ! |
1479 7 * / % << >>
1480 8 unary - unary ~
1481 */
1482 static operator_rankT op_rank[O_max] = {
1483 0, /* O_illegal */
1484 0, /* O_absent */
1485 0, /* O_constant */
1486 0, /* O_symbol */
1487 0, /* O_symbol_rva */
1488 0, /* O_register */
1489 0, /* O_big */
1490 9, /* O_uminus */
1491 9, /* O_bit_not */
1492 9, /* O_logical_not */
1493 8, /* O_multiply */
1494 8, /* O_divide */
1495 8, /* O_modulus */
1496 8, /* O_left_shift */
1497 8, /* O_right_shift */
1498 7, /* O_bit_inclusive_or */
1499 7, /* O_bit_or_not */
1500 7, /* O_bit_exclusive_or */
1501 7, /* O_bit_and */
1502 5, /* O_add */
1503 5, /* O_subtract */
1504 4, /* O_eq */
1505 4, /* O_ne */
1506 4, /* O_lt */
1507 4, /* O_le */
1508 4, /* O_ge */
1509 4, /* O_gt */
1510 3, /* O_logical_and */
1511 2, /* O_logical_or */
1512 1, /* O_index */
1513 };
1514
1515 /* Unfortunately, in MRI mode for the m68k, multiplication and
1516 division have lower precedence than the bit wise operators. This
1517 function sets the operator precedences correctly for the current
1518 mode. Also, MRI uses a different bit_not operator, and this fixes
1519 that as well. */
1520
1521 #define STANDARD_MUL_PRECEDENCE 8
1522 #define MRI_MUL_PRECEDENCE 6
1523
1524 void
1525 expr_set_precedence (void)
1526 {
1527 if (flag_m68k_mri)
1528 {
1529 op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
1530 op_rank[O_divide] = MRI_MUL_PRECEDENCE;
1531 op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
1532 }
1533 else
1534 {
1535 op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1536 op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1537 op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1538 }
1539 }
1540
1541 void
1542 expr_set_rank (operatorT op, operator_rankT rank)
1543 {
1544 gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank));
1545 op_rank[op] = rank;
1546 }
1547
1548 /* Initialize the expression parser. */
1549
1550 void
1551 expr_begin (void)
1552 {
1553 expr_set_precedence ();
1554
1555 /* Verify that X_op field is wide enough. */
1556 {
1557 expressionS e;
1558 e.X_op = O_max;
1559 gas_assert (e.X_op == O_max);
1560 }
1561 }
1562 \f
1563 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1564 sets NUM_CHARS to the number of characters in the operator.
1565 Does not advance INPUT_LINE_POINTER. */
1566
1567 static inline operatorT
1568 operatorf (int *num_chars)
1569 {
1570 int c;
1571 operatorT ret;
1572
1573 c = *input_line_pointer & 0xff;
1574 *num_chars = 1;
1575
1576 if (is_end_of_line[c])
1577 return O_illegal;
1578
1579 #ifdef md_operator
1580 if (is_name_beginner (c))
1581 {
1582 char *name;
1583 char ec = get_symbol_name (& name);
1584
1585 ret = md_operator (name, 2, &ec);
1586 switch (ret)
1587 {
1588 case O_absent:
1589 *input_line_pointer = ec;
1590 input_line_pointer = name;
1591 break;
1592 case O_uminus:
1593 case O_bit_not:
1594 case O_logical_not:
1595 as_bad (_("invalid use of operator \"%s\""), name);
1596 ret = O_illegal;
1597 /* FALLTHROUGH */
1598 default:
1599 *input_line_pointer = ec;
1600 *num_chars = input_line_pointer - name;
1601 input_line_pointer = name;
1602 return ret;
1603 }
1604 }
1605 #endif
1606
1607 switch (c)
1608 {
1609 default:
1610 ret = op_encoding[c];
1611 #ifdef md_operator
1612 if (ret == O_illegal)
1613 {
1614 char *start = input_line_pointer;
1615
1616 ret = md_operator (NULL, 2, NULL);
1617 if (ret != O_illegal)
1618 *num_chars = input_line_pointer - start;
1619 input_line_pointer = start;
1620 }
1621 #endif
1622 return ret;
1623
1624 case '+':
1625 case '-':
1626 return op_encoding[c];
1627
1628 case '<':
1629 switch (input_line_pointer[1])
1630 {
1631 default:
1632 return op_encoding[c];
1633 case '<':
1634 ret = O_left_shift;
1635 break;
1636 case '>':
1637 ret = O_ne;
1638 break;
1639 case '=':
1640 ret = O_le;
1641 break;
1642 }
1643 *num_chars = 2;
1644 return ret;
1645
1646 case '=':
1647 if (input_line_pointer[1] != '=')
1648 return op_encoding[c];
1649
1650 *num_chars = 2;
1651 return O_eq;
1652
1653 case '>':
1654 switch (input_line_pointer[1])
1655 {
1656 default:
1657 return op_encoding[c];
1658 case '>':
1659 ret = O_right_shift;
1660 break;
1661 case '=':
1662 ret = O_ge;
1663 break;
1664 }
1665 *num_chars = 2;
1666 return ret;
1667
1668 case '!':
1669 switch (input_line_pointer[1])
1670 {
1671 case '!':
1672 /* We accept !! as equivalent to ^ for MRI compatibility. */
1673 *num_chars = 2;
1674 return O_bit_exclusive_or;
1675 case '=':
1676 /* We accept != as equivalent to <>. */
1677 *num_chars = 2;
1678 return O_ne;
1679 default:
1680 if (flag_m68k_mri)
1681 return O_bit_inclusive_or;
1682 return op_encoding[c];
1683 }
1684
1685 case '|':
1686 if (input_line_pointer[1] != '|')
1687 return op_encoding[c];
1688
1689 *num_chars = 2;
1690 return O_logical_or;
1691
1692 case '&':
1693 if (input_line_pointer[1] != '&')
1694 return op_encoding[c];
1695
1696 *num_chars = 2;
1697 return O_logical_and;
1698 }
1699
1700 /* NOTREACHED */
1701 }
1702
1703 /* Implement "word-size + 1 bit" addition for
1704 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1705 is used so that the full range of unsigned word values and the full range of
1706 signed word values can be represented in an O_constant expression, which is
1707 useful e.g. for .sleb128 directives. */
1708
1709 void
1710 add_to_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1711 {
1712 valueT ures = resultP->X_add_number;
1713 valueT uamount = amount;
1714
1715 resultP->X_add_number += uamount;
1716
1717 resultP->X_extrabit ^= rhs_highbit;
1718
1719 if (ures + uamount < ures)
1720 resultP->X_extrabit ^= 1;
1721 }
1722
1723 /* Similarly, for subtraction. */
1724
1725 void
1726 subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1727 {
1728 valueT ures = resultP->X_add_number;
1729 valueT uamount = amount;
1730
1731 resultP->X_add_number -= uamount;
1732
1733 resultP->X_extrabit ^= rhs_highbit;
1734
1735 if (ures < uamount)
1736 resultP->X_extrabit ^= 1;
1737 }
1738
1739 /* Parse an expression. */
1740
1741 segT
1742 expr (int rankarg, /* Larger # is higher rank. */
1743 expressionS *resultP, /* Deliver result here. */
1744 enum expr_mode mode /* Controls behavior. */)
1745 {
1746 operator_rankT rank = (operator_rankT) rankarg;
1747 segT retval;
1748 expressionS right;
1749 operatorT op_left;
1750 operatorT op_right;
1751 int op_chars;
1752
1753 know (rankarg >= 0);
1754
1755 /* Save the value of dot for the fixup code. */
1756 if (rank == 0)
1757 {
1758 dot_value = frag_now_fix ();
1759 dot_frag = frag_now;
1760 }
1761
1762 retval = operand (resultP, mode);
1763
1764 /* operand () gobbles spaces. */
1765 know (*input_line_pointer != ' ');
1766
1767 op_left = operatorf (&op_chars);
1768 while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1769 {
1770 segT rightseg;
1771 offsetT frag_off;
1772
1773 input_line_pointer += op_chars; /* -> after operator. */
1774
1775 right.X_md = 0;
1776 rightseg = expr (op_rank[(int) op_left], &right, mode);
1777 if (right.X_op == O_absent)
1778 {
1779 as_warn (_("missing operand; zero assumed"));
1780 right.X_op = O_constant;
1781 right.X_add_number = 0;
1782 right.X_add_symbol = NULL;
1783 right.X_op_symbol = NULL;
1784 }
1785
1786 know (*input_line_pointer != ' ');
1787
1788 if (op_left == O_index)
1789 {
1790 if (*input_line_pointer != ']')
1791 as_bad ("missing right bracket");
1792 else
1793 {
1794 ++input_line_pointer;
1795 SKIP_WHITESPACE ();
1796 }
1797 }
1798
1799 op_right = operatorf (&op_chars);
1800
1801 know (op_right == O_illegal || op_left == O_index
1802 || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1803 know ((int) op_left >= (int) O_multiply);
1804 #ifndef md_operator
1805 know ((int) op_left <= (int) O_index);
1806 #else
1807 know ((int) op_left < (int) O_max);
1808 #endif
1809
1810 /* input_line_pointer->after right-hand quantity. */
1811 /* left-hand quantity in resultP. */
1812 /* right-hand quantity in right. */
1813 /* operator in op_left. */
1814
1815 if (resultP->X_op == O_big)
1816 {
1817 if (resultP->X_add_number > 0)
1818 as_warn (_("left operand is a bignum; integer 0 assumed"));
1819 else
1820 as_warn (_("left operand is a float; integer 0 assumed"));
1821 resultP->X_op = O_constant;
1822 resultP->X_add_number = 0;
1823 resultP->X_add_symbol = NULL;
1824 resultP->X_op_symbol = NULL;
1825 }
1826 if (right.X_op == O_big)
1827 {
1828 if (right.X_add_number > 0)
1829 as_warn (_("right operand is a bignum; integer 0 assumed"));
1830 else
1831 as_warn (_("right operand is a float; integer 0 assumed"));
1832 right.X_op = O_constant;
1833 right.X_add_number = 0;
1834 right.X_add_symbol = NULL;
1835 right.X_op_symbol = NULL;
1836 }
1837
1838 if (mode == expr_defer
1839 && ((resultP->X_add_symbol != NULL
1840 && S_IS_FORWARD_REF (resultP->X_add_symbol))
1841 || (right.X_add_symbol != NULL
1842 && S_IS_FORWARD_REF (right.X_add_symbol))))
1843 goto general;
1844
1845 /* Optimize common cases. */
1846 #ifdef md_optimize_expr
1847 if (md_optimize_expr (resultP, op_left, &right))
1848 {
1849 /* Skip. */
1850 ;
1851 }
1852 else
1853 #endif
1854 #ifndef md_register_arithmetic
1855 # define md_register_arithmetic 1
1856 #endif
1857 if (op_left == O_add && right.X_op == O_constant
1858 && (md_register_arithmetic || resultP->X_op != O_register))
1859 {
1860 /* X + constant. */
1861 add_to_result (resultP, right.X_add_number, right.X_extrabit);
1862 }
1863 /* This case comes up in PIC code. */
1864 else if (op_left == O_subtract
1865 && right.X_op == O_symbol
1866 && resultP->X_op == O_symbol
1867 && retval == rightseg
1868 #ifdef md_allow_local_subtract
1869 && md_allow_local_subtract (resultP, & right, rightseg)
1870 #endif
1871 && ((SEG_NORMAL (rightseg)
1872 && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
1873 && !S_FORCE_RELOC (right.X_add_symbol, 0))
1874 || right.X_add_symbol == resultP->X_add_symbol)
1875 && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1876 symbol_get_frag (right.X_add_symbol),
1877 &frag_off))
1878 {
1879 offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
1880 - S_GET_VALUE (right.X_add_symbol);
1881 subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1882 subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
1883 add_to_result (resultP, symval_diff, symval_diff < 0);
1884 resultP->X_op = O_constant;
1885 resultP->X_add_symbol = 0;
1886 }
1887 else if (op_left == O_subtract && right.X_op == O_constant
1888 && (md_register_arithmetic || resultP->X_op != O_register))
1889 {
1890 /* X - constant. */
1891 subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1892 }
1893 else if (op_left == O_add && resultP->X_op == O_constant
1894 && (md_register_arithmetic || right.X_op != O_register))
1895 {
1896 /* Constant + X. */
1897 resultP->X_op = right.X_op;
1898 resultP->X_add_symbol = right.X_add_symbol;
1899 resultP->X_op_symbol = right.X_op_symbol;
1900 add_to_result (resultP, right.X_add_number, right.X_extrabit);
1901 retval = rightseg;
1902 }
1903 else if (resultP->X_op == O_constant && right.X_op == O_constant)
1904 {
1905 /* Constant OP constant. */
1906 offsetT v = right.X_add_number;
1907 if (v == 0 && (op_left == O_divide || op_left == O_modulus))
1908 {
1909 as_warn (_("division by zero"));
1910 v = 1;
1911 }
1912 if ((valueT) v >= sizeof(valueT) * CHAR_BIT
1913 && (op_left == O_left_shift || op_left == O_right_shift))
1914 {
1915 as_warn_value_out_of_range (_("shift count"), v, 0,
1916 sizeof(valueT) * CHAR_BIT - 1,
1917 NULL, 0);
1918 resultP->X_add_number = v = 0;
1919 }
1920 switch (op_left)
1921 {
1922 default: goto general;
1923 case O_multiply: resultP->X_add_number *= v; break;
1924 case O_divide: resultP->X_add_number /= v; break;
1925 case O_modulus: resultP->X_add_number %= v; break;
1926 case O_left_shift:
1927 /* We always use unsigned shifts. According to the ISO
1928 C standard, left shift of a signed type having a
1929 negative value is undefined behaviour, and right
1930 shift of a signed type having negative value is
1931 implementation defined. Left shift of a signed type
1932 when the result overflows is also undefined
1933 behaviour. So don't trigger ubsan warnings or rely
1934 on characteristics of the compiler. */
1935 resultP->X_add_number
1936 = (valueT) resultP->X_add_number << (valueT) v;
1937 break;
1938 case O_right_shift:
1939 resultP->X_add_number
1940 = (valueT) resultP->X_add_number >> (valueT) v;
1941 break;
1942 case O_bit_inclusive_or: resultP->X_add_number |= v; break;
1943 case O_bit_or_not: resultP->X_add_number |= ~v; break;
1944 case O_bit_exclusive_or: resultP->X_add_number ^= v; break;
1945 case O_bit_and: resultP->X_add_number &= v; break;
1946 /* Constant + constant (O_add) is handled by the
1947 previous if statement for constant + X, so is omitted
1948 here. */
1949 case O_subtract:
1950 subtract_from_result (resultP, v, 0);
1951 break;
1952 case O_eq:
1953 resultP->X_add_number =
1954 resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
1955 break;
1956 case O_ne:
1957 resultP->X_add_number =
1958 resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
1959 break;
1960 case O_lt:
1961 resultP->X_add_number =
1962 resultP->X_add_number < v ? ~ (offsetT) 0 : 0;
1963 break;
1964 case O_le:
1965 resultP->X_add_number =
1966 resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
1967 break;
1968 case O_ge:
1969 resultP->X_add_number =
1970 resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
1971 break;
1972 case O_gt:
1973 resultP->X_add_number =
1974 resultP->X_add_number > v ? ~ (offsetT) 0 : 0;
1975 break;
1976 case O_logical_and:
1977 resultP->X_add_number = resultP->X_add_number && v;
1978 break;
1979 case O_logical_or:
1980 resultP->X_add_number = resultP->X_add_number || v;
1981 break;
1982 }
1983 }
1984 else if (resultP->X_op == O_symbol
1985 && right.X_op == O_symbol
1986 && (op_left == O_add
1987 || op_left == O_subtract
1988 || (resultP->X_add_number == 0
1989 && right.X_add_number == 0)))
1990 {
1991 /* Symbol OP symbol. */
1992 resultP->X_op = op_left;
1993 resultP->X_op_symbol = right.X_add_symbol;
1994 if (op_left == O_add)
1995 add_to_result (resultP, right.X_add_number, right.X_extrabit);
1996 else if (op_left == O_subtract)
1997 {
1998 subtract_from_result (resultP, right.X_add_number,
1999 right.X_extrabit);
2000 if (retval == rightseg
2001 && SEG_NORMAL (retval)
2002 && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
2003 && !S_FORCE_RELOC (right.X_add_symbol, 0))
2004 {
2005 retval = absolute_section;
2006 rightseg = absolute_section;
2007 }
2008 }
2009 }
2010 else
2011 {
2012 general:
2013 /* The general case. */
2014 resultP->X_add_symbol = make_expr_symbol (resultP);
2015 resultP->X_op_symbol = make_expr_symbol (&right);
2016 resultP->X_op = op_left;
2017 resultP->X_add_number = 0;
2018 resultP->X_unsigned = 1;
2019 resultP->X_extrabit = 0;
2020 }
2021
2022 if (retval != rightseg)
2023 {
2024 if (retval == undefined_section)
2025 ;
2026 else if (rightseg == undefined_section)
2027 retval = rightseg;
2028 else if (retval == expr_section)
2029 ;
2030 else if (rightseg == expr_section)
2031 retval = rightseg;
2032 else if (retval == reg_section)
2033 ;
2034 else if (rightseg == reg_section)
2035 retval = rightseg;
2036 else if (rightseg == absolute_section)
2037 ;
2038 else if (retval == absolute_section)
2039 retval = rightseg;
2040 #ifdef DIFF_EXPR_OK
2041 else if (op_left == O_subtract)
2042 ;
2043 #endif
2044 else
2045 as_bad (_("operation combines symbols in different segments"));
2046 }
2047
2048 op_left = op_right;
2049 } /* While next operator is >= this rank. */
2050
2051 /* The PA port needs this information. */
2052 if (resultP->X_add_symbol)
2053 symbol_mark_used (resultP->X_add_symbol);
2054
2055 if (rank == 0 && mode == expr_evaluate)
2056 resolve_expression (resultP);
2057
2058 return resultP->X_op == O_constant ? absolute_section : retval;
2059 }
2060
2061 /* Resolve an expression without changing any symbols/sub-expressions
2062 used. */
2063
2064 int
2065 resolve_expression (expressionS *expressionP)
2066 {
2067 /* Help out with CSE. */
2068 valueT final_val = expressionP->X_add_number;
2069 symbolS *add_symbol = expressionP->X_add_symbol;
2070 symbolS *orig_add_symbol = add_symbol;
2071 symbolS *op_symbol = expressionP->X_op_symbol;
2072 operatorT op = expressionP->X_op;
2073 valueT left, right;
2074 segT seg_left, seg_right;
2075 fragS *frag_left, *frag_right;
2076 offsetT frag_off;
2077
2078 switch (op)
2079 {
2080 default:
2081 return 0;
2082
2083 case O_constant:
2084 case O_register:
2085 left = 0;
2086 break;
2087
2088 case O_symbol:
2089 case O_symbol_rva:
2090 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2091 return 0;
2092
2093 break;
2094
2095 case O_uminus:
2096 case O_bit_not:
2097 case O_logical_not:
2098 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2099 return 0;
2100
2101 if (seg_left != absolute_section)
2102 return 0;
2103
2104 if (op == O_logical_not)
2105 left = !left;
2106 else if (op == O_uminus)
2107 left = -left;
2108 else
2109 left = ~left;
2110 op = O_constant;
2111 break;
2112
2113 case O_multiply:
2114 case O_divide:
2115 case O_modulus:
2116 case O_left_shift:
2117 case O_right_shift:
2118 case O_bit_inclusive_or:
2119 case O_bit_or_not:
2120 case O_bit_exclusive_or:
2121 case O_bit_and:
2122 case O_add:
2123 case O_subtract:
2124 case O_eq:
2125 case O_ne:
2126 case O_lt:
2127 case O_le:
2128 case O_ge:
2129 case O_gt:
2130 case O_logical_and:
2131 case O_logical_or:
2132 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
2133 || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
2134 return 0;
2135
2136 /* Simplify addition or subtraction of a constant by folding the
2137 constant into X_add_number. */
2138 if (op == O_add)
2139 {
2140 if (seg_right == absolute_section)
2141 {
2142 final_val += right;
2143 op = O_symbol;
2144 break;
2145 }
2146 else if (seg_left == absolute_section)
2147 {
2148 final_val += left;
2149 left = right;
2150 seg_left = seg_right;
2151 add_symbol = op_symbol;
2152 orig_add_symbol = expressionP->X_op_symbol;
2153 op = O_symbol;
2154 break;
2155 }
2156 }
2157 else if (op == O_subtract)
2158 {
2159 if (seg_right == absolute_section)
2160 {
2161 final_val -= right;
2162 op = O_symbol;
2163 break;
2164 }
2165 }
2166
2167 /* Equality and non-equality tests are permitted on anything.
2168 Subtraction, and other comparison operators are permitted if
2169 both operands are in the same section.
2170 Shifts by constant zero are permitted on anything.
2171 Multiplies, bit-ors, and bit-ands with constant zero are
2172 permitted on anything.
2173 Multiplies and divides by constant one are permitted on
2174 anything.
2175 Binary operations with both operands being the same register
2176 or undefined symbol are permitted if the result doesn't depend
2177 on the input value.
2178 Otherwise, both operands must be absolute. We already handled
2179 the case of addition or subtraction of a constant above. */
2180 frag_off = 0;
2181 if (!(seg_left == absolute_section
2182 && seg_right == absolute_section)
2183 && !(op == O_eq || op == O_ne)
2184 && !((op == O_subtract
2185 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2186 && seg_left == seg_right
2187 && (finalize_syms
2188 || frag_offset_fixed_p (frag_left, frag_right, &frag_off)
2189 || (op == O_gt
2190 && frag_gtoffset_p (left, frag_left,
2191 right, frag_right, &frag_off)))
2192 && (seg_left != reg_section || left == right)
2193 && (seg_left != undefined_section || add_symbol == op_symbol)))
2194 {
2195 if ((seg_left == absolute_section && left == 0)
2196 || (seg_right == absolute_section && right == 0))
2197 {
2198 if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2199 {
2200 if (!(seg_right == absolute_section && right == 0))
2201 {
2202 seg_left = seg_right;
2203 left = right;
2204 add_symbol = op_symbol;
2205 orig_add_symbol = expressionP->X_op_symbol;
2206 }
2207 op = O_symbol;
2208 break;
2209 }
2210 else if (op == O_left_shift || op == O_right_shift)
2211 {
2212 if (!(seg_left == absolute_section && left == 0))
2213 {
2214 op = O_symbol;
2215 break;
2216 }
2217 }
2218 else if (op != O_multiply
2219 && op != O_bit_or_not && op != O_bit_and)
2220 return 0;
2221 }
2222 else if (op == O_multiply
2223 && seg_left == absolute_section && left == 1)
2224 {
2225 seg_left = seg_right;
2226 left = right;
2227 add_symbol = op_symbol;
2228 orig_add_symbol = expressionP->X_op_symbol;
2229 op = O_symbol;
2230 break;
2231 }
2232 else if ((op == O_multiply || op == O_divide)
2233 && seg_right == absolute_section && right == 1)
2234 {
2235 op = O_symbol;
2236 break;
2237 }
2238 else if (!(left == right
2239 && ((seg_left == reg_section && seg_right == reg_section)
2240 || (seg_left == undefined_section
2241 && seg_right == undefined_section
2242 && add_symbol == op_symbol))))
2243 return 0;
2244 else if (op == O_bit_and || op == O_bit_inclusive_or)
2245 {
2246 op = O_symbol;
2247 break;
2248 }
2249 else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2250 return 0;
2251 }
2252
2253 right += frag_off / OCTETS_PER_BYTE;
2254 switch (op)
2255 {
2256 case O_add: left += right; break;
2257 case O_subtract: left -= right; break;
2258 case O_multiply: left *= right; break;
2259 case O_divide:
2260 if (right == 0)
2261 return 0;
2262 left = (offsetT) left / (offsetT) right;
2263 break;
2264 case O_modulus:
2265 if (right == 0)
2266 return 0;
2267 left = (offsetT) left % (offsetT) right;
2268 break;
2269 case O_left_shift: left <<= right; break;
2270 case O_right_shift: left >>= right; break;
2271 case O_bit_inclusive_or: left |= right; break;
2272 case O_bit_or_not: left |= ~right; break;
2273 case O_bit_exclusive_or: left ^= right; break;
2274 case O_bit_and: left &= right; break;
2275 case O_eq:
2276 case O_ne:
2277 left = (left == right
2278 && seg_left == seg_right
2279 && (finalize_syms || frag_left == frag_right)
2280 && (seg_left != undefined_section
2281 || add_symbol == op_symbol)
2282 ? ~ (valueT) 0 : 0);
2283 if (op == O_ne)
2284 left = ~left;
2285 break;
2286 case O_lt:
2287 left = (offsetT) left < (offsetT) right ? ~ (valueT) 0 : 0;
2288 break;
2289 case O_le:
2290 left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2291 break;
2292 case O_ge:
2293 left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2294 break;
2295 case O_gt:
2296 left = (offsetT) left > (offsetT) right ? ~ (valueT) 0 : 0;
2297 break;
2298 case O_logical_and: left = left && right; break;
2299 case O_logical_or: left = left || right; break;
2300 default: abort ();
2301 }
2302
2303 op = O_constant;
2304 break;
2305 }
2306
2307 if (op == O_symbol)
2308 {
2309 if (seg_left == absolute_section)
2310 op = O_constant;
2311 else if (seg_left == reg_section && final_val == 0)
2312 op = O_register;
2313 else if (!symbol_same_p (add_symbol, orig_add_symbol))
2314 final_val += left;
2315 expressionP->X_add_symbol = add_symbol;
2316 }
2317 expressionP->X_op = op;
2318
2319 if (op == O_constant || op == O_register)
2320 final_val += left;
2321 expressionP->X_add_number = final_val;
2322
2323 return 1;
2324 }
2325 \f
2326 /* This lives here because it belongs equally in expr.c & read.c.
2327 expr.c is just a branch office read.c anyway, and putting it
2328 here lessens the crowd at read.c.
2329
2330 Assume input_line_pointer is at start of symbol name, or the
2331 start of a double quote enclosed symbol name.
2332 Advance input_line_pointer past symbol name.
2333 Turn that character into a '\0', returning its former value,
2334 which may be the closing double quote.
2335 This allows a string compare (RMS wants symbol names to be strings)
2336 of the symbol name.
2337 There will always be a char following symbol name, because all good
2338 lines end in end-of-line. */
2339
2340 char
2341 get_symbol_name (char ** ilp_return)
2342 {
2343 char c;
2344
2345 * ilp_return = input_line_pointer;
2346 /* We accept FAKE_LABEL_CHAR in a name in case this is being called with a
2347 constructed string. */
2348 if (is_name_beginner (c = *input_line_pointer++)
2349 || (input_from_string && c == FAKE_LABEL_CHAR))
2350 {
2351 while (is_part_of_name (c = *input_line_pointer++)
2352 || (input_from_string && c == FAKE_LABEL_CHAR))
2353 ;
2354 if (is_name_ender (c))
2355 c = *input_line_pointer++;
2356 }
2357 else if (c == '"')
2358 {
2359 bool backslash_seen;
2360
2361 * ilp_return = input_line_pointer;
2362 do
2363 {
2364 backslash_seen = c == '\\';
2365 c = * input_line_pointer ++;
2366 }
2367 while (c != 0 && (c != '"' || backslash_seen));
2368
2369 if (c == 0)
2370 as_warn (_("missing closing '\"'"));
2371 }
2372 *--input_line_pointer = 0;
2373 return c;
2374 }
2375
2376 /* Replace the NUL character pointed to by input_line_pointer
2377 with C. If C is \" then advance past it. Return the character
2378 now pointed to by input_line_pointer. */
2379
2380 char
2381 restore_line_pointer (char c)
2382 {
2383 * input_line_pointer = c;
2384 if (c == '"')
2385 c = * ++ input_line_pointer;
2386 return c;
2387 }
2388
2389 unsigned int
2390 get_single_number (void)
2391 {
2392 expressionS exp;
2393 operand (&exp, expr_normal);
2394 return exp.X_add_number;
2395 }