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