1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2016 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 static void floating_constant (expressionS
* expressionP
);
39 static valueT
generic_bignum_to_int32 (void);
41 static valueT
generic_bignum_to_int64 (void);
43 static void integer_constant (int radix
, expressionS
* expressionP
);
44 static void mri_char_constant (expressionS
*);
45 static void clean_up_expression (expressionS
* expressionP
);
46 static segT
operand (expressionS
*, enum expr_mode
);
47 static operatorT
operatorf (int *);
49 /* We keep a mapping of expression symbols to file positions, so that
50 we can provide better error messages. */
52 struct expr_symbol_line
{
53 struct expr_symbol_line
*next
;
59 static struct expr_symbol_line
*expr_symbol_lines
;
61 /* Build a dummy symbol to hold a complex expression. This is how we
62 build expressions up out of other expressions. The symbol is put
63 into the fake section expr_section. */
66 make_expr_symbol (expressionS
*expressionP
)
70 struct expr_symbol_line
*n
;
72 if (expressionP
->X_op
== O_symbol
73 && expressionP
->X_add_number
== 0)
74 return expressionP
->X_add_symbol
;
76 if (expressionP
->X_op
== O_big
)
78 /* This won't work, because the actual value is stored in
79 generic_floating_point_number or generic_bignum, and we are
80 going to lose it if we haven't already. */
81 if (expressionP
->X_add_number
> 0)
82 as_bad (_("bignum invalid"));
84 as_bad (_("floating point number invalid"));
85 zero
.X_op
= O_constant
;
86 zero
.X_add_number
= 0;
89 clean_up_expression (&zero
);
93 /* Putting constant symbols in absolute_section rather than
94 expr_section is convenient for the old a.out code, for which
95 S_GET_SEGMENT does not always retrieve the value put in by
97 symbolP
= symbol_create (FAKE_LABEL_NAME
,
98 (expressionP
->X_op
== O_constant
100 : expressionP
->X_op
== O_register
103 0, &zero_address_frag
);
104 symbol_set_value_expression (symbolP
, expressionP
);
106 if (expressionP
->X_op
== O_constant
)
107 resolve_symbol_value (symbolP
);
109 n
= XNEW (struct expr_symbol_line
);
111 n
->file
= as_where (&n
->line
);
112 n
->next
= expr_symbol_lines
;
113 expr_symbol_lines
= n
;
118 /* Return the file and line number for an expr symbol. Return
119 non-zero if something was found, 0 if no information is known for
123 expr_symbol_where (symbolS
*sym
, const char **pfile
, unsigned int *pline
)
125 struct expr_symbol_line
*l
;
127 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
140 /* Utilities for building expressions.
141 Since complex expressions are recorded as symbols for use in other
142 expressions these return a symbolS * and not an expressionS *.
143 These explicitly do not take an "add_number" argument. */
144 /* ??? For completeness' sake one might want expr_build_symbol.
145 It would just return its argument. */
147 /* Build an expression for an unsigned constant.
148 The corresponding one for signed constants is missing because
149 there's currently no need for it. One could add an unsigned_p flag
150 but that seems more clumsy. */
153 expr_build_uconstant (offsetT value
)
158 e
.X_add_number
= value
;
161 return make_expr_symbol (&e
);
164 /* Build an expression for the current location ('.'). */
167 expr_build_dot (void)
171 current_location (&e
);
172 return symbol_clone_if_forward_ref (make_expr_symbol (&e
));
175 /* Build any floating-point literal here.
176 Also build any bignum literal here. */
178 /* Seems atof_machine can backscan through generic_bignum and hit whatever
179 happens to be loaded before it in memory. And its way too complicated
180 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
181 and never write into the early words, thus they'll always be zero.
182 I hate Dean's floating-point code. Bleh. */
183 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
185 FLONUM_TYPE generic_floating_point_number
= {
186 &generic_bignum
[6], /* low. (JF: Was 0) */
187 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
195 floating_constant (expressionS
*expressionP
)
197 /* input_line_pointer -> floating-point constant. */
200 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
201 &generic_floating_point_number
);
205 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
207 as_bad (_("bad floating-point constant: exponent overflow"));
211 as_bad (_("bad floating-point constant: unknown error code=%d"),
215 expressionP
->X_op
= O_big
;
216 /* input_line_pointer -> just after constant, which may point to
218 expressionP
->X_add_number
= -1;
222 generic_bignum_to_int32 (void)
225 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
226 | (generic_bignum
[0] & LITTLENUM_MASK
);
227 number
&= 0xffffffff;
233 generic_bignum_to_int64 (void)
236 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
237 << LITTLENUM_NUMBER_OF_BITS
)
238 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
239 << LITTLENUM_NUMBER_OF_BITS
)
240 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
241 << LITTLENUM_NUMBER_OF_BITS
)
242 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
248 integer_constant (int radix
, expressionS
*expressionP
)
250 char *start
; /* Start of number. */
253 valueT number
; /* Offset or (absolute) value. */
254 short int digit
; /* Value of next digit in current radix. */
255 short int maxdig
= 0; /* Highest permitted digit value. */
256 int too_many_digits
= 0; /* If we see >= this number of. */
257 char *name
; /* Points to name of symbol. */
258 symbolS
*symbolP
; /* Points to symbol. */
260 int small
; /* True if fits in 32 bits. */
262 /* May be bignum, or may fit in 32 bits. */
263 /* Most numbers fit into 32 bits, and we want this case to be fast.
264 so we pretend it will fit into 32 bits. If, after making up a 32
265 bit number, we realise that we have scanned more digits than
266 comfortably fit into 32 bits, we re-scan the digits coding them
267 into a bignum. For decimal and octal numbers we are
268 conservative: Some numbers may be assumed bignums when in fact
269 they do fit into 32 bits. Numbers of any radix can have excess
270 leading zeros: We strive to recognise this and cast them back
271 into 32 bits. We must check that the bignum really is more than
272 32 bits, and change it back to a 32-bit number if it fits. The
273 number we are looking for is expected to be positive, but if it
274 fits into 32 bits as an unsigned number, we let it be a 32-bit
275 number. The cavalier approach is for speed in ordinary cases. */
276 /* This has been extended for 64 bits. We blindly assume that if
277 you're compiling in 64-bit mode, the target is a 64-bit machine.
278 This should be cleaned up. */
282 #else /* includes non-bfd case, mostly */
286 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
288 expressionP
->X_op
= O_absent
;
292 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
296 /* In MRI mode, the number may have a suffix indicating the
297 radix. For that matter, it might actually be a floating
299 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
301 if (*suffix
== 'e' || *suffix
== 'E')
305 if (suffix
== input_line_pointer
)
314 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
315 we distinguish between 'B' and 'b'. This is the case for
317 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
321 else if (c
== 'O' || c
== 'Q')
325 else if (suffix
[1] == '.' || c
== 'E' || flt
)
327 floating_constant (expressionP
);
342 too_many_digits
= valuesize
+ 1;
346 too_many_digits
= (valuesize
+ 2) / 3 + 1;
350 too_many_digits
= (valuesize
+ 3) / 4 + 1;
354 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
357 start
= input_line_pointer
;
358 c
= *input_line_pointer
++;
360 (digit
= hex_value (c
)) < maxdig
;
361 c
= *input_line_pointer
++)
363 number
= number
* radix
+ digit
;
365 /* c contains character after number. */
366 /* input_line_pointer->char after c. */
367 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
369 if (radix
== 16 && c
== '_')
371 /* This is literal of the form 0x333_0_12345678_1.
372 This example is equivalent to 0x00000333000000001234567800000001. */
374 int num_little_digits
= 0;
376 input_line_pointer
= start
; /* -> 1st digit. */
378 know (LITTLENUM_NUMBER_OF_BITS
== 16);
380 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
383 /* Convert one 64-bit word. */
386 for (c
= *input_line_pointer
++;
387 (digit
= hex_value (c
)) < maxdig
;
388 c
= *(input_line_pointer
++))
390 number
= number
* radix
+ digit
;
394 /* Check for 8 digit per word max. */
396 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
398 /* Add this chunk to the bignum.
399 Shift things down 2 little digits. */
400 know (LITTLENUM_NUMBER_OF_BITS
== 16);
401 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
404 generic_bignum
[i
] = generic_bignum
[i
- 2];
406 /* Add the new digits as the least significant new ones. */
407 generic_bignum
[0] = number
& 0xffffffff;
408 generic_bignum
[1] = number
>> 16;
411 /* Again, c is char after number, input_line_pointer->after c. */
413 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
414 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
416 gas_assert (num_little_digits
>= 4);
418 if (num_little_digits
!= 8)
419 as_bad (_("a bignum with underscores must have exactly 4 words"));
421 /* We might have some leading zeros. These can be trimmed to give
422 us a change to fit this constant into a small number. */
423 while (generic_bignum
[num_little_digits
- 1] == 0
424 && num_little_digits
> 1)
427 if (num_little_digits
<= 2)
429 /* will fit into 32 bits. */
430 number
= generic_bignum_to_int32 ();
434 else if (num_little_digits
<= 4)
436 /* Will fit into 64 bits. */
437 number
= generic_bignum_to_int64 ();
445 /* Number of littlenums in the bignum. */
446 number
= num_little_digits
;
451 /* We saw a lot of digits. manufacture a bignum the hard way. */
452 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
453 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
456 leader
= generic_bignum
;
457 generic_bignum
[0] = 0;
458 generic_bignum
[1] = 0;
459 generic_bignum
[2] = 0;
460 generic_bignum
[3] = 0;
461 input_line_pointer
= start
; /* -> 1st digit. */
462 c
= *input_line_pointer
++;
463 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
465 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
469 work
= carry
+ radix
* *pointer
;
470 *pointer
= work
& LITTLENUM_MASK
;
471 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
475 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
477 /* Room to grow a longer bignum. */
482 /* Again, c is char after number. */
483 /* input_line_pointer -> after c. */
484 know (LITTLENUM_NUMBER_OF_BITS
== 16);
485 if (leader
< generic_bignum
+ 2)
487 /* Will fit into 32 bits. */
488 number
= generic_bignum_to_int32 ();
492 else if (leader
< generic_bignum
+ 4)
494 /* Will fit into 64 bits. */
495 number
= generic_bignum_to_int64 ();
501 /* Number of littlenums in the bignum. */
502 number
= leader
- generic_bignum
+ 1;
506 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
508 && input_line_pointer
- 1 == suffix
)
509 c
= *input_line_pointer
++;
511 #ifndef tc_allow_U_suffix
512 #define tc_allow_U_suffix 1
514 /* PR 19910: Look for, and ignore, a U suffix to the number. */
515 if (tc_allow_U_suffix
&& (c
== 'U' || c
== 'u'))
516 c
= * input_line_pointer
++;
520 /* Here with number, in correct radix. c is the next char.
521 Note that unlike un*x, we allow "011f" "0x9f" to both mean
522 the same as the (conventional) "9f".
523 This is simply easier than checking for strict canonical
526 if (LOCAL_LABELS_FB
&& c
== 'b')
528 /* Backward ref to local label.
529 Because it is backward, expect it to be defined. */
530 /* Construct a local label. */
531 name
= fb_label_name ((int) number
, 0);
533 /* Seen before, or symbol is defined: OK. */
534 symbolP
= symbol_find (name
);
535 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
537 /* Local labels are never absolute. Don't waste time
538 checking absoluteness. */
539 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
541 expressionP
->X_op
= O_symbol
;
542 expressionP
->X_add_symbol
= symbolP
;
546 /* Either not seen or not defined. */
547 /* @@ Should print out the original string instead of
548 the parsed number. */
549 as_bad (_("backward ref to unknown label \"%d:\""),
551 expressionP
->X_op
= O_constant
;
554 expressionP
->X_add_number
= 0;
556 else if (LOCAL_LABELS_FB
&& c
== 'f')
558 /* Forward reference. Expect symbol to be undefined or
559 unknown. undefined: seen it before. unknown: never seen
562 Construct a local label name, then an undefined symbol.
563 Don't create a xseg frag for it: caller may do that.
564 Just return it as never seen before. */
565 name
= fb_label_name ((int) number
, 1);
566 symbolP
= symbol_find_or_make (name
);
567 /* We have no need to check symbol properties. */
568 #ifndef many_segments
569 /* Since "know" puts its arg into a "string", we
570 can't have newlines in the argument. */
571 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
573 expressionP
->X_op
= O_symbol
;
574 expressionP
->X_add_symbol
= symbolP
;
575 expressionP
->X_add_number
= 0;
577 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
579 /* If the dollar label is *currently* defined, then this is just
580 another reference to it. If it is not *currently* defined,
581 then this is a fresh instantiation of that number, so create
584 if (dollar_label_defined ((long) number
))
586 name
= dollar_label_name ((long) number
, 0);
587 symbolP
= symbol_find (name
);
588 know (symbolP
!= NULL
);
592 name
= dollar_label_name ((long) number
, 1);
593 symbolP
= symbol_find_or_make (name
);
596 expressionP
->X_op
= O_symbol
;
597 expressionP
->X_add_symbol
= symbolP
;
598 expressionP
->X_add_number
= 0;
602 expressionP
->X_op
= O_constant
;
603 expressionP
->X_add_number
= number
;
604 input_line_pointer
--; /* Restore following character. */
605 } /* Really just a number. */
609 /* Not a small number. */
610 expressionP
->X_op
= O_big
;
611 expressionP
->X_add_number
= number
; /* Number of littlenums. */
612 input_line_pointer
--; /* -> char following number. */
616 /* Parse an MRI multi character constant. */
619 mri_char_constant (expressionS
*expressionP
)
623 if (*input_line_pointer
== '\''
624 && input_line_pointer
[1] != '\'')
626 expressionP
->X_op
= O_constant
;
627 expressionP
->X_add_number
= 0;
631 /* In order to get the correct byte ordering, we must build the
632 number in reverse. */
633 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
637 generic_bignum
[i
] = 0;
638 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
640 if (*input_line_pointer
== '\'')
642 if (input_line_pointer
[1] != '\'')
644 ++input_line_pointer
;
646 generic_bignum
[i
] <<= 8;
647 generic_bignum
[i
] += *input_line_pointer
;
648 ++input_line_pointer
;
651 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
653 /* If there is more than one littlenum, left justify the
654 last one to make it match the earlier ones. If there is
655 only one, we can just use the value directly. */
656 for (; j
< CHARS_PER_LITTLENUM
; j
++)
657 generic_bignum
[i
] <<= 8;
660 if (*input_line_pointer
== '\''
661 && input_line_pointer
[1] != '\'')
667 as_bad (_("character constant too large"));
676 c
= SIZE_OF_LARGE_NUMBER
- i
;
677 for (j
= 0; j
< c
; j
++)
678 generic_bignum
[j
] = generic_bignum
[i
+ j
];
682 know (LITTLENUM_NUMBER_OF_BITS
== 16);
685 expressionP
->X_op
= O_big
;
686 expressionP
->X_add_number
= i
;
690 expressionP
->X_op
= O_constant
;
692 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
694 expressionP
->X_add_number
=
695 (((generic_bignum
[1] & LITTLENUM_MASK
)
696 << LITTLENUM_NUMBER_OF_BITS
)
697 | (generic_bignum
[0] & LITTLENUM_MASK
));
700 /* Skip the final closing quote. */
701 ++input_line_pointer
;
704 /* Return an expression representing the current location. This
705 handles the magic symbol `.'. */
708 current_location (expressionS
*expressionp
)
710 if (now_seg
== absolute_section
)
712 expressionp
->X_op
= O_constant
;
713 expressionp
->X_add_number
= abs_section_offset
;
717 expressionp
->X_op
= O_symbol
;
718 expressionp
->X_add_symbol
= &dot_symbol
;
719 expressionp
->X_add_number
= 0;
723 /* In: Input_line_pointer points to 1st char of operand, which may
727 The operand may have been empty: in this case X_op == O_absent.
728 Input_line_pointer->(next non-blank) char after operand. */
731 operand (expressionS
*expressionP
, enum expr_mode mode
)
734 symbolS
*symbolP
; /* Points to symbol. */
735 char *name
; /* Points to name of symbol. */
738 /* All integers are regarded as unsigned unless they are negated.
739 This is because the only thing which cares whether a number is
740 unsigned is the code in emit_expr which extends constants into
741 bignums. It should only sign extend negative numbers, so that
742 something like ``.quad 0x80000000'' is not sign extended even
743 though it appears negative if valueT is 32 bits. */
744 expressionP
->X_unsigned
= 1;
745 expressionP
->X_extrabit
= 0;
747 /* Digits, assume it is a bignum. */
749 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
750 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
752 if (is_end_of_line
[(unsigned char) c
])
766 input_line_pointer
--;
768 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
773 #ifdef LITERAL_PREFIXDOLLAR_HEX
775 /* $L is the start of a local label, not a hex constant. */
776 if (* input_line_pointer
== 'L')
778 integer_constant (16, expressionP
);
782 #ifdef LITERAL_PREFIXPERCENT_BIN
784 integer_constant (2, expressionP
);
789 /* Non-decimal radix. */
791 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
795 /* Check for a hex or float constant. */
796 for (s
= input_line_pointer
; hex_p (*s
); s
++)
798 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
800 --input_line_pointer
;
801 integer_constant (0, expressionP
);
805 c
= *input_line_pointer
;
814 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
816 integer_constant (0, expressionP
);
822 if (c
&& strchr (FLT_CHARS
, c
))
824 input_line_pointer
++;
825 floating_constant (expressionP
);
826 expressionP
->X_add_number
= - TOLOWER (c
);
830 /* The string was only zero. */
831 expressionP
->X_op
= O_constant
;
832 expressionP
->X_add_number
= 0;
841 input_line_pointer
++;
842 integer_constant (16, expressionP
);
846 if (LOCAL_LABELS_FB
&& !flag_m68k_mri
847 && input_line_pointer
[1] != '0'
848 && input_line_pointer
[1] != '1')
850 /* Parse this as a back reference to label 0. */
851 input_line_pointer
--;
852 integer_constant (10, expressionP
);
855 /* Otherwise, parse this as a binary number. */
858 if (input_line_pointer
[1] == '0'
859 || input_line_pointer
[1] == '1')
861 input_line_pointer
++;
862 integer_constant (2, expressionP
);
865 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
866 input_line_pointer
++;
877 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
887 /* If it says "0f" and it could possibly be a floating point
888 number, make it one. Otherwise, make it a local label,
889 and try to deal with parsing the rest later. */
890 if (!is_end_of_line
[(unsigned char) input_line_pointer
[1]]
891 && strchr (FLT_CHARS
, 'f') != NULL
)
893 char *cp
= input_line_pointer
+ 1;
895 atof_generic (&cp
, ".", EXP_CHARS
,
896 &generic_floating_point_number
);
898 /* Was nothing parsed, or does it look like an
900 is_label
= (cp
== input_line_pointer
+ 1
901 || (cp
== input_line_pointer
+ 2
902 && (cp
[-1] == '-' || cp
[-1] == '+'))
908 input_line_pointer
--;
909 integer_constant (10, expressionP
);
917 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
919 integer_constant (0, expressionP
);
929 input_line_pointer
++;
930 floating_constant (expressionP
);
931 expressionP
->X_add_number
= - TOLOWER (c
);
935 if (LOCAL_LABELS_DOLLAR
)
937 integer_constant (10, expressionP
);
946 #ifndef NEED_INDEX_OPERATOR
948 # ifdef md_need_index_operator
949 if (md_need_index_operator())
955 /* Didn't begin with digit & not a name. */
956 segment
= expr (0, expressionP
, mode
);
957 /* expression () will pass trailing whitespace. */
958 if ((c
== '(' && *input_line_pointer
!= ')')
959 || (c
== '[' && *input_line_pointer
!= ']'))
961 if (* input_line_pointer
)
962 as_bad (_("found '%c', expected: '%c'"),
963 * input_line_pointer
, c
== '(' ? ')' : ']');
965 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
968 input_line_pointer
++;
970 /* Here with input_line_pointer -> char after "(...)". */
975 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
977 as_bad (_("EBCDIC constants are not supported"));
980 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
982 ++input_line_pointer
;
988 /* Warning: to conform to other people's assemblers NO
989 ESCAPEMENT is permitted for a single quote. The next
990 character, parity errors and all, is taken as the value
991 of the operand. VERY KINKY. */
992 expressionP
->X_op
= O_constant
;
993 expressionP
->X_add_number
= *input_line_pointer
++;
997 mri_char_constant (expressionP
);
1002 /* Double quote is the bitwise not operator in MRI mode. */
1003 if (! flag_m68k_mri
)
1008 /* '~' is permitted to start a label on the Delta. */
1009 if (is_name_beginner (c
))
1018 operand (expressionP
, mode
);
1019 if (expressionP
->X_op
== O_constant
)
1021 /* input_line_pointer -> char after operand. */
1024 expressionP
->X_add_number
1025 = - (addressT
) expressionP
->X_add_number
;
1026 /* Notice: '-' may overflow: no warning is given.
1027 This is compatible with other people's
1028 assemblers. Sigh. */
1029 expressionP
->X_unsigned
= 0;
1030 if (expressionP
->X_add_number
)
1031 expressionP
->X_extrabit
^= 1;
1033 else if (c
== '~' || c
== '"')
1034 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1036 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1038 else if (expressionP
->X_op
== O_big
1039 && expressionP
->X_add_number
<= 0
1041 && (generic_floating_point_number
.sign
== '+'
1042 || generic_floating_point_number
.sign
== 'P'))
1044 /* Negative flonum (eg, -1.000e0). */
1045 if (generic_floating_point_number
.sign
== '+')
1046 generic_floating_point_number
.sign
= '-';
1048 generic_floating_point_number
.sign
= 'N';
1050 else if (expressionP
->X_op
== O_big
1051 && expressionP
->X_add_number
> 0)
1055 if (c
== '~' || c
== '-')
1057 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1058 generic_bignum
[i
] = ~generic_bignum
[i
];
1060 /* Extend the bignum to at least the size of .octa. */
1061 if (expressionP
->X_add_number
< SIZE_OF_LARGE_NUMBER
)
1063 expressionP
->X_add_number
= SIZE_OF_LARGE_NUMBER
;
1064 for (; i
< expressionP
->X_add_number
; ++i
)
1065 generic_bignum
[i
] = ~(LITTLENUM_TYPE
) 0;
1069 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1071 generic_bignum
[i
] += 1;
1072 if (generic_bignum
[i
])
1078 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1079 if (generic_bignum
[i
] != 0)
1081 expressionP
->X_add_number
= i
>= expressionP
->X_add_number
;
1082 expressionP
->X_op
= O_constant
;
1083 expressionP
->X_unsigned
= 1;
1084 expressionP
->X_extrabit
= 0;
1087 else if (expressionP
->X_op
!= O_illegal
1088 && expressionP
->X_op
!= O_absent
)
1092 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1094 expressionP
->X_op
= O_uminus
;
1095 else if (c
== '~' || c
== '"')
1096 expressionP
->X_op
= O_bit_not
;
1098 expressionP
->X_op
= O_logical_not
;
1099 expressionP
->X_add_number
= 0;
1103 as_warn (_("Unary operator %c ignored because bad operand follows"),
1108 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1110 /* '$' is the program counter when in MRI mode, or when
1111 DOLLAR_DOT is defined. */
1113 if (! flag_m68k_mri
)
1116 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1118 /* In MRI mode and on Z80, '$' is also used as the prefix
1119 for a hexadecimal constant. */
1120 integer_constant (16, expressionP
);
1124 if (is_part_of_name (*input_line_pointer
))
1127 current_location (expressionP
);
1132 if (!is_part_of_name (*input_line_pointer
))
1134 current_location (expressionP
);
1137 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1138 && ! is_part_of_name (input_line_pointer
[8]))
1139 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1140 && ! is_part_of_name (input_line_pointer
[7])))
1144 start
= (input_line_pointer
[1] == 't'
1145 || input_line_pointer
[1] == 'T');
1146 input_line_pointer
+= start
? 8 : 7;
1148 if (*input_line_pointer
!= '(')
1149 as_bad (_("syntax error in .startof. or .sizeof."));
1154 ++input_line_pointer
;
1156 c
= get_symbol_name (& name
);
1158 buf
= concat (start
? ".startof." : ".sizeof.", name
,
1160 symbolP
= symbol_make (buf
);
1163 expressionP
->X_op
= O_symbol
;
1164 expressionP
->X_add_symbol
= symbolP
;
1165 expressionP
->X_add_number
= 0;
1167 *input_line_pointer
= c
;
1168 SKIP_WHITESPACE_AFTER_NAME ();
1169 if (*input_line_pointer
!= ')')
1170 as_bad (_("syntax error in .startof. or .sizeof."));
1172 ++input_line_pointer
;
1183 /* Can't imagine any other kind of operand. */
1184 expressionP
->X_op
= O_absent
;
1185 input_line_pointer
--;
1190 if (! flag_m68k_mri
)
1192 integer_constant (2, expressionP
);
1196 if (! flag_m68k_mri
)
1198 integer_constant (8, expressionP
);
1202 if (! flag_m68k_mri
)
1205 /* In MRI mode, this is a floating point constant represented
1206 using hexadecimal digits. */
1208 ++input_line_pointer
;
1209 integer_constant (16, expressionP
);
1213 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1216 current_location (expressionP
);
1221 #if defined(md_need_index_operator) || defined(TC_M68K)
1224 if (is_name_beginner (c
) || c
== '"') /* Here if did not begin with a digit. */
1226 /* Identifier begins here.
1227 This is kludged for speed, so code is repeated. */
1229 -- input_line_pointer
;
1230 c
= get_symbol_name (&name
);
1234 operatorT op
= md_operator (name
, 1, &c
);
1239 restore_line_pointer (c
);
1243 restore_line_pointer (c
);
1247 restore_line_pointer (c
);
1251 as_bad (_("invalid use of operator \"%s\""), name
);
1257 if (op
!= O_absent
&& op
!= O_illegal
)
1259 restore_line_pointer (c
);
1260 expr (9, expressionP
, mode
);
1261 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1262 expressionP
->X_op_symbol
= NULL
;
1263 expressionP
->X_add_number
= 0;
1264 expressionP
->X_op
= op
;
1270 #ifdef md_parse_name
1271 /* This is a hook for the backend to parse certain names
1272 specially in certain contexts. If a name always has a
1273 specific value, it can often be handled by simply
1274 entering it in the symbol table. */
1275 if (md_parse_name (name
, expressionP
, mode
, &c
))
1277 restore_line_pointer (c
);
1283 /* The MRI i960 assembler permits
1285 FIXME: This should use md_parse_name. */
1287 && (strcasecmp (name
, "sizeof") == 0
1288 || strcasecmp (name
, "startof") == 0))
1293 start
= (name
[1] == 't'
1296 *input_line_pointer
= c
;
1297 SKIP_WHITESPACE_AFTER_NAME ();
1299 c
= get_symbol_name (& name
);
1301 buf
= concat (start
? ".startof." : ".sizeof.", name
,
1303 symbolP
= symbol_make (buf
);
1306 expressionP
->X_op
= O_symbol
;
1307 expressionP
->X_add_symbol
= symbolP
;
1308 expressionP
->X_add_number
= 0;
1310 *input_line_pointer
= c
;
1311 SKIP_WHITESPACE_AFTER_NAME ();
1316 symbolP
= symbol_find_or_make (name
);
1318 /* If we have an absolute symbol or a reg, then we know its
1320 segment
= S_GET_SEGMENT (symbolP
);
1321 if (mode
!= expr_defer
1322 && segment
== absolute_section
1323 && !S_FORCE_RELOC (symbolP
, 0))
1325 expressionP
->X_op
= O_constant
;
1326 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1328 else if (mode
!= expr_defer
&& segment
== reg_section
)
1330 expressionP
->X_op
= O_register
;
1331 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1335 expressionP
->X_op
= O_symbol
;
1336 expressionP
->X_add_symbol
= symbolP
;
1337 expressionP
->X_add_number
= 0;
1340 restore_line_pointer (c
);
1344 /* Let the target try to parse it. Success is indicated by changing
1345 the X_op field to something other than O_absent and pointing
1346 input_line_pointer past the expression. If it can't parse the
1347 expression, X_op and input_line_pointer should be unchanged. */
1348 expressionP
->X_op
= O_absent
;
1349 --input_line_pointer
;
1350 md_operand (expressionP
);
1351 if (expressionP
->X_op
== O_absent
)
1353 ++input_line_pointer
;
1354 as_bad (_("bad expression"));
1355 expressionP
->X_op
= O_constant
;
1356 expressionP
->X_add_number
= 0;
1362 /* It is more 'efficient' to clean up the expressionS when they are
1363 created. Doing it here saves lines of code. */
1364 clean_up_expression (expressionP
);
1365 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1366 know (*input_line_pointer
!= ' ');
1368 /* The PA port needs this information. */
1369 if (expressionP
->X_add_symbol
)
1370 symbol_mark_used (expressionP
->X_add_symbol
);
1372 if (mode
!= expr_defer
)
1374 expressionP
->X_add_symbol
1375 = symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1376 expressionP
->X_op_symbol
1377 = symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1380 switch (expressionP
->X_op
)
1383 return absolute_section
;
1385 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1391 /* Internal. Simplify a struct expression for use by expr (). */
1393 /* In: address of an expressionS.
1394 The X_op field of the expressionS may only take certain values.
1395 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1397 Out: expressionS may have been modified:
1398 Unused fields zeroed to help expr (). */
1401 clean_up_expression (expressionS
*expressionP
)
1403 switch (expressionP
->X_op
)
1407 expressionP
->X_add_number
= 0;
1412 expressionP
->X_add_symbol
= NULL
;
1417 expressionP
->X_op_symbol
= NULL
;
1424 /* Expression parser. */
1426 /* We allow an empty expression, and just assume (absolute,0) silently.
1427 Unary operators and parenthetical expressions are treated as operands.
1428 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1430 We used to do an aho/ullman shift-reduce parser, but the logic got so
1431 warped that I flushed it and wrote a recursive-descent parser instead.
1432 Now things are stable, would anybody like to write a fast parser?
1433 Most expressions are either register (which does not even reach here)
1434 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1435 So I guess it doesn't really matter how inefficient more complex expressions
1438 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1439 Also, we have consumed any leading or trailing spaces (operand does that)
1440 and done all intervening operators.
1442 This returns the segment of the result, which will be
1443 absolute_section or the segment of a symbol. */
1446 #define __ O_illegal
1448 #define O_SINGLE_EQ O_illegal
1451 /* Maps ASCII -> operators. */
1452 static const operatorT op_encoding
[256] = {
1453 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1454 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1456 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1457 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1458 __
, __
, __
, __
, __
, __
, __
, __
,
1459 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1460 __
, __
, __
, __
, __
, __
, __
, __
,
1461 __
, __
, __
, __
, __
, __
, __
, __
,
1462 __
, __
, __
, __
, __
, __
, __
, __
,
1464 #ifdef NEED_INDEX_OPERATOR
1469 __
, __
, O_bit_exclusive_or
, __
,
1470 __
, __
, __
, __
, __
, __
, __
, __
,
1471 __
, __
, __
, __
, __
, __
, __
, __
,
1472 __
, __
, __
, __
, __
, __
, __
, __
,
1473 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1475 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1476 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1477 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1478 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1479 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1480 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1481 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1482 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1486 0 operand, (expression)
1491 5 used for * / % in MRI mode
1496 static operator_rankT op_rank
[O_max
] = {
1501 0, /* O_symbol_rva */
1506 9, /* O_logical_not */
1510 8, /* O_left_shift */
1511 8, /* O_right_shift */
1512 7, /* O_bit_inclusive_or */
1513 7, /* O_bit_or_not */
1514 7, /* O_bit_exclusive_or */
1524 3, /* O_logical_and */
1525 2, /* O_logical_or */
1529 /* Unfortunately, in MRI mode for the m68k, multiplication and
1530 division have lower precedence than the bit wise operators. This
1531 function sets the operator precedences correctly for the current
1532 mode. Also, MRI uses a different bit_not operator, and this fixes
1535 #define STANDARD_MUL_PRECEDENCE 8
1536 #define MRI_MUL_PRECEDENCE 6
1539 expr_set_precedence (void)
1543 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1544 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1545 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1549 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1550 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1551 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1556 expr_set_rank (operatorT op
, operator_rankT rank
)
1558 gas_assert (op
>= O_md1
&& op
< ARRAY_SIZE (op_rank
));
1562 /* Initialize the expression parser. */
1567 expr_set_precedence ();
1569 /* Verify that X_op field is wide enough. */
1573 gas_assert (e
.X_op
== O_max
);
1577 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1578 sets NUM_CHARS to the number of characters in the operator.
1579 Does not advance INPUT_LINE_POINTER. */
1581 static inline operatorT
1582 operatorf (int *num_chars
)
1587 c
= *input_line_pointer
& 0xff;
1590 if (is_end_of_line
[c
])
1594 if (is_name_beginner (c
))
1597 char ec
= get_symbol_name (& name
);
1599 ret
= md_operator (name
, 2, &ec
);
1603 *input_line_pointer
= ec
;
1604 input_line_pointer
= name
;
1609 as_bad (_("invalid use of operator \"%s\""), name
);
1613 *input_line_pointer
= ec
;
1614 *num_chars
= input_line_pointer
- name
;
1615 input_line_pointer
= name
;
1624 ret
= op_encoding
[c
];
1626 if (ret
== O_illegal
)
1628 char *start
= input_line_pointer
;
1630 ret
= md_operator (NULL
, 2, NULL
);
1631 if (ret
!= O_illegal
)
1632 *num_chars
= input_line_pointer
- start
;
1633 input_line_pointer
= start
;
1640 return op_encoding
[c
];
1643 switch (input_line_pointer
[1])
1646 return op_encoding
[c
];
1661 if (input_line_pointer
[1] != '=')
1662 return op_encoding
[c
];
1668 switch (input_line_pointer
[1])
1671 return op_encoding
[c
];
1673 ret
= O_right_shift
;
1683 switch (input_line_pointer
[1])
1686 /* We accept !! as equivalent to ^ for MRI compatibility. */
1688 return O_bit_exclusive_or
;
1690 /* We accept != as equivalent to <>. */
1695 return O_bit_inclusive_or
;
1696 return op_encoding
[c
];
1700 if (input_line_pointer
[1] != '|')
1701 return op_encoding
[c
];
1704 return O_logical_or
;
1707 if (input_line_pointer
[1] != '&')
1708 return op_encoding
[c
];
1711 return O_logical_and
;
1717 /* Implement "word-size + 1 bit" addition for
1718 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1719 is used so that the full range of unsigned word values and the full range of
1720 signed word values can be represented in an O_constant expression, which is
1721 useful e.g. for .sleb128 directives. */
1724 add_to_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1726 valueT ures
= resultP
->X_add_number
;
1727 valueT uamount
= amount
;
1729 resultP
->X_add_number
+= amount
;
1731 resultP
->X_extrabit
^= rhs_highbit
;
1733 if (ures
+ uamount
< ures
)
1734 resultP
->X_extrabit
^= 1;
1737 /* Similarly, for subtraction. */
1740 subtract_from_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1742 valueT ures
= resultP
->X_add_number
;
1743 valueT uamount
= amount
;
1745 resultP
->X_add_number
-= amount
;
1747 resultP
->X_extrabit
^= rhs_highbit
;
1750 resultP
->X_extrabit
^= 1;
1753 /* Parse an expression. */
1756 expr (int rankarg
, /* Larger # is higher rank. */
1757 expressionS
*resultP
, /* Deliver result here. */
1758 enum expr_mode mode
/* Controls behavior. */)
1760 operator_rankT rank
= (operator_rankT
) rankarg
;
1767 know (rankarg
>= 0);
1769 /* Save the value of dot for the fixup code. */
1772 dot_value
= frag_now_fix ();
1773 dot_frag
= frag_now
;
1776 retval
= operand (resultP
, mode
);
1778 /* operand () gobbles spaces. */
1779 know (*input_line_pointer
!= ' ');
1781 op_left
= operatorf (&op_chars
);
1782 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1787 input_line_pointer
+= op_chars
; /* -> after operator. */
1790 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1791 if (right
.X_op
== O_absent
)
1793 as_warn (_("missing operand; zero assumed"));
1794 right
.X_op
= O_constant
;
1795 right
.X_add_number
= 0;
1796 right
.X_add_symbol
= NULL
;
1797 right
.X_op_symbol
= NULL
;
1800 know (*input_line_pointer
!= ' ');
1802 if (op_left
== O_index
)
1804 if (*input_line_pointer
!= ']')
1805 as_bad ("missing right bracket");
1808 ++input_line_pointer
;
1813 op_right
= operatorf (&op_chars
);
1815 know (op_right
== O_illegal
|| op_left
== O_index
1816 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1817 know ((int) op_left
>= (int) O_multiply
);
1819 know ((int) op_left
<= (int) O_index
);
1821 know ((int) op_left
< (int) O_max
);
1824 /* input_line_pointer->after right-hand quantity. */
1825 /* left-hand quantity in resultP. */
1826 /* right-hand quantity in right. */
1827 /* operator in op_left. */
1829 if (resultP
->X_op
== O_big
)
1831 if (resultP
->X_add_number
> 0)
1832 as_warn (_("left operand is a bignum; integer 0 assumed"));
1834 as_warn (_("left operand is a float; integer 0 assumed"));
1835 resultP
->X_op
= O_constant
;
1836 resultP
->X_add_number
= 0;
1837 resultP
->X_add_symbol
= NULL
;
1838 resultP
->X_op_symbol
= NULL
;
1840 if (right
.X_op
== O_big
)
1842 if (right
.X_add_number
> 0)
1843 as_warn (_("right operand is a bignum; integer 0 assumed"));
1845 as_warn (_("right operand is a float; integer 0 assumed"));
1846 right
.X_op
= O_constant
;
1847 right
.X_add_number
= 0;
1848 right
.X_add_symbol
= NULL
;
1849 right
.X_op_symbol
= NULL
;
1852 /* Optimize common cases. */
1853 #ifdef md_optimize_expr
1854 if (md_optimize_expr (resultP
, op_left
, &right
))
1861 #ifndef md_register_arithmetic
1862 # define md_register_arithmetic 1
1864 if (op_left
== O_add
&& right
.X_op
== O_constant
1865 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1868 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1870 /* This case comes up in PIC code. */
1871 else if (op_left
== O_subtract
1872 && right
.X_op
== O_symbol
1873 && resultP
->X_op
== O_symbol
1874 && retval
== rightseg
1875 #ifdef md_allow_local_subtract
1876 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1878 && ((SEG_NORMAL (rightseg
)
1879 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1880 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1881 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1882 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1883 symbol_get_frag (right
.X_add_symbol
),
1886 offsetT symval_diff
= S_GET_VALUE (resultP
->X_add_symbol
)
1887 - S_GET_VALUE (right
.X_add_symbol
);
1888 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1889 subtract_from_result (resultP
, frag_off
/ OCTETS_PER_BYTE
, 0);
1890 add_to_result (resultP
, symval_diff
, symval_diff
< 0);
1891 resultP
->X_op
= O_constant
;
1892 resultP
->X_add_symbol
= 0;
1894 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1895 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1898 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1900 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1901 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1904 resultP
->X_op
= right
.X_op
;
1905 resultP
->X_add_symbol
= right
.X_add_symbol
;
1906 resultP
->X_op_symbol
= right
.X_op_symbol
;
1907 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1910 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1912 /* Constant OP constant. */
1913 offsetT v
= right
.X_add_number
;
1914 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1916 as_warn (_("division by zero"));
1919 if ((valueT
) v
>= sizeof(valueT
) * CHAR_BIT
1920 && (op_left
== O_left_shift
|| op_left
== O_right_shift
))
1922 as_warn_value_out_of_range (_("shift count"), v
, 0,
1923 sizeof(valueT
) * CHAR_BIT
- 1,
1925 resultP
->X_add_number
= v
= 0;
1929 default: goto general
;
1930 case O_multiply
: resultP
->X_add_number
*= v
; break;
1931 case O_divide
: resultP
->X_add_number
/= v
; break;
1932 case O_modulus
: resultP
->X_add_number
%= v
; break;
1933 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1935 /* We always use unsigned shifts, to avoid relying on
1936 characteristics of the compiler used to compile gas. */
1937 resultP
->X_add_number
=
1938 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1940 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1941 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1942 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1943 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1944 /* Constant + constant (O_add) is handled by the
1945 previous if statement for constant + X, so is omitted
1948 subtract_from_result (resultP
, v
, 0);
1951 resultP
->X_add_number
=
1952 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1955 resultP
->X_add_number
=
1956 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1959 resultP
->X_add_number
=
1960 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1963 resultP
->X_add_number
=
1964 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1967 resultP
->X_add_number
=
1968 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1971 resultP
->X_add_number
=
1972 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1975 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1978 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1982 else if (resultP
->X_op
== O_symbol
1983 && right
.X_op
== O_symbol
1984 && (op_left
== O_add
1985 || op_left
== O_subtract
1986 || (resultP
->X_add_number
== 0
1987 && right
.X_add_number
== 0)))
1989 /* Symbol OP symbol. */
1990 resultP
->X_op
= op_left
;
1991 resultP
->X_op_symbol
= right
.X_add_symbol
;
1992 if (op_left
== O_add
)
1993 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1994 else if (op_left
== O_subtract
)
1996 subtract_from_result (resultP
, right
.X_add_number
,
1998 if (retval
== rightseg
1999 && SEG_NORMAL (retval
)
2000 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
2001 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
2003 retval
= absolute_section
;
2004 rightseg
= absolute_section
;
2011 /* The general case. */
2012 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
2013 resultP
->X_op_symbol
= make_expr_symbol (&right
);
2014 resultP
->X_op
= op_left
;
2015 resultP
->X_add_number
= 0;
2016 resultP
->X_unsigned
= 1;
2017 resultP
->X_extrabit
= 0;
2020 if (retval
!= rightseg
)
2022 if (retval
== undefined_section
)
2024 else if (rightseg
== undefined_section
)
2026 else if (retval
== expr_section
)
2028 else if (rightseg
== expr_section
)
2030 else if (retval
== reg_section
)
2032 else if (rightseg
== reg_section
)
2034 else if (rightseg
== absolute_section
)
2036 else if (retval
== absolute_section
)
2039 else if (op_left
== O_subtract
)
2043 as_bad (_("operation combines symbols in different segments"));
2047 } /* While next operator is >= this rank. */
2049 /* The PA port needs this information. */
2050 if (resultP
->X_add_symbol
)
2051 symbol_mark_used (resultP
->X_add_symbol
);
2053 if (rank
== 0 && mode
== expr_evaluate
)
2054 resolve_expression (resultP
);
2056 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
2059 /* Resolve an expression without changing any symbols/sub-expressions
2063 resolve_expression (expressionS
*expressionP
)
2065 /* Help out with CSE. */
2066 valueT final_val
= expressionP
->X_add_number
;
2067 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
2068 symbolS
*orig_add_symbol
= add_symbol
;
2069 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
2070 operatorT op
= expressionP
->X_op
;
2072 segT seg_left
, seg_right
;
2073 fragS
*frag_left
, *frag_right
;
2088 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2096 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2099 if (seg_left
!= absolute_section
)
2102 if (op
== O_logical_not
)
2104 else if (op
== O_uminus
)
2116 case O_bit_inclusive_or
:
2118 case O_bit_exclusive_or
:
2130 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
2131 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
2134 /* Simplify addition or subtraction of a constant by folding the
2135 constant into X_add_number. */
2138 if (seg_right
== absolute_section
)
2144 else if (seg_left
== absolute_section
)
2148 seg_left
= seg_right
;
2149 add_symbol
= op_symbol
;
2150 orig_add_symbol
= expressionP
->X_op_symbol
;
2155 else if (op
== O_subtract
)
2157 if (seg_right
== absolute_section
)
2165 /* Equality and non-equality tests are permitted on anything.
2166 Subtraction, and other comparison operators are permitted if
2167 both operands are in the same section.
2168 Shifts by constant zero are permitted on anything.
2169 Multiplies, bit-ors, and bit-ands with constant zero are
2170 permitted on anything.
2171 Multiplies and divides by constant one are permitted on
2173 Binary operations with both operands being the same register
2174 or undefined symbol are permitted if the result doesn't depend
2176 Otherwise, both operands must be absolute. We already handled
2177 the case of addition or subtraction of a constant above. */
2179 if (!(seg_left
== absolute_section
2180 && seg_right
== absolute_section
)
2181 && !(op
== O_eq
|| op
== O_ne
)
2182 && !((op
== O_subtract
2183 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2184 && seg_left
== seg_right
2186 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
))
2187 && (seg_left
!= reg_section
|| left
== right
)
2188 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2190 if ((seg_left
== absolute_section
&& left
== 0)
2191 || (seg_right
== absolute_section
&& right
== 0))
2193 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2195 if (!(seg_right
== absolute_section
&& right
== 0))
2197 seg_left
= seg_right
;
2199 add_symbol
= op_symbol
;
2200 orig_add_symbol
= expressionP
->X_op_symbol
;
2205 else if (op
== O_left_shift
|| op
== O_right_shift
)
2207 if (!(seg_left
== absolute_section
&& left
== 0))
2213 else if (op
!= O_multiply
2214 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2217 else if (op
== O_multiply
2218 && seg_left
== absolute_section
&& left
== 1)
2220 seg_left
= seg_right
;
2222 add_symbol
= op_symbol
;
2223 orig_add_symbol
= expressionP
->X_op_symbol
;
2227 else if ((op
== O_multiply
|| op
== O_divide
)
2228 && seg_right
== absolute_section
&& right
== 1)
2233 else if (!(left
== right
2234 && ((seg_left
== reg_section
&& seg_right
== reg_section
)
2235 || (seg_left
== undefined_section
2236 && seg_right
== undefined_section
2237 && add_symbol
== op_symbol
))))
2239 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2244 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2248 right
+= frag_off
/ OCTETS_PER_BYTE
;
2251 case O_add
: left
+= right
; break;
2252 case O_subtract
: left
-= right
; break;
2253 case O_multiply
: left
*= right
; break;
2257 left
= (offsetT
) left
/ (offsetT
) right
;
2262 left
= (offsetT
) left
% (offsetT
) right
;
2264 case O_left_shift
: left
<<= right
; break;
2265 case O_right_shift
: left
>>= right
; break;
2266 case O_bit_inclusive_or
: left
|= right
; break;
2267 case O_bit_or_not
: left
|= ~right
; break;
2268 case O_bit_exclusive_or
: left
^= right
; break;
2269 case O_bit_and
: left
&= right
; break;
2272 left
= (left
== right
2273 && seg_left
== seg_right
2274 && (finalize_syms
|| frag_left
== frag_right
)
2275 && (seg_left
!= undefined_section
2276 || add_symbol
== op_symbol
)
2277 ? ~ (valueT
) 0 : 0);
2282 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2285 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2288 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2291 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2293 case O_logical_and
: left
= left
&& right
; break;
2294 case O_logical_or
: left
= left
|| right
; break;
2304 if (seg_left
== absolute_section
)
2306 else if (seg_left
== reg_section
&& final_val
== 0)
2308 else if (!symbol_same_p (add_symbol
, orig_add_symbol
))
2310 expressionP
->X_add_symbol
= add_symbol
;
2312 expressionP
->X_op
= op
;
2314 if (op
== O_constant
|| op
== O_register
)
2316 expressionP
->X_add_number
= final_val
;
2321 /* This lives here because it belongs equally in expr.c & read.c.
2322 expr.c is just a branch office read.c anyway, and putting it
2323 here lessens the crowd at read.c.
2325 Assume input_line_pointer is at start of symbol name, or the
2326 start of a double quote enclosed symbol name.
2327 Advance input_line_pointer past symbol name.
2328 Turn that character into a '\0', returning its former value,
2329 which may be the closing double quote.
2330 This allows a string compare (RMS wants symbol names to be strings)
2332 There will always be a char following symbol name, because all good
2333 lines end in end-of-line. */
2336 get_symbol_name (char ** ilp_return
)
2340 * ilp_return
= input_line_pointer
;
2341 /* We accept \001 in a name in case this is being called with a
2342 constructed string. */
2343 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2345 while (is_part_of_name (c
= *input_line_pointer
++)
2348 if (is_name_ender (c
))
2349 c
= *input_line_pointer
++;
2353 bfd_boolean backslash_seen
;
2355 * ilp_return
= input_line_pointer
;
2358 backslash_seen
= c
== '\\';
2359 c
= * input_line_pointer
++;
2361 while (c
!= 0 && (c
!= '"' || backslash_seen
));
2364 as_warn (_("missing closing '\"'"));
2366 *--input_line_pointer
= 0;
2370 /* Replace the NUL character pointed to by input_line_pointer
2371 with C. If C is \" then advance past it. Return the character
2372 now pointed to by input_line_pointer. */
2375 restore_line_pointer (char c
)
2377 * input_line_pointer
= c
;
2379 c
= * ++ input_line_pointer
;
2384 get_single_number (void)
2387 operand (&exp
, expr_normal
);
2388 return exp
.X_add_number
;