1 /* expr.c -operands, expressions-
2 Copyright (C) 1987-2014 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 extern const char EXP_CHARS
[], FLT_CHARS
[];
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
= (struct expr_symbol_line
*) xmalloc (sizeof *n
);
113 as_where (&n
->file
, &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
, 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 ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
292 /* In MRI mode, the number may have a suffix indicating the
293 radix. For that matter, it might actually be a floating
295 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
297 if (*suffix
== 'e' || *suffix
== 'E')
301 if (suffix
== input_line_pointer
)
310 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
311 we distinguish between 'B' and 'b'. This is the case for
313 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
317 else if (c
== 'O' || c
== 'Q')
321 else if (suffix
[1] == '.' || c
== 'E' || flt
)
323 floating_constant (expressionP
);
338 too_many_digits
= valuesize
+ 1;
342 too_many_digits
= (valuesize
+ 2) / 3 + 1;
346 too_many_digits
= (valuesize
+ 3) / 4 + 1;
350 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
353 start
= input_line_pointer
;
354 c
= *input_line_pointer
++;
356 (digit
= hex_value (c
)) < maxdig
;
357 c
= *input_line_pointer
++)
359 number
= number
* radix
+ digit
;
361 /* c contains character after number. */
362 /* input_line_pointer->char after c. */
363 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
365 if (radix
== 16 && c
== '_')
367 /* This is literal of the form 0x333_0_12345678_1.
368 This example is equivalent to 0x00000333000000001234567800000001. */
370 int num_little_digits
= 0;
372 input_line_pointer
= start
; /* -> 1st digit. */
374 know (LITTLENUM_NUMBER_OF_BITS
== 16);
376 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
379 /* Convert one 64-bit word. */
382 for (c
= *input_line_pointer
++;
383 (digit
= hex_value (c
)) < maxdig
;
384 c
= *(input_line_pointer
++))
386 number
= number
* radix
+ digit
;
390 /* Check for 8 digit per word max. */
392 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
394 /* Add this chunk to the bignum.
395 Shift things down 2 little digits. */
396 know (LITTLENUM_NUMBER_OF_BITS
== 16);
397 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
400 generic_bignum
[i
] = generic_bignum
[i
- 2];
402 /* Add the new digits as the least significant new ones. */
403 generic_bignum
[0] = number
& 0xffffffff;
404 generic_bignum
[1] = number
>> 16;
407 /* Again, c is char after number, input_line_pointer->after c. */
409 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
410 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
412 gas_assert (num_little_digits
>= 4);
414 if (num_little_digits
!= 8)
415 as_bad (_("a bignum with underscores must have exactly 4 words"));
417 /* We might have some leading zeros. These can be trimmed to give
418 us a change to fit this constant into a small number. */
419 while (generic_bignum
[num_little_digits
- 1] == 0
420 && num_little_digits
> 1)
423 if (num_little_digits
<= 2)
425 /* will fit into 32 bits. */
426 number
= generic_bignum_to_int32 ();
430 else if (num_little_digits
<= 4)
432 /* Will fit into 64 bits. */
433 number
= generic_bignum_to_int64 ();
441 /* Number of littlenums in the bignum. */
442 number
= num_little_digits
;
447 /* We saw a lot of digits. manufacture a bignum the hard way. */
448 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
449 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
452 leader
= generic_bignum
;
453 generic_bignum
[0] = 0;
454 generic_bignum
[1] = 0;
455 generic_bignum
[2] = 0;
456 generic_bignum
[3] = 0;
457 input_line_pointer
= start
; /* -> 1st digit. */
458 c
= *input_line_pointer
++;
459 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
461 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
465 work
= carry
+ radix
* *pointer
;
466 *pointer
= work
& LITTLENUM_MASK
;
467 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
471 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
473 /* Room to grow a longer bignum. */
478 /* Again, c is char after number. */
479 /* input_line_pointer -> after c. */
480 know (LITTLENUM_NUMBER_OF_BITS
== 16);
481 if (leader
< generic_bignum
+ 2)
483 /* Will fit into 32 bits. */
484 number
= generic_bignum_to_int32 ();
488 else if (leader
< generic_bignum
+ 4)
490 /* Will fit into 64 bits. */
491 number
= generic_bignum_to_int64 ();
497 /* Number of littlenums in the bignum. */
498 number
= leader
- generic_bignum
+ 1;
502 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
504 && input_line_pointer
- 1 == suffix
)
505 c
= *input_line_pointer
++;
509 /* Here with number, in correct radix. c is the next char.
510 Note that unlike un*x, we allow "011f" "0x9f" to both mean
511 the same as the (conventional) "9f".
512 This is simply easier than checking for strict canonical
515 if (LOCAL_LABELS_FB
&& c
== 'b')
517 /* Backward ref to local label.
518 Because it is backward, expect it to be defined. */
519 /* Construct a local label. */
520 name
= fb_label_name ((int) number
, 0);
522 /* Seen before, or symbol is defined: OK. */
523 symbolP
= symbol_find (name
);
524 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
526 /* Local labels are never absolute. Don't waste time
527 checking absoluteness. */
528 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
530 expressionP
->X_op
= O_symbol
;
531 expressionP
->X_add_symbol
= symbolP
;
535 /* Either not seen or not defined. */
536 /* @@ Should print out the original string instead of
537 the parsed number. */
538 as_bad (_("backward ref to unknown label \"%d:\""),
540 expressionP
->X_op
= O_constant
;
543 expressionP
->X_add_number
= 0;
545 else if (LOCAL_LABELS_FB
&& c
== 'f')
547 /* Forward reference. Expect symbol to be undefined or
548 unknown. undefined: seen it before. unknown: never seen
551 Construct a local label name, then an undefined symbol.
552 Don't create a xseg frag for it: caller may do that.
553 Just return it as never seen before. */
554 name
= fb_label_name ((int) number
, 1);
555 symbolP
= symbol_find_or_make (name
);
556 /* We have no need to check symbol properties. */
557 #ifndef many_segments
558 /* Since "know" puts its arg into a "string", we
559 can't have newlines in the argument. */
560 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
562 expressionP
->X_op
= O_symbol
;
563 expressionP
->X_add_symbol
= symbolP
;
564 expressionP
->X_add_number
= 0;
566 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
568 /* If the dollar label is *currently* defined, then this is just
569 another reference to it. If it is not *currently* defined,
570 then this is a fresh instantiation of that number, so create
573 if (dollar_label_defined ((long) number
))
575 name
= dollar_label_name ((long) number
, 0);
576 symbolP
= symbol_find (name
);
577 know (symbolP
!= NULL
);
581 name
= dollar_label_name ((long) number
, 1);
582 symbolP
= symbol_find_or_make (name
);
585 expressionP
->X_op
= O_symbol
;
586 expressionP
->X_add_symbol
= symbolP
;
587 expressionP
->X_add_number
= 0;
591 expressionP
->X_op
= O_constant
;
592 expressionP
->X_add_number
= number
;
593 input_line_pointer
--; /* Restore following character. */
594 } /* Really just a number. */
598 /* Not a small number. */
599 expressionP
->X_op
= O_big
;
600 expressionP
->X_add_number
= number
; /* Number of littlenums. */
601 input_line_pointer
--; /* -> char following number. */
605 /* Parse an MRI multi character constant. */
608 mri_char_constant (expressionS
*expressionP
)
612 if (*input_line_pointer
== '\''
613 && input_line_pointer
[1] != '\'')
615 expressionP
->X_op
= O_constant
;
616 expressionP
->X_add_number
= 0;
620 /* In order to get the correct byte ordering, we must build the
621 number in reverse. */
622 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
626 generic_bignum
[i
] = 0;
627 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
629 if (*input_line_pointer
== '\'')
631 if (input_line_pointer
[1] != '\'')
633 ++input_line_pointer
;
635 generic_bignum
[i
] <<= 8;
636 generic_bignum
[i
] += *input_line_pointer
;
637 ++input_line_pointer
;
640 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
642 /* If there is more than one littlenum, left justify the
643 last one to make it match the earlier ones. If there is
644 only one, we can just use the value directly. */
645 for (; j
< CHARS_PER_LITTLENUM
; j
++)
646 generic_bignum
[i
] <<= 8;
649 if (*input_line_pointer
== '\''
650 && input_line_pointer
[1] != '\'')
656 as_bad (_("character constant too large"));
665 c
= SIZE_OF_LARGE_NUMBER
- i
;
666 for (j
= 0; j
< c
; j
++)
667 generic_bignum
[j
] = generic_bignum
[i
+ j
];
671 know (LITTLENUM_NUMBER_OF_BITS
== 16);
674 expressionP
->X_op
= O_big
;
675 expressionP
->X_add_number
= i
;
679 expressionP
->X_op
= O_constant
;
681 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
683 expressionP
->X_add_number
=
684 (((generic_bignum
[1] & LITTLENUM_MASK
)
685 << LITTLENUM_NUMBER_OF_BITS
)
686 | (generic_bignum
[0] & LITTLENUM_MASK
));
689 /* Skip the final closing quote. */
690 ++input_line_pointer
;
693 /* Return an expression representing the current location. This
694 handles the magic symbol `.'. */
697 current_location (expressionS
*expressionp
)
699 if (now_seg
== absolute_section
)
701 expressionp
->X_op
= O_constant
;
702 expressionp
->X_add_number
= abs_section_offset
;
706 expressionp
->X_op
= O_symbol
;
707 expressionp
->X_add_symbol
= &dot_symbol
;
708 expressionp
->X_add_number
= 0;
712 /* In: Input_line_pointer points to 1st char of operand, which may
716 The operand may have been empty: in this case X_op == O_absent.
717 Input_line_pointer->(next non-blank) char after operand. */
720 operand (expressionS
*expressionP
, enum expr_mode mode
)
723 symbolS
*symbolP
; /* Points to symbol. */
724 char *name
; /* Points to name of symbol. */
727 /* All integers are regarded as unsigned unless they are negated.
728 This is because the only thing which cares whether a number is
729 unsigned is the code in emit_expr which extends constants into
730 bignums. It should only sign extend negative numbers, so that
731 something like ``.quad 0x80000000'' is not sign extended even
732 though it appears negative if valueT is 32 bits. */
733 expressionP
->X_unsigned
= 1;
734 expressionP
->X_extrabit
= 0;
736 /* Digits, assume it is a bignum. */
738 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
739 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
741 if (is_end_of_line
[(unsigned char) c
])
755 input_line_pointer
--;
757 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
762 #ifdef LITERAL_PREFIXDOLLAR_HEX
764 /* $L is the start of a local label, not a hex constant. */
765 if (* input_line_pointer
== 'L')
767 integer_constant (16, expressionP
);
771 #ifdef LITERAL_PREFIXPERCENT_BIN
773 integer_constant (2, expressionP
);
778 /* Non-decimal radix. */
780 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
784 /* Check for a hex or float constant. */
785 for (s
= input_line_pointer
; hex_p (*s
); s
++)
787 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
789 --input_line_pointer
;
790 integer_constant (0, expressionP
);
794 c
= *input_line_pointer
;
803 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
805 integer_constant (0, expressionP
);
811 if (c
&& strchr (FLT_CHARS
, c
))
813 input_line_pointer
++;
814 floating_constant (expressionP
);
815 expressionP
->X_add_number
= - TOLOWER (c
);
819 /* The string was only zero. */
820 expressionP
->X_op
= O_constant
;
821 expressionP
->X_add_number
= 0;
830 input_line_pointer
++;
831 integer_constant (16, expressionP
);
835 if (LOCAL_LABELS_FB
&& ! (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
))
837 /* This code used to check for '+' and '-' here, and, in
838 some conditions, fall through to call
839 integer_constant. However, that didn't make sense,
840 as integer_constant only accepts digits. */
841 /* Some of our code elsewhere does permit digits greater
842 than the expected base; for consistency, do the same
844 if (input_line_pointer
[1] < '0'
845 || input_line_pointer
[1] > '9')
847 /* Parse this as a back reference to label 0. */
848 input_line_pointer
--;
849 integer_constant (10, expressionP
);
852 /* Otherwise, parse this as a binary number. */
856 input_line_pointer
++;
857 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
859 integer_constant (2, expressionP
);
870 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
878 /* If it says "0f" and it could possibly be a floating point
879 number, make it one. Otherwise, make it a local label,
880 and try to deal with parsing the rest later. */
881 if (!input_line_pointer
[1]
882 || (is_end_of_line
[0xff & input_line_pointer
[1]])
883 || strchr (FLT_CHARS
, 'f') == NULL
)
886 char *cp
= input_line_pointer
+ 1;
887 int r
= atof_generic (&cp
, ".", EXP_CHARS
,
888 &generic_floating_point_number
);
892 case ERROR_EXPONENT_OVERFLOW
:
893 if (*cp
== 'f' || *cp
== 'b')
894 /* Looks like a difference expression. */
896 else if (cp
== input_line_pointer
+ 1)
897 /* No characters has been accepted -- looks like
903 as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
908 /* Okay, now we've sorted it out. We resume at one of these
909 two labels, depending on what we've decided we're probably
912 input_line_pointer
--;
913 integer_constant (10, expressionP
);
923 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
925 integer_constant (0, expressionP
);
935 input_line_pointer
++;
936 floating_constant (expressionP
);
937 expressionP
->X_add_number
= - TOLOWER (c
);
941 if (LOCAL_LABELS_DOLLAR
)
943 integer_constant (10, expressionP
);
952 #ifndef NEED_INDEX_OPERATOR
954 # ifdef md_need_index_operator
955 if (md_need_index_operator())
961 /* Didn't begin with digit & not a name. */
962 segment
= expr (0, expressionP
, mode
);
963 /* expression () will pass trailing whitespace. */
964 if ((c
== '(' && *input_line_pointer
!= ')')
965 || (c
== '[' && *input_line_pointer
!= ']'))
966 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 name
= input_line_pointer
;
1157 c
= get_symbol_end ();
1159 buf
= (char *) xmalloc (strlen (name
) + 10);
1161 sprintf (buf
, ".startof.%s", name
);
1163 sprintf (buf
, ".sizeof.%s", name
);
1164 symbolP
= symbol_make (buf
);
1167 expressionP
->X_op
= O_symbol
;
1168 expressionP
->X_add_symbol
= symbolP
;
1169 expressionP
->X_add_number
= 0;
1171 *input_line_pointer
= c
;
1173 if (*input_line_pointer
!= ')')
1174 as_bad (_("syntax error in .startof. or .sizeof."));
1176 ++input_line_pointer
;
1187 /* Can't imagine any other kind of operand. */
1188 expressionP
->X_op
= O_absent
;
1189 input_line_pointer
--;
1194 if (! flag_m68k_mri
)
1196 integer_constant (2, expressionP
);
1200 if (! flag_m68k_mri
)
1202 integer_constant (8, expressionP
);
1206 if (! flag_m68k_mri
)
1209 /* In MRI mode, this is a floating point constant represented
1210 using hexadecimal digits. */
1212 ++input_line_pointer
;
1213 integer_constant (16, expressionP
);
1217 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1220 current_location (expressionP
);
1225 #if defined(md_need_index_operator) || defined(TC_M68K)
1228 if (is_name_beginner (c
)) /* Here if did not begin with a digit. */
1230 /* Identifier begins here.
1231 This is kludged for speed, so code is repeated. */
1233 name
= --input_line_pointer
;
1234 c
= get_symbol_end ();
1238 operatorT op
= md_operator (name
, 1, &c
);
1243 *input_line_pointer
= c
;
1247 *input_line_pointer
= c
;
1251 *input_line_pointer
= c
;
1255 as_bad (_("invalid use of operator \"%s\""), name
);
1260 if (op
!= O_absent
&& op
!= O_illegal
)
1262 *input_line_pointer
= c
;
1263 expr (9, expressionP
, mode
);
1264 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1265 expressionP
->X_op_symbol
= NULL
;
1266 expressionP
->X_add_number
= 0;
1267 expressionP
->X_op
= op
;
1273 #ifdef md_parse_name
1274 /* This is a hook for the backend to parse certain names
1275 specially in certain contexts. If a name always has a
1276 specific value, it can often be handled by simply
1277 entering it in the symbol table. */
1278 if (md_parse_name (name
, expressionP
, mode
, &c
))
1280 *input_line_pointer
= c
;
1286 /* The MRI i960 assembler permits
1288 FIXME: This should use md_parse_name. */
1290 && (strcasecmp (name
, "sizeof") == 0
1291 || strcasecmp (name
, "startof") == 0))
1296 start
= (name
[1] == 't'
1299 *input_line_pointer
= c
;
1302 name
= input_line_pointer
;
1303 c
= get_symbol_end ();
1305 buf
= (char *) xmalloc (strlen (name
) + 10);
1307 sprintf (buf
, ".startof.%s", name
);
1309 sprintf (buf
, ".sizeof.%s", name
);
1310 symbolP
= symbol_make (buf
);
1313 expressionP
->X_op
= O_symbol
;
1314 expressionP
->X_add_symbol
= symbolP
;
1315 expressionP
->X_add_number
= 0;
1317 *input_line_pointer
= c
;
1324 symbolP
= symbol_find_or_make (name
);
1326 /* If we have an absolute symbol or a reg, then we know its
1328 segment
= S_GET_SEGMENT (symbolP
);
1329 if (mode
!= expr_defer
1330 && segment
== absolute_section
1331 && !S_FORCE_RELOC (symbolP
, 0))
1333 expressionP
->X_op
= O_constant
;
1334 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1336 else if (mode
!= expr_defer
&& segment
== reg_section
)
1338 expressionP
->X_op
= O_register
;
1339 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1343 expressionP
->X_op
= O_symbol
;
1344 expressionP
->X_add_symbol
= symbolP
;
1345 expressionP
->X_add_number
= 0;
1347 *input_line_pointer
= c
;
1351 /* Let the target try to parse it. Success is indicated by changing
1352 the X_op field to something other than O_absent and pointing
1353 input_line_pointer past the expression. If it can't parse the
1354 expression, X_op and input_line_pointer should be unchanged. */
1355 expressionP
->X_op
= O_absent
;
1356 --input_line_pointer
;
1357 md_operand (expressionP
);
1358 if (expressionP
->X_op
== O_absent
)
1360 ++input_line_pointer
;
1361 as_bad (_("bad expression"));
1362 expressionP
->X_op
= O_constant
;
1363 expressionP
->X_add_number
= 0;
1369 /* It is more 'efficient' to clean up the expressionS when they are
1370 created. Doing it here saves lines of code. */
1371 clean_up_expression (expressionP
);
1372 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1373 know (*input_line_pointer
!= ' ');
1375 /* The PA port needs this information. */
1376 if (expressionP
->X_add_symbol
)
1377 symbol_mark_used (expressionP
->X_add_symbol
);
1379 if (mode
!= expr_defer
)
1381 expressionP
->X_add_symbol
1382 = symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1383 expressionP
->X_op_symbol
1384 = symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1387 switch (expressionP
->X_op
)
1390 return absolute_section
;
1392 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1398 /* Internal. Simplify a struct expression for use by expr (). */
1400 /* In: address of an expressionS.
1401 The X_op field of the expressionS may only take certain values.
1402 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1404 Out: expressionS may have been modified:
1405 Unused fields zeroed to help expr (). */
1408 clean_up_expression (expressionS
*expressionP
)
1410 switch (expressionP
->X_op
)
1414 expressionP
->X_add_number
= 0;
1419 expressionP
->X_add_symbol
= NULL
;
1424 expressionP
->X_op_symbol
= NULL
;
1431 /* Expression parser. */
1433 /* We allow an empty expression, and just assume (absolute,0) silently.
1434 Unary operators and parenthetical expressions are treated as operands.
1435 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1437 We used to do an aho/ullman shift-reduce parser, but the logic got so
1438 warped that I flushed it and wrote a recursive-descent parser instead.
1439 Now things are stable, would anybody like to write a fast parser?
1440 Most expressions are either register (which does not even reach here)
1441 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1442 So I guess it doesn't really matter how inefficient more complex expressions
1445 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1446 Also, we have consumed any leading or trailing spaces (operand does that)
1447 and done all intervening operators.
1449 This returns the segment of the result, which will be
1450 absolute_section or the segment of a symbol. */
1453 #define __ O_illegal
1455 #define O_SINGLE_EQ O_illegal
1458 /* Maps ASCII -> operators. */
1459 static const operatorT op_encoding
[256] = {
1460 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1461 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1463 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1464 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1465 __
, __
, __
, __
, __
, __
, __
, __
,
1466 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1467 __
, __
, __
, __
, __
, __
, __
, __
,
1468 __
, __
, __
, __
, __
, __
, __
, __
,
1469 __
, __
, __
, __
, __
, __
, __
, __
,
1471 #ifdef NEED_INDEX_OPERATOR
1476 __
, __
, O_bit_exclusive_or
, __
,
1477 __
, __
, __
, __
, __
, __
, __
, __
,
1478 __
, __
, __
, __
, __
, __
, __
, __
,
1479 __
, __
, __
, __
, __
, __
, __
, __
,
1480 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1482 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1483 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1484 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1485 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1486 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1487 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1488 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1489 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1493 0 operand, (expression)
1498 5 used for * / % in MRI mode
1503 static operator_rankT op_rank
[O_max
] = {
1508 0, /* O_symbol_rva */
1513 9, /* O_logical_not */
1517 8, /* O_left_shift */
1518 8, /* O_right_shift */
1519 7, /* O_bit_inclusive_or */
1520 7, /* O_bit_or_not */
1521 7, /* O_bit_exclusive_or */
1531 3, /* O_logical_and */
1532 2, /* O_logical_or */
1536 /* Unfortunately, in MRI mode for the m68k, multiplication and
1537 division have lower precedence than the bit wise operators. This
1538 function sets the operator precedences correctly for the current
1539 mode. Also, MRI uses a different bit_not operator, and this fixes
1542 #define STANDARD_MUL_PRECEDENCE 8
1543 #define MRI_MUL_PRECEDENCE 6
1546 expr_set_precedence (void)
1550 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1551 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1552 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1556 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1557 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1558 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1563 expr_set_rank (operatorT op
, operator_rankT rank
)
1565 gas_assert (op
>= O_md1
&& op
< ARRAY_SIZE (op_rank
));
1569 /* Initialize the expression parser. */
1574 expr_set_precedence ();
1576 /* Verify that X_op field is wide enough. */
1580 gas_assert (e
.X_op
== O_max
);
1584 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1585 sets NUM_CHARS to the number of characters in the operator.
1586 Does not advance INPUT_LINE_POINTER. */
1588 static inline operatorT
1589 operatorf (int *num_chars
)
1594 c
= *input_line_pointer
& 0xff;
1597 if (is_end_of_line
[c
])
1601 if (is_name_beginner (c
))
1603 char *name
= input_line_pointer
;
1604 char ec
= get_symbol_end ();
1606 ret
= md_operator (name
, 2, &ec
);
1610 *input_line_pointer
= ec
;
1611 input_line_pointer
= name
;
1616 as_bad (_("invalid use of operator \"%s\""), name
);
1620 *input_line_pointer
= ec
;
1621 *num_chars
= input_line_pointer
- name
;
1622 input_line_pointer
= name
;
1631 ret
= op_encoding
[c
];
1633 if (ret
== O_illegal
)
1635 char *start
= input_line_pointer
;
1637 ret
= md_operator (NULL
, 2, NULL
);
1638 if (ret
!= O_illegal
)
1639 *num_chars
= input_line_pointer
- start
;
1640 input_line_pointer
= start
;
1647 return op_encoding
[c
];
1650 switch (input_line_pointer
[1])
1653 return op_encoding
[c
];
1668 if (input_line_pointer
[1] != '=')
1669 return op_encoding
[c
];
1675 switch (input_line_pointer
[1])
1678 return op_encoding
[c
];
1680 ret
= O_right_shift
;
1690 switch (input_line_pointer
[1])
1693 /* We accept !! as equivalent to ^ for MRI compatibility. */
1695 return O_bit_exclusive_or
;
1697 /* We accept != as equivalent to <>. */
1702 return O_bit_inclusive_or
;
1703 return op_encoding
[c
];
1707 if (input_line_pointer
[1] != '|')
1708 return op_encoding
[c
];
1711 return O_logical_or
;
1714 if (input_line_pointer
[1] != '&')
1715 return op_encoding
[c
];
1718 return O_logical_and
;
1724 /* Implement "word-size + 1 bit" addition for
1725 {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}. This
1726 is used so that the full range of unsigned word values and the full range of
1727 signed word values can be represented in an O_constant expression, which is
1728 useful e.g. for .sleb128 directives. */
1731 add_to_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1733 valueT ures
= resultP
->X_add_number
;
1734 valueT uamount
= amount
;
1736 resultP
->X_add_number
+= amount
;
1738 resultP
->X_extrabit
^= rhs_highbit
;
1740 if (ures
+ uamount
< ures
)
1741 resultP
->X_extrabit
^= 1;
1744 /* Similarly, for subtraction. */
1747 subtract_from_result (expressionS
*resultP
, offsetT amount
, int rhs_highbit
)
1749 valueT ures
= resultP
->X_add_number
;
1750 valueT uamount
= amount
;
1752 resultP
->X_add_number
-= amount
;
1754 resultP
->X_extrabit
^= rhs_highbit
;
1757 resultP
->X_extrabit
^= 1;
1760 /* Parse an expression. */
1763 expr (int rankarg
, /* Larger # is higher rank. */
1764 expressionS
*resultP
, /* Deliver result here. */
1765 enum expr_mode mode
/* Controls behavior. */)
1767 operator_rankT rank
= (operator_rankT
) rankarg
;
1774 know (rankarg
>= 0);
1776 /* Save the value of dot for the fixup code. */
1779 dot_value
= frag_now_fix ();
1780 dot_frag
= frag_now
;
1783 retval
= operand (resultP
, mode
);
1785 /* operand () gobbles spaces. */
1786 know (*input_line_pointer
!= ' ');
1788 op_left
= operatorf (&op_chars
);
1789 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1794 input_line_pointer
+= op_chars
; /* -> after operator. */
1797 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1798 if (right
.X_op
== O_absent
)
1800 as_warn (_("missing operand; zero assumed"));
1801 right
.X_op
= O_constant
;
1802 right
.X_add_number
= 0;
1803 right
.X_add_symbol
= NULL
;
1804 right
.X_op_symbol
= NULL
;
1807 know (*input_line_pointer
!= ' ');
1809 if (op_left
== O_index
)
1811 if (*input_line_pointer
!= ']')
1812 as_bad ("missing right bracket");
1815 ++input_line_pointer
;
1820 op_right
= operatorf (&op_chars
);
1822 know (op_right
== O_illegal
|| op_left
== O_index
1823 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1824 know ((int) op_left
>= (int) O_multiply
);
1826 know ((int) op_left
<= (int) O_index
);
1828 know ((int) op_left
< (int) O_max
);
1831 /* input_line_pointer->after right-hand quantity. */
1832 /* left-hand quantity in resultP. */
1833 /* right-hand quantity in right. */
1834 /* operator in op_left. */
1836 if (resultP
->X_op
== O_big
)
1838 if (resultP
->X_add_number
> 0)
1839 as_warn (_("left operand is a bignum; integer 0 assumed"));
1841 as_warn (_("left operand is a float; integer 0 assumed"));
1842 resultP
->X_op
= O_constant
;
1843 resultP
->X_add_number
= 0;
1844 resultP
->X_add_symbol
= NULL
;
1845 resultP
->X_op_symbol
= NULL
;
1847 if (right
.X_op
== O_big
)
1849 if (right
.X_add_number
> 0)
1850 as_warn (_("right operand is a bignum; integer 0 assumed"));
1852 as_warn (_("right operand is a float; integer 0 assumed"));
1853 right
.X_op
= O_constant
;
1854 right
.X_add_number
= 0;
1855 right
.X_add_symbol
= NULL
;
1856 right
.X_op_symbol
= NULL
;
1859 /* Optimize common cases. */
1860 #ifdef md_optimize_expr
1861 if (md_optimize_expr (resultP
, op_left
, &right
))
1868 #ifndef md_register_arithmetic
1869 # define md_register_arithmetic 1
1871 if (op_left
== O_add
&& right
.X_op
== O_constant
1872 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1875 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1877 /* This case comes up in PIC code. */
1878 else if (op_left
== O_subtract
1879 && right
.X_op
== O_symbol
1880 && resultP
->X_op
== O_symbol
1881 && retval
== rightseg
1882 #ifdef md_allow_local_subtract
1883 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1885 && ((SEG_NORMAL (rightseg
)
1886 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1887 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1888 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1889 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1890 symbol_get_frag (right
.X_add_symbol
),
1893 offsetT symval_diff
= S_GET_VALUE (resultP
->X_add_symbol
)
1894 - S_GET_VALUE (right
.X_add_symbol
);
1895 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1896 subtract_from_result (resultP
, frag_off
/ OCTETS_PER_BYTE
, 0);
1897 add_to_result (resultP
, symval_diff
, symval_diff
< 0);
1898 resultP
->X_op
= O_constant
;
1899 resultP
->X_add_symbol
= 0;
1901 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1902 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1905 subtract_from_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1907 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1908 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1911 resultP
->X_op
= right
.X_op
;
1912 resultP
->X_add_symbol
= right
.X_add_symbol
;
1913 resultP
->X_op_symbol
= right
.X_op_symbol
;
1914 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
1917 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1919 /* Constant OP constant. */
1920 offsetT v
= right
.X_add_number
;
1921 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1923 as_warn (_("division by zero"));
1926 if ((valueT
) v
>= sizeof(valueT
) * CHAR_BIT
1927 && (op_left
== O_left_shift
|| op_left
== O_right_shift
))
1929 as_warn_value_out_of_range (_("shift count"), v
, 0,
1930 sizeof(valueT
) * CHAR_BIT
- 1,
1932 resultP
->X_add_number
= v
= 0;
1936 default: goto general
;
1937 case O_multiply
: resultP
->X_add_number
*= v
; break;
1938 case O_divide
: resultP
->X_add_number
/= v
; break;
1939 case O_modulus
: resultP
->X_add_number
%= v
; break;
1940 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1942 /* We always use unsigned shifts, to avoid relying on
1943 characteristics of the compiler used to compile gas. */
1944 resultP
->X_add_number
=
1945 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1947 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1948 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1949 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1950 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1951 /* Constant + constant (O_add) is handled by the
1952 previous if statement for constant + X, so is omitted
1955 subtract_from_result (resultP
, v
, 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
=
1979 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1982 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1985 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1989 else if (resultP
->X_op
== O_symbol
1990 && right
.X_op
== O_symbol
1991 && (op_left
== O_add
1992 || op_left
== O_subtract
1993 || (resultP
->X_add_number
== 0
1994 && right
.X_add_number
== 0)))
1996 /* Symbol OP symbol. */
1997 resultP
->X_op
= op_left
;
1998 resultP
->X_op_symbol
= right
.X_add_symbol
;
1999 if (op_left
== O_add
)
2000 add_to_result (resultP
, right
.X_add_number
, right
.X_extrabit
);
2001 else if (op_left
== O_subtract
)
2003 subtract_from_result (resultP
, right
.X_add_number
,
2005 if (retval
== rightseg
2006 && SEG_NORMAL (retval
)
2007 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
2008 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
2010 retval
= absolute_section
;
2011 rightseg
= absolute_section
;
2018 /* The general case. */
2019 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
2020 resultP
->X_op_symbol
= make_expr_symbol (&right
);
2021 resultP
->X_op
= op_left
;
2022 resultP
->X_add_number
= 0;
2023 resultP
->X_unsigned
= 1;
2024 resultP
->X_extrabit
= 0;
2027 if (retval
!= rightseg
)
2029 if (retval
== undefined_section
)
2031 else if (rightseg
== undefined_section
)
2033 else if (retval
== expr_section
)
2035 else if (rightseg
== expr_section
)
2037 else if (retval
== reg_section
)
2039 else if (rightseg
== reg_section
)
2041 else if (rightseg
== absolute_section
)
2043 else if (retval
== absolute_section
)
2046 else if (op_left
== O_subtract
)
2050 as_bad (_("operation combines symbols in different segments"));
2054 } /* While next operator is >= this rank. */
2056 /* The PA port needs this information. */
2057 if (resultP
->X_add_symbol
)
2058 symbol_mark_used (resultP
->X_add_symbol
);
2060 if (rank
== 0 && mode
== expr_evaluate
)
2061 resolve_expression (resultP
);
2063 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
2066 /* Resolve an expression without changing any symbols/sub-expressions
2070 resolve_expression (expressionS
*expressionP
)
2072 /* Help out with CSE. */
2073 valueT final_val
= expressionP
->X_add_number
;
2074 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
2075 symbolS
*orig_add_symbol
= add_symbol
;
2076 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
2077 operatorT op
= expressionP
->X_op
;
2079 segT seg_left
, seg_right
;
2080 fragS
*frag_left
, *frag_right
;
2095 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2103 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2106 if (seg_left
!= absolute_section
)
2109 if (op
== O_logical_not
)
2111 else if (op
== O_uminus
)
2123 case O_bit_inclusive_or
:
2125 case O_bit_exclusive_or
:
2137 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
2138 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
2141 /* Simplify addition or subtraction of a constant by folding the
2142 constant into X_add_number. */
2145 if (seg_right
== absolute_section
)
2151 else if (seg_left
== absolute_section
)
2155 seg_left
= seg_right
;
2156 add_symbol
= op_symbol
;
2157 orig_add_symbol
= expressionP
->X_op_symbol
;
2162 else if (op
== O_subtract
)
2164 if (seg_right
== absolute_section
)
2172 /* Equality and non-equality tests are permitted on anything.
2173 Subtraction, and other comparison operators are permitted if
2174 both operands are in the same section.
2175 Shifts by constant zero are permitted on anything.
2176 Multiplies, bit-ors, and bit-ands with constant zero are
2177 permitted on anything.
2178 Multiplies and divides by constant one are permitted on
2180 Binary operations with both operands being the same register
2181 or undefined symbol are permitted if the result doesn't depend
2183 Otherwise, both operands must be absolute. We already handled
2184 the case of addition or subtraction of a constant above. */
2186 if (!(seg_left
== absolute_section
2187 && seg_right
== absolute_section
)
2188 && !(op
== O_eq
|| op
== O_ne
)
2189 && !((op
== O_subtract
2190 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2191 && seg_left
== seg_right
2193 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
))
2194 && (seg_left
!= reg_section
|| left
== right
)
2195 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2197 if ((seg_left
== absolute_section
&& left
== 0)
2198 || (seg_right
== absolute_section
&& right
== 0))
2200 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2202 if (!(seg_right
== absolute_section
&& right
== 0))
2204 seg_left
= seg_right
;
2206 add_symbol
= op_symbol
;
2207 orig_add_symbol
= expressionP
->X_op_symbol
;
2212 else if (op
== O_left_shift
|| op
== O_right_shift
)
2214 if (!(seg_left
== absolute_section
&& left
== 0))
2220 else if (op
!= O_multiply
2221 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2224 else if (op
== O_multiply
2225 && seg_left
== absolute_section
&& left
== 1)
2227 seg_left
= seg_right
;
2229 add_symbol
= op_symbol
;
2230 orig_add_symbol
= expressionP
->X_op_symbol
;
2234 else if ((op
== O_multiply
|| op
== O_divide
)
2235 && seg_right
== absolute_section
&& right
== 1)
2240 else if (!(left
== right
2241 && ((seg_left
== reg_section
&& seg_right
== reg_section
)
2242 || (seg_left
== undefined_section
2243 && seg_right
== undefined_section
2244 && add_symbol
== op_symbol
))))
2246 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2251 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2255 right
+= frag_off
/ OCTETS_PER_BYTE
;
2258 case O_add
: left
+= right
; break;
2259 case O_subtract
: left
-= right
; break;
2260 case O_multiply
: left
*= right
; break;
2264 left
= (offsetT
) left
/ (offsetT
) right
;
2269 left
= (offsetT
) left
% (offsetT
) right
;
2271 case O_left_shift
: left
<<= right
; break;
2272 case O_right_shift
: left
>>= right
; break;
2273 case O_bit_inclusive_or
: left
|= right
; break;
2274 case O_bit_or_not
: left
|= ~right
; break;
2275 case O_bit_exclusive_or
: left
^= right
; break;
2276 case O_bit_and
: left
&= right
; break;
2279 left
= (left
== right
2280 && seg_left
== seg_right
2281 && (finalize_syms
|| frag_left
== frag_right
)
2282 && (seg_left
!= undefined_section
2283 || add_symbol
== op_symbol
)
2284 ? ~ (valueT
) 0 : 0);
2289 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2292 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2295 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2298 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2300 case O_logical_and
: left
= left
&& right
; break;
2301 case O_logical_or
: left
= left
|| right
; break;
2311 if (seg_left
== absolute_section
)
2313 else if (seg_left
== reg_section
&& final_val
== 0)
2315 else if (!symbol_same_p (add_symbol
, orig_add_symbol
))
2317 expressionP
->X_add_symbol
= add_symbol
;
2319 expressionP
->X_op
= op
;
2321 if (op
== O_constant
|| op
== O_register
)
2323 expressionP
->X_add_number
= final_val
;
2328 /* This lives here because it belongs equally in expr.c & read.c.
2329 expr.c is just a branch office read.c anyway, and putting it
2330 here lessens the crowd at read.c.
2332 Assume input_line_pointer is at start of symbol name.
2333 Advance input_line_pointer past symbol name.
2334 Turn that character into a '\0', returning its former value.
2335 This allows a string compare (RMS wants symbol names to be strings)
2337 There will always be a char following symbol name, because all good
2338 lines end in end-of-line. */
2341 get_symbol_end (void)
2345 /* We accept \001 in a name in case this is being called with a
2346 constructed string. */
2347 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2349 while (is_part_of_name (c
= *input_line_pointer
++)
2352 if (is_name_ender (c
))
2353 c
= *input_line_pointer
++;
2355 *--input_line_pointer
= 0;
2360 get_single_number (void)
2363 operand (&exp
, expr_normal
);
2364 return exp
.X_add_number
;