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