1 /* expr.c -operands, expressions-
2 Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011,
4 2012 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This is really a branch office of as-read.c. I split it out to clearly
24 distinguish the world of expressions from the world of statements.
25 (It also gives smaller files to re-compile.)
26 Here, "operand"s are of expressions, not instructions. */
28 #define min(a, b) ((a) < (b) ? (a) : (b))
31 #include "safe-ctype.h"
41 static void floating_constant (expressionS
* expressionP
);
42 static valueT
generic_bignum_to_int32 (void);
44 static valueT
generic_bignum_to_int64 (void);
46 static void integer_constant (int radix
, expressionS
* expressionP
);
47 static void mri_char_constant (expressionS
*);
48 static void clean_up_expression (expressionS
* expressionP
);
49 static segT
operand (expressionS
*, enum expr_mode
);
50 static operatorT
operatorf (int *);
52 extern const char EXP_CHARS
[], FLT_CHARS
[];
54 /* We keep a mapping of expression symbols to file positions, so that
55 we can provide better error messages. */
57 struct expr_symbol_line
{
58 struct expr_symbol_line
*next
;
64 static struct expr_symbol_line
*expr_symbol_lines
;
66 /* Build a dummy symbol to hold a complex expression. This is how we
67 build expressions up out of other expressions. The symbol is put
68 into the fake section expr_section. */
71 make_expr_symbol (expressionS
*expressionP
)
75 struct expr_symbol_line
*n
;
77 if (expressionP
->X_op
== O_symbol
78 && expressionP
->X_add_number
== 0)
79 return expressionP
->X_add_symbol
;
81 if (expressionP
->X_op
== O_big
)
83 /* This won't work, because the actual value is stored in
84 generic_floating_point_number or generic_bignum, and we are
85 going to lose it if we haven't already. */
86 if (expressionP
->X_add_number
> 0)
87 as_bad (_("bignum invalid"));
89 as_bad (_("floating point number invalid"));
90 zero
.X_op
= O_constant
;
91 zero
.X_add_number
= 0;
93 clean_up_expression (&zero
);
97 /* Putting constant symbols in absolute_section rather than
98 expr_section is convenient for the old a.out code, for which
99 S_GET_SEGMENT does not always retrieve the value put in by
101 symbolP
= symbol_create (FAKE_LABEL_NAME
,
102 (expressionP
->X_op
== O_constant
104 : expressionP
->X_op
== O_register
107 0, &zero_address_frag
);
108 symbol_set_value_expression (symbolP
, expressionP
);
110 if (expressionP
->X_op
== O_constant
)
111 resolve_symbol_value (symbolP
);
113 n
= (struct expr_symbol_line
*) xmalloc (sizeof *n
);
115 as_where (&n
->file
, &n
->line
);
116 n
->next
= expr_symbol_lines
;
117 expr_symbol_lines
= n
;
122 /* Return the file and line number for an expr symbol. Return
123 non-zero if something was found, 0 if no information is known for
127 expr_symbol_where (symbolS
*sym
, char **pfile
, unsigned int *pline
)
129 register struct expr_symbol_line
*l
;
131 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
144 /* Utilities for building expressions.
145 Since complex expressions are recorded as symbols for use in other
146 expressions these return a symbolS * and not an expressionS *.
147 These explicitly do not take an "add_number" argument. */
148 /* ??? For completeness' sake one might want expr_build_symbol.
149 It would just return its argument. */
151 /* Build an expression for an unsigned constant.
152 The corresponding one for signed constants is missing because
153 there's currently no need for it. One could add an unsigned_p flag
154 but that seems more clumsy. */
157 expr_build_uconstant (offsetT value
)
162 e
.X_add_number
= value
;
164 return make_expr_symbol (&e
);
167 /* Build an expression for the current location ('.'). */
170 expr_build_dot (void)
174 current_location (&e
);
175 return symbol_clone_if_forward_ref (make_expr_symbol (&e
));
178 /* Build any floating-point literal here.
179 Also build any bignum literal here. */
181 /* Seems atof_machine can backscan through generic_bignum and hit whatever
182 happens to be loaded before it in memory. And its way too complicated
183 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
184 and never write into the early words, thus they'll always be zero.
185 I hate Dean's floating-point code. Bleh. */
186 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
188 FLONUM_TYPE generic_floating_point_number
= {
189 &generic_bignum
[6], /* low. (JF: Was 0) */
190 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
198 floating_constant (expressionS
*expressionP
)
200 /* input_line_pointer -> floating-point constant. */
203 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
204 &generic_floating_point_number
);
208 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
210 as_bad (_("bad floating-point constant: exponent overflow"));
214 as_bad (_("bad floating-point constant: unknown error code=%d"),
218 expressionP
->X_op
= O_big
;
219 /* input_line_pointer -> just after constant, which may point to
221 expressionP
->X_add_number
= -1;
225 generic_bignum_to_int32 (void)
228 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
229 | (generic_bignum
[0] & LITTLENUM_MASK
);
230 number
&= 0xffffffff;
236 generic_bignum_to_int64 (void)
239 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
240 << LITTLENUM_NUMBER_OF_BITS
)
241 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
242 << LITTLENUM_NUMBER_OF_BITS
)
243 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
244 << LITTLENUM_NUMBER_OF_BITS
)
245 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
251 integer_constant (int radix
, expressionS
*expressionP
)
253 char *start
; /* Start of number. */
256 valueT number
; /* Offset or (absolute) value. */
257 short int digit
; /* Value of next digit in current radix. */
258 short int maxdig
= 0; /* Highest permitted digit value. */
259 int too_many_digits
= 0; /* If we see >= this number of. */
260 char *name
; /* Points to name of symbol. */
261 symbolS
*symbolP
; /* Points to symbol. */
263 int small
; /* True if fits in 32 bits. */
265 /* May be bignum, or may fit in 32 bits. */
266 /* Most numbers fit into 32 bits, and we want this case to be fast.
267 so we pretend it will fit into 32 bits. If, after making up a 32
268 bit number, we realise that we have scanned more digits than
269 comfortably fit into 32 bits, we re-scan the digits coding them
270 into a bignum. For decimal and octal numbers we are
271 conservative: Some numbers may be assumed bignums when in fact
272 they do fit into 32 bits. Numbers of any radix can have excess
273 leading zeros: We strive to recognise this and cast them back
274 into 32 bits. We must check that the bignum really is more than
275 32 bits, and change it back to a 32-bit number if it fits. The
276 number we are looking for is expected to be positive, but if it
277 fits into 32 bits as an unsigned number, we let it be a 32-bit
278 number. The cavalier approach is for speed in ordinary cases. */
279 /* This has been extended for 64 bits. We blindly assume that if
280 you're compiling in 64-bit mode, the target is a 64-bit machine.
281 This should be cleaned up. */
285 #else /* includes non-bfd case, mostly */
289 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
293 /* In MRI mode, the number may have a suffix indicating the
294 radix. For that matter, it might actually be a floating
296 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
298 if (*suffix
== 'e' || *suffix
== 'E')
302 if (suffix
== input_line_pointer
)
311 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
312 we distinguish between 'B' and 'b'. This is the case for
314 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
318 else if (c
== 'O' || c
== 'Q')
322 else if (suffix
[1] == '.' || c
== 'E' || flt
)
324 floating_constant (expressionP
);
339 too_many_digits
= valuesize
+ 1;
343 too_many_digits
= (valuesize
+ 2) / 3 + 1;
347 too_many_digits
= (valuesize
+ 3) / 4 + 1;
351 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
354 start
= input_line_pointer
;
355 c
= *input_line_pointer
++;
357 (digit
= hex_value (c
)) < maxdig
;
358 c
= *input_line_pointer
++)
360 number
= number
* radix
+ digit
;
362 /* c contains character after number. */
363 /* input_line_pointer->char after c. */
364 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
366 if (radix
== 16 && c
== '_')
368 /* This is literal of the form 0x333_0_12345678_1.
369 This example is equivalent to 0x00000333000000001234567800000001. */
371 int num_little_digits
= 0;
373 input_line_pointer
= start
; /* -> 1st digit. */
375 know (LITTLENUM_NUMBER_OF_BITS
== 16);
377 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
380 /* Convert one 64-bit word. */
383 for (c
= *input_line_pointer
++;
384 (digit
= hex_value (c
)) < maxdig
;
385 c
= *(input_line_pointer
++))
387 number
= number
* radix
+ digit
;
391 /* Check for 8 digit per word max. */
393 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
395 /* Add this chunk to the bignum.
396 Shift things down 2 little digits. */
397 know (LITTLENUM_NUMBER_OF_BITS
== 16);
398 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
401 generic_bignum
[i
] = generic_bignum
[i
- 2];
403 /* Add the new digits as the least significant new ones. */
404 generic_bignum
[0] = number
& 0xffffffff;
405 generic_bignum
[1] = number
>> 16;
408 /* Again, c is char after number, input_line_pointer->after c. */
410 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
411 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
413 gas_assert (num_little_digits
>= 4);
415 if (num_little_digits
!= 8)
416 as_bad (_("a bignum with underscores must have exactly 4 words"));
418 /* We might have some leading zeros. These can be trimmed to give
419 us a change to fit this constant into a small number. */
420 while (generic_bignum
[num_little_digits
- 1] == 0
421 && num_little_digits
> 1)
424 if (num_little_digits
<= 2)
426 /* will fit into 32 bits. */
427 number
= generic_bignum_to_int32 ();
431 else if (num_little_digits
<= 4)
433 /* Will fit into 64 bits. */
434 number
= generic_bignum_to_int64 ();
442 /* Number of littlenums in the bignum. */
443 number
= num_little_digits
;
448 /* We saw a lot of digits. manufacture a bignum the hard way. */
449 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
450 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
453 leader
= generic_bignum
;
454 generic_bignum
[0] = 0;
455 generic_bignum
[1] = 0;
456 generic_bignum
[2] = 0;
457 generic_bignum
[3] = 0;
458 input_line_pointer
= start
; /* -> 1st digit. */
459 c
= *input_line_pointer
++;
460 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
462 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
466 work
= carry
+ radix
* *pointer
;
467 *pointer
= work
& LITTLENUM_MASK
;
468 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
472 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
474 /* Room to grow a longer bignum. */
479 /* Again, c is char after number. */
480 /* input_line_pointer -> after c. */
481 know (LITTLENUM_NUMBER_OF_BITS
== 16);
482 if (leader
< generic_bignum
+ 2)
484 /* Will fit into 32 bits. */
485 number
= generic_bignum_to_int32 ();
489 else if (leader
< generic_bignum
+ 4)
491 /* Will fit into 64 bits. */
492 number
= generic_bignum_to_int64 ();
498 /* Number of littlenums in the bignum. */
499 number
= leader
- generic_bignum
+ 1;
503 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
505 && input_line_pointer
- 1 == suffix
)
506 c
= *input_line_pointer
++;
510 /* Here with number, in correct radix. c is the next char.
511 Note that unlike un*x, we allow "011f" "0x9f" to both mean
512 the same as the (conventional) "9f".
513 This is simply easier than checking for strict canonical
516 if (LOCAL_LABELS_FB
&& c
== 'b')
518 /* Backward ref to local label.
519 Because it is backward, expect it to be defined. */
520 /* Construct a local label. */
521 name
= fb_label_name ((int) number
, 0);
523 /* Seen before, or symbol is defined: OK. */
524 symbolP
= symbol_find (name
);
525 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
527 /* Local labels are never absolute. Don't waste time
528 checking absoluteness. */
529 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
531 expressionP
->X_op
= O_symbol
;
532 expressionP
->X_add_symbol
= symbolP
;
536 /* Either not seen or not defined. */
537 /* @@ Should print out the original string instead of
538 the parsed number. */
539 as_bad (_("backward ref to unknown label \"%d:\""),
541 expressionP
->X_op
= O_constant
;
544 expressionP
->X_add_number
= 0;
546 else if (LOCAL_LABELS_FB
&& c
== 'f')
548 /* Forward reference. Expect symbol to be undefined or
549 unknown. undefined: seen it before. unknown: never seen
552 Construct a local label name, then an undefined symbol.
553 Don't create a xseg frag for it: caller may do that.
554 Just return it as never seen before. */
555 name
= fb_label_name ((int) number
, 1);
556 symbolP
= symbol_find_or_make (name
);
557 /* We have no need to check symbol properties. */
558 #ifndef many_segments
559 /* Since "know" puts its arg into a "string", we
560 can't have newlines in the argument. */
561 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
563 expressionP
->X_op
= O_symbol
;
564 expressionP
->X_add_symbol
= symbolP
;
565 expressionP
->X_add_number
= 0;
567 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
569 /* If the dollar label is *currently* defined, then this is just
570 another reference to it. If it is not *currently* defined,
571 then this is a fresh instantiation of that number, so create
574 if (dollar_label_defined ((long) number
))
576 name
= dollar_label_name ((long) number
, 0);
577 symbolP
= symbol_find (name
);
578 know (symbolP
!= NULL
);
582 name
= dollar_label_name ((long) number
, 1);
583 symbolP
= symbol_find_or_make (name
);
586 expressionP
->X_op
= O_symbol
;
587 expressionP
->X_add_symbol
= symbolP
;
588 expressionP
->X_add_number
= 0;
592 expressionP
->X_op
= O_constant
;
593 expressionP
->X_add_number
= number
;
594 input_line_pointer
--; /* Restore following character. */
595 } /* Really just a number. */
599 /* Not a small number. */
600 expressionP
->X_op
= O_big
;
601 expressionP
->X_add_number
= number
; /* Number of littlenums. */
602 input_line_pointer
--; /* -> char following number. */
606 /* Parse an MRI multi character constant. */
609 mri_char_constant (expressionS
*expressionP
)
613 if (*input_line_pointer
== '\''
614 && input_line_pointer
[1] != '\'')
616 expressionP
->X_op
= O_constant
;
617 expressionP
->X_add_number
= 0;
621 /* In order to get the correct byte ordering, we must build the
622 number in reverse. */
623 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
627 generic_bignum
[i
] = 0;
628 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
630 if (*input_line_pointer
== '\'')
632 if (input_line_pointer
[1] != '\'')
634 ++input_line_pointer
;
636 generic_bignum
[i
] <<= 8;
637 generic_bignum
[i
] += *input_line_pointer
;
638 ++input_line_pointer
;
641 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
643 /* If there is more than one littlenum, left justify the
644 last one to make it match the earlier ones. If there is
645 only one, we can just use the value directly. */
646 for (; j
< CHARS_PER_LITTLENUM
; j
++)
647 generic_bignum
[i
] <<= 8;
650 if (*input_line_pointer
== '\''
651 && input_line_pointer
[1] != '\'')
657 as_bad (_("character constant too large"));
666 c
= SIZE_OF_LARGE_NUMBER
- i
;
667 for (j
= 0; j
< c
; j
++)
668 generic_bignum
[j
] = generic_bignum
[i
+ j
];
672 know (LITTLENUM_NUMBER_OF_BITS
== 16);
675 expressionP
->X_op
= O_big
;
676 expressionP
->X_add_number
= i
;
680 expressionP
->X_op
= O_constant
;
682 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
684 expressionP
->X_add_number
=
685 (((generic_bignum
[1] & LITTLENUM_MASK
)
686 << LITTLENUM_NUMBER_OF_BITS
)
687 | (generic_bignum
[0] & LITTLENUM_MASK
));
690 /* Skip the final closing quote. */
691 ++input_line_pointer
;
694 /* Return an expression representing the current location. This
695 handles the magic symbol `.'. */
698 current_location (expressionS
*expressionp
)
700 if (now_seg
== absolute_section
)
702 expressionp
->X_op
= O_constant
;
703 expressionp
->X_add_number
= abs_section_offset
;
707 expressionp
->X_op
= O_symbol
;
708 expressionp
->X_add_symbol
= &dot_symbol
;
709 expressionp
->X_add_number
= 0;
713 /* In: Input_line_pointer points to 1st char of operand, which may
717 The operand may have been empty: in this case X_op == O_absent.
718 Input_line_pointer->(next non-blank) char after operand. */
721 operand (expressionS
*expressionP
, enum expr_mode mode
)
724 symbolS
*symbolP
; /* Points to symbol. */
725 char *name
; /* Points to name of symbol. */
728 /* All integers are regarded as unsigned unless they are negated.
729 This is because the only thing which cares whether a number is
730 unsigned is the code in emit_expr which extends constants into
731 bignums. It should only sign extend negative numbers, so that
732 something like ``.quad 0x80000000'' is not sign extended even
733 though it appears negative if valueT is 32 bits. */
734 expressionP
->X_unsigned
= 1;
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
= - expressionP
->X_add_number
;
1025 /* Notice: '-' may overflow: no warning is given.
1026 This is compatible with other people's
1027 assemblers. Sigh. */
1028 expressionP
->X_unsigned
= 0;
1030 else if (c
== '~' || c
== '"')
1031 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1033 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1035 else if (expressionP
->X_op
== O_big
1036 && expressionP
->X_add_number
<= 0
1038 && (generic_floating_point_number
.sign
== '+'
1039 || generic_floating_point_number
.sign
== 'P'))
1041 /* Negative flonum (eg, -1.000e0). */
1042 if (generic_floating_point_number
.sign
== '+')
1043 generic_floating_point_number
.sign
= '-';
1045 generic_floating_point_number
.sign
= 'N';
1047 else if (expressionP
->X_op
== O_big
1048 && expressionP
->X_add_number
> 0)
1052 if (c
== '~' || c
== '-')
1054 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1055 generic_bignum
[i
] = ~generic_bignum
[i
];
1057 /* Extend the bignum to at least the size of .octa. */
1058 if (expressionP
->X_add_number
< SIZE_OF_LARGE_NUMBER
)
1060 expressionP
->X_add_number
= SIZE_OF_LARGE_NUMBER
;
1061 for (; i
< expressionP
->X_add_number
; ++i
)
1062 generic_bignum
[i
] = ~(LITTLENUM_TYPE
) 0;
1066 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1068 generic_bignum
[i
] += 1;
1069 if (generic_bignum
[i
])
1075 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1076 if (generic_bignum
[i
] != 0)
1078 expressionP
->X_add_number
= i
>= expressionP
->X_add_number
;
1079 expressionP
->X_op
= O_constant
;
1080 expressionP
->X_unsigned
= 1;
1083 else if (expressionP
->X_op
!= O_illegal
1084 && expressionP
->X_op
!= O_absent
)
1088 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1090 expressionP
->X_op
= O_uminus
;
1091 else if (c
== '~' || c
== '"')
1092 expressionP
->X_op
= O_bit_not
;
1094 expressionP
->X_op
= O_logical_not
;
1095 expressionP
->X_add_number
= 0;
1099 as_warn (_("Unary operator %c ignored because bad operand follows"),
1104 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1106 /* '$' is the program counter when in MRI mode, or when
1107 DOLLAR_DOT is defined. */
1109 if (! flag_m68k_mri
)
1112 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1114 /* In MRI mode and on Z80, '$' is also used as the prefix
1115 for a hexadecimal constant. */
1116 integer_constant (16, expressionP
);
1120 if (is_part_of_name (*input_line_pointer
))
1123 current_location (expressionP
);
1128 if (!is_part_of_name (*input_line_pointer
))
1130 current_location (expressionP
);
1133 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1134 && ! is_part_of_name (input_line_pointer
[8]))
1135 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1136 && ! is_part_of_name (input_line_pointer
[7])))
1140 start
= (input_line_pointer
[1] == 't'
1141 || input_line_pointer
[1] == 'T');
1142 input_line_pointer
+= start
? 8 : 7;
1144 if (*input_line_pointer
!= '(')
1145 as_bad (_("syntax error in .startof. or .sizeof."));
1150 ++input_line_pointer
;
1152 name
= input_line_pointer
;
1153 c
= get_symbol_end ();
1155 buf
= (char *) xmalloc (strlen (name
) + 10);
1157 sprintf (buf
, ".startof.%s", name
);
1159 sprintf (buf
, ".sizeof.%s", 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
;
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
)) /* Here if did not begin with a digit. */
1226 /* Identifier begins here.
1227 This is kludged for speed, so code is repeated. */
1229 name
= --input_line_pointer
;
1230 c
= get_symbol_end ();
1234 operatorT op
= md_operator (name
, 1, &c
);
1239 *input_line_pointer
= c
;
1243 *input_line_pointer
= c
;
1247 *input_line_pointer
= c
;
1251 as_bad (_("invalid use of operator \"%s\""), name
);
1256 if (op
!= O_absent
&& op
!= O_illegal
)
1258 *input_line_pointer
= c
;
1259 expr (9, expressionP
, mode
);
1260 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1261 expressionP
->X_op_symbol
= NULL
;
1262 expressionP
->X_add_number
= 0;
1263 expressionP
->X_op
= op
;
1269 #ifdef md_parse_name
1270 /* This is a hook for the backend to parse certain names
1271 specially in certain contexts. If a name always has a
1272 specific value, it can often be handled by simply
1273 entering it in the symbol table. */
1274 if (md_parse_name (name
, expressionP
, mode
, &c
))
1276 *input_line_pointer
= c
;
1282 /* The MRI i960 assembler permits
1284 FIXME: This should use md_parse_name. */
1286 && (strcasecmp (name
, "sizeof") == 0
1287 || strcasecmp (name
, "startof") == 0))
1292 start
= (name
[1] == 't'
1295 *input_line_pointer
= c
;
1298 name
= input_line_pointer
;
1299 c
= get_symbol_end ();
1301 buf
= (char *) xmalloc (strlen (name
) + 10);
1303 sprintf (buf
, ".startof.%s", name
);
1305 sprintf (buf
, ".sizeof.%s", name
);
1306 symbolP
= symbol_make (buf
);
1309 expressionP
->X_op
= O_symbol
;
1310 expressionP
->X_add_symbol
= symbolP
;
1311 expressionP
->X_add_number
= 0;
1313 *input_line_pointer
= c
;
1320 symbolP
= symbol_find_or_make (name
);
1322 /* If we have an absolute symbol or a reg, then we know its
1324 segment
= S_GET_SEGMENT (symbolP
);
1325 if (mode
!= expr_defer
1326 && segment
== absolute_section
1327 && !S_FORCE_RELOC (symbolP
, 0))
1329 expressionP
->X_op
= O_constant
;
1330 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1332 else if (mode
!= expr_defer
&& segment
== reg_section
)
1334 expressionP
->X_op
= O_register
;
1335 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1339 expressionP
->X_op
= O_symbol
;
1340 expressionP
->X_add_symbol
= symbolP
;
1341 expressionP
->X_add_number
= 0;
1343 *input_line_pointer
= c
;
1347 /* Let the target try to parse it. Success is indicated by changing
1348 the X_op field to something other than O_absent and pointing
1349 input_line_pointer past the expression. If it can't parse the
1350 expression, X_op and input_line_pointer should be unchanged. */
1351 expressionP
->X_op
= O_absent
;
1352 --input_line_pointer
;
1353 md_operand (expressionP
);
1354 if (expressionP
->X_op
== O_absent
)
1356 ++input_line_pointer
;
1357 as_bad (_("bad expression"));
1358 expressionP
->X_op
= O_constant
;
1359 expressionP
->X_add_number
= 0;
1365 /* It is more 'efficient' to clean up the expressionS when they are
1366 created. Doing it here saves lines of code. */
1367 clean_up_expression (expressionP
);
1368 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1369 know (*input_line_pointer
!= ' ');
1371 /* The PA port needs this information. */
1372 if (expressionP
->X_add_symbol
)
1373 symbol_mark_used (expressionP
->X_add_symbol
);
1375 if (mode
!= expr_defer
)
1377 expressionP
->X_add_symbol
1378 = symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1379 expressionP
->X_op_symbol
1380 = symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1383 switch (expressionP
->X_op
)
1386 return absolute_section
;
1388 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1394 /* Internal. Simplify a struct expression for use by expr (). */
1396 /* In: address of an expressionS.
1397 The X_op field of the expressionS may only take certain values.
1398 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1400 Out: expressionS may have been modified:
1401 Unused fields zeroed to help expr (). */
1404 clean_up_expression (expressionS
*expressionP
)
1406 switch (expressionP
->X_op
)
1410 expressionP
->X_add_number
= 0;
1415 expressionP
->X_add_symbol
= NULL
;
1420 expressionP
->X_op_symbol
= NULL
;
1427 /* Expression parser. */
1429 /* We allow an empty expression, and just assume (absolute,0) silently.
1430 Unary operators and parenthetical expressions are treated as operands.
1431 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1433 We used to do an aho/ullman shift-reduce parser, but the logic got so
1434 warped that I flushed it and wrote a recursive-descent parser instead.
1435 Now things are stable, would anybody like to write a fast parser?
1436 Most expressions are either register (which does not even reach here)
1437 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1438 So I guess it doesn't really matter how inefficient more complex expressions
1441 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1442 Also, we have consumed any leading or trailing spaces (operand does that)
1443 and done all intervening operators.
1445 This returns the segment of the result, which will be
1446 absolute_section or the segment of a symbol. */
1449 #define __ O_illegal
1451 #define O_SINGLE_EQ O_illegal
1454 /* Maps ASCII -> operators. */
1455 static const operatorT op_encoding
[256] = {
1456 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1457 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1459 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1460 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1461 __
, __
, __
, __
, __
, __
, __
, __
,
1462 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1463 __
, __
, __
, __
, __
, __
, __
, __
,
1464 __
, __
, __
, __
, __
, __
, __
, __
,
1465 __
, __
, __
, __
, __
, __
, __
, __
,
1467 #ifdef NEED_INDEX_OPERATOR
1472 __
, __
, O_bit_exclusive_or
, __
,
1473 __
, __
, __
, __
, __
, __
, __
, __
,
1474 __
, __
, __
, __
, __
, __
, __
, __
,
1475 __
, __
, __
, __
, __
, __
, __
, __
,
1476 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1478 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1479 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1480 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1481 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1482 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1483 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1484 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1485 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1489 0 operand, (expression)
1494 5 used for * / % in MRI mode
1499 static operator_rankT op_rank
[O_max
] = {
1504 0, /* O_symbol_rva */
1509 9, /* O_logical_not */
1513 8, /* O_left_shift */
1514 8, /* O_right_shift */
1515 7, /* O_bit_inclusive_or */
1516 7, /* O_bit_or_not */
1517 7, /* O_bit_exclusive_or */
1527 3, /* O_logical_and */
1528 2, /* O_logical_or */
1532 /* Unfortunately, in MRI mode for the m68k, multiplication and
1533 division have lower precedence than the bit wise operators. This
1534 function sets the operator precedences correctly for the current
1535 mode. Also, MRI uses a different bit_not operator, and this fixes
1538 #define STANDARD_MUL_PRECEDENCE 8
1539 #define MRI_MUL_PRECEDENCE 6
1542 expr_set_precedence (void)
1546 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1547 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1548 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1552 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1553 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1554 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1559 expr_set_rank (operatorT op
, operator_rankT rank
)
1561 gas_assert (op
>= O_md1
&& op
< ARRAY_SIZE (op_rank
));
1565 /* Initialize the expression parser. */
1570 expr_set_precedence ();
1572 /* Verify that X_op field is wide enough. */
1576 gas_assert (e
.X_op
== O_max
);
1580 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1581 sets NUM_CHARS to the number of characters in the operator.
1582 Does not advance INPUT_LINE_POINTER. */
1584 static inline operatorT
1585 operatorf (int *num_chars
)
1590 c
= *input_line_pointer
& 0xff;
1593 if (is_end_of_line
[c
])
1597 if (is_name_beginner (c
))
1599 char *name
= input_line_pointer
;
1600 char ec
= get_symbol_end ();
1602 ret
= md_operator (name
, 2, &ec
);
1606 *input_line_pointer
= ec
;
1607 input_line_pointer
= name
;
1612 as_bad (_("invalid use of operator \"%s\""), name
);
1616 *input_line_pointer
= ec
;
1617 *num_chars
= input_line_pointer
- name
;
1618 input_line_pointer
= name
;
1627 ret
= op_encoding
[c
];
1629 if (ret
== O_illegal
)
1631 char *start
= input_line_pointer
;
1633 ret
= md_operator (NULL
, 2, NULL
);
1634 if (ret
!= O_illegal
)
1635 *num_chars
= input_line_pointer
- start
;
1636 input_line_pointer
= start
;
1643 return op_encoding
[c
];
1646 switch (input_line_pointer
[1])
1649 return op_encoding
[c
];
1664 if (input_line_pointer
[1] != '=')
1665 return op_encoding
[c
];
1671 switch (input_line_pointer
[1])
1674 return op_encoding
[c
];
1676 ret
= O_right_shift
;
1686 switch (input_line_pointer
[1])
1689 /* We accept !! as equivalent to ^ for MRI compatibility. */
1691 return O_bit_exclusive_or
;
1693 /* We accept != as equivalent to <>. */
1698 return O_bit_inclusive_or
;
1699 return op_encoding
[c
];
1703 if (input_line_pointer
[1] != '|')
1704 return op_encoding
[c
];
1707 return O_logical_or
;
1710 if (input_line_pointer
[1] != '&')
1711 return op_encoding
[c
];
1714 return O_logical_and
;
1720 /* Parse an expression. */
1723 expr (int rankarg
, /* Larger # is higher rank. */
1724 expressionS
*resultP
, /* Deliver result here. */
1725 enum expr_mode mode
/* Controls behavior. */)
1727 operator_rankT rank
= (operator_rankT
) rankarg
;
1734 know (rankarg
>= 0);
1736 /* Save the value of dot for the fixup code. */
1739 dot_value
= frag_now_fix ();
1740 dot_frag
= frag_now
;
1743 retval
= operand (resultP
, mode
);
1745 /* operand () gobbles spaces. */
1746 know (*input_line_pointer
!= ' ');
1748 op_left
= operatorf (&op_chars
);
1749 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1754 input_line_pointer
+= op_chars
; /* -> after operator. */
1757 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1758 if (right
.X_op
== O_absent
)
1760 as_warn (_("missing operand; zero assumed"));
1761 right
.X_op
= O_constant
;
1762 right
.X_add_number
= 0;
1763 right
.X_add_symbol
= NULL
;
1764 right
.X_op_symbol
= NULL
;
1767 know (*input_line_pointer
!= ' ');
1769 if (op_left
== O_index
)
1771 if (*input_line_pointer
!= ']')
1772 as_bad ("missing right bracket");
1775 ++input_line_pointer
;
1780 op_right
= operatorf (&op_chars
);
1782 know (op_right
== O_illegal
|| op_left
== O_index
1783 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1784 know ((int) op_left
>= (int) O_multiply
);
1786 know ((int) op_left
<= (int) O_index
);
1788 know ((int) op_left
< (int) O_max
);
1791 /* input_line_pointer->after right-hand quantity. */
1792 /* left-hand quantity in resultP. */
1793 /* right-hand quantity in right. */
1794 /* operator in op_left. */
1796 if (resultP
->X_op
== O_big
)
1798 if (resultP
->X_add_number
> 0)
1799 as_warn (_("left operand is a bignum; integer 0 assumed"));
1801 as_warn (_("left operand is a float; integer 0 assumed"));
1802 resultP
->X_op
= O_constant
;
1803 resultP
->X_add_number
= 0;
1804 resultP
->X_add_symbol
= NULL
;
1805 resultP
->X_op_symbol
= NULL
;
1807 if (right
.X_op
== O_big
)
1809 if (right
.X_add_number
> 0)
1810 as_warn (_("right operand is a bignum; integer 0 assumed"));
1812 as_warn (_("right operand is a float; integer 0 assumed"));
1813 right
.X_op
= O_constant
;
1814 right
.X_add_number
= 0;
1815 right
.X_add_symbol
= NULL
;
1816 right
.X_op_symbol
= NULL
;
1819 /* Optimize common cases. */
1820 #ifdef md_optimize_expr
1821 if (md_optimize_expr (resultP
, op_left
, &right
))
1828 #ifndef md_register_arithmetic
1829 # define md_register_arithmetic 1
1831 if (op_left
== O_add
&& right
.X_op
== O_constant
1832 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1835 resultP
->X_add_number
+= right
.X_add_number
;
1837 /* This case comes up in PIC code. */
1838 else if (op_left
== O_subtract
1839 && right
.X_op
== O_symbol
1840 && resultP
->X_op
== O_symbol
1841 && retval
== rightseg
1842 #ifdef md_allow_local_subtract
1843 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1845 && ((SEG_NORMAL (rightseg
)
1846 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1847 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1848 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1849 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1850 symbol_get_frag (right
.X_add_symbol
),
1853 resultP
->X_add_number
-= right
.X_add_number
;
1854 resultP
->X_add_number
-= frag_off
/ OCTETS_PER_BYTE
;
1855 resultP
->X_add_number
+= (S_GET_VALUE (resultP
->X_add_symbol
)
1856 - S_GET_VALUE (right
.X_add_symbol
));
1857 resultP
->X_op
= O_constant
;
1858 resultP
->X_add_symbol
= 0;
1860 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1861 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1864 resultP
->X_add_number
-= right
.X_add_number
;
1866 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1867 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1870 resultP
->X_op
= right
.X_op
;
1871 resultP
->X_add_symbol
= right
.X_add_symbol
;
1872 resultP
->X_op_symbol
= right
.X_op_symbol
;
1873 resultP
->X_add_number
+= right
.X_add_number
;
1876 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1878 /* Constant OP constant. */
1879 offsetT v
= right
.X_add_number
;
1880 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1882 as_warn (_("division by zero"));
1885 if ((valueT
) v
>= sizeof(valueT
) * CHAR_BIT
1886 && (op_left
== O_left_shift
|| op_left
== O_right_shift
))
1888 as_warn_value_out_of_range (_("shift count"), v
, 0,
1889 sizeof(valueT
) * CHAR_BIT
- 1,
1891 resultP
->X_add_number
= v
= 0;
1895 default: goto general
;
1896 case O_multiply
: resultP
->X_add_number
*= v
; break;
1897 case O_divide
: resultP
->X_add_number
/= v
; break;
1898 case O_modulus
: resultP
->X_add_number
%= v
; break;
1899 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1901 /* We always use unsigned shifts, to avoid relying on
1902 characteristics of the compiler used to compile gas. */
1903 resultP
->X_add_number
=
1904 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1906 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1907 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1908 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1909 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1910 /* Constant + constant (O_add) is handled by the
1911 previous if statement for constant + X, so is omitted
1913 case O_subtract
: resultP
->X_add_number
-= v
; break;
1915 resultP
->X_add_number
=
1916 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1919 resultP
->X_add_number
=
1920 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1923 resultP
->X_add_number
=
1924 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1927 resultP
->X_add_number
=
1928 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1931 resultP
->X_add_number
=
1932 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1935 resultP
->X_add_number
=
1936 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1939 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1942 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1946 else if (resultP
->X_op
== O_symbol
1947 && right
.X_op
== O_symbol
1948 && (op_left
== O_add
1949 || op_left
== O_subtract
1950 || (resultP
->X_add_number
== 0
1951 && right
.X_add_number
== 0)))
1953 /* Symbol OP symbol. */
1954 resultP
->X_op
= op_left
;
1955 resultP
->X_op_symbol
= right
.X_add_symbol
;
1956 if (op_left
== O_add
)
1957 resultP
->X_add_number
+= right
.X_add_number
;
1958 else if (op_left
== O_subtract
)
1960 resultP
->X_add_number
-= right
.X_add_number
;
1961 if (retval
== rightseg
1962 && SEG_NORMAL (retval
)
1963 && !S_FORCE_RELOC (resultP
->X_add_symbol
, 0)
1964 && !S_FORCE_RELOC (right
.X_add_symbol
, 0))
1966 retval
= absolute_section
;
1967 rightseg
= absolute_section
;
1974 /* The general case. */
1975 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
1976 resultP
->X_op_symbol
= make_expr_symbol (&right
);
1977 resultP
->X_op
= op_left
;
1978 resultP
->X_add_number
= 0;
1979 resultP
->X_unsigned
= 1;
1982 if (retval
!= rightseg
)
1984 if (retval
== undefined_section
)
1986 else if (rightseg
== undefined_section
)
1988 else if (retval
== expr_section
)
1990 else if (rightseg
== expr_section
)
1992 else if (retval
== reg_section
)
1994 else if (rightseg
== reg_section
)
1996 else if (rightseg
== absolute_section
)
1998 else if (retval
== absolute_section
)
2001 else if (op_left
== O_subtract
)
2005 as_bad (_("operation combines symbols in different segments"));
2009 } /* While next operator is >= this rank. */
2011 /* The PA port needs this information. */
2012 if (resultP
->X_add_symbol
)
2013 symbol_mark_used (resultP
->X_add_symbol
);
2015 if (rank
== 0 && mode
== expr_evaluate
)
2016 resolve_expression (resultP
);
2018 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
2021 /* Resolve an expression without changing any symbols/sub-expressions
2025 resolve_expression (expressionS
*expressionP
)
2027 /* Help out with CSE. */
2028 valueT final_val
= expressionP
->X_add_number
;
2029 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
2030 symbolS
*orig_add_symbol
= add_symbol
;
2031 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
2032 operatorT op
= expressionP
->X_op
;
2034 segT seg_left
, seg_right
;
2035 fragS
*frag_left
, *frag_right
;
2050 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2058 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
2061 if (seg_left
!= absolute_section
)
2064 if (op
== O_logical_not
)
2066 else if (op
== O_uminus
)
2078 case O_bit_inclusive_or
:
2080 case O_bit_exclusive_or
:
2092 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
2093 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
2096 /* Simplify addition or subtraction of a constant by folding the
2097 constant into X_add_number. */
2100 if (seg_right
== absolute_section
)
2106 else if (seg_left
== absolute_section
)
2110 seg_left
= seg_right
;
2111 add_symbol
= op_symbol
;
2112 orig_add_symbol
= expressionP
->X_op_symbol
;
2117 else if (op
== O_subtract
)
2119 if (seg_right
== absolute_section
)
2127 /* Equality and non-equality tests are permitted on anything.
2128 Subtraction, and other comparison operators are permitted if
2129 both operands are in the same section.
2130 Shifts by constant zero are permitted on anything.
2131 Multiplies, bit-ors, and bit-ands with constant zero are
2132 permitted on anything.
2133 Multiplies and divides by constant one are permitted on
2135 Binary operations with both operands being the same register
2136 or undefined symbol are permitted if the result doesn't depend
2138 Otherwise, both operands must be absolute. We already handled
2139 the case of addition or subtraction of a constant above. */
2141 if (!(seg_left
== absolute_section
2142 && seg_right
== absolute_section
)
2143 && !(op
== O_eq
|| op
== O_ne
)
2144 && !((op
== O_subtract
2145 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2146 && seg_left
== seg_right
2148 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
))
2149 && (seg_left
!= reg_section
|| left
== right
)
2150 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2152 if ((seg_left
== absolute_section
&& left
== 0)
2153 || (seg_right
== absolute_section
&& right
== 0))
2155 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2157 if (!(seg_right
== absolute_section
&& right
== 0))
2159 seg_left
= seg_right
;
2161 add_symbol
= op_symbol
;
2162 orig_add_symbol
= expressionP
->X_op_symbol
;
2167 else if (op
== O_left_shift
|| op
== O_right_shift
)
2169 if (!(seg_left
== absolute_section
&& left
== 0))
2175 else if (op
!= O_multiply
2176 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2179 else if (op
== O_multiply
2180 && seg_left
== absolute_section
&& left
== 1)
2182 seg_left
= seg_right
;
2184 add_symbol
= op_symbol
;
2185 orig_add_symbol
= expressionP
->X_op_symbol
;
2189 else if ((op
== O_multiply
|| op
== O_divide
)
2190 && seg_right
== absolute_section
&& right
== 1)
2195 else if (!(left
== right
2196 && ((seg_left
== reg_section
&& seg_right
== reg_section
)
2197 || (seg_left
== undefined_section
2198 && seg_right
== undefined_section
2199 && add_symbol
== op_symbol
))))
2201 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2206 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2210 right
+= frag_off
/ OCTETS_PER_BYTE
;
2213 case O_add
: left
+= right
; break;
2214 case O_subtract
: left
-= right
; break;
2215 case O_multiply
: left
*= right
; break;
2219 left
= (offsetT
) left
/ (offsetT
) right
;
2224 left
= (offsetT
) left
% (offsetT
) right
;
2226 case O_left_shift
: left
<<= right
; break;
2227 case O_right_shift
: left
>>= right
; break;
2228 case O_bit_inclusive_or
: left
|= right
; break;
2229 case O_bit_or_not
: left
|= ~right
; break;
2230 case O_bit_exclusive_or
: left
^= right
; break;
2231 case O_bit_and
: left
&= right
; break;
2234 left
= (left
== right
2235 && seg_left
== seg_right
2236 && (finalize_syms
|| frag_left
== frag_right
)
2237 && (seg_left
!= undefined_section
2238 || add_symbol
== op_symbol
)
2239 ? ~ (valueT
) 0 : 0);
2244 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2247 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2250 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2253 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2255 case O_logical_and
: left
= left
&& right
; break;
2256 case O_logical_or
: left
= left
|| right
; break;
2266 if (seg_left
== absolute_section
)
2268 else if (seg_left
== reg_section
&& final_val
== 0)
2270 else if (!symbol_same_p (add_symbol
, orig_add_symbol
))
2272 expressionP
->X_add_symbol
= add_symbol
;
2274 expressionP
->X_op
= op
;
2276 if (op
== O_constant
|| op
== O_register
)
2278 expressionP
->X_add_number
= final_val
;
2283 /* This lives here because it belongs equally in expr.c & read.c.
2284 expr.c is just a branch office read.c anyway, and putting it
2285 here lessens the crowd at read.c.
2287 Assume input_line_pointer is at start of symbol name.
2288 Advance input_line_pointer past symbol name.
2289 Turn that character into a '\0', returning its former value.
2290 This allows a string compare (RMS wants symbol names to be strings)
2292 There will always be a char following symbol name, because all good
2293 lines end in end-of-line. */
2296 get_symbol_end (void)
2300 /* We accept \001 in a name in case this is being called with a
2301 constructed string. */
2302 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2304 while (is_part_of_name (c
= *input_line_pointer
++)
2307 if (is_name_ender (c
))
2308 c
= *input_line_pointer
++;
2310 *--input_line_pointer
= 0;
2315 get_single_number (void)
2318 operand (&exp
, expr_normal
);
2319 return exp
.X_add_number
;