1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2020 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"
38 bfd_boolean literal_prefix_dollar_hex
= FALSE
;
40 static void floating_constant (expressionS
* expressionP
);
41 static valueT
generic_bignum_to_int32 (void);
43 static valueT
generic_bignum_to_int64 (void);
45 static void integer_constant (int radix
, expressionS
* expressionP
);
46 static void mri_char_constant (expressionS
*);
47 static void clean_up_expression (expressionS
* expressionP
);
48 static segT
operand (expressionS
*, enum expr_mode
);
49 static operatorT
operatorf (int *);
51 /* We keep a mapping of expression symbols to file positions, so that
52 we can provide better error messages. */
54 struct expr_symbol_line
{
55 struct expr_symbol_line
*next
;
61 static struct expr_symbol_line
*expr_symbol_lines
;
63 /* Build a dummy symbol to hold a complex expression. This is how we
64 build expressions up out of other expressions. The symbol is put
65 into the fake section expr_section. */
68 make_expr_symbol (expressionS
*expressionP
)
72 struct expr_symbol_line
*n
;
74 if (expressionP
->X_op
== O_symbol
75 && expressionP
->X_add_number
== 0)
76 return expressionP
->X_add_symbol
;
78 if (expressionP
->X_op
== O_big
)
80 /* This won't work, because the actual value is stored in
81 generic_floating_point_number or generic_bignum, and we are
82 going to lose it if we haven't already. */
83 if (expressionP
->X_add_number
> 0)
84 as_bad (_("bignum invalid"));
86 as_bad (_("floating point number invalid"));
87 zero
.X_op
= O_constant
;
88 zero
.X_add_number
= 0;
91 clean_up_expression (&zero
);
95 /* Putting constant symbols in absolute_section rather than
96 expr_section is convenient for the old a.out code, for which
97 S_GET_SEGMENT does not always retrieve the value put in by
99 symbolP
= symbol_create (FAKE_LABEL_NAME
,
100 (expressionP
->X_op
== O_constant
102 : expressionP
->X_op
== O_register
105 0, &zero_address_frag
);
106 symbol_set_value_expression (symbolP
, expressionP
);
108 if (expressionP
->X_op
== O_constant
)
109 resolve_symbol_value (symbolP
);
111 n
= XNEW (struct expr_symbol_line
);
113 n
->file
= as_where (&n
->line
);
114 n
->next
= expr_symbol_lines
;
115 expr_symbol_lines
= n
;
120 /* Return the file and line number for an expr symbol. Return
121 non-zero if something was found, 0 if no information is known for
125 expr_symbol_where (symbolS
*sym
, const char **pfile
, unsigned int *pline
)
127 struct expr_symbol_line
*l
;
129 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
142 /* Utilities for building expressions.
143 Since complex expressions are recorded as symbols for use in other
144 expressions these return a symbolS * and not an expressionS *.
145 These explicitly do not take an "add_number" argument. */
146 /* ??? For completeness' sake one might want expr_build_symbol.
147 It would just return its argument. */
149 /* Build an expression for an unsigned constant.
150 The corresponding one for signed constants is missing because
151 there's currently no need for it. One could add an unsigned_p flag
152 but that seems more clumsy. */
155 expr_build_uconstant (offsetT value
)
160 e
.X_add_number
= value
;
163 return make_expr_symbol (&e
);
166 /* Build an expression for the current location ('.'). */
169 expr_build_dot (void)
173 current_location (&e
);
174 return symbol_clone_if_forward_ref (make_expr_symbol (&e
));
177 /* Build any floating-point literal here.
178 Also build any bignum literal here. */
180 /* Seems atof_machine can backscan through generic_bignum and hit whatever
181 happens to be loaded before it in memory. And its way too complicated
182 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
183 and never write into the early words, thus they'll always be zero.
184 I hate Dean's floating-point code. Bleh. */
185 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
187 FLONUM_TYPE generic_floating_point_number
= {
188 &generic_bignum
[6], /* low. (JF: Was 0) */
189 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
197 floating_constant (expressionS
*expressionP
)
199 /* input_line_pointer -> floating-point constant. */
202 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
203 &generic_floating_point_number
);
207 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
209 as_bad (_("bad floating-point constant: exponent overflow"));
213 as_bad (_("bad floating-point constant: unknown error code=%d"),
217 expressionP
->X_op
= O_big
;
218 /* input_line_pointer -> just after constant, which may point to
220 expressionP
->X_add_number
= -1;
224 generic_bignum_to_int32 (void)
227 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
228 | (generic_bignum
[0] & LITTLENUM_MASK
);
229 number
&= 0xffffffff;
235 generic_bignum_to_int64 (void)
238 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
239 << LITTLENUM_NUMBER_OF_BITS
)
240 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
241 << LITTLENUM_NUMBER_OF_BITS
)
242 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
243 << LITTLENUM_NUMBER_OF_BITS
)
244 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
250 integer_constant (int radix
, expressionS
*expressionP
)
252 char *start
; /* Start of number. */
255 valueT number
; /* Offset or (absolute) value. */
256 short int digit
; /* Value of next digit in current radix. */
257 short int maxdig
= 0; /* Highest permitted digit value. */
258 int too_many_digits
= 0; /* If we see >= this number of. */
259 char *name
; /* Points to name of symbol. */
260 symbolS
*symbolP
; /* Points to symbol. */
262 int small
; /* True if fits in 32 bits. */
264 /* May be bignum, or may fit in 32 bits. */
265 /* Most numbers fit into 32 bits, and we want this case to be fast.
266 so we pretend it will fit into 32 bits. If, after making up a 32
267 bit number, we realise that we have scanned more digits than
268 comfortably fit into 32 bits, we re-scan the digits coding them
269 into a bignum. For decimal and octal numbers we are
270 conservative: Some numbers may be assumed bignums when in fact
271 they do fit into 32 bits. Numbers of any radix can have excess
272 leading zeros: We strive to recognise this and cast them back
273 into 32 bits. We must check that the bignum really is more than
274 32 bits, and change it back to a 32-bit number if it fits. The
275 number we are looking for is expected to be positive, but if it
276 fits into 32 bits as an unsigned number, we let it be a 32-bit
277 number. The cavalier approach is for speed in ordinary cases. */
278 /* This has been extended for 64 bits. We blindly assume that if
279 you're compiling in 64-bit mode, the target is a 64-bit machine.
280 This should be cleaned up. */
284 #else /* includes non-bfd case, mostly */
288 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
290 expressionP
->X_op
= O_absent
;
294 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
298 /* In MRI mode, the number may have a suffix indicating the
299 radix. For that matter, it might actually be a floating
301 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
303 if (*suffix
== 'e' || *suffix
== 'E')
307 if (suffix
== input_line_pointer
)
316 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
317 we distinguish between 'B' and 'b'. This is the case for
319 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
323 else if (c
== 'O' || c
== 'Q')
327 else if (suffix
[1] == '.' || c
== 'E' || flt
)
329 floating_constant (expressionP
);
344 too_many_digits
= valuesize
+ 1;
348 too_many_digits
= (valuesize
+ 2) / 3 + 1;
352 too_many_digits
= (valuesize
+ 3) / 4 + 1;
356 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
359 start
= input_line_pointer
;
360 c
= *input_line_pointer
++;
362 (digit
= hex_value (c
)) < maxdig
;
363 c
= *input_line_pointer
++)
365 number
= number
* radix
+ digit
;
367 /* c contains character after number. */
368 /* input_line_pointer->char after c. */
369 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
371 if (radix
== 16 && c
== '_')
373 /* This is literal of the form 0x333_0_12345678_1.
374 This example is equivalent to 0x00000333000000001234567800000001. */
376 int num_little_digits
= 0;
378 input_line_pointer
= start
; /* -> 1st digit. */
380 know (LITTLENUM_NUMBER_OF_BITS
== 16);
382 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
385 /* Convert one 64-bit word. */
388 for (c
= *input_line_pointer
++;
389 (digit
= hex_value (c
)) < maxdig
;
390 c
= *(input_line_pointer
++))
392 number
= number
* radix
+ digit
;
396 /* Check for 8 digit per word max. */
398 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
400 /* Add this chunk to the bignum.
401 Shift things down 2 little digits. */
402 know (LITTLENUM_NUMBER_OF_BITS
== 16);
403 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
406 generic_bignum
[i
] = generic_bignum
[i
- 2];
408 /* Add the new digits as the least significant new ones. */
409 generic_bignum
[0] = number
& 0xffffffff;
410 generic_bignum
[1] = number
>> 16;
413 /* Again, c is char after number, input_line_pointer->after c. */
415 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
416 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
418 gas_assert (num_little_digits
>= 4);
420 if (num_little_digits
!= 8)
421 as_bad (_("a bignum with underscores must have exactly 4 words"));
423 /* We might have some leading zeros. These can be trimmed to give
424 us a change to fit this constant into a small number. */
425 while (generic_bignum
[num_little_digits
- 1] == 0
426 && num_little_digits
> 1)
429 if (num_little_digits
<= 2)
431 /* will fit into 32 bits. */
432 number
= generic_bignum_to_int32 ();
436 else if (num_little_digits
<= 4)
438 /* Will fit into 64 bits. */
439 number
= generic_bignum_to_int64 ();
447 /* Number of littlenums in the bignum. */
448 number
= num_little_digits
;
453 /* We saw a lot of digits. manufacture a bignum the hard way. */
454 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
455 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
458 leader
= generic_bignum
;
459 generic_bignum
[0] = 0;
460 generic_bignum
[1] = 0;
461 generic_bignum
[2] = 0;
462 generic_bignum
[3] = 0;
463 input_line_pointer
= start
; /* -> 1st digit. */
464 c
= *input_line_pointer
++;
465 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
467 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
471 work
= carry
+ radix
* *pointer
;
472 *pointer
= work
& LITTLENUM_MASK
;
473 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
477 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
479 /* Room to grow a longer bignum. */
484 /* Again, c is char after number. */
485 /* input_line_pointer -> after c. */
486 know (LITTLENUM_NUMBER_OF_BITS
== 16);
487 if (leader
< generic_bignum
+ 2)
489 /* Will fit into 32 bits. */
490 number
= generic_bignum_to_int32 ();
494 else if (leader
< generic_bignum
+ 4)
496 /* Will fit into 64 bits. */
497 number
= generic_bignum_to_int64 ();
503 /* Number of littlenums in the bignum. */
504 number
= leader
- generic_bignum
+ 1;
508 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
510 && input_line_pointer
- 1 == suffix
)
511 c
= *input_line_pointer
++;
513 #ifndef tc_allow_U_suffix
514 #define tc_allow_U_suffix 1
516 /* PR 19910: Look for, and ignore, a U suffix to the number. */
517 if (tc_allow_U_suffix
&& (c
== 'U' || c
== 'u'))
518 c
= * input_line_pointer
++;
520 #ifndef tc_allow_L_suffix
521 #define tc_allow_L_suffix 1
523 /* PR 20732: Look for, and ignore, a L or LL suffix to the number. */
524 if (tc_allow_L_suffix
)
525 while (c
== 'L' || c
== 'l')
526 c
= * input_line_pointer
++;
530 /* Here with number, in correct radix. c is the next char.
531 Note that unlike un*x, we allow "011f" "0x9f" to both mean
532 the same as the (conventional) "9f".
533 This is simply easier than checking for strict canonical
536 if (LOCAL_LABELS_FB
&& c
== 'b')
538 /* Backward ref to local label.
539 Because it is backward, expect it to be defined. */
540 /* Construct a local label. */
541 name
= fb_label_name ((int) number
, 0);
543 /* Seen before, or symbol is defined: OK. */
544 symbolP
= symbol_find (name
);
545 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
547 /* Local labels are never absolute. Don't waste time
548 checking absoluteness. */
549 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
551 expressionP
->X_op
= O_symbol
;
552 expressionP
->X_add_symbol
= symbolP
;
556 /* Either not seen or not defined. */
557 /* @@ Should print out the original string instead of
558 the parsed number. */
559 as_bad (_("backward ref to unknown label \"%d:\""),
561 expressionP
->X_op
= O_constant
;
564 expressionP
->X_add_number
= 0;
566 else if (LOCAL_LABELS_FB
&& c
== 'f')
568 /* Forward reference. Expect symbol to be undefined or
569 unknown. undefined: seen it before. unknown: never seen
572 Construct a local label name, then an undefined symbol.
573 Don't create a xseg frag for it: caller may do that.
574 Just return it as never seen before. */
575 name
= fb_label_name ((int) number
, 1);
576 symbolP
= symbol_find_or_make (name
);
577 /* We have no need to check symbol properties. */
578 #ifndef many_segments
579 /* Since "know" puts its arg into a "string", we
580 can't have newlines in the argument. */
581 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
583 expressionP
->X_op
= O_symbol
;
584 expressionP
->X_add_symbol
= symbolP
;
585 expressionP
->X_add_number
= 0;
587 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
589 /* If the dollar label is *currently* defined, then this is just
590 another reference to it. If it is not *currently* defined,
591 then this is a fresh instantiation of that number, so create
594 if (dollar_label_defined ((long) number
))
596 name
= dollar_label_name ((long) number
, 0);
597 symbolP
= symbol_find (name
);
598 know (symbolP
!= NULL
);
602 name
= dollar_label_name ((long) number
, 1);
603 symbolP
= symbol_find_or_make (name
);
606 expressionP
->X_op
= O_symbol
;
607 expressionP
->X_add_symbol
= symbolP
;
608 expressionP
->X_add_number
= 0;
612 expressionP
->X_op
= O_constant
;
613 expressionP
->X_add_number
= number
;
614 input_line_pointer
--; /* Restore following character. */
615 } /* Really just a number. */
619 /* Not a small number. */
620 expressionP
->X_op
= O_big
;
621 expressionP
->X_add_number
= number
; /* Number of littlenums. */
622 input_line_pointer
--; /* -> char following number. */
626 /* Parse an MRI multi character constant. */
629 mri_char_constant (expressionS
*expressionP
)
633 if (*input_line_pointer
== '\''
634 && input_line_pointer
[1] != '\'')
636 expressionP
->X_op
= O_constant
;
637 expressionP
->X_add_number
= 0;
641 /* In order to get the correct byte ordering, we must build the
642 number in reverse. */
643 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
647 generic_bignum
[i
] = 0;
648 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
650 if (*input_line_pointer
== '\'')
652 if (input_line_pointer
[1] != '\'')
654 ++input_line_pointer
;
656 generic_bignum
[i
] <<= 8;
657 generic_bignum
[i
] += *input_line_pointer
;
658 ++input_line_pointer
;
661 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
663 /* If there is more than one littlenum, left justify the
664 last one to make it match the earlier ones. If there is
665 only one, we can just use the value directly. */
666 for (; j
< CHARS_PER_LITTLENUM
; j
++)
667 generic_bignum
[i
] <<= 8;
670 if (*input_line_pointer
== '\''
671 && input_line_pointer
[1] != '\'')
677 as_bad (_("character constant too large"));
686 c
= SIZE_OF_LARGE_NUMBER
- i
;
687 for (j
= 0; j
< c
; j
++)
688 generic_bignum
[j
] = generic_bignum
[i
+ j
];
692 know (LITTLENUM_NUMBER_OF_BITS
== 16);
695 expressionP
->X_op
= O_big
;
696 expressionP
->X_add_number
= i
;
700 expressionP
->X_op
= O_constant
;
702 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
704 expressionP
->X_add_number
=
705 (((generic_bignum
[1] & LITTLENUM_MASK
)
706 << LITTLENUM_NUMBER_OF_BITS
)
707 | (generic_bignum
[0] & LITTLENUM_MASK
));
710 /* Skip the final closing quote. */
711 ++input_line_pointer
;
714 /* Return an expression representing the current location. This
715 handles the magic symbol `.'. */
718 current_location (expressionS
*expressionp
)
720 if (now_seg
== absolute_section
)
722 expressionp
->X_op
= O_constant
;
723 expressionp
->X_add_number
= abs_section_offset
;
727 expressionp
->X_op
= O_symbol
;
728 expressionp
->X_add_symbol
= &dot_symbol
;
729 expressionp
->X_add_number
= 0;
733 /* In: Input_line_pointer points to 1st char of operand, which may
737 The operand may have been empty: in this case X_op == O_absent.
738 Input_line_pointer->(next non-blank) char after operand. */
741 operand (expressionS
*expressionP
, enum expr_mode mode
)
744 symbolS
*symbolP
; /* Points to symbol. */
745 char *name
; /* Points to name of symbol. */
748 /* All integers are regarded as unsigned unless they are negated.
749 This is because the only thing which cares whether a number is
750 unsigned is the code in emit_expr which extends constants into
751 bignums. It should only sign extend negative numbers, so that
752 something like ``.quad 0x80000000'' is not sign extended even
753 though it appears negative if valueT is 32 bits. */
754 expressionP
->X_unsigned
= 1;
755 expressionP
->X_extrabit
= 0;
757 /* Digits, assume it is a bignum. */
759 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
760 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
762 if (is_end_of_line
[(unsigned char) c
])
776 input_line_pointer
--;
778 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
783 #ifdef LITERAL_PREFIXPERCENT_BIN
785 integer_constant (2, expressionP
);
790 /* Non-decimal radix. */
792 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
796 /* Check for a hex or float constant. */
797 for (s
= input_line_pointer
; hex_p (*s
); s
++)
799 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
801 --input_line_pointer
;
802 integer_constant (0, expressionP
);
806 c
= *input_line_pointer
;
815 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
817 integer_constant (0, expressionP
);
823 if (c
&& strchr (FLT_CHARS
, c
))
825 input_line_pointer
++;
826 floating_constant (expressionP
);
827 expressionP
->X_add_number
= - TOLOWER (c
);
831 /* The string was only zero. */
832 expressionP
->X_op
= O_constant
;
833 expressionP
->X_add_number
= 0;
842 input_line_pointer
++;
843 integer_constant (16, expressionP
);
847 if (LOCAL_LABELS_FB
&& !flag_m68k_mri
848 && input_line_pointer
[1] != '0'
849 && input_line_pointer
[1] != '1')
851 /* Parse this as a back reference to label 0. */
852 input_line_pointer
--;
853 integer_constant (10, expressionP
);
856 /* Otherwise, parse this as a binary number. */
859 if (input_line_pointer
[1] == '0'
860 || input_line_pointer
[1] == '1')
862 input_line_pointer
++;
863 integer_constant (2, expressionP
);
866 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
867 input_line_pointer
++;
878 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
888 /* If it says "0f" and it could possibly be a floating point
889 number, make it one. Otherwise, make it a local label,
890 and try to deal with parsing the rest later. */
891 if (!is_end_of_line
[(unsigned char) input_line_pointer
[1]]
892 && strchr (FLT_CHARS
, 'f') != NULL
)
894 char *cp
= input_line_pointer
+ 1;
896 atof_generic (&cp
, ".", EXP_CHARS
,
897 &generic_floating_point_number
);
899 /* Was nothing parsed, or does it look like an
901 is_label
= (cp
== input_line_pointer
+ 1
902 || (cp
== input_line_pointer
+ 2
903 && (cp
[-1] == '-' || cp
[-1] == '+'))
909 input_line_pointer
--;
910 integer_constant (10, expressionP
);
918 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
920 integer_constant (0, expressionP
);
930 input_line_pointer
++;
931 floating_constant (expressionP
);
932 expressionP
->X_add_number
= - TOLOWER (c
);
936 if (LOCAL_LABELS_DOLLAR
)
938 integer_constant (10, expressionP
);
947 #ifndef NEED_INDEX_OPERATOR
949 # ifdef md_need_index_operator
950 if (md_need_index_operator())
956 /* Didn't begin with digit & not a name. */
957 segment
= expr (0, expressionP
, mode
);
958 /* expression () will pass trailing whitespace. */
959 if ((c
== '(' && *input_line_pointer
!= ')')
960 || (c
== '[' && *input_line_pointer
!= ']'))
962 if (* input_line_pointer
)
963 as_bad (_("found '%c', expected: '%c'"),
964 * input_line_pointer
, c
== '(' ? ')' : ']');
966 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
969 input_line_pointer
++;
971 /* Here with input_line_pointer -> char after "(...)". */
976 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
978 as_bad (_("EBCDIC constants are not supported"));
981 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
983 ++input_line_pointer
;
989 /* Warning: to conform to other people's assemblers NO
990 ESCAPEMENT is permitted for a single quote. The next
991 character, parity errors and all, is taken as the value
992 of the operand. VERY KINKY. */
993 expressionP
->X_op
= O_constant
;
994 expressionP
->X_add_number
= *input_line_pointer
++;
998 mri_char_constant (expressionP
);
1003 /* Double quote is the bitwise not operator in MRI mode. */
1004 if (! flag_m68k_mri
)
1009 /* '~' is permitted to start a label on the Delta. */
1010 if (is_name_beginner (c
))
1020 operand (expressionP
, mode
);
1021 if (expressionP
->X_op
== O_constant
)
1023 /* input_line_pointer -> char after operand. */
1026 expressionP
->X_add_number
1027 = - (addressT
) expressionP
->X_add_number
;
1028 /* Notice: '-' may overflow: no warning is given.
1029 This is compatible with other people's
1030 assemblers. Sigh. */
1031 expressionP
->X_unsigned
= 0;
1032 if (expressionP
->X_add_number
)
1033 expressionP
->X_extrabit
^= 1;
1035 else if (c
== '~' || c
== '"')
1036 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1038 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1040 else if (expressionP
->X_op
== O_big
1041 && expressionP
->X_add_number
<= 0
1043 && (generic_floating_point_number
.sign
== '+'
1044 || generic_floating_point_number
.sign
== 'P'))
1046 /* Negative flonum (eg, -1.000e0). */
1047 if (generic_floating_point_number
.sign
== '+')
1048 generic_floating_point_number
.sign
= '-';
1050 generic_floating_point_number
.sign
= 'N';
1052 else if (expressionP
->X_op
== O_big
1053 && expressionP
->X_add_number
> 0)
1057 if (c
== '~' || c
== '-')
1059 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1060 generic_bignum
[i
] = ~generic_bignum
[i
];
1062 /* Extend the bignum to at least the size of .octa. */
1063 if (expressionP
->X_add_number
< SIZE_OF_LARGE_NUMBER
)
1065 expressionP
->X_add_number
= SIZE_OF_LARGE_NUMBER
;
1066 for (; i
< expressionP
->X_add_number
; ++i
)
1067 generic_bignum
[i
] = ~(LITTLENUM_TYPE
) 0;
1071 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1073 generic_bignum
[i
] += 1;
1074 if (generic_bignum
[i
])
1080 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1081 if (generic_bignum
[i
] != 0)
1083 expressionP
->X_add_number
= i
>= expressionP
->X_add_number
;
1084 expressionP
->X_op
= O_constant
;
1085 expressionP
->X_unsigned
= 1;
1086 expressionP
->X_extrabit
= 0;
1089 else if (expressionP
->X_op
!= O_illegal
1090 && expressionP
->X_op
!= O_absent
)
1094 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1096 expressionP
->X_op
= O_uminus
;
1097 else if (c
== '~' || c
== '"')
1098 expressionP
->X_op
= O_bit_not
;
1100 expressionP
->X_op
= O_logical_not
;
1101 expressionP
->X_add_number
= 0;
1105 as_warn (_("Unary operator %c ignored because bad operand follows"),
1110 #if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1112 if (literal_prefix_dollar_hex
)
1114 /* $L is the start of a local label, not a hex constant. */
1115 if (* input_line_pointer
== 'L')
1117 integer_constant (16, expressionP
);
1126 /* '$' is the program counter when in MRI mode, or when
1127 DOLLAR_DOT is defined. */
1129 if (! flag_m68k_mri
)
1132 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1134 /* In MRI mode and on Z80, '$' is also used as the prefix
1135 for a hexadecimal constant. */
1136 integer_constant (16, expressionP
);
1140 if (is_part_of_name (*input_line_pointer
))
1143 current_location (expressionP
);
1148 if (!is_part_of_name (*input_line_pointer
))
1150 current_location (expressionP
);
1153 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1154 && ! is_part_of_name (input_line_pointer
[8]))
1155 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1156 && ! is_part_of_name (input_line_pointer
[7])))
1160 start
= (input_line_pointer
[1] == 't'
1161 || input_line_pointer
[1] == 'T');
1162 input_line_pointer
+= start
? 8 : 7;
1165 /* Cover for the as_bad () invocations below. */
1166 expressionP
->X_op
= O_absent
;
1168 if (*input_line_pointer
!= '(')
1169 as_bad (_("syntax error in .startof. or .sizeof."));
1174 ++input_line_pointer
;
1176 c
= get_symbol_name (& name
);
1179 as_bad (_("expected symbol name"));
1180 (void) restore_line_pointer (c
);
1182 ignore_rest_of_line ();
1184 ++input_line_pointer
;
1188 buf
= concat (start
? ".startof." : ".sizeof.", name
,
1190 symbolP
= symbol_make (buf
);
1193 expressionP
->X_op
= O_symbol
;
1194 expressionP
->X_add_symbol
= symbolP
;
1195 expressionP
->X_add_number
= 0;
1197 *input_line_pointer
= c
;
1198 SKIP_WHITESPACE_AFTER_NAME ();
1199 if (*input_line_pointer
!= ')')
1200 as_bad (_("syntax error in .startof. or .sizeof."));
1202 ++input_line_pointer
;
1213 /* Can't imagine any other kind of operand. */
1214 expressionP
->X_op
= O_absent
;
1215 input_line_pointer
--;
1220 if (! flag_m68k_mri
)
1222 integer_constant (2, expressionP
);
1226 if (! flag_m68k_mri
)
1228 integer_constant (8, expressionP
);
1232 if (! flag_m68k_mri
)
1235 /* In MRI mode, this is a floating point constant represented
1236 using hexadecimal digits. */
1238 ++input_line_pointer
;
1239 integer_constant (16, expressionP
);
1243 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1246 current_location (expressionP
);
1251 #if defined(md_need_index_operator) || defined(TC_M68K)
1254 if (is_name_beginner (c
) || c
== '"') /* Here if did not begin with a digit. */
1256 /* Identifier begins here.
1257 This is kludged for speed, so code is repeated. */
1259 -- input_line_pointer
;
1260 c
= get_symbol_name (&name
);
1264 operatorT op
= md_operator (name
, 1, &c
);
1269 restore_line_pointer (c
);
1273 restore_line_pointer (c
);
1277 restore_line_pointer (c
);
1281 as_bad (_("invalid use of operator \"%s\""), name
);
1287 if (op
!= O_absent
&& op
!= O_illegal
)
1289 restore_line_pointer (c
);
1290 expr (9, expressionP
, mode
);
1291 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1292 expressionP
->X_op_symbol
= NULL
;
1293 expressionP
->X_add_number
= 0;
1294 expressionP
->X_op
= op
;
1300 #ifdef md_parse_name
1301 /* This is a hook for the backend to parse certain names
1302 specially in certain contexts. If a name always has a
1303 specific value, it can often be handled by simply
1304 entering it in the symbol table. */
1305 if (md_parse_name (name
, expressionP
, mode
, &c
))
1307 restore_line_pointer (c
);
1312 symbolP
= symbol_find_or_make (name
);
1314 /* If we have an absolute symbol or a reg, then we know its
1316 segment
= S_GET_SEGMENT (symbolP
);
1317 if (mode
!= expr_defer
1318 && segment
== absolute_section
1319 && !S_FORCE_RELOC (symbolP
, 0))
1321 expressionP
->X_op
= O_constant
;
1322 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1324 else if (mode
!= expr_defer
&& segment
== reg_section
)
1326 expressionP
->X_op
= O_register
;
1327 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1331 expressionP
->X_op
= O_symbol
;
1332 expressionP
->X_add_symbol
= symbolP
;
1333 expressionP
->X_add_number
= 0;
1336 restore_line_pointer (c
);
1340 /* Let the target try to parse it. Success is indicated by changing
1341 the X_op field to something other than O_absent and pointing
1342 input_line_pointer past the expression. If it can't parse the
1343 expression, X_op and input_line_pointer should be unchanged. */
1344 expressionP
->X_op
= O_absent
;
1345 --input_line_pointer
;
1346 md_operand (expressionP
);
1347 if (expressionP
->X_op
== O_absent
)
1349 ++input_line_pointer
;
1350 as_bad (_("bad expression"));
1351 expressionP
->X_op
= O_constant
;
1352 expressionP
->X_add_number
= 0;
1358 /* It is more 'efficient' to clean up the expressionS when they are
1359 created. Doing it here saves lines of code. */
1360 clean_up_expression (expressionP
);
1361 SKIP_ALL_WHITESPACE (); /* -> 1st char after operand. */
1362 know (*input_line_pointer
!= ' ');
1364 /* The PA port needs this information. */
1365 if (expressionP
->X_add_symbol
)
1366 symbol_mark_used (expressionP
->X_add_symbol
);
1368 if (mode
!= expr_defer
)
1370 expressionP
->X_add_symbol
1371 = symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1372 expressionP
->X_op_symbol
1373 = symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1376 switch (expressionP
->X_op
)
1379 return absolute_section
;
1381 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1387 /* Internal. Simplify a struct expression for use by expr (). */
1389 /* In: address of an expressionS.
1390 The X_op field of the expressionS may only take certain values.
1391 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1393 Out: expressionS may have been modified:
1394 Unused fields zeroed to help expr (). */
1397 clean_up_expression (expressionS
*expressionP
)
1399 switch (expressionP
->X_op
)
1403 expressionP
->X_add_number
= 0;
1408 expressionP
->X_add_symbol
= NULL
;
1413 expressionP
->X_op_symbol
= NULL
;
1420 /* Expression parser. */
1422 /* We allow an empty expression, and just assume (absolute,0) silently.
1423 Unary operators and parenthetical expressions are treated as operands.
1424 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1426 We used to do an aho/ullman shift-reduce parser, but the logic got so
1427 warped that I flushed it and wrote a recursive-descent parser instead.
1428 Now things are stable, would anybody like to write a fast parser?
1429 Most expressions are either register (which does not even reach here)
1430 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1431 So I guess it doesn't really matter how inefficient more complex expressions
1434 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1435 Also, we have consumed any leading or trailing spaces (operand does that)
1436 and done all intervening operators.
1438 This returns the segment of the result, which will be
1439 absolute_section or the segment of a symbol. */
1442 #define __ O_illegal
1444 #define O_SINGLE_EQ O_illegal
1447 /* Maps ASCII -> operators. */
1448 static const operatorT op_encoding
[256] = {
1449 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1450 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1452 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1453 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1454 __
, __
, __
, __
, __
, __
, __
, __
,
1455 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1456 __
, __
, __
, __
, __
, __
, __
, __
,
1457 __
, __
, __
, __
, __
, __
, __
, __
,
1458 __
, __
, __
, __
, __
, __
, __
, __
,
1460 #ifdef NEED_INDEX_OPERATOR
1465 __
, __
, O_bit_exclusive_or
, __
,
1466 __
, __
, __
, __
, __
, __
, __
, __
,
1467 __
, __
, __
, __
, __
, __
, __
, __
,
1468 __
, __
, __
, __
, __
, __
, __
, __
,
1469 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1471 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1472 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1473 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1474 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1475 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1476 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1477 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1478 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1482 0 operand, (expression)
1487 5 used for * / % in MRI mode
1492 static operator_rankT op_rank
[O_max
] = {
1497 0, /* O_symbol_rva */
1502 9, /* O_logical_not */
1506 8, /* O_left_shift */
1507 8, /* O_right_shift */
1508 7, /* O_bit_inclusive_or */
1509 7, /* O_bit_or_not */
1510 7, /* O_bit_exclusive_or */
1520 3, /* O_logical_and */
1521 2, /* O_logical_or */
1525 /* Unfortunately, in MRI mode for the m68k, multiplication and
1526 division have lower precedence than the bit wise operators. This
1527 function sets the operator precedences correctly for the current
1528 mode. Also, MRI uses a different bit_not operator, and this fixes
1531 #define STANDARD_MUL_PRECEDENCE 8
1532 #define MRI_MUL_PRECEDENCE 6
1535 expr_set_precedence (void)
1539 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1540 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1541 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1545 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1546 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1547 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1552 expr_set_rank (operatorT op
, operator_rankT rank
)
1554 gas_assert (op
>= O_md1
&& op
< ARRAY_SIZE (op_rank
));
1558 /* Initialize the expression parser. */
1563 expr_set_precedence ();
1565 /* Verify that X_op field is wide enough. */
1569 gas_assert (e
.X_op
== O_max
);
1573 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1574 sets NUM_CHARS to the number of characters in the operator.
1575 Does not advance INPUT_LINE_POINTER. */
1577 static inline operatorT
1578 operatorf (int *num_chars
)
1583 c
= *input_line_pointer
& 0xff;
1586 if (is_end_of_line
[c
])
1590 if (is_name_beginner (c
))
1593 char ec
= get_symbol_name (& name
);
1595 ret
= md_operator (name
, 2, &ec
);
1599 *input_line_pointer
= ec
;
1600 input_line_pointer
= name
;
1605 as_bad (_("invalid use of operator \"%s\""), name
);
1609 *input_line_pointer
= ec
;
1610 *num_chars
= input_line_pointer
- name
;
1611 input_line_pointer
= name
;
1620 ret
= op_encoding
[c
];
1622 if (ret
== O_illegal
)
1624 char *start
= input_line_pointer
;
1626 ret
= md_operator (NULL
, 2, NULL
);
1627 if (ret
!= O_illegal
)
1628 *num_chars
= input_line_pointer
- start
;
1629 input_line_pointer
= start
;
1636 return op_encoding
[c
];
1639 switch (input_line_pointer
[1])
1642 return op_encoding
[c
];
1657 if (input_line_pointer
[1] != '=')
1658 return op_encoding
[c
];
1664 switch (input_line_pointer
[1])
1667 return op_encoding
[c
];
1669 ret
= O_right_shift
;
1679 switch (input_line_pointer
[1])
1682 /* We accept !! as equivalent to ^ for MRI compatibility. */
1684 return O_bit_exclusive_or
;
1686 /* We accept != as equivalent to <>. */
1691 return O_bit_inclusive_or
;
1692 return op_encoding
[c
];
1696 if (input_line_pointer
[1] != '|')
1697 return op_encoding
[c
];
1700 return O_logical_or
;
1703 if (input_line_pointer
[1] != '&')
1704 return op_encoding
[c
];
1707 return O_logical_and
;
1713 /* Implement "word-size + 1 bit" addition for
1714 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1715 is used so that the full range of unsigned word values and the full range of
1716 signed word values can be represented in an O_constant expression, which is
1717 useful e.g. for .sleb128 directives. */
1720 add_to_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1722 valueT ures
= resultP
->X_add_number
;
1723 valueT uamount
= amount
;
1725 resultP
->X_add_number
+= amount
;
1727 resultP
->X_extrabit
^= rhs_highbit
;
1729 if (ures
+ uamount
< ures
)
1730 resultP
->X_extrabit
^= 1;
1733 /* Similarly, for subtraction. */
1736 subtract_from_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1738 valueT ures
= resultP
->X_add_number
;
1739 valueT uamount
= amount
;
1741 resultP
->X_add_number
-= amount
;
1743 resultP
->X_extrabit
^= rhs_highbit
;
1746 resultP
->X_extrabit
^= 1;
1749 /* Parse an expression. */
1752 expr (int rankarg
, /* Larger # is higher rank. */
1753 expressionS
*resultP
, /* Deliver result here. */
1754 enum expr_mode mode
/* Controls behavior. */)
1756 operator_rankT rank
= (operator_rankT
) rankarg
;
1763 know (rankarg
>= 0);
1765 /* Save the value of dot for the fixup code. */
1768 dot_value
= frag_now_fix ();
1769 dot_frag
= frag_now
;
1772 retval
= operand (resultP
, mode
);
1774 /* operand () gobbles spaces. */
1775 know (*input_line_pointer
!= ' ');
1777 op_left
= operatorf (&op_chars
);
1778 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1783 input_line_pointer
+= op_chars
; /* -> after operator. */
1786 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1787 if (right
.X_op
== O_absent
)
1789 as_warn (_("missing operand; zero assumed"));
1790 right
.X_op
= O_constant
;
1791 right
.X_add_number
= 0;
1792 right
.X_add_symbol
= NULL
;
1793 right
.X_op_symbol
= NULL
;
1796 know (*input_line_pointer
!= ' ');
1798 if (op_left
== O_index
)
1800 if (*input_line_pointer
!= ']')
1801 as_bad ("missing right bracket");
1804 ++input_line_pointer
;
1809 op_right
= operatorf (&op_chars
);
1811 know (op_right
== O_illegal
|| op_left
== O_index
1812 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1813 know ((int) op_left
>= (int) O_multiply
);
1815 know ((int) op_left
<= (int) O_index
);
1817 know ((int) op_left
< (int) O_max
);
1820 /* input_line_pointer->after right-hand quantity. */
1821 /* left-hand quantity in resultP. */
1822 /* right-hand quantity in right. */
1823 /* operator in op_left. */
1825 if (resultP
->X_op
== O_big
)
1827 if (resultP
->X_add_number
> 0)
1828 as_warn (_("left operand is a bignum; integer 0 assumed"));
1830 as_warn (_("left operand is a float; integer 0 assumed"));
1831 resultP
->X_op
= O_constant
;
1832 resultP
->X_add_number
= 0;
1833 resultP
->X_add_symbol
= NULL
;
1834 resultP
->X_op_symbol
= NULL
;
1836 if (right
.X_op
== O_big
)
1838 if (right
.X_add_number
> 0)
1839 as_warn (_("right operand is a bignum; integer 0 assumed"));
1841 as_warn (_("right operand is a float; integer 0 assumed"));
1842 right
.X_op
= O_constant
;
1843 right
.X_add_number
= 0;
1844 right
.X_add_symbol
= NULL
;
1845 right
.X_op_symbol
= NULL
;
1848 if (mode
== expr_defer
1849 && ((resultP
->X_add_symbol
!= NULL
1850 && S_IS_FORWARD_REF (resultP
->X_add_symbol
))
1851 || (right
.X_add_symbol
!= NULL
1852 && S_IS_FORWARD_REF (right
.X_add_symbol
))))
1855 /* Optimize common cases. */
1856 #ifdef md_optimize_expr
1857 if (md_optimize_expr (resultP
, op_left
, &right
))
1864 #ifndef md_register_arithmetic
1865 # define md_register_arithmetic 1
1867 if (op_left
== O_add
&& right
.X_op
== O_constant
1868 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1871 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1873 /* This case comes up in PIC code. */
1874 else if (op_left
== O_subtract
1875 && right
.X_op
== O_symbol
1876 && resultP
->X_op
== O_symbol
1877 && retval
== rightseg
1878 #ifdef md_allow_local_subtract
1879 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1881 && ((SEG_NORMAL (rightseg
)
1882 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1883 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1884 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1885 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1886 symbol_get_frag (right
.X_add_symbol
),
1889 offsetT symval_diff
= S_GET_VALUE (resultP
->X_add_symbol
)
1890 - S_GET_VALUE (right
.X_add_symbol
);
1891 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1892 subtract_from_result (resultP
, frag_off
/ OCTETS_PER_BYTE
, 0);
1893 add_to_result (resultP
, symval_diff
, symval_diff
< 0);
1894 resultP
->X_op
= O_constant
;
1895 resultP
->X_add_symbol
= 0;
1897 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1898 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1901 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1903 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1904 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1907 resultP
->X_op
= right
.X_op
;
1908 resultP
->X_add_symbol
= right
.X_add_symbol
;
1909 resultP
->X_op_symbol
= right
.X_op_symbol
;
1910 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1913 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1915 /* Constant OP constant. */
1916 offsetT v
= right
.X_add_number
;
1917 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1919 as_warn (_("division by zero"));
1922 if ((valueT
) v
>= sizeof(valueT
) * CHAR_BIT
1923 && (op_left
== O_left_shift
|| op_left
== O_right_shift
))
1925 as_warn_value_out_of_range (_("shift count"), v
, 0,
1926 sizeof(valueT
) * CHAR_BIT
- 1,
1928 resultP
->X_add_number
= v
= 0;
1932 default: goto general
;
1933 case O_multiply
: resultP
->X_add_number
*= v
; break;
1934 case O_divide
: resultP
->X_add_number
/= v
; break;
1935 case O_modulus
: resultP
->X_add_number
%= v
; break;
1936 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1938 /* We always use unsigned shifts, to avoid relying on
1939 characteristics of the compiler used to compile gas. */
1940 resultP
->X_add_number
=
1941 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1943 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1944 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1945 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1946 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1947 /* Constant + constant (O_add) is handled by the
1948 previous if statement for constant + X, so is omitted
1951 subtract_from_result (resultP
, v
, 0);
1954 resultP
->X_add_number
=
1955 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1958 resultP
->X_add_number
=
1959 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1962 resultP
->X_add_number
=
1963 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1966 resultP
->X_add_number
=
1967 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1970 resultP
->X_add_number
=
1971 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1974 resultP
->X_add_number
=
1975 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1978 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1981 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1985 else if (resultP
->X_op
== O_symbol
1986 && right
.X_op
== O_symbol
1987 && (op_left
== O_add
1988 || op_left
== O_subtract
1989 || (resultP
->X_add_number
== 0
1990 && right
.X_add_number
== 0)))
1992 /* Symbol OP symbol. */
1993 resultP
->X_op
= op_left
;
1994 resultP
->X_op_symbol
= right
.X_add_symbol
;
1995 if (op_left
== O_add
)
1996 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1997 else if (op_left
== O_subtract
)
1999 subtract_from_result (resultP
, right
.X_add_number
,
2001 if (retval
== rightseg
2002 && SEG_NORMAL (retval
)
2003 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
2004 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
2006 retval
= absolute_section
;
2007 rightseg
= absolute_section
;
2014 /* The general case. */
2015 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
2016 resultP
->X_op_symbol
= make_expr_symbol (&right
);
2017 resultP
->X_op
= op_left
;
2018 resultP
->X_add_number
= 0;
2019 resultP
->X_unsigned
= 1;
2020 resultP
->X_extrabit
= 0;
2023 if (retval
!= rightseg
)
2025 if (retval
== undefined_section
)
2027 else if (rightseg
== undefined_section
)
2029 else if (retval
== expr_section
)
2031 else if (rightseg
== expr_section
)
2033 else if (retval
== reg_section
)
2035 else if (rightseg
== reg_section
)
2037 else if (rightseg
== absolute_section
)
2039 else if (retval
== absolute_section
)
2042 else if (op_left
== O_subtract
)
2046 as_bad (_("operation combines symbols in different segments"));
2050 } /* While next operator is >= this rank. */
2052 /* The PA port needs this information. */
2053 if (resultP
->X_add_symbol
)
2054 symbol_mark_used (resultP
->X_add_symbol
);
2056 if (rank
== 0 && mode
== expr_evaluate
)
2057 resolve_expression (resultP
);
2059 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
2062 /* Resolve an expression without changing any symbols/sub-expressions
2066 resolve_expression (expressionS
*expressionP
)
2068 /* Help out with CSE. */
2069 valueT final_val
= expressionP
->X_add_number
;
2070 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
2071 symbolS
*orig_add_symbol
= add_symbol
;
2072 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
2073 operatorT op
= expressionP
->X_op
;
2075 segT seg_left
, seg_right
;
2076 fragS
*frag_left
, *frag_right
;
2091 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2099 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2102 if (seg_left
!= absolute_section
)
2105 if (op
== O_logical_not
)
2107 else if (op
== O_uminus
)
2119 case O_bit_inclusive_or
:
2121 case O_bit_exclusive_or
:
2133 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
2134 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
2137 /* Simplify addition or subtraction of a constant by folding the
2138 constant into X_add_number. */
2141 if (seg_right
== absolute_section
)
2147 else if (seg_left
== absolute_section
)
2151 seg_left
= seg_right
;
2152 add_symbol
= op_symbol
;
2153 orig_add_symbol
= expressionP
->X_op_symbol
;
2158 else if (op
== O_subtract
)
2160 if (seg_right
== absolute_section
)
2168 /* Equality and non-equality tests are permitted on anything.
2169 Subtraction, and other comparison operators are permitted if
2170 both operands are in the same section.
2171 Shifts by constant zero are permitted on anything.
2172 Multiplies, bit-ors, and bit-ands with constant zero are
2173 permitted on anything.
2174 Multiplies and divides by constant one are permitted on
2176 Binary operations with both operands being the same register
2177 or undefined symbol are permitted if the result doesn't depend
2179 Otherwise, both operands must be absolute. We already handled
2180 the case of addition or subtraction of a constant above. */
2182 if (!(seg_left
== absolute_section
2183 && seg_right
== absolute_section
)
2184 && !(op
== O_eq
|| op
== O_ne
)
2185 && !((op
== O_subtract
2186 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2187 && seg_left
== seg_right
2189 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
)
2191 && frag_gtoffset_p (left
, frag_left
,
2192 right
, frag_right
, &frag_off
)))
2193 && (seg_left
!= reg_section
|| left
== right
)
2194 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2196 if ((seg_left
== absolute_section
&& left
== 0)
2197 || (seg_right
== absolute_section
&& right
== 0))
2199 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2201 if (!(seg_right
== absolute_section
&& right
== 0))
2203 seg_left
= seg_right
;
2205 add_symbol
= op_symbol
;
2206 orig_add_symbol
= expressionP
->X_op_symbol
;
2211 else if (op
== O_left_shift
|| op
== O_right_shift
)
2213 if (!(seg_left
== absolute_section
&& left
== 0))
2219 else if (op
!= O_multiply
2220 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2223 else if (op
== O_multiply
2224 && seg_left
== absolute_section
&& left
== 1)
2226 seg_left
= seg_right
;
2228 add_symbol
= op_symbol
;
2229 orig_add_symbol
= expressionP
->X_op_symbol
;
2233 else if ((op
== O_multiply
|| op
== O_divide
)
2234 && seg_right
== absolute_section
&& right
== 1)
2239 else if (!(left
== right
2240 && ((seg_left
== reg_section
&& seg_right
== reg_section
)
2241 || (seg_left
== undefined_section
2242 && seg_right
== undefined_section
2243 && add_symbol
== op_symbol
))))
2245 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2250 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2254 right
+= frag_off
/ OCTETS_PER_BYTE
;
2257 case O_add
: left
+= right
; break;
2258 case O_subtract
: left
-= right
; break;
2259 case O_multiply
: left
*= right
; break;
2263 left
= (offsetT
) left
/ (offsetT
) right
;
2268 left
= (offsetT
) left
% (offsetT
) right
;
2270 case O_left_shift
: left
<<= right
; break;
2271 case O_right_shift
: left
>>= right
; break;
2272 case O_bit_inclusive_or
: left
|= right
; break;
2273 case O_bit_or_not
: left
|= ~right
; break;
2274 case O_bit_exclusive_or
: left
^= right
; break;
2275 case O_bit_and
: left
&= right
; break;
2278 left
= (left
== right
2279 && seg_left
== seg_right
2280 && (finalize_syms
|| frag_left
== frag_right
)
2281 && (seg_left
!= undefined_section
2282 || add_symbol
== op_symbol
)
2283 ? ~ (valueT
) 0 : 0);
2288 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2291 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2294 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2297 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2299 case O_logical_and
: left
= left
&& right
; break;
2300 case O_logical_or
: left
= left
|| right
; break;
2310 if (seg_left
== absolute_section
)
2312 else if (seg_left
== reg_section
&& final_val
== 0)
2314 else if (!symbol_same_p (add_symbol
, orig_add_symbol
))
2316 expressionP
->X_add_symbol
= add_symbol
;
2318 expressionP
->X_op
= op
;
2320 if (op
== O_constant
|| op
== O_register
)
2322 expressionP
->X_add_number
= final_val
;
2327 /* This lives here because it belongs equally in expr.c & read.c.
2328 expr.c is just a branch office read.c anyway, and putting it
2329 here lessens the crowd at read.c.
2331 Assume input_line_pointer is at start of symbol name, or the
2332 start of a double quote enclosed symbol name.
2333 Advance input_line_pointer past symbol name.
2334 Turn that character into a '\0', returning its former value,
2335 which may be the closing double quote.
2336 This allows a string compare (RMS wants symbol names to be strings)
2338 There will always be a char following symbol name, because all good
2339 lines end in end-of-line. */
2342 get_symbol_name (char ** ilp_return
)
2346 * ilp_return
= input_line_pointer
;
2347 /* We accept FAKE_LABEL_CHAR in a name in case this is being called with a
2348 constructed string. */
2349 if (is_name_beginner (c
= *input_line_pointer
++)
2350 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
2352 while (is_part_of_name (c
= *input_line_pointer
++)
2353 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
2355 if (is_name_ender (c
))
2356 c
= *input_line_pointer
++;
2360 bfd_boolean backslash_seen
;
2362 * ilp_return
= input_line_pointer
;
2365 backslash_seen
= c
== '\\';
2366 c
= * input_line_pointer
++;
2368 while (c
!= 0 && (c
!= '"' || backslash_seen
));
2371 as_warn (_("missing closing '\"'"));
2373 *--input_line_pointer
= 0;
2377 /* Replace the NUL character pointed to by input_line_pointer
2378 with C. If C is \" then advance past it. Return the character
2379 now pointed to by input_line_pointer. */
2382 restore_line_pointer (char c
)
2384 * input_line_pointer
= c
;
2386 c
= * ++ input_line_pointer
;
2391 get_single_number (void)
2394 operand (&exp
, expr_normal
);
2395 return exp
.X_add_number
;