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