1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2024 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* This is really a branch office of as-read.c. I split it out to clearly
22 distinguish the world of expressions from the world of statements.
23 (It also gives smaller files to re-compile.)
24 Here, "operand"s are of expressions, not instructions. */
26 #define min(a, b) ((a) < (b) ? (a) : (b))
29 #include "safe-ctype.h"
36 bool literal_prefix_dollar_hex
= false;
38 static void clean_up_expression (expressionS
* expressionP
);
40 /* We keep a mapping of expression symbols to file positions, so that
41 we can provide better error messages. */
43 struct expr_symbol_line
{
44 struct expr_symbol_line
*next
;
50 static struct expr_symbol_line
*expr_symbol_lines
;
52 static const expressionS zero
= { .X_op
= O_constant
};
54 /* Build a dummy symbol to hold a complex expression. This is how we
55 build expressions up out of other expressions. The symbol is put
56 into the fake section expr_section. */
59 make_expr_symbol (const expressionS
*expressionP
)
62 struct expr_symbol_line
*n
;
64 if (expressionP
->X_op
== O_symbol
65 && expressionP
->X_add_number
== 0)
66 return expressionP
->X_add_symbol
;
68 if (expressionP
->X_op
== O_big
)
70 /* This won't work, because the actual value is stored in
71 generic_floating_point_number or generic_bignum, and we are
72 going to lose it if we haven't already. */
73 if (expressionP
->X_add_number
> 0)
74 as_bad (_("bignum invalid"));
76 as_bad (_("floating point number invalid"));
80 /* Putting constant symbols in absolute_section rather than
81 expr_section is convenient for the old a.out code, for which
82 S_GET_SEGMENT does not always retrieve the value put in by
84 symbolP
= symbol_create (FAKE_LABEL_NAME
,
85 (expressionP
->X_op
== O_constant
87 : expressionP
->X_op
== O_register
90 &zero_address_frag
, 0);
91 symbol_set_value_expression (symbolP
, expressionP
);
93 if (expressionP
->X_op
== O_constant
)
94 resolve_symbol_value (symbolP
);
96 n
= notes_alloc (sizeof (*n
));
98 n
->file
= as_where (&n
->line
);
99 n
->next
= expr_symbol_lines
;
100 expr_symbol_lines
= n
;
105 /* Return the file and line number for an expr symbol. Return
106 non-zero if something was found, 0 if no information is known for
110 expr_symbol_where (symbolS
*sym
, const char **pfile
, unsigned int *pline
)
112 struct expr_symbol_line
*l
;
114 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
127 /* Look up a previously used .startof. / .sizeof. symbol, or make a fresh
129 static symbolS
**seen
[2];
130 static unsigned int nr_seen
[2];
133 symbol_lookup_or_make (const char *name
, bool start
)
135 char *buf
= concat (start
? ".startof." : ".sizeof.", name
, NULL
);
139 for (i
= 0; i
< nr_seen
[start
]; ++i
)
141 symbolP
= seen
[start
][i
];
146 name
= S_GET_NAME (symbolP
);
147 if ((symbols_case_sensitive
149 : strcasecmp (buf
, name
)) == 0)
156 symbolP
= symbol_make (buf
);
159 if (i
>= nr_seen
[start
])
161 unsigned int nr
= (i
+ 1) * 2;
163 seen
[start
] = XRESIZEVEC (symbolS
*, seen
[start
], nr
);
165 memset (&seen
[start
][i
+ 1], 0, (nr
- i
- 1) * sizeof(seen
[0][0]));
168 seen
[start
][i
] = symbolP
;
173 /* Utilities for building expressions.
174 Since complex expressions are recorded as symbols for use in other
175 expressions these return a symbolS * and not an expressionS *.
176 These explicitly do not take an "add_number" argument. */
177 /* ??? For completeness' sake one might want expr_build_symbol.
178 It would just return its argument. */
180 /* Build an expression for an unsigned constant.
181 The corresponding one for signed constants is missing because
182 there's currently no need for it. One could add an unsigned_p flag
183 but that seems more clumsy. */
186 expr_build_uconstant (offsetT value
)
191 e
.X_add_number
= value
;
194 return make_expr_symbol (&e
);
197 /* Build an expression for the current location ('.'). */
200 expr_build_dot (void)
204 current_location (&e
);
205 return symbol_clone_if_forward_ref (make_expr_symbol (&e
));
208 /* Build any floating-point literal here.
209 Also build any bignum literal here. */
211 /* Seems atof_machine can backscan through generic_bignum and hit whatever
212 happens to be loaded before it in memory. And its way too complicated
213 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
214 and never write into the early words, thus they'll always be zero.
215 I hate Dean's floating-point code. Bleh. */
216 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
218 FLONUM_TYPE generic_floating_point_number
= {
219 &generic_bignum
[6], /* low. (JF: Was 0) */
220 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
228 floating_constant (expressionS
*expressionP
)
230 /* input_line_pointer -> floating-point constant. */
233 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
234 &generic_floating_point_number
);
238 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
240 as_bad (_("bad floating-point constant: exponent overflow"));
244 as_bad (_("bad floating-point constant: unknown error code=%d"),
248 expressionP
->X_op
= O_big
;
249 /* input_line_pointer -> just after constant, which may point to
251 expressionP
->X_add_number
= -1;
255 generic_bignum_to_int32 (void)
257 return ((((uint32_t) generic_bignum
[1] & LITTLENUM_MASK
)
258 << LITTLENUM_NUMBER_OF_BITS
)
259 | ((uint32_t) generic_bignum
[0] & LITTLENUM_MASK
));
263 generic_bignum_to_int64 (void)
265 return ((((((((uint64_t) generic_bignum
[3] & LITTLENUM_MASK
)
266 << LITTLENUM_NUMBER_OF_BITS
)
267 | ((uint64_t) generic_bignum
[2] & LITTLENUM_MASK
))
268 << LITTLENUM_NUMBER_OF_BITS
)
269 | ((uint64_t) generic_bignum
[1] & LITTLENUM_MASK
))
270 << LITTLENUM_NUMBER_OF_BITS
)
271 | ((uint64_t) generic_bignum
[0] & LITTLENUM_MASK
));
275 integer_constant (int radix
, expressionS
*expressionP
)
277 char *start
; /* Start of number. */
280 valueT number
; /* Offset or (absolute) value. */
281 short int digit
; /* Value of next digit in current radix. */
282 int too_many_digits
= 0; /* If we see >= this number of. */
283 char *name
; /* Points to name of symbol. */
284 symbolS
*symbolP
; /* Points to symbol. */
286 bool small
; /* True if fits in 32 bits (64 bits with BFD64). */
288 /* May be bignum, or may fit in 32 bits. */
289 /* Most numbers fit into 32 bits, and we want this case to be fast.
290 so we pretend it will fit into 32 bits. If, after making up a 32
291 bit number, we realise that we have scanned more digits than
292 comfortably fit into 32 bits, we re-scan the digits coding them
293 into a bignum. For decimal and octal numbers we are
294 conservative: Some numbers may be assumed bignums when in fact
295 they do fit into 32 bits. Numbers of any radix can have excess
296 leading zeros: We strive to recognise this and cast them back
297 into 32 bits. We must check that the bignum really is more than
298 32 bits, and change it back to a 32-bit number if it fits. The
299 number we are looking for is expected to be positive, but if it
300 fits into 32 bits as an unsigned number, we let it be a 32-bit
301 number. The cavalier approach is for speed in ordinary cases. */
302 /* This has been extended for 64 bits. We blindly assume that if
303 you're compiling in 64-bit mode, the target is a 64-bit machine.
304 This should be cleaned up. */
308 #else /* includes non-bfd case, mostly */
312 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
314 expressionP
->X_op
= O_absent
;
318 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
322 /* In MRI mode, the number may have a suffix indicating the
323 radix. For that matter, it might actually be a floating
325 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
327 if (*suffix
== 'e' || *suffix
== 'E')
331 if (suffix
== input_line_pointer
)
340 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
341 we distinguish between 'B' and 'b'. This is the case for
343 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
347 else if (c
== 'O' || c
== 'Q')
351 else if (suffix
[1] == '.' || c
== 'E' || flt
)
353 floating_constant (expressionP
);
367 too_many_digits
= valuesize
+ 1;
370 too_many_digits
= (valuesize
+ 2) / 3 + 1;
373 too_many_digits
= (valuesize
+ 3) / 4 + 1;
376 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
380 start
= input_line_pointer
;
381 c
= *input_line_pointer
++;
383 (digit
= hex_value (c
)) < radix
;
384 c
= *input_line_pointer
++)
386 number
= number
* radix
+ digit
;
388 /* c contains character after number. */
389 /* input_line_pointer->char after c. */
390 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
392 if (radix
== 16 && c
== '_')
394 /* This is literal of the form 0x333_0_12345678_1.
395 This example is equivalent to 0x00000333000000001234567800000001. */
397 int num_little_digits
= 0;
399 input_line_pointer
= start
; /* -> 1st digit. */
401 know (LITTLENUM_NUMBER_OF_BITS
== 16);
403 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
406 /* Convert one 64-bit word. */
409 for (c
= *input_line_pointer
++;
410 (digit
= hex_value (c
)) < radix
;
411 c
= *(input_line_pointer
++))
413 number
= number
* radix
+ digit
;
417 /* Check for 8 digit per word max. */
419 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
421 /* Add this chunk to the bignum.
422 Shift things down 2 little digits. */
423 know (LITTLENUM_NUMBER_OF_BITS
== 16);
424 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
427 generic_bignum
[i
] = generic_bignum
[i
- 2];
429 /* Add the new digits as the least significant new ones. */
430 generic_bignum
[0] = number
& 0xffffffff;
431 generic_bignum
[1] = number
>> 16;
434 /* Again, c is char after number, input_line_pointer->after c. */
436 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
437 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
439 gas_assert (num_little_digits
>= 4);
441 if (num_little_digits
!= 8)
442 as_bad (_("a bignum with underscores must have exactly 4 words"));
444 /* We might have some leading zeros. These can be trimmed to give
445 us a change to fit this constant into a small number. */
446 while (generic_bignum
[num_little_digits
- 1] == 0
447 && num_little_digits
> 1)
450 if (num_little_digits
<= 2)
452 /* will fit into 32 bits. */
453 number
= generic_bignum_to_int32 ();
457 else if (num_little_digits
<= 4)
459 /* Will fit into 64 bits. */
460 number
= generic_bignum_to_int64 ();
468 /* Number of littlenums in the bignum. */
469 number
= num_little_digits
;
474 /* We saw a lot of digits. manufacture a bignum the hard way. */
475 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
476 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
479 leader
= generic_bignum
;
480 generic_bignum
[0] = 0;
481 generic_bignum
[1] = 0;
482 generic_bignum
[2] = 0;
483 generic_bignum
[3] = 0;
484 input_line_pointer
= start
; /* -> 1st digit. */
485 c
= *input_line_pointer
++;
486 for (; (carry
= hex_value (c
)) < radix
; c
= *input_line_pointer
++)
488 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
492 work
= carry
+ radix
* *pointer
;
493 *pointer
= work
& LITTLENUM_MASK
;
494 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
498 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
500 /* Room to grow a longer bignum. */
505 /* Again, c is char after number. */
506 /* input_line_pointer -> after c. */
507 know (LITTLENUM_NUMBER_OF_BITS
== 16);
508 if (leader
< generic_bignum
+ 2)
510 /* Will fit into 32 bits. */
511 number
= generic_bignum_to_int32 ();
515 else if (leader
< generic_bignum
+ 4)
517 /* Will fit into 64 bits. */
518 number
= generic_bignum_to_int64 ();
524 /* Number of littlenums in the bignum. */
525 number
= leader
- generic_bignum
+ 1;
529 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
531 && input_line_pointer
- 1 == suffix
)
532 c
= *input_line_pointer
++;
534 #ifndef tc_allow_U_suffix
535 #define tc_allow_U_suffix 1
537 bool u_seen
= !tc_allow_U_suffix
;
538 /* PR 19910: Look for, and ignore, a U suffix to the number. */
539 if (!u_seen
&& (c
== 'U' || c
== 'u'))
541 c
= *input_line_pointer
++;
545 #ifndef tc_allow_L_suffix
546 #define tc_allow_L_suffix 1
548 bool l_seen
= !tc_allow_L_suffix
;
549 /* PR 20732: Look for, and ignore, a L or LL suffix to the number. */
550 if (tc_allow_L_suffix
&& (c
== 'L' || c
== 'l'))
552 c
= * input_line_pointer
++;
554 if (c
== 'L' || c
== 'l')
555 c
= *input_line_pointer
++;
556 if (!u_seen
&& (c
== 'U' || c
== 'u'))
557 c
= *input_line_pointer
++;
562 /* Here with number, in correct radix. c is the next char. */
563 bool maybe_label
= suffix
== NULL
564 && (!tc_allow_U_suffix
|| !u_seen
)
565 && (!tc_allow_L_suffix
|| !l_seen
)
567 (radix
== 8 && input_line_pointer
== start
+ 1));
569 if (LOCAL_LABELS_FB
&& c
== 'b' && maybe_label
)
571 /* Backward ref to local label.
572 Because it is backward, expect it to be defined. */
573 /* Construct a local label. */
574 name
= fb_label_name (number
, 0);
576 /* Seen before, or symbol is defined: OK. */
577 symbolP
= symbol_find (name
);
578 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
580 expressionP
->X_op
= O_symbol
;
581 expressionP
->X_add_symbol
= symbolP
;
585 /* Either not seen or not defined. */
586 /* @@ Should print out the original string instead of
587 the parsed number. */
588 as_bad (_("backward ref to unknown label \"%d:\""),
590 expressionP
->X_op
= O_constant
;
593 expressionP
->X_add_number
= 0;
595 else if (LOCAL_LABELS_FB
&& c
== 'f' && maybe_label
)
597 /* Forward reference. Expect symbol to be undefined or
598 unknown. undefined: seen it before. unknown: never seen
601 Construct a local label name, then an undefined symbol.
602 Don't create a xseg frag for it: caller may do that.
603 Just return it as never seen before. */
604 name
= fb_label_name (number
, 1);
605 symbolP
= symbol_find_or_make (name
);
606 /* We have no need to check symbol properties. */
607 expressionP
->X_op
= O_symbol
;
608 expressionP
->X_add_symbol
= symbolP
;
609 expressionP
->X_add_number
= 0;
611 else if (LOCAL_LABELS_DOLLAR
&& c
== '$' && maybe_label
)
613 /* If the dollar label is *currently* defined, then this is just
614 another reference to it. If it is not *currently* defined,
615 then this is a fresh instantiation of that number, so create
618 if (dollar_label_defined (number
))
620 name
= dollar_label_name (number
, 0);
621 symbolP
= symbol_find (name
);
622 know (symbolP
!= NULL
);
626 name
= dollar_label_name (number
, 1);
627 symbolP
= symbol_find_or_make (name
);
630 expressionP
->X_op
= O_symbol
;
631 expressionP
->X_add_symbol
= symbolP
;
632 expressionP
->X_add_number
= 0;
636 expressionP
->X_op
= O_constant
;
637 expressionP
->X_add_number
= number
;
638 input_line_pointer
--; /* Restore following character. */
639 } /* Really just a number. */
643 /* Not a small number. */
644 expressionP
->X_op
= O_big
;
645 expressionP
->X_add_number
= number
; /* Number of littlenums. */
646 input_line_pointer
--; /* -> char following number. */
650 /* Parse an MRI multi character constant. */
653 mri_char_constant (expressionS
*expressionP
)
657 if (*input_line_pointer
== '\''
658 && input_line_pointer
[1] != '\'')
660 expressionP
->X_op
= O_constant
;
661 expressionP
->X_add_number
= 0;
665 /* In order to get the correct byte ordering, we must build the
666 number in reverse. */
667 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
671 generic_bignum
[i
] = 0;
672 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
674 if (*input_line_pointer
== '\'')
676 if (input_line_pointer
[1] != '\'')
678 ++input_line_pointer
;
680 generic_bignum
[i
] <<= 8;
681 generic_bignum
[i
] += *input_line_pointer
;
682 ++input_line_pointer
;
685 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
687 /* If there is more than one littlenum, left justify the
688 last one to make it match the earlier ones. If there is
689 only one, we can just use the value directly. */
690 for (; j
< CHARS_PER_LITTLENUM
; j
++)
691 generic_bignum
[i
] <<= 8;
694 if (*input_line_pointer
== '\''
695 && input_line_pointer
[1] != '\'')
701 as_bad (_("character constant too large"));
710 c
= SIZE_OF_LARGE_NUMBER
- i
;
711 for (j
= 0; j
< c
; j
++)
712 generic_bignum
[j
] = generic_bignum
[i
+ j
];
716 know (LITTLENUM_NUMBER_OF_BITS
== 16);
719 expressionP
->X_op
= O_big
;
720 expressionP
->X_add_number
= i
;
724 expressionP
->X_op
= O_constant
;
726 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
728 expressionP
->X_add_number
=
729 (((generic_bignum
[1] & LITTLENUM_MASK
)
730 << LITTLENUM_NUMBER_OF_BITS
)
731 | (generic_bignum
[0] & LITTLENUM_MASK
));
734 /* Skip the final closing quote. */
735 ++input_line_pointer
;
738 /* Return an expression representing the current location. This
739 handles the magic symbol `.'. */
742 current_location (expressionS
*expressionp
)
744 if (now_seg
== absolute_section
)
746 expressionp
->X_op
= O_constant
;
747 expressionp
->X_add_number
= abs_section_offset
;
751 expressionp
->X_op
= O_symbol
;
752 expressionp
->X_add_symbol
= &dot_symbol
;
753 expressionp
->X_add_number
= 0;
757 #ifndef md_register_arithmetic
758 # define md_register_arithmetic 1
761 /* In: Input_line_pointer points to 1st char of operand, which may
765 The operand may have been empty: in this case X_op == O_absent.
766 Input_line_pointer->(next non-blank) char after operand. */
769 operand (expressionS
*expressionP
, enum expr_mode mode
)
772 symbolS
*symbolP
; /* Points to symbol. */
773 char *name
; /* Points to name of symbol. */
775 operatorT op
= O_absent
; /* For unary operators. */
777 /* All integers are regarded as unsigned unless they are negated.
778 This is because the only thing which cares whether a number is
779 unsigned is the code in emit_expr which extends constants into
780 bignums. It should only sign extend negative numbers, so that
781 something like ``.quad 0x80000000'' is not sign extended even
782 though it appears negative if valueT is 32 bits. */
783 expressionP
->X_unsigned
= 1;
784 expressionP
->X_extrabit
= 0;
786 /* Digits, assume it is a bignum. */
788 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
789 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
791 if (is_end_of_line
[(unsigned char) c
])
805 input_line_pointer
--;
807 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
812 #ifdef LITERAL_PREFIXPERCENT_BIN
814 integer_constant (2, expressionP
);
819 /* Non-decimal radix. */
821 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
825 /* Check for a hex or float constant. */
826 for (s
= input_line_pointer
; hex_p (*s
); s
++)
828 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
830 --input_line_pointer
;
831 integer_constant (0, expressionP
);
835 c
= *input_line_pointer
;
844 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
846 integer_constant (0, expressionP
);
852 if (c
&& strchr (FLT_CHARS
, c
))
854 input_line_pointer
++;
855 floating_constant (expressionP
);
856 expressionP
->X_add_number
= - TOLOWER (c
);
860 /* The string was only zero. */
861 expressionP
->X_op
= O_constant
;
862 expressionP
->X_add_number
= 0;
871 input_line_pointer
++;
872 integer_constant (16, expressionP
);
876 if (LOCAL_LABELS_FB
&& !flag_m68k_mri
877 && input_line_pointer
[1] != '0'
878 && input_line_pointer
[1] != '1')
880 /* Parse this as a back reference to label 0. */
881 input_line_pointer
--;
882 integer_constant (10, expressionP
);
885 /* Otherwise, parse this as a binary number. */
888 if (input_line_pointer
[1] == '0'
889 || input_line_pointer
[1] == '1')
891 input_line_pointer
++;
892 integer_constant (2, expressionP
);
895 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
896 input_line_pointer
++;
901 /* Accept an L suffix to the zero. */
902 if (tc_allow_L_suffix
)
908 /* Accept a U suffix to the zero. */
909 if (!tc_allow_U_suffix
)
921 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
931 /* If it says "0f" and it could possibly be a floating point
932 number, make it one. Otherwise, make it a local label,
933 and try to deal with parsing the rest later. */
934 if (!is_end_of_line
[(unsigned char) input_line_pointer
[1]]
935 && strchr (FLT_CHARS
, 'f') != NULL
)
937 char *cp
= input_line_pointer
+ 1;
939 atof_generic (&cp
, ".", EXP_CHARS
,
940 &generic_floating_point_number
);
942 /* Was nothing parsed, or does it look like an
944 is_label
= (cp
== input_line_pointer
+ 1
945 || (cp
== input_line_pointer
+ 2
946 && (cp
[-1] == '-' || cp
[-1] == '+'))
952 input_line_pointer
--;
953 integer_constant (10, expressionP
);
961 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
963 integer_constant (0, expressionP
);
973 input_line_pointer
++;
974 floating_constant (expressionP
);
975 expressionP
->X_add_number
= - TOLOWER (c
);
979 if (LOCAL_LABELS_DOLLAR
)
981 integer_constant (10, expressionP
);
990 #ifndef NEED_INDEX_OPERATOR
992 # ifdef md_need_index_operator
993 if (md_need_index_operator())
999 /* Didn't begin with digit & not a name. */
1000 segment
= expr (0, expressionP
, mode
);
1001 /* expression () will pass trailing whitespace. */
1002 if ((c
== '(' && *input_line_pointer
!= ')')
1003 || (c
== '[' && *input_line_pointer
!= ']'))
1005 if (* input_line_pointer
)
1006 as_bad (_("found '%c', expected: '%c'"),
1007 * input_line_pointer
, c
== '(' ? ')' : ']');
1009 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
1012 input_line_pointer
++;
1013 SKIP_ALL_WHITESPACE ();
1014 /* Here with input_line_pointer -> char after "(...)". */
1019 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
1021 as_bad (_("EBCDIC constants are not supported"));
1024 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
1026 ++input_line_pointer
;
1030 if (! flag_m68k_mri
)
1032 /* Warning: to conform to other people's assemblers NO
1033 ESCAPEMENT is permitted for a single quote. The next
1034 character, parity errors and all, is taken as the value
1035 of the operand. VERY KINKY. */
1036 expressionP
->X_op
= O_constant
;
1037 expressionP
->X_add_number
= *input_line_pointer
++;
1041 mri_char_constant (expressionP
);
1046 /* Double quote is the bitwise not operator in MRI mode. */
1047 if (! flag_m68k_mri
)
1052 /* '~' is permitted to start a label on the Delta. */
1053 if (is_name_beginner (c
))
1068 operand (expressionP
, mode
);
1070 #ifdef md_optimize_expr
1071 if (md_optimize_expr (NULL
, op
, expressionP
))
1078 if (expressionP
->X_op
== O_constant
)
1080 /* input_line_pointer -> char after operand. */
1083 expressionP
->X_add_number
1084 = - (addressT
) expressionP
->X_add_number
;
1085 /* Notice: '-' may overflow: no warning is given.
1086 This is compatible with other people's
1087 assemblers. Sigh. */
1088 expressionP
->X_unsigned
= 0;
1089 if (expressionP
->X_add_number
)
1090 expressionP
->X_extrabit
^= 1;
1092 else if (op
== O_bit_not
)
1094 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1095 expressionP
->X_extrabit
^= 1;
1096 expressionP
->X_unsigned
= 0;
1098 else if (op
== O_logical_not
)
1100 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1101 expressionP
->X_unsigned
= 1;
1102 expressionP
->X_extrabit
= 0;
1105 else if (expressionP
->X_op
== O_big
1106 && expressionP
->X_add_number
<= 0
1108 && (generic_floating_point_number
.sign
== '+'
1109 || generic_floating_point_number
.sign
== 'P'))
1111 /* Negative flonum (eg, -1.000e0). */
1112 if (generic_floating_point_number
.sign
== '+')
1113 generic_floating_point_number
.sign
= '-';
1115 generic_floating_point_number
.sign
= 'N';
1117 else if (expressionP
->X_op
== O_big
1118 && expressionP
->X_add_number
> 0)
1122 if (op
== O_uminus
|| op
== O_bit_not
)
1124 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1125 generic_bignum
[i
] = ~generic_bignum
[i
];
1127 /* Extend the bignum to at least the size of .octa. */
1128 if (expressionP
->X_add_number
< SIZE_OF_LARGE_NUMBER
)
1130 expressionP
->X_add_number
= SIZE_OF_LARGE_NUMBER
;
1131 for (; i
< expressionP
->X_add_number
; ++i
)
1132 generic_bignum
[i
] = ~(LITTLENUM_TYPE
) 0;
1136 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1138 generic_bignum
[i
] += 1;
1139 if (generic_bignum
[i
])
1143 else if (op
== O_logical_not
)
1145 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1146 if (generic_bignum
[i
] != 0)
1148 expressionP
->X_add_number
= i
>= expressionP
->X_add_number
;
1149 expressionP
->X_op
= O_constant
;
1150 expressionP
->X_unsigned
= 1;
1151 expressionP
->X_extrabit
= 0;
1154 else if (expressionP
->X_op
!= O_illegal
1155 && expressionP
->X_op
!= O_absent
)
1159 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1160 expressionP
->X_op
= op
;
1161 expressionP
->X_add_number
= 0;
1163 else if (!md_register_arithmetic
&& expressionP
->X_op
== O_register
)
1165 /* Convert to binary '+'. */
1166 expressionP
->X_op_symbol
= make_expr_symbol (expressionP
);
1167 expressionP
->X_add_symbol
= make_expr_symbol (&zero
);
1168 expressionP
->X_add_number
= 0;
1169 expressionP
->X_op
= O_add
;
1173 as_warn (_("Unary operator %c ignored because bad operand follows"),
1178 #if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1180 if (literal_prefix_dollar_hex
)
1182 /* $L is the start of a local label, not a hex constant. */
1183 if (* input_line_pointer
== 'L')
1185 integer_constant (16, expressionP
);
1194 /* '$' is the program counter when in MRI mode, or when
1195 DOLLAR_DOT is defined. */
1197 if (! flag_m68k_mri
)
1200 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1202 /* In MRI mode and on Z80, '$' is also used as the prefix
1203 for a hexadecimal constant. */
1204 integer_constant (16, expressionP
);
1208 if (is_part_of_name (*input_line_pointer
))
1211 current_location (expressionP
);
1216 if (!is_part_of_name (*input_line_pointer
))
1218 current_location (expressionP
);
1221 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1222 && ! is_part_of_name (input_line_pointer
[8]))
1223 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1224 && ! is_part_of_name (input_line_pointer
[7])))
1228 start
= (input_line_pointer
[1] == 't'
1229 || input_line_pointer
[1] == 'T');
1230 input_line_pointer
+= start
? 8 : 7;
1233 /* Cover for the as_bad () invocations below. */
1234 expressionP
->X_op
= O_absent
;
1236 if (*input_line_pointer
!= '(')
1237 as_bad (_("syntax error in .startof. or .sizeof."));
1240 ++input_line_pointer
;
1242 c
= get_symbol_name (& name
);
1245 as_bad (_("expected symbol name"));
1246 (void) restore_line_pointer (c
);
1248 ++input_line_pointer
;
1252 expressionP
->X_op
= O_symbol
;
1253 expressionP
->X_add_symbol
= symbol_lookup_or_make (name
, start
);
1254 expressionP
->X_add_number
= 0;
1256 restore_line_pointer (c
);
1258 if (*input_line_pointer
!= ')')
1259 as_bad (_("syntax error in .startof. or .sizeof."));
1261 ++input_line_pointer
;
1272 /* Can't imagine any other kind of operand. */
1273 expressionP
->X_op
= O_absent
;
1274 input_line_pointer
--;
1279 if (! flag_m68k_mri
)
1281 integer_constant (2, expressionP
);
1285 if (! flag_m68k_mri
)
1287 integer_constant (8, expressionP
);
1291 if (! flag_m68k_mri
)
1294 /* In MRI mode, this is a floating point constant represented
1295 using hexadecimal digits. */
1297 ++input_line_pointer
;
1298 integer_constant (16, expressionP
);
1302 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1305 current_location (expressionP
);
1310 #if defined(md_need_index_operator) || defined(TC_M68K)
1313 if (is_name_beginner (c
) || c
== '"') /* Here if did not begin with a digit. */
1315 /* Identifier begins here.
1316 This is kludged for speed, so code is repeated. */
1318 -- input_line_pointer
;
1319 c
= get_symbol_name (&name
);
1323 op
= md_operator (name
, 1, &c
);
1327 restore_line_pointer (c
);
1331 restore_line_pointer (c
);
1335 restore_line_pointer (c
);
1339 as_bad (_("invalid use of operator \"%s\""), name
);
1345 if (op
!= O_absent
&& op
!= O_illegal
)
1347 restore_line_pointer (c
);
1348 expr (9, expressionP
, mode
);
1349 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1350 expressionP
->X_op_symbol
= NULL
;
1351 expressionP
->X_add_number
= 0;
1352 expressionP
->X_op
= op
;
1358 #ifdef md_parse_name
1359 /* This is a hook for the backend to parse certain names
1360 specially in certain contexts. If a name always has a
1361 specific value, it can often be handled by simply
1362 entering it in the symbol table. */
1363 if (md_parse_name (name
, expressionP
, mode
, &c
))
1365 restore_line_pointer (c
);
1370 symbolP
= symbol_find_or_make (name
);
1372 /* If we have an absolute symbol or a reg, then we know its
1374 segment
= S_GET_SEGMENT (symbolP
);
1375 if (mode
!= expr_defer
1376 && segment
== absolute_section
1377 && !S_FORCE_RELOC (symbolP
, 0))
1379 expressionP
->X_op
= O_constant
;
1380 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1382 else if (mode
!= expr_defer
&& segment
== reg_section
)
1384 expressionP
->X_op
= O_register
;
1385 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1389 expressionP
->X_op
= O_symbol
;
1390 expressionP
->X_add_symbol
= symbolP
;
1391 expressionP
->X_add_number
= 0;
1394 restore_line_pointer (c
);
1398 /* Let the target try to parse it. Success is indicated by changing
1399 the X_op field to something other than O_absent and pointing
1400 input_line_pointer past the expression. If it can't parse the
1401 expression, X_op and input_line_pointer should be unchanged. */
1402 expressionP
->X_op
= O_absent
;
1403 --input_line_pointer
;
1404 md_operand (expressionP
);
1405 if (expressionP
->X_op
== O_absent
)
1407 ++input_line_pointer
;
1408 as_bad (_("bad expression"));
1409 expressionP
->X_op
= O_constant
;
1410 expressionP
->X_add_number
= 0;
1416 /* It is more 'efficient' to clean up the expressionS when they are
1417 created. Doing it here saves lines of code. */
1418 clean_up_expression (expressionP
);
1419 SKIP_ALL_WHITESPACE (); /* -> 1st char after operand. */
1420 know (*input_line_pointer
!= ' ');
1422 /* The PA port needs this information. */
1423 if (expressionP
->X_add_symbol
)
1424 symbol_mark_used (expressionP
->X_add_symbol
);
1426 if (mode
!= expr_defer
)
1428 expressionP
->X_add_symbol
1429 = symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1430 expressionP
->X_op_symbol
1431 = symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1434 switch (expressionP
->X_op
)
1437 return absolute_section
;
1439 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1445 /* Internal. Simplify a struct expression for use by expr (). */
1447 /* In: address of an expressionS.
1448 The X_op field of the expressionS may only take certain values.
1449 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1451 Out: expressionS may have been modified:
1452 Unused fields zeroed to help expr (). */
1455 clean_up_expression (expressionS
*expressionP
)
1457 switch (expressionP
->X_op
)
1461 expressionP
->X_add_number
= 0;
1466 expressionP
->X_add_symbol
= NULL
;
1471 expressionP
->X_op_symbol
= NULL
;
1478 /* Expression parser. */
1480 /* We allow an empty expression, and just assume (absolute,0) silently.
1481 Unary operators and parenthetical expressions are treated as operands.
1482 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1484 We used to do an aho/ullman shift-reduce parser, but the logic got so
1485 warped that I flushed it and wrote a recursive-descent parser instead.
1486 Now things are stable, would anybody like to write a fast parser?
1487 Most expressions are either register (which does not even reach here)
1488 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1489 So I guess it doesn't really matter how inefficient more complex expressions
1492 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1493 Also, we have consumed any leading or trailing spaces (operand does that)
1494 and done all intervening operators.
1496 This returns the segment of the result, which will be
1497 absolute_section or the segment of a symbol. */
1500 #define __ O_illegal
1502 #define O_SINGLE_EQ O_illegal
1505 /* Maps ASCII -> operators. */
1506 static const operatorT op_encoding
[256] = {
1507 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1508 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1510 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1511 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1512 __
, __
, __
, __
, __
, __
, __
, __
,
1513 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1514 __
, __
, __
, __
, __
, __
, __
, __
,
1515 __
, __
, __
, __
, __
, __
, __
, __
,
1516 __
, __
, __
, __
, __
, __
, __
, __
,
1518 #ifdef NEED_INDEX_OPERATOR
1523 __
, __
, O_bit_exclusive_or
, __
,
1524 __
, __
, __
, __
, __
, __
, __
, __
,
1525 __
, __
, __
, __
, __
, __
, __
, __
,
1526 __
, __
, __
, __
, __
, __
, __
, __
,
1527 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1529 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1530 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1531 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1532 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1533 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1534 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1535 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1536 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1540 0 operand, (expression)
1545 5 used for * / % in MRI mode
1550 static operator_rankT op_rank
[O_max
] = {
1555 0, /* O_symbol_rva */
1561 9, /* O_logical_not */
1565 8, /* O_left_shift */
1566 8, /* O_right_shift */
1567 7, /* O_bit_inclusive_or */
1568 7, /* O_bit_or_not */
1569 7, /* O_bit_exclusive_or */
1579 3, /* O_logical_and */
1580 2, /* O_logical_or */
1584 /* Unfortunately, in MRI mode for the m68k, multiplication and
1585 division have lower precedence than the bit wise operators. This
1586 function sets the operator precedences correctly for the current
1587 mode. Also, MRI uses a different bit_not operator, and this fixes
1590 #define STANDARD_MUL_PRECEDENCE 8
1591 #define MRI_MUL_PRECEDENCE 6
1594 expr_set_precedence (void)
1598 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1599 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1600 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1604 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1605 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1606 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1611 expr_set_rank (operatorT op
, operator_rankT rank
)
1613 gas_assert (op
>= O_md1
&& op
< ARRAY_SIZE (op_rank
));
1617 /* Initialize the expression parser. */
1622 expr_set_precedence ();
1624 /* Verify that X_op field is wide enough. */
1628 gas_assert (e
.X_op
== O_max
);
1631 memset (seen
, 0, sizeof seen
);
1632 memset (nr_seen
, 0, sizeof nr_seen
);
1633 expr_symbol_lines
= NULL
;
1639 for (size_t i
= 0; i
< ARRAY_SIZE (seen
); i
++)
1643 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1644 sets NUM_CHARS to the number of characters in the operator.
1645 Does not advance INPUT_LINE_POINTER. */
1647 static inline operatorT
1648 operatorf (int *num_chars
)
1653 c
= *input_line_pointer
& 0xff;
1656 if (is_end_of_line
[c
])
1660 if (is_name_beginner (c
))
1663 char ec
= get_symbol_name (& name
);
1665 ret
= md_operator (name
, 2, &ec
);
1669 *input_line_pointer
= ec
;
1670 input_line_pointer
= name
;
1675 as_bad (_("invalid use of operator \"%s\""), name
);
1679 *input_line_pointer
= ec
;
1680 *num_chars
= input_line_pointer
- name
;
1681 input_line_pointer
= name
;
1690 ret
= op_encoding
[c
];
1692 if (ret
== O_illegal
)
1694 char *start
= input_line_pointer
;
1696 ret
= md_operator (NULL
, 2, NULL
);
1697 if (ret
!= O_illegal
)
1698 *num_chars
= input_line_pointer
- start
;
1699 input_line_pointer
= start
;
1706 return op_encoding
[c
];
1709 switch (input_line_pointer
[1])
1712 return op_encoding
[c
];
1727 if (input_line_pointer
[1] != '=')
1728 return op_encoding
[c
];
1734 switch (input_line_pointer
[1])
1737 return op_encoding
[c
];
1739 ret
= O_right_shift
;
1749 switch (input_line_pointer
[1])
1752 /* We accept !! as equivalent to ^ for MRI compatibility. */
1754 return O_bit_exclusive_or
;
1756 /* We accept != as equivalent to <>. */
1761 return O_bit_inclusive_or
;
1762 return op_encoding
[c
];
1766 if (input_line_pointer
[1] != '|')
1767 return op_encoding
[c
];
1770 return O_logical_or
;
1773 if (input_line_pointer
[1] != '&')
1774 return op_encoding
[c
];
1777 return O_logical_and
;
1783 /* Implement "word-size + 1 bit" addition for
1784 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1785 is used so that the full range of unsigned word values and the full range of
1786 signed word values can be represented in an O_constant expression, which is
1787 useful e.g. for .sleb128 directives. */
1790 add_to_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1792 valueT ures
= resultP
->X_add_number
;
1793 valueT uamount
= amount
;
1795 resultP
->X_add_number
+= uamount
;
1797 resultP
->X_extrabit
^= rhs_highbit
;
1799 if (ures
+ uamount
< ures
)
1800 resultP
->X_extrabit
^= 1;
1803 /* Similarly, for subtraction. */
1806 subtract_from_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1808 valueT ures
= resultP
->X_add_number
;
1809 valueT uamount
= amount
;
1811 resultP
->X_add_number
-= uamount
;
1813 resultP
->X_extrabit
^= rhs_highbit
;
1816 resultP
->X_extrabit
^= 1;
1819 /* Parse an expression. */
1822 expr (int rankarg
, /* Larger # is higher rank. */
1823 expressionS
*resultP
, /* Deliver result here. */
1824 enum expr_mode mode
/* Controls behavior. */)
1826 operator_rankT rank
= (operator_rankT
) rankarg
;
1833 know (rankarg
>= 0);
1835 /* Save the value of dot for the fixup code. */
1838 dot_value
= frag_now_fix ();
1839 dot_frag
= frag_now
;
1842 retval
= operand (resultP
, mode
);
1844 /* operand () gobbles spaces. */
1845 know (*input_line_pointer
!= ' ');
1847 op_left
= operatorf (&op_chars
);
1848 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1854 input_line_pointer
+= op_chars
; /* -> after operator. */
1857 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1858 if (right
.X_op
== O_absent
)
1860 as_warn (_("missing operand; zero assumed"));
1861 right
.X_op
= O_constant
;
1862 right
.X_add_number
= 0;
1863 right
.X_add_symbol
= NULL
;
1864 right
.X_op_symbol
= NULL
;
1867 know (*input_line_pointer
!= ' ');
1869 if (op_left
== O_index
)
1871 if (*input_line_pointer
!= ']')
1872 as_bad ("missing right bracket");
1875 ++input_line_pointer
;
1880 op_right
= operatorf (&op_chars
);
1882 know (op_right
== O_illegal
|| op_left
== O_index
1883 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1884 know ((int) op_left
>= (int) O_multiply
);
1886 know ((int) op_left
<= (int) O_index
);
1888 know ((int) op_left
< (int) O_max
);
1891 /* input_line_pointer->after right-hand quantity. */
1892 /* left-hand quantity in resultP. */
1893 /* right-hand quantity in right. */
1894 /* operator in op_left. */
1896 if (resultP
->X_op
== O_big
)
1898 if (resultP
->X_add_number
> 0)
1899 as_warn (_("left operand is a bignum; integer 0 assumed"));
1901 as_warn (_("left operand is a float; integer 0 assumed"));
1902 resultP
->X_op
= O_constant
;
1903 resultP
->X_add_number
= 0;
1904 resultP
->X_add_symbol
= NULL
;
1905 resultP
->X_op_symbol
= NULL
;
1907 if (right
.X_op
== O_big
)
1909 if (right
.X_add_number
> 0)
1910 as_warn (_("right operand is a bignum; integer 0 assumed"));
1912 as_warn (_("right operand is a float; integer 0 assumed"));
1913 right
.X_op
= O_constant
;
1914 right
.X_add_number
= 0;
1915 right
.X_add_symbol
= NULL
;
1916 right
.X_op_symbol
= NULL
;
1919 is_unsigned
= resultP
->X_unsigned
&& right
.X_unsigned
;
1921 if (mode
== expr_defer
1922 && ((resultP
->X_add_symbol
!= NULL
1923 && S_IS_FORWARD_REF (resultP
->X_add_symbol
))
1924 || (right
.X_add_symbol
!= NULL
1925 && S_IS_FORWARD_REF (right
.X_add_symbol
))))
1928 /* Optimize common cases. */
1929 #ifdef md_optimize_expr
1930 if (md_optimize_expr (resultP
, op_left
, &right
))
1933 is_unsigned
= resultP
->X_unsigned
;
1937 if (op_left
== O_add
&& right
.X_op
== O_constant
1938 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1941 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1943 /* This case comes up in PIC code. */
1944 else if (op_left
== O_subtract
1945 && right
.X_op
== O_symbol
1946 && resultP
->X_op
== O_symbol
1947 && retval
== rightseg
1948 #ifdef md_allow_local_subtract
1949 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1951 && ((SEG_NORMAL (rightseg
)
1952 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1953 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1954 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1955 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1956 symbol_get_frag (right
.X_add_symbol
),
1959 offsetT symval_diff
= S_GET_VALUE (resultP
->X_add_symbol
)
1960 - S_GET_VALUE (right
.X_add_symbol
);
1961 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1962 subtract_from_result (resultP
, frag_off
/ OCTETS_PER_BYTE
, 0);
1963 add_to_result (resultP
, symval_diff
, symval_diff
< 0);
1964 resultP
->X_op
= O_constant
;
1965 resultP
->X_add_symbol
= 0;
1966 is_unsigned
= false;
1968 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1969 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1972 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1973 is_unsigned
= false;
1975 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1976 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1979 resultP
->X_op
= right
.X_op
;
1980 resultP
->X_add_symbol
= right
.X_add_symbol
;
1981 resultP
->X_op_symbol
= right
.X_op_symbol
;
1982 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1985 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1987 /* Constant OP constant. */
1988 offsetT v
= right
.X_add_number
;
1989 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1991 as_warn (_("division by zero"));
1996 default: goto general
;
1998 /* Do the multiply as unsigned to silence ubsan. The
1999 result is of course the same when we throw away high
2000 bits of the result. */
2001 resultP
->X_add_number
*= (valueT
) v
;
2003 case O_divide
: resultP
->X_add_number
/= v
; break;
2004 case O_modulus
: resultP
->X_add_number
%= v
; break;
2007 /* We always use unsigned shifts. According to the ISO
2008 C standard, left shift of a signed type having a
2009 negative value is undefined behaviour, and right
2010 shift of a signed type having negative value is
2011 implementation defined. Left shift of a signed type
2012 when the result overflows is also undefined
2013 behaviour. So don't trigger ubsan warnings or rely
2014 on characteristics of the compiler. */
2015 if ((valueT
) v
>= sizeof (valueT
) * CHAR_BIT
)
2017 as_warn_value_out_of_range (_("shift count"), v
, 0,
2018 sizeof (valueT
) * CHAR_BIT
- 1,
2020 resultP
->X_add_number
= 0;
2022 else if (op_left
== O_left_shift
)
2023 resultP
->X_add_number
2024 = (valueT
) resultP
->X_add_number
<< (valueT
) v
;
2026 resultP
->X_add_number
2027 = (valueT
) resultP
->X_add_number
>> (valueT
) v
;
2028 is_unsigned
= resultP
->X_unsigned
;
2030 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
2031 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
2032 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
2033 case O_bit_and
: resultP
->X_add_number
&= v
; break;
2034 /* Constant + constant (O_add) is handled by the
2035 previous if statement for constant + X, so is omitted
2038 subtract_from_result (resultP
, v
, 0);
2039 is_unsigned
= false;
2042 resultP
->X_add_number
=
2043 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
2044 is_unsigned
= false;
2047 resultP
->X_add_number
=
2048 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
2049 is_unsigned
= false;
2052 resultP
->X_add_number
=
2053 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
2054 is_unsigned
= false;
2057 resultP
->X_add_number
=
2058 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
2059 is_unsigned
= false;
2062 resultP
->X_add_number
=
2063 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
2064 is_unsigned
= false;
2067 resultP
->X_add_number
=
2068 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
2069 is_unsigned
= false;
2072 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
2076 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
2081 else if (resultP
->X_op
== O_symbol
2082 && right
.X_op
== O_symbol
2083 && (op_left
== O_add
2084 || op_left
== O_subtract
2085 || (resultP
->X_add_number
== 0
2086 && right
.X_add_number
== 0)))
2088 /* Symbol OP symbol. */
2089 resultP
->X_op
= op_left
;
2090 resultP
->X_op_symbol
= right
.X_add_symbol
;
2091 if (op_left
== O_add
)
2092 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
2093 else if (op_left
== O_subtract
)
2095 subtract_from_result (resultP
, right
.X_add_number
,
2097 if (retval
== rightseg
2098 && SEG_NORMAL (retval
)
2099 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
2100 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
2102 retval
= absolute_section
;
2103 rightseg
= absolute_section
;
2110 /* The general case. */
2111 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
2112 resultP
->X_op_symbol
= make_expr_symbol (&right
);
2113 resultP
->X_op
= op_left
;
2114 resultP
->X_add_number
= 0;
2115 resultP
->X_extrabit
= 0;
2118 resultP
->X_unsigned
= is_unsigned
;
2120 if (retval
!= rightseg
)
2122 if (retval
== undefined_section
)
2124 else if (rightseg
== undefined_section
)
2126 else if (retval
== expr_section
)
2128 else if (rightseg
== expr_section
)
2130 else if (retval
== reg_section
)
2132 else if (rightseg
== reg_section
)
2134 else if (rightseg
== absolute_section
)
2136 else if (retval
== absolute_section
)
2139 else if (op_left
== O_subtract
)
2143 as_bad (_("operation combines symbols in different segments"));
2147 } /* While next operator is >= this rank. */
2149 /* The PA port needs this information. */
2150 if (resultP
->X_add_symbol
)
2151 symbol_mark_used (resultP
->X_add_symbol
);
2153 if (rank
== 0 && mode
== expr_evaluate
)
2154 resolve_expression (resultP
);
2156 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
2159 /* Resolve an expression without changing any symbols/sub-expressions
2163 resolve_expression (expressionS
*expressionP
)
2165 /* Help out with CSE. */
2166 valueT final_val
= expressionP
->X_add_number
;
2167 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
2168 symbolS
*orig_add_symbol
= add_symbol
;
2169 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
2170 operatorT op
= expressionP
->X_op
;
2172 segT seg_left
, seg_right
;
2173 fragS
*frag_left
, *frag_right
;
2188 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2196 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2199 if (seg_left
!= absolute_section
)
2202 if (op
== O_logical_not
)
2204 else if (op
== O_uminus
)
2216 case O_bit_inclusive_or
:
2218 case O_bit_exclusive_or
:
2230 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
2231 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
2234 /* Simplify addition or subtraction of a constant by folding the
2235 constant into X_add_number. */
2238 if (seg_right
== absolute_section
)
2244 else if (seg_left
== absolute_section
)
2248 seg_left
= seg_right
;
2249 add_symbol
= op_symbol
;
2250 orig_add_symbol
= expressionP
->X_op_symbol
;
2255 else if (op
== O_subtract
)
2257 if (seg_right
== absolute_section
)
2265 /* Equality and non-equality tests are permitted on anything.
2266 Subtraction, and other comparison operators are permitted if
2267 both operands are in the same section.
2268 Shifts by constant zero are permitted on anything.
2269 Multiplies, bit-ors, and bit-ands with constant zero are
2270 permitted on anything.
2271 Multiplies and divides by constant one are permitted on
2273 Binary operations with both operands being the same register
2274 or undefined symbol are permitted if the result doesn't depend
2276 Otherwise, both operands must be absolute. We already handled
2277 the case of addition or subtraction of a constant above. */
2279 if (!(seg_left
== absolute_section
2280 && seg_right
== absolute_section
)
2281 && !(op
== O_eq
|| op
== O_ne
)
2282 && !((op
== O_subtract
2283 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2284 && seg_left
== seg_right
2286 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
)
2288 && frag_gtoffset_p (left
, frag_left
,
2289 right
, frag_right
, &frag_off
)))
2290 && (seg_left
!= reg_section
|| left
== right
)
2291 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2293 if ((seg_left
== absolute_section
&& left
== 0)
2294 || (seg_right
== absolute_section
&& right
== 0))
2296 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2298 if (!(seg_right
== absolute_section
&& right
== 0))
2300 seg_left
= seg_right
;
2302 add_symbol
= op_symbol
;
2303 orig_add_symbol
= expressionP
->X_op_symbol
;
2308 else if (op
== O_left_shift
|| op
== O_right_shift
)
2310 if (!(seg_left
== absolute_section
&& left
== 0))
2316 else if (op
!= O_multiply
2317 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2320 else if (op
== O_multiply
2321 && seg_left
== absolute_section
&& left
== 1)
2323 seg_left
= seg_right
;
2325 add_symbol
= op_symbol
;
2326 orig_add_symbol
= expressionP
->X_op_symbol
;
2330 else if ((op
== O_multiply
|| op
== O_divide
)
2331 && seg_right
== absolute_section
&& right
== 1)
2336 else if (!(left
== right
2337 && ((seg_left
== reg_section
&& seg_right
== reg_section
)
2338 || (seg_left
== undefined_section
2339 && seg_right
== undefined_section
2340 && add_symbol
== op_symbol
))))
2342 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2347 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2351 right
+= frag_off
/ OCTETS_PER_BYTE
;
2354 case O_add
: left
+= right
; break;
2355 case O_subtract
: left
-= right
; break;
2356 case O_multiply
: left
*= right
; break;
2360 left
= (offsetT
) left
/ (offsetT
) right
;
2365 left
= (offsetT
) left
% (offsetT
) right
;
2368 if (right
>= sizeof (left
) * CHAR_BIT
)
2374 if (right
>= sizeof (left
) * CHAR_BIT
)
2379 case O_bit_inclusive_or
: left
|= right
; break;
2380 case O_bit_or_not
: left
|= ~right
; break;
2381 case O_bit_exclusive_or
: left
^= right
; break;
2382 case O_bit_and
: left
&= right
; break;
2385 left
= (left
== right
2386 && seg_left
== seg_right
2387 && (finalize_syms
|| frag_left
== frag_right
)
2388 && (seg_left
!= undefined_section
2389 || add_symbol
== op_symbol
)
2390 ? ~ (valueT
) 0 : 0);
2395 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2398 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2401 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2404 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2406 case O_logical_and
: left
= left
&& right
; break;
2407 case O_logical_or
: left
= left
|| right
; break;
2417 if (seg_left
== absolute_section
)
2419 else if (seg_left
== reg_section
&& final_val
== 0)
2421 else if (!symbol_same_p (add_symbol
, orig_add_symbol
))
2423 expressionP
->X_add_symbol
= add_symbol
;
2425 expressionP
->X_op
= op
;
2427 if (op
== O_constant
|| op
== O_register
)
2429 expressionP
->X_add_number
= final_val
;
2434 /* "Look through" register equates. */
2435 void resolve_register (expressionS
*expP
)
2439 const expressionS
*e
= expP
;
2441 if (expP
->X_op
!= O_symbol
)
2446 sym
= e
->X_add_symbol
;
2447 acc
+= e
->X_add_number
;
2448 e
= symbol_get_value_expression (sym
);
2450 while (symbol_equated_p (sym
));
2452 if (e
->X_op
== O_register
)
2455 expP
->X_add_number
+= acc
;
2459 /* This lives here because it belongs equally in expr.c & read.c.
2460 expr.c is just a branch office read.c anyway, and putting it
2461 here lessens the crowd at read.c.
2463 Assume input_line_pointer is at start of symbol name, or the
2464 start of a double quote enclosed symbol name. Advance
2465 input_line_pointer past symbol name. Turn that character into a '\0',
2466 returning its former value, which may be the closing double quote.
2468 This allows a string compare (RMS wants symbol names to be strings)
2471 NOTE: The input buffer is further altered when adjacent strings are
2472 concatenated by the function. Callers caring about the original buffer
2473 contents will need to make a copy before calling here.
2475 There will always be a char following symbol name, because all good
2476 lines end in end-of-line. */
2479 get_symbol_name (char ** ilp_return
)
2483 * ilp_return
= input_line_pointer
;
2484 /* We accept FAKE_LABEL_CHAR in a name in case this is being called with a
2485 constructed string. */
2486 if (is_name_beginner (c
= *input_line_pointer
++)
2487 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
2489 while (is_part_of_name (c
= *input_line_pointer
++)
2490 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
2492 if (is_name_ender (c
))
2493 c
= *input_line_pointer
++;
2497 char *dst
= input_line_pointer
;
2499 * ilp_return
= input_line_pointer
;
2502 c
= *input_line_pointer
++;
2506 as_warn (_("missing closing '\"'"));
2512 char *ilp_save
= input_line_pointer
;
2515 if (*input_line_pointer
== '"')
2517 ++input_line_pointer
;
2520 input_line_pointer
= ilp_save
;
2525 switch (*input_line_pointer
)
2529 c
= *input_line_pointer
++;
2534 as_warn (_("'\\%c' in quoted symbol name; "
2535 "behavior may change in the future"),
2536 *input_line_pointer
);
2544 *--input_line_pointer
= 0;
2548 /* Replace the NUL character pointed to by input_line_pointer
2549 with C. If C is \" then advance past it. Return the character
2550 now pointed to by input_line_pointer. */
2553 restore_line_pointer (char c
)
2555 * input_line_pointer
= c
;
2557 c
= * ++ input_line_pointer
;
2562 get_single_number (void)
2565 operand (&exp
, expr_normal
);
2566 return exp
.X_add_number
;