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
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
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 2, or (at your option)
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.
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
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. */
28 #define min(a, b) ((a) < (b) ? (a) : (b))
31 #include "safe-ctype.h"
34 static void floating_constant (expressionS * expressionP);
35 static valueT generic_bignum_to_int32 (void);
37 static valueT generic_bignum_to_int64 (void);
39 static void integer_constant (int radix, expressionS * expressionP);
40 static void mri_char_constant (expressionS *);
41 static void current_location (expressionS *);
42 static void clean_up_expression (expressionS * expressionP);
43 static segT operand (expressionS *, enum expr_mode);
44 static operatorT operator (int *);
46 extern const char EXP_CHARS[], FLT_CHARS[];
48 /* We keep a mapping of expression symbols to file positions, so that
49 we can provide better error messages. */
51 struct expr_symbol_line {
52 struct expr_symbol_line *next;
58 static struct expr_symbol_line *expr_symbol_lines;
60 /* Build a dummy symbol to hold a complex expression. This is how we
61 build expressions up out of other expressions. The symbol is put
62 into the fake section expr_section. */
65 make_expr_symbol (expressionS *expressionP)
69 struct expr_symbol_line *n;
71 if (expressionP->X_op == O_symbol
72 && expressionP->X_add_number == 0)
73 return expressionP->X_add_symbol;
75 if (expressionP->X_op == O_big)
77 /* This won't work, because the actual value is stored in
78 generic_floating_point_number or generic_bignum, and we are
79 going to lose it if we haven't already. */
80 if (expressionP->X_add_number > 0)
81 as_bad (_("bignum invalid"));
83 as_bad (_("floating point number invalid"));
84 zero.X_op = O_constant;
85 zero.X_add_number = 0;
87 clean_up_expression (&zero);
91 /* Putting constant symbols in absolute_section rather than
92 expr_section is convenient for the old a.out code, for which
93 S_GET_SEGMENT does not always retrieve the value put in by
95 symbolP = symbol_create (FAKE_LABEL_NAME,
96 (expressionP->X_op == O_constant
99 0, &zero_address_frag);
100 symbol_set_value_expression (symbolP, expressionP);
102 if (expressionP->X_op == O_constant)
103 resolve_symbol_value (symbolP);
105 n = (struct expr_symbol_line *) xmalloc (sizeof *n);
107 as_where (&n->file, &n->line);
108 n->next = expr_symbol_lines;
109 expr_symbol_lines = n;
114 /* Return the file and line number for an expr symbol. Return
115 non-zero if something was found, 0 if no information is known for
119 expr_symbol_where (symbolS *sym, char **pfile, unsigned int *pline)
121 register struct expr_symbol_line *l;
123 for (l = expr_symbol_lines; l != NULL; l = l->next)
136 /* Utilities for building expressions.
137 Since complex expressions are recorded as symbols for use in other
138 expressions these return a symbolS * and not an expressionS *.
139 These explicitly do not take an "add_number" argument. */
140 /* ??? For completeness' sake one might want expr_build_symbol.
141 It would just return its argument. */
143 /* Build an expression for an unsigned constant.
144 The corresponding one for signed constants is missing because
145 there's currently no need for it. One could add an unsigned_p flag
146 but that seems more clumsy. */
149 expr_build_uconstant (offsetT value)
154 e.X_add_number = value;
156 return make_expr_symbol (&e);
159 /* Build an expression for the current location ('.'). */
162 expr_build_dot (void)
166 current_location (&e);
167 return make_expr_symbol (&e);
170 /* Build any floating-point literal here.
171 Also build any bignum literal here. */
173 /* Seems atof_machine can backscan through generic_bignum and hit whatever
174 happens to be loaded before it in memory. And its way too complicated
175 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
176 and never write into the early words, thus they'll always be zero.
177 I hate Dean's floating-point code. Bleh. */
178 LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
180 FLONUM_TYPE generic_floating_point_number = {
181 &generic_bignum[6], /* low. (JF: Was 0) */
182 &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high. JF: (added +6) */
190 floating_constant (expressionS *expressionP)
192 /* input_line_pointer -> floating-point constant. */
195 error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
196 &generic_floating_point_number);
200 if (error_code == ERROR_EXPONENT_OVERFLOW)
202 as_bad (_("bad floating-point constant: exponent overflow"));
206 as_bad (_("bad floating-point constant: unknown error code=%d"),
210 expressionP->X_op = O_big;
211 /* input_line_pointer -> just after constant, which may point to
213 expressionP->X_add_number = -1;
217 generic_bignum_to_int32 (void)
220 ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
221 | (generic_bignum[0] & LITTLENUM_MASK);
222 number &= 0xffffffff;
228 generic_bignum_to_int64 (void)
231 ((((((((valueT) generic_bignum[3] & LITTLENUM_MASK)
232 << LITTLENUM_NUMBER_OF_BITS)
233 | ((valueT) generic_bignum[2] & LITTLENUM_MASK))
234 << LITTLENUM_NUMBER_OF_BITS)
235 | ((valueT) generic_bignum[1] & LITTLENUM_MASK))
236 << LITTLENUM_NUMBER_OF_BITS)
237 | ((valueT) generic_bignum[0] & LITTLENUM_MASK));
243 integer_constant (int radix, expressionS *expressionP)
245 char *start; /* Start of number. */
248 valueT number; /* Offset or (absolute) value. */
249 short int digit; /* Value of next digit in current radix. */
250 short int maxdig = 0; /* Highest permitted digit value. */
251 int too_many_digits = 0; /* If we see >= this number of. */
252 char *name; /* Points to name of symbol. */
253 symbolS *symbolP; /* Points to symbol. */
255 int small; /* True if fits in 32 bits. */
257 /* May be bignum, or may fit in 32 bits. */
258 /* Most numbers fit into 32 bits, and we want this case to be fast.
259 so we pretend it will fit into 32 bits. If, after making up a 32
260 bit number, we realise that we have scanned more digits than
261 comfortably fit into 32 bits, we re-scan the digits coding them
262 into a bignum. For decimal and octal numbers we are
263 conservative: Some numbers may be assumed bignums when in fact
264 they do fit into 32 bits. Numbers of any radix can have excess
265 leading zeros: We strive to recognise this and cast them back
266 into 32 bits. We must check that the bignum really is more than
267 32 bits, and change it back to a 32-bit number if it fits. The
268 number we are looking for is expected to be positive, but if it
269 fits into 32 bits as an unsigned number, we let it be a 32-bit
270 number. The cavalier approach is for speed in ordinary cases. */
271 /* This has been extended for 64 bits. We blindly assume that if
272 you're compiling in 64-bit mode, the target is a 64-bit machine.
273 This should be cleaned up. */
277 #else /* includes non-bfd case, mostly */
281 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
285 /* In MRI mode, the number may have a suffix indicating the
286 radix. For that matter, it might actually be a floating
288 for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
290 if (*suffix == 'e' || *suffix == 'E')
294 if (suffix == input_line_pointer)
303 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
304 we distinguish between 'B' and 'b'. This is the case for
306 if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B')
310 else if (c == 'O' || c == 'Q')
314 else if (suffix[1] == '.' || c == 'E' || flt)
316 floating_constant (expressionP);
331 too_many_digits = valuesize + 1;
335 too_many_digits = (valuesize + 2) / 3 + 1;
339 too_many_digits = (valuesize + 3) / 4 + 1;
343 too_many_digits = (valuesize + 11) / 4; /* Very rough. */
346 start = input_line_pointer;
347 c = *input_line_pointer++;
349 (digit = hex_value (c)) < maxdig;
350 c = *input_line_pointer++)
352 number = number * radix + digit;
354 /* c contains character after number. */
355 /* input_line_pointer->char after c. */
356 small = (input_line_pointer - start - 1) < too_many_digits;
358 if (radix == 16 && c == '_')
360 /* This is literal of the form 0x333_0_12345678_1.
361 This example is equivalent to 0x00000333000000001234567800000001. */
363 int num_little_digits = 0;
365 input_line_pointer = start; /* -> 1st digit. */
367 know (LITTLENUM_NUMBER_OF_BITS == 16);
369 for (c = '_'; c == '_'; num_little_digits += 2)
372 /* Convert one 64-bit word. */
375 for (c = *input_line_pointer++;
376 (digit = hex_value (c)) < maxdig;
377 c = *(input_line_pointer++))
379 number = number * radix + digit;
383 /* Check for 8 digit per word max. */
385 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
387 /* Add this chunk to the bignum.
388 Shift things down 2 little digits. */
389 know (LITTLENUM_NUMBER_OF_BITS == 16);
390 for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
393 generic_bignum[i] = generic_bignum[i - 2];
395 /* Add the new digits as the least significant new ones. */
396 generic_bignum[0] = number & 0xffffffff;
397 generic_bignum[1] = number >> 16;
400 /* Again, c is char after number, input_line_pointer->after c. */
402 if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
403 num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
405 assert (num_little_digits >= 4);
407 if (num_little_digits != 8)
408 as_bad (_("a bignum with underscores must have exactly 4 words"));
410 /* We might have some leading zeros. These can be trimmed to give
411 us a change to fit this constant into a small number. */
412 while (generic_bignum[num_little_digits - 1] == 0
413 && num_little_digits > 1)
416 if (num_little_digits <= 2)
418 /* will fit into 32 bits. */
419 number = generic_bignum_to_int32 ();
423 else if (num_little_digits <= 4)
425 /* Will fit into 64 bits. */
426 number = generic_bignum_to_int64 ();
434 /* Number of littlenums in the bignum. */
435 number = num_little_digits;
440 /* We saw a lot of digits. manufacture a bignum the hard way. */
441 LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum. */
442 LITTLENUM_TYPE *pointer; /* -> littlenum we are frobbing now. */
445 leader = generic_bignum;
446 generic_bignum[0] = 0;
447 generic_bignum[1] = 0;
448 generic_bignum[2] = 0;
449 generic_bignum[3] = 0;
450 input_line_pointer = start; /* -> 1st digit. */
451 c = *input_line_pointer++;
452 for (; (carry = hex_value (c)) < maxdig; c = *input_line_pointer++)
454 for (pointer = generic_bignum; pointer <= leader; pointer++)
458 work = carry + radix * *pointer;
459 *pointer = work & LITTLENUM_MASK;
460 carry = work >> LITTLENUM_NUMBER_OF_BITS;
464 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
466 /* Room to grow a longer bignum. */
471 /* Again, c is char after number. */
472 /* input_line_pointer -> after c. */
473 know (LITTLENUM_NUMBER_OF_BITS == 16);
474 if (leader < generic_bignum + 2)
476 /* Will fit into 32 bits. */
477 number = generic_bignum_to_int32 ();
481 else if (leader < generic_bignum + 4)
483 /* Will fit into 64 bits. */
484 number = generic_bignum_to_int64 ();
490 /* Number of littlenums in the bignum. */
491 number = leader - generic_bignum + 1;
495 if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
497 && input_line_pointer - 1 == suffix)
498 c = *input_line_pointer++;
502 /* Here with number, in correct radix. c is the next char.
503 Note that unlike un*x, we allow "011f" "0x9f" to both mean
504 the same as the (conventional) "9f".
505 This is simply easier than checking for strict canonical
508 if (LOCAL_LABELS_FB && c == 'b')
510 /* Backward ref to local label.
511 Because it is backward, expect it to be defined. */
512 /* Construct a local label. */
513 name = fb_label_name ((int) number, 0);
515 /* Seen before, or symbol is defined: OK. */
516 symbolP = symbol_find (name);
517 if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
519 /* Local labels are never absolute. Don't waste time
520 checking absoluteness. */
521 know (SEG_NORMAL (S_GET_SEGMENT (symbolP)));
523 expressionP->X_op = O_symbol;
524 expressionP->X_add_symbol = symbolP;
528 /* Either not seen or not defined. */
529 /* @@ Should print out the original string instead of
530 the parsed number. */
531 as_bad (_("backward ref to unknown label \"%d:\""),
533 expressionP->X_op = O_constant;
536 expressionP->X_add_number = 0;
538 else if (LOCAL_LABELS_FB && c == 'f')
540 /* Forward reference. Expect symbol to be undefined or
541 unknown. undefined: seen it before. unknown: never seen
544 Construct a local label name, then an undefined symbol.
545 Don't create a xseg frag for it: caller may do that.
546 Just return it as never seen before. */
547 name = fb_label_name ((int) number, 1);
548 symbolP = symbol_find_or_make (name);
549 /* We have no need to check symbol properties. */
550 #ifndef many_segments
551 /* Since "know" puts its arg into a "string", we
552 can't have newlines in the argument. */
553 know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section);
555 expressionP->X_op = O_symbol;
556 expressionP->X_add_symbol = symbolP;
557 expressionP->X_add_number = 0;
559 else if (LOCAL_LABELS_DOLLAR && c == '$')
561 /* If the dollar label is *currently* defined, then this is just
562 another reference to it. If it is not *currently* defined,
563 then this is a fresh instantiation of that number, so create
566 if (dollar_label_defined ((long) number))
568 name = dollar_label_name ((long) number, 0);
569 symbolP = symbol_find (name);
570 know (symbolP != NULL);
574 name = dollar_label_name ((long) number, 1);
575 symbolP = symbol_find_or_make (name);
578 expressionP->X_op = O_symbol;
579 expressionP->X_add_symbol = symbolP;
580 expressionP->X_add_number = 0;
584 expressionP->X_op = O_constant;
585 expressionP->X_add_number = number;
586 input_line_pointer--; /* Restore following character. */
587 } /* Really just a number. */
591 /* Not a small number. */
592 expressionP->X_op = O_big;
593 expressionP->X_add_number = number; /* Number of littlenums. */
594 input_line_pointer--; /* -> char following number. */
598 /* Parse an MRI multi character constant. */
601 mri_char_constant (expressionS *expressionP)
605 if (*input_line_pointer == '\''
606 && input_line_pointer[1] != '\'')
608 expressionP->X_op = O_constant;
609 expressionP->X_add_number = 0;
613 /* In order to get the correct byte ordering, we must build the
614 number in reverse. */
615 for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
619 generic_bignum[i] = 0;
620 for (j = 0; j < CHARS_PER_LITTLENUM; j++)
622 if (*input_line_pointer == '\'')
624 if (input_line_pointer[1] != '\'')
626 ++input_line_pointer;
628 generic_bignum[i] <<= 8;
629 generic_bignum[i] += *input_line_pointer;
630 ++input_line_pointer;
633 if (i < SIZE_OF_LARGE_NUMBER - 1)
635 /* If there is more than one littlenum, left justify the
636 last one to make it match the earlier ones. If there is
637 only one, we can just use the value directly. */
638 for (; j < CHARS_PER_LITTLENUM; j++)
639 generic_bignum[i] <<= 8;
642 if (*input_line_pointer == '\''
643 && input_line_pointer[1] != '\'')
649 as_bad (_("character constant too large"));
658 c = SIZE_OF_LARGE_NUMBER - i;
659 for (j = 0; j < c; j++)
660 generic_bignum[j] = generic_bignum[i + j];
664 know (LITTLENUM_NUMBER_OF_BITS == 16);
667 expressionP->X_op = O_big;
668 expressionP->X_add_number = i;
672 expressionP->X_op = O_constant;
674 expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
676 expressionP->X_add_number =
677 (((generic_bignum[1] & LITTLENUM_MASK)
678 << LITTLENUM_NUMBER_OF_BITS)
679 | (generic_bignum[0] & LITTLENUM_MASK));
682 /* Skip the final closing quote. */
683 ++input_line_pointer;
686 /* Return an expression representing the current location. This
687 handles the magic symbol `.'. */
690 current_location (expressionS *expressionp)
692 if (now_seg == absolute_section)
694 expressionp->X_op = O_constant;
695 expressionp->X_add_number = abs_section_offset;
699 expressionp->X_op = O_symbol;
700 expressionp->X_add_symbol = symbol_temp_new_now ();
701 expressionp->X_add_number = 0;
705 /* In: Input_line_pointer points to 1st char of operand, which may
709 The operand may have been empty: in this case X_op == O_absent.
710 Input_line_pointer->(next non-blank) char after operand. */
713 operand (expressionS *expressionP, enum expr_mode mode)
716 symbolS *symbolP; /* Points to symbol. */
717 char *name; /* Points to name of symbol. */
720 /* All integers are regarded as unsigned unless they are negated.
721 This is because the only thing which cares whether a number is
722 unsigned is the code in emit_expr which extends constants into
723 bignums. It should only sign extend negative numbers, so that
724 something like ``.quad 0x80000000'' is not sign extended even
725 though it appears negative if valueT is 32 bits. */
726 expressionP->X_unsigned = 1;
728 /* Digits, assume it is a bignum. */
730 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
731 c = *input_line_pointer++; /* input_line_pointer -> past char in c. */
733 if (is_end_of_line[(unsigned char) c])
747 input_line_pointer--;
749 integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
754 #ifdef LITERAL_PREFIXDOLLAR_HEX
756 /* $L is the start of a local label, not a hex constant. */
757 if (* input_line_pointer == 'L')
759 integer_constant (16, expressionP);
763 #ifdef LITERAL_PREFIXPERCENT_BIN
765 integer_constant (2, expressionP);
770 /* Non-decimal radix. */
772 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
776 /* Check for a hex or float constant. */
777 for (s = input_line_pointer; hex_p (*s); s++)
779 if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
781 --input_line_pointer;
782 integer_constant (0, expressionP);
786 c = *input_line_pointer;
795 if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
797 integer_constant (0, expressionP);
803 if (c && strchr (FLT_CHARS, c))
805 input_line_pointer++;
806 floating_constant (expressionP);
807 expressionP->X_add_number = - TOLOWER (c);
811 /* The string was only zero. */
812 expressionP->X_op = O_constant;
813 expressionP->X_add_number = 0;
822 input_line_pointer++;
823 integer_constant (16, expressionP);
827 if (LOCAL_LABELS_FB && ! (flag_m68k_mri || NUMBERS_WITH_SUFFIX))
829 /* This code used to check for '+' and '-' here, and, in
830 some conditions, fall through to call
831 integer_constant. However, that didn't make sense,
832 as integer_constant only accepts digits. */
833 /* Some of our code elsewhere does permit digits greater
834 than the expected base; for consistency, do the same
836 if (input_line_pointer[1] < '0'
837 || input_line_pointer[1] > '9')
839 /* Parse this as a back reference to label 0. */
840 input_line_pointer--;
841 integer_constant (10, expressionP);
844 /* Otherwise, parse this as a binary number. */
848 input_line_pointer++;
849 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
851 integer_constant (2, expressionP);
862 integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
870 /* If it says "0f" and it could possibly be a floating point
871 number, make it one. Otherwise, make it a local label,
872 and try to deal with parsing the rest later. */
873 if (!input_line_pointer[1]
874 || (is_end_of_line[0xff & input_line_pointer[1]])
875 || strchr (FLT_CHARS, 'f') == NULL)
878 char *cp = input_line_pointer + 1;
879 int r = atof_generic (&cp, ".", EXP_CHARS,
880 &generic_floating_point_number);
884 case ERROR_EXPONENT_OVERFLOW:
885 if (*cp == 'f' || *cp == 'b')
886 /* Looks like a difference expression. */
888 else if (cp == input_line_pointer + 1)
889 /* No characters has been accepted -- looks like
895 as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
900 /* Okay, now we've sorted it out. We resume at one of these
901 two labels, depending on what we've decided we're probably
904 input_line_pointer--;
905 integer_constant (10, expressionP);
915 if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
917 integer_constant (0, expressionP);
927 input_line_pointer++;
928 floating_constant (expressionP);
929 expressionP->X_add_number = - TOLOWER (c);
933 if (LOCAL_LABELS_DOLLAR)
935 integer_constant (10, expressionP);
945 #ifndef NEED_INDEX_OPERATOR
948 /* Didn't begin with digit & not a name. */
949 if (mode != expr_defer)
950 segment = expression (expressionP);
952 segment = deferred_expression (expressionP);
953 /* expression () will pass trailing whitespace. */
954 if ((c == '(' && *input_line_pointer != ')')
955 || (c == '[' && *input_line_pointer != ']'))
956 as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
958 input_line_pointer++;
960 /* Here with input_line_pointer -> char after "(...)". */
965 if (! flag_m68k_mri || *input_line_pointer != '\'')
967 as_bad (_("EBCDIC constants are not supported"));
970 if (! flag_m68k_mri || *input_line_pointer != '\'')
972 ++input_line_pointer;
978 /* Warning: to conform to other people's assemblers NO
979 ESCAPEMENT is permitted for a single quote. The next
980 character, parity errors and all, is taken as the value
981 of the operand. VERY KINKY. */
982 expressionP->X_op = O_constant;
983 expressionP->X_add_number = *input_line_pointer++;
987 mri_char_constant (expressionP);
992 /* Double quote is the bitwise not operator in MRI mode. */
998 /* '~' is permitted to start a label on the Delta. */
999 if (is_name_beginner (c))
1005 operand (expressionP, mode);
1006 if (expressionP->X_op == O_constant)
1008 /* input_line_pointer -> char after operand. */
1011 expressionP->X_add_number = - expressionP->X_add_number;
1012 /* Notice: '-' may overflow: no warning is given.
1013 This is compatible with other people's
1014 assemblers. Sigh. */
1015 expressionP->X_unsigned = 0;
1017 else if (c == '~' || c == '"')
1018 expressionP->X_add_number = ~ expressionP->X_add_number;
1020 expressionP->X_add_number = ! expressionP->X_add_number;
1022 else if (expressionP->X_op == O_big
1023 && expressionP->X_add_number <= 0
1025 && (generic_floating_point_number.sign == '+'
1026 || generic_floating_point_number.sign == 'P'))
1028 /* Negative flonum (eg, -1.000e0). */
1029 if (generic_floating_point_number.sign == '+')
1030 generic_floating_point_number.sign = '-';
1032 generic_floating_point_number.sign = 'N';
1034 else if (expressionP->X_op == O_big
1035 && expressionP->X_add_number > 0)
1039 if (c == '~' || c == '-')
1041 for (i = 0; i < expressionP->X_add_number; ++i)
1042 generic_bignum[i] = ~generic_bignum[i];
1044 /* Extend the bignum to at least the size of .octa. */
1045 if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1047 expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1048 for (; i < expressionP->X_add_number; ++i)
1049 generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1053 for (i = 0; i < expressionP->X_add_number; ++i)
1055 generic_bignum[i] += 1;
1056 if (generic_bignum[i])
1062 for (i = 0; i < expressionP->X_add_number; ++i)
1063 if (generic_bignum[i] != 0)
1065 expressionP->X_add_number = i >= expressionP->X_add_number;
1066 expressionP->X_op = O_constant;
1067 expressionP->X_unsigned = 1;
1070 else if (expressionP->X_op != O_illegal
1071 && expressionP->X_op != O_absent)
1075 expressionP->X_add_symbol = make_expr_symbol (expressionP);
1077 expressionP->X_op = O_uminus;
1078 else if (c == '~' || c == '"')
1079 expressionP->X_op = O_bit_not;
1081 expressionP->X_op = O_logical_not;
1082 expressionP->X_add_number = 0;
1086 as_warn (_("Unary operator %c ignored because bad operand follows"),
1091 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1093 /* '$' is the program counter when in MRI mode, or when
1094 DOLLAR_DOT is defined. */
1096 if (! flag_m68k_mri)
1099 if (DOLLAR_AMBIGU && hex_p (*input_line_pointer))
1101 /* In MRI mode and on Z80, '$' is also used as the prefix
1102 for a hexadecimal constant. */
1103 integer_constant (16, expressionP);
1107 if (is_part_of_name (*input_line_pointer))
1110 current_location (expressionP);
1115 if (!is_part_of_name (*input_line_pointer))
1117 current_location (expressionP);
1120 else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1121 && ! is_part_of_name (input_line_pointer[8]))
1122 || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1123 && ! is_part_of_name (input_line_pointer[7])))
1127 start = (input_line_pointer[1] == 't'
1128 || input_line_pointer[1] == 'T');
1129 input_line_pointer += start ? 8 : 7;
1131 if (*input_line_pointer != '(')
1132 as_bad (_("syntax error in .startof. or .sizeof."));
1137 ++input_line_pointer;
1139 name = input_line_pointer;
1140 c = get_symbol_end ();
1142 buf = (char *) xmalloc (strlen (name) + 10);
1144 sprintf (buf, ".startof.%s", name);
1146 sprintf (buf, ".sizeof.%s", name);
1147 symbolP = symbol_make (buf);
1150 expressionP->X_op = O_symbol;
1151 expressionP->X_add_symbol = symbolP;
1152 expressionP->X_add_number = 0;
1154 *input_line_pointer = c;
1156 if (*input_line_pointer != ')')
1157 as_bad (_("syntax error in .startof. or .sizeof."));
1159 ++input_line_pointer;
1170 /* Can't imagine any other kind of operand. */
1171 expressionP->X_op = O_absent;
1172 input_line_pointer--;
1177 if (! flag_m68k_mri)
1179 integer_constant (2, expressionP);
1183 if (! flag_m68k_mri)
1185 integer_constant (8, expressionP);
1189 if (! flag_m68k_mri)
1192 /* In MRI mode, this is a floating point constant represented
1193 using hexadecimal digits. */
1195 ++input_line_pointer;
1196 integer_constant (16, expressionP);
1200 if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
1203 current_location (expressionP);
1211 if (is_name_beginner (c)) /* Here if did not begin with a digit. */
1213 /* Identifier begins here.
1214 This is kludged for speed, so code is repeated. */
1216 name = --input_line_pointer;
1217 c = get_symbol_end ();
1219 #ifdef md_parse_name
1220 /* This is a hook for the backend to parse certain names
1221 specially in certain contexts. If a name always has a
1222 specific value, it can often be handled by simply
1223 entering it in the symbol table. */
1224 if (md_parse_name (name, expressionP, mode, &c))
1226 *input_line_pointer = c;
1232 /* The MRI i960 assembler permits
1234 FIXME: This should use md_parse_name. */
1236 && (strcasecmp (name, "sizeof") == 0
1237 || strcasecmp (name, "startof") == 0))
1242 start = (name[1] == 't'
1245 *input_line_pointer = c;
1248 name = input_line_pointer;
1249 c = get_symbol_end ();
1251 buf = (char *) xmalloc (strlen (name) + 10);
1253 sprintf (buf, ".startof.%s", name);
1255 sprintf (buf, ".sizeof.%s", name);
1256 symbolP = symbol_make (buf);
1259 expressionP->X_op = O_symbol;
1260 expressionP->X_add_symbol = symbolP;
1261 expressionP->X_add_number = 0;
1263 *input_line_pointer = c;
1270 symbolP = symbol_find_or_make (name);
1272 /* If we have an absolute symbol or a reg, then we know its
1274 segment = S_GET_SEGMENT (symbolP);
1275 if (mode != expr_defer && segment == absolute_section)
1277 expressionP->X_op = O_constant;
1278 expressionP->X_add_number = S_GET_VALUE (symbolP);
1280 else if (mode != expr_defer && segment == reg_section)
1282 expressionP->X_op = O_register;
1283 expressionP->X_add_number = S_GET_VALUE (symbolP);
1287 expressionP->X_op = O_symbol;
1288 expressionP->X_add_symbol = symbolP;
1289 expressionP->X_add_number = 0;
1291 *input_line_pointer = c;
1295 /* Let the target try to parse it. Success is indicated by changing
1296 the X_op field to something other than O_absent and pointing
1297 input_line_pointer past the expression. If it can't parse the
1298 expression, X_op and input_line_pointer should be unchanged. */
1299 expressionP->X_op = O_absent;
1300 --input_line_pointer;
1301 md_operand (expressionP);
1302 if (expressionP->X_op == O_absent)
1304 ++input_line_pointer;
1305 as_bad (_("bad expression"));
1306 expressionP->X_op = O_constant;
1307 expressionP->X_add_number = 0;
1313 /* It is more 'efficient' to clean up the expressionS when they are
1314 created. Doing it here saves lines of code. */
1315 clean_up_expression (expressionP);
1316 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1317 know (*input_line_pointer != ' ');
1319 /* The PA port needs this information. */
1320 if (expressionP->X_add_symbol)
1321 symbol_mark_used (expressionP->X_add_symbol);
1323 expressionP->X_add_symbol = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1324 expressionP->X_op_symbol = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1326 switch (expressionP->X_op)
1329 return absolute_section;
1331 return S_GET_SEGMENT (expressionP->X_add_symbol);
1337 /* Internal. Simplify a struct expression for use by expr (). */
1339 /* In: address of an expressionS.
1340 The X_op field of the expressionS may only take certain values.
1341 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1343 Out: expressionS may have been modified:
1344 Unused fields zeroed to help expr (). */
1347 clean_up_expression (expressionS *expressionP)
1349 switch (expressionP->X_op)
1353 expressionP->X_add_number = 0;
1358 expressionP->X_add_symbol = NULL;
1363 expressionP->X_op_symbol = NULL;
1370 /* Expression parser. */
1372 /* We allow an empty expression, and just assume (absolute,0) silently.
1373 Unary operators and parenthetical expressions are treated as operands.
1374 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1376 We used to do an aho/ullman shift-reduce parser, but the logic got so
1377 warped that I flushed it and wrote a recursive-descent parser instead.
1378 Now things are stable, would anybody like to write a fast parser?
1379 Most expressions are either register (which does not even reach here)
1380 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1381 So I guess it doesn't really matter how inefficient more complex expressions
1384 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1385 Also, we have consumed any leading or trailing spaces (operand does that)
1386 and done all intervening operators.
1388 This returns the segment of the result, which will be
1389 absolute_section or the segment of a symbol. */
1392 #define __ O_illegal
1394 #define O_SINGLE_EQ O_illegal
1397 /* Maps ASCII -> operators. */
1398 static const operatorT op_encoding[256] = {
1399 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1400 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1402 __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
1403 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1404 __, __, __, __, __, __, __, __,
1405 __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __,
1406 __, __, __, __, __, __, __, __,
1407 __, __, __, __, __, __, __, __,
1408 __, __, __, __, __, __, __, __,
1410 #ifdef NEED_INDEX_OPERATOR
1415 __, __, O_bit_exclusive_or, __,
1416 __, __, __, __, __, __, __, __,
1417 __, __, __, __, __, __, __, __,
1418 __, __, __, __, __, __, __, __,
1419 __, __, __, __, O_bit_inclusive_or, __, __, __,
1421 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1422 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1423 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1424 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1425 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1426 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1427 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1428 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1432 0 operand, (expression)
1437 5 used for * / % in MRI mode
1442 static operator_rankT op_rank[] = {
1447 0, /* O_symbol_rva */
1452 9, /* O_logical_not */
1456 8, /* O_left_shift */
1457 8, /* O_right_shift */
1458 7, /* O_bit_inclusive_or */
1459 7, /* O_bit_or_not */
1460 7, /* O_bit_exclusive_or */
1470 3, /* O_logical_and */
1471 2, /* O_logical_or */
1491 /* Unfortunately, in MRI mode for the m68k, multiplication and
1492 division have lower precedence than the bit wise operators. This
1493 function sets the operator precedences correctly for the current
1494 mode. Also, MRI uses a different bit_not operator, and this fixes
1497 #define STANDARD_MUL_PRECEDENCE 8
1498 #define MRI_MUL_PRECEDENCE 6
1501 expr_set_precedence (void)
1505 op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
1506 op_rank[O_divide] = MRI_MUL_PRECEDENCE;
1507 op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
1511 op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1512 op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1513 op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1517 /* Initialize the expression parser. */
1522 expr_set_precedence ();
1524 /* Verify that X_op field is wide enough. */
1528 assert (e.X_op == O_max);
1532 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1533 sets NUM_CHARS to the number of characters in the operator.
1534 Does not advance INPUT_LINE_POINTER. */
1536 static inline operatorT
1537 operator (int *num_chars)
1542 c = *input_line_pointer & 0xff;
1545 if (is_end_of_line[c])
1551 return op_encoding[c];
1555 return op_encoding[c];
1558 switch (input_line_pointer[1])
1561 return op_encoding[c];
1576 if (input_line_pointer[1] != '=')
1577 return op_encoding[c];
1583 switch (input_line_pointer[1])
1586 return op_encoding[c];
1588 ret = O_right_shift;
1598 switch (input_line_pointer[1])
1601 /* We accept !! as equivalent to ^ for MRI compatibility. */
1603 return O_bit_exclusive_or;
1605 /* We accept != as equivalent to <>. */
1610 return O_bit_inclusive_or;
1611 return op_encoding[c];
1615 if (input_line_pointer[1] != '|')
1616 return op_encoding[c];
1619 return O_logical_or;
1622 if (input_line_pointer[1] != '&')
1623 return op_encoding[c];
1626 return O_logical_and;
1632 /* Parse an expression. */
1635 expr (int rankarg, /* Larger # is higher rank. */
1636 expressionS *resultP, /* Deliver result here. */
1637 enum expr_mode mode /* Controls behavior. */)
1639 operator_rankT rank = (operator_rankT) rankarg;
1646 know (rankarg >= 0);
1648 /* Save the value of dot for the fixup code. */
1650 dot_value = frag_now_fix ();
1652 retval = operand (resultP, mode);
1654 /* operand () gobbles spaces. */
1655 know (*input_line_pointer != ' ');
1657 op_left = operator (&op_chars);
1658 while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1663 input_line_pointer += op_chars; /* -> after operator. */
1665 rightseg = expr (op_rank[(int) op_left], &right, mode);
1666 if (right.X_op == O_absent)
1668 as_warn (_("missing operand; zero assumed"));
1669 right.X_op = O_constant;
1670 right.X_add_number = 0;
1671 right.X_add_symbol = NULL;
1672 right.X_op_symbol = NULL;
1675 know (*input_line_pointer != ' ');
1677 if (op_left == O_index)
1679 if (*input_line_pointer != ']')
1680 as_bad ("missing right bracket");
1683 ++input_line_pointer;
1688 op_right = operator (&op_chars);
1690 know (op_right == O_illegal
1691 || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1692 know ((int) op_left >= (int) O_multiply
1693 && (int) op_left <= (int) O_index);
1695 /* input_line_pointer->after right-hand quantity. */
1696 /* left-hand quantity in resultP. */
1697 /* right-hand quantity in right. */
1698 /* operator in op_left. */
1700 if (resultP->X_op == O_big)
1702 if (resultP->X_add_number > 0)
1703 as_warn (_("left operand is a bignum; integer 0 assumed"));
1705 as_warn (_("left operand is a float; integer 0 assumed"));
1706 resultP->X_op = O_constant;
1707 resultP->X_add_number = 0;
1708 resultP->X_add_symbol = NULL;
1709 resultP->X_op_symbol = NULL;
1711 if (right.X_op == O_big)
1713 if (right.X_add_number > 0)
1714 as_warn (_("right operand is a bignum; integer 0 assumed"));
1716 as_warn (_("right operand is a float; integer 0 assumed"));
1717 right.X_op = O_constant;
1718 right.X_add_number = 0;
1719 right.X_add_symbol = NULL;
1720 right.X_op_symbol = NULL;
1723 /* Optimize common cases. */
1724 #ifdef md_optimize_expr
1725 if (md_optimize_expr (resultP, op_left, &right))
1732 if (op_left == O_add && right.X_op == O_constant)
1735 resultP->X_add_number += right.X_add_number;
1737 /* This case comes up in PIC code. */
1738 else if (op_left == O_subtract
1739 && right.X_op == O_symbol
1740 && resultP->X_op == O_symbol
1741 && retval == rightseg
1742 && (SEG_NORMAL (rightseg)
1743 || right.X_add_symbol == resultP->X_add_symbol)
1744 && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1745 symbol_get_frag (right.X_add_symbol),
1748 resultP->X_add_number -= right.X_add_number;
1749 resultP->X_add_number -= frag_off / OCTETS_PER_BYTE;
1750 resultP->X_add_number += (S_GET_VALUE (resultP->X_add_symbol)
1751 - S_GET_VALUE (right.X_add_symbol));
1752 resultP->X_op = O_constant;
1753 resultP->X_add_symbol = 0;
1755 else if (op_left == O_subtract && right.X_op == O_constant)
1758 resultP->X_add_number -= right.X_add_number;
1760 else if (op_left == O_add && resultP->X_op == O_constant)
1763 resultP->X_op = right.X_op;
1764 resultP->X_add_symbol = right.X_add_symbol;
1765 resultP->X_op_symbol = right.X_op_symbol;
1766 resultP->X_add_number += right.X_add_number;
1769 else if (resultP->X_op == O_constant && right.X_op == O_constant)
1771 /* Constant OP constant. */
1772 offsetT v = right.X_add_number;
1773 if (v == 0 && (op_left == O_divide || op_left == O_modulus))
1775 as_warn (_("division by zero"));
1781 case O_multiply: resultP->X_add_number *= v; break;
1782 case O_divide: resultP->X_add_number /= v; break;
1783 case O_modulus: resultP->X_add_number %= v; break;
1784 case O_left_shift: resultP->X_add_number <<= v; break;
1786 /* We always use unsigned shifts, to avoid relying on
1787 characteristics of the compiler used to compile gas. */
1788 resultP->X_add_number =
1789 (offsetT) ((valueT) resultP->X_add_number >> (valueT) v);
1791 case O_bit_inclusive_or: resultP->X_add_number |= v; break;
1792 case O_bit_or_not: resultP->X_add_number |= ~v; break;
1793 case O_bit_exclusive_or: resultP->X_add_number ^= v; break;
1794 case O_bit_and: resultP->X_add_number &= v; break;
1795 /* Constant + constant (O_add) is handled by the
1796 previous if statement for constant + X, so is omitted
1798 case O_subtract: resultP->X_add_number -= v; break;
1800 resultP->X_add_number =
1801 resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
1804 resultP->X_add_number =
1805 resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
1808 resultP->X_add_number =
1809 resultP->X_add_number < v ? ~ (offsetT) 0 : 0;
1812 resultP->X_add_number =
1813 resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
1816 resultP->X_add_number =
1817 resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
1820 resultP->X_add_number =
1821 resultP->X_add_number > v ? ~ (offsetT) 0 : 0;
1824 resultP->X_add_number = resultP->X_add_number && v;
1827 resultP->X_add_number = resultP->X_add_number || v;
1831 else if (resultP->X_op == O_symbol
1832 && right.X_op == O_symbol
1833 && (op_left == O_add
1834 || op_left == O_subtract
1835 || (resultP->X_add_number == 0
1836 && right.X_add_number == 0)))
1838 /* Symbol OP symbol. */
1839 resultP->X_op = op_left;
1840 resultP->X_op_symbol = right.X_add_symbol;
1841 if (op_left == O_add)
1842 resultP->X_add_number += right.X_add_number;
1843 else if (op_left == O_subtract)
1845 resultP->X_add_number -= right.X_add_number;
1846 if (retval == rightseg && SEG_NORMAL (retval))
1848 retval = absolute_section;
1849 rightseg = absolute_section;
1855 /* The general case. */
1856 resultP->X_add_symbol = make_expr_symbol (resultP);
1857 resultP->X_op_symbol = make_expr_symbol (&right);
1858 resultP->X_op = op_left;
1859 resultP->X_add_number = 0;
1860 resultP->X_unsigned = 1;
1863 if (retval != rightseg)
1865 if (! SEG_NORMAL (retval))
1867 if (retval != undefined_section || SEG_NORMAL (rightseg))
1870 else if (SEG_NORMAL (rightseg)
1872 && op_left != O_subtract
1875 as_bad (_("operation combines symbols in different segments"));
1879 } /* While next operator is >= this rank. */
1881 /* The PA port needs this information. */
1882 if (resultP->X_add_symbol)
1883 symbol_mark_used (resultP->X_add_symbol);
1885 if (rank == 0 && mode == expr_evaluate)
1886 resolve_expression (resultP);
1888 return resultP->X_op == O_constant ? absolute_section : retval;
1891 /* Resolve an expression without changing any symbols/sub-expressions
1895 resolve_expression (expressionS *expressionP)
1897 /* Help out with CSE. */
1898 valueT final_val = expressionP->X_add_number;
1899 symbolS *add_symbol = expressionP->X_add_symbol;
1900 symbolS *op_symbol = expressionP->X_op_symbol;
1901 operatorT op = expressionP->X_op;
1903 segT seg_left, seg_right;
1904 fragS *frag_left, *frag_right;
1919 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
1927 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
1930 if (seg_left != absolute_section)
1933 if (op == O_logical_not)
1935 else if (op == O_uminus)
1947 case O_bit_inclusive_or:
1949 case O_bit_exclusive_or:
1961 if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
1962 || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
1965 /* Simplify addition or subtraction of a constant by folding the
1966 constant into X_add_number. */
1969 if (seg_right == absolute_section)
1975 else if (seg_left == absolute_section)
1979 seg_left = seg_right;
1980 add_symbol = op_symbol;
1985 else if (op == O_subtract)
1987 if (seg_right == absolute_section)
1995 /* Equality and non-equality tests are permitted on anything.
1996 Subtraction, and other comparison operators are permitted if
1997 both operands are in the same section.
1998 Shifts by constant zero are permitted on anything.
1999 Multiplies, bit-ors, and bit-ands with constant zero are
2000 permitted on anything.
2001 Multiplies and divides by constant one are permitted on
2003 Binary operations with both operands being the same register
2004 or undefined symbol are permitted if the result doesn't depend
2006 Otherwise, both operands must be absolute. We already handled
2007 the case of addition or subtraction of a constant above. */
2009 if (!(seg_left == absolute_section
2010 && seg_right == absolute_section)
2011 && !(op == O_eq || op == O_ne)
2012 && !((op == O_subtract
2013 || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2014 && seg_left == seg_right
2016 || frag_offset_fixed_p (frag_left, frag_right, &frag_off))
2017 && (seg_left != reg_section || left == right)
2018 && (seg_left != undefined_section || add_symbol == op_symbol)))
2020 if ((seg_left == absolute_section && left == 0)
2021 || (seg_right == absolute_section && right == 0))
2023 if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2025 if (seg_right != absolute_section || right != 0)
2027 seg_left = seg_right;
2029 add_symbol = op_symbol;
2034 else if (op == O_left_shift || op == O_right_shift)
2036 if (seg_left != absolute_section || left != 0)
2042 else if (op != O_multiply
2043 && op != O_bit_or_not && op != O_bit_and)
2046 else if (op == O_multiply
2047 && seg_left == absolute_section && left == 1)
2049 seg_left = seg_right;
2051 add_symbol = op_symbol;
2055 else if ((op == O_multiply || op == O_divide)
2056 && seg_right == absolute_section && right == 1)
2061 else if (left != right
2062 || ((seg_left != reg_section || seg_right != reg_section)
2063 && (seg_left != undefined_section
2064 || seg_right != undefined_section
2065 || add_symbol != op_symbol)))
2067 else if (op == O_bit_and || op == O_bit_inclusive_or)
2072 else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2076 right += frag_off / OCTETS_PER_BYTE;
2079 case O_add: left += right; break;
2080 case O_subtract: left -= right; break;
2081 case O_multiply: left *= right; break;
2085 left = (offsetT) left / (offsetT) right;
2090 left = (offsetT) left % (offsetT) right;
2092 case O_left_shift: left <<= right; break;
2093 case O_right_shift: left >>= right; break;
2094 case O_bit_inclusive_or: left |= right; break;
2095 case O_bit_or_not: left |= ~right; break;
2096 case O_bit_exclusive_or: left ^= right; break;
2097 case O_bit_and: left &= right; break;
2100 left = (left == right
2101 && seg_left == seg_right
2102 && (finalize_syms || frag_left == frag_right)
2103 && (seg_left != undefined_section
2104 || add_symbol == op_symbol)
2105 ? ~ (valueT) 0 : 0);
2110 left = (offsetT) left < (offsetT) right ? ~ (valueT) 0 : 0;
2113 left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2116 left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2119 left = (offsetT) left > (offsetT) right ? ~ (valueT) 0 : 0;
2121 case O_logical_and: left = left && right; break;
2122 case O_logical_or: left = left || right; break;
2132 if (seg_left == absolute_section)
2134 else if (seg_left == reg_section && final_val == 0)
2136 else if (add_symbol != expressionP->X_add_symbol)
2138 expressionP->X_add_symbol = add_symbol;
2140 expressionP->X_op = op;
2142 if (op == O_constant || op == O_register)
2144 expressionP->X_add_number = final_val;
2149 /* This lives here because it belongs equally in expr.c & read.c.
2150 expr.c is just a branch office read.c anyway, and putting it
2151 here lessens the crowd at read.c.
2153 Assume input_line_pointer is at start of symbol name.
2154 Advance input_line_pointer past symbol name.
2155 Turn that character into a '\0', returning its former value.
2156 This allows a string compare (RMS wants symbol names to be strings)
2158 There will always be a char following symbol name, because all good
2159 lines end in end-of-line. */
2162 get_symbol_end (void)
2166 /* We accept \001 in a name in case this is being called with a
2167 constructed string. */
2168 if (is_name_beginner (c = *input_line_pointer++) || c == '\001')
2170 while (is_part_of_name (c = *input_line_pointer++)
2173 if (is_name_ender (c))
2174 c = *input_line_pointer++;
2176 *--input_line_pointer = 0;
2181 get_single_number (void)
2184 operand (&exp, expr_normal);
2185 return exp.X_add_number;