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