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
4 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"
34 static void floating_constant (expressionS
* expressionP
);
35 static valueT
generic_bignum_to_int32 (void);
37 static valueT
generic_bignum_to_int64 (void);
39 static void integer_constant (int radix
, expressionS
* expressionP
);
40 static void mri_char_constant (expressionS
*);
41 static void current_location (expressionS
*);
42 static void clean_up_expression (expressionS
* expressionP
);
43 static segT
operand (expressionS
*, enum expr_mode
);
44 static operatorT
operator (int *);
46 extern const char EXP_CHARS
[], FLT_CHARS
[];
48 /* We keep a mapping of expression symbols to file positions, so that
49 we can provide better error messages. */
51 struct expr_symbol_line
{
52 struct expr_symbol_line
*next
;
58 static struct expr_symbol_line
*expr_symbol_lines
;
60 /* Build a dummy symbol to hold a complex expression. This is how we
61 build expressions up out of other expressions. The symbol is put
62 into the fake section expr_section. */
65 make_expr_symbol (expressionS
*expressionP
)
69 struct expr_symbol_line
*n
;
71 if (expressionP
->X_op
== O_symbol
72 && expressionP
->X_add_number
== 0)
73 return expressionP
->X_add_symbol
;
75 if (expressionP
->X_op
== O_big
)
77 /* This won't work, because the actual value is stored in
78 generic_floating_point_number or generic_bignum, and we are
79 going to lose it if we haven't already. */
80 if (expressionP
->X_add_number
> 0)
81 as_bad (_("bignum invalid"));
83 as_bad (_("floating point number invalid"));
84 zero
.X_op
= O_constant
;
85 zero
.X_add_number
= 0;
87 clean_up_expression (&zero
);
91 /* Putting constant symbols in absolute_section rather than
92 expr_section is convenient for the old a.out code, for which
93 S_GET_SEGMENT does not always retrieve the value put in by
95 symbolP
= symbol_create (FAKE_LABEL_NAME
,
96 (expressionP
->X_op
== O_constant
98 : expressionP
->X_op
== O_register
101 0, &zero_address_frag
);
102 symbol_set_value_expression (symbolP
, expressionP
);
104 if (expressionP
->X_op
== O_constant
)
105 resolve_symbol_value (symbolP
);
107 n
= (struct expr_symbol_line
*) xmalloc (sizeof *n
);
109 as_where (&n
->file
, &n
->line
);
110 n
->next
= expr_symbol_lines
;
111 expr_symbol_lines
= n
;
116 /* Return the file and line number for an expr symbol. Return
117 non-zero if something was found, 0 if no information is known for
121 expr_symbol_where (symbolS
*sym
, char **pfile
, unsigned int *pline
)
123 register struct expr_symbol_line
*l
;
125 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
138 /* Utilities for building expressions.
139 Since complex expressions are recorded as symbols for use in other
140 expressions these return a symbolS * and not an expressionS *.
141 These explicitly do not take an "add_number" argument. */
142 /* ??? For completeness' sake one might want expr_build_symbol.
143 It would just return its argument. */
145 /* Build an expression for an unsigned constant.
146 The corresponding one for signed constants is missing because
147 there's currently no need for it. One could add an unsigned_p flag
148 but that seems more clumsy. */
151 expr_build_uconstant (offsetT value
)
156 e
.X_add_number
= value
;
158 return make_expr_symbol (&e
);
161 /* Build an expression for the current location ('.'). */
164 expr_build_dot (void)
168 current_location (&e
);
169 return make_expr_symbol (&e
);
172 /* Build any floating-point literal here.
173 Also build any bignum literal here. */
175 /* Seems atof_machine can backscan through generic_bignum and hit whatever
176 happens to be loaded before it in memory. And its way too complicated
177 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
178 and never write into the early words, thus they'll always be zero.
179 I hate Dean's floating-point code. Bleh. */
180 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
182 FLONUM_TYPE generic_floating_point_number
= {
183 &generic_bignum
[6], /* low. (JF: Was 0) */
184 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
192 floating_constant (expressionS
*expressionP
)
194 /* input_line_pointer -> floating-point constant. */
197 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
198 &generic_floating_point_number
);
202 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
204 as_bad (_("bad floating-point constant: exponent overflow"));
208 as_bad (_("bad floating-point constant: unknown error code=%d"),
212 expressionP
->X_op
= O_big
;
213 /* input_line_pointer -> just after constant, which may point to
215 expressionP
->X_add_number
= -1;
219 generic_bignum_to_int32 (void)
222 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
223 | (generic_bignum
[0] & LITTLENUM_MASK
);
224 number
&= 0xffffffff;
230 generic_bignum_to_int64 (void)
233 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
234 << LITTLENUM_NUMBER_OF_BITS
)
235 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
236 << LITTLENUM_NUMBER_OF_BITS
)
237 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
238 << LITTLENUM_NUMBER_OF_BITS
)
239 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
245 integer_constant (int radix
, expressionS
*expressionP
)
247 char *start
; /* Start of number. */
250 valueT number
; /* Offset or (absolute) value. */
251 short int digit
; /* Value of next digit in current radix. */
252 short int maxdig
= 0; /* Highest permitted digit value. */
253 int too_many_digits
= 0; /* If we see >= this number of. */
254 char *name
; /* Points to name of symbol. */
255 symbolS
*symbolP
; /* Points to symbol. */
257 int small
; /* True if fits in 32 bits. */
259 /* May be bignum, or may fit in 32 bits. */
260 /* Most numbers fit into 32 bits, and we want this case to be fast.
261 so we pretend it will fit into 32 bits. If, after making up a 32
262 bit number, we realise that we have scanned more digits than
263 comfortably fit into 32 bits, we re-scan the digits coding them
264 into a bignum. For decimal and octal numbers we are
265 conservative: Some numbers may be assumed bignums when in fact
266 they do fit into 32 bits. Numbers of any radix can have excess
267 leading zeros: We strive to recognise this and cast them back
268 into 32 bits. We must check that the bignum really is more than
269 32 bits, and change it back to a 32-bit number if it fits. The
270 number we are looking for is expected to be positive, but if it
271 fits into 32 bits as an unsigned number, we let it be a 32-bit
272 number. The cavalier approach is for speed in ordinary cases. */
273 /* This has been extended for 64 bits. We blindly assume that if
274 you're compiling in 64-bit mode, the target is a 64-bit machine.
275 This should be cleaned up. */
279 #else /* includes non-bfd case, mostly */
283 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
287 /* In MRI mode, the number may have a suffix indicating the
288 radix. For that matter, it might actually be a floating
290 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
292 if (*suffix
== 'e' || *suffix
== 'E')
296 if (suffix
== input_line_pointer
)
305 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
306 we distinguish between 'B' and 'b'. This is the case for
308 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
312 else if (c
== 'O' || c
== 'Q')
316 else if (suffix
[1] == '.' || c
== 'E' || flt
)
318 floating_constant (expressionP
);
333 too_many_digits
= valuesize
+ 1;
337 too_many_digits
= (valuesize
+ 2) / 3 + 1;
341 too_many_digits
= (valuesize
+ 3) / 4 + 1;
345 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
348 start
= input_line_pointer
;
349 c
= *input_line_pointer
++;
351 (digit
= hex_value (c
)) < maxdig
;
352 c
= *input_line_pointer
++)
354 number
= number
* radix
+ digit
;
356 /* c contains character after number. */
357 /* input_line_pointer->char after c. */
358 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
360 if (radix
== 16 && c
== '_')
362 /* This is literal of the form 0x333_0_12345678_1.
363 This example is equivalent to 0x00000333000000001234567800000001. */
365 int num_little_digits
= 0;
367 input_line_pointer
= start
; /* -> 1st digit. */
369 know (LITTLENUM_NUMBER_OF_BITS
== 16);
371 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
374 /* Convert one 64-bit word. */
377 for (c
= *input_line_pointer
++;
378 (digit
= hex_value (c
)) < maxdig
;
379 c
= *(input_line_pointer
++))
381 number
= number
* radix
+ digit
;
385 /* Check for 8 digit per word max. */
387 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
389 /* Add this chunk to the bignum.
390 Shift things down 2 little digits. */
391 know (LITTLENUM_NUMBER_OF_BITS
== 16);
392 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
395 generic_bignum
[i
] = generic_bignum
[i
- 2];
397 /* Add the new digits as the least significant new ones. */
398 generic_bignum
[0] = number
& 0xffffffff;
399 generic_bignum
[1] = number
>> 16;
402 /* Again, c is char after number, input_line_pointer->after c. */
404 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
405 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
407 assert (num_little_digits
>= 4);
409 if (num_little_digits
!= 8)
410 as_bad (_("a bignum with underscores must have exactly 4 words"));
412 /* We might have some leading zeros. These can be trimmed to give
413 us a change to fit this constant into a small number. */
414 while (generic_bignum
[num_little_digits
- 1] == 0
415 && num_little_digits
> 1)
418 if (num_little_digits
<= 2)
420 /* will fit into 32 bits. */
421 number
= generic_bignum_to_int32 ();
425 else if (num_little_digits
<= 4)
427 /* Will fit into 64 bits. */
428 number
= generic_bignum_to_int64 ();
436 /* Number of littlenums in the bignum. */
437 number
= num_little_digits
;
442 /* We saw a lot of digits. manufacture a bignum the hard way. */
443 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
444 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
447 leader
= generic_bignum
;
448 generic_bignum
[0] = 0;
449 generic_bignum
[1] = 0;
450 generic_bignum
[2] = 0;
451 generic_bignum
[3] = 0;
452 input_line_pointer
= start
; /* -> 1st digit. */
453 c
= *input_line_pointer
++;
454 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
456 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
460 work
= carry
+ radix
* *pointer
;
461 *pointer
= work
& LITTLENUM_MASK
;
462 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
466 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
468 /* Room to grow a longer bignum. */
473 /* Again, c is char after number. */
474 /* input_line_pointer -> after c. */
475 know (LITTLENUM_NUMBER_OF_BITS
== 16);
476 if (leader
< generic_bignum
+ 2)
478 /* Will fit into 32 bits. */
479 number
= generic_bignum_to_int32 ();
483 else if (leader
< generic_bignum
+ 4)
485 /* Will fit into 64 bits. */
486 number
= generic_bignum_to_int64 ();
492 /* Number of littlenums in the bignum. */
493 number
= leader
- generic_bignum
+ 1;
497 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
499 && input_line_pointer
- 1 == suffix
)
500 c
= *input_line_pointer
++;
504 /* Here with number, in correct radix. c is the next char.
505 Note that unlike un*x, we allow "011f" "0x9f" to both mean
506 the same as the (conventional) "9f".
507 This is simply easier than checking for strict canonical
510 if (LOCAL_LABELS_FB
&& c
== 'b')
512 /* Backward ref to local label.
513 Because it is backward, expect it to be defined. */
514 /* Construct a local label. */
515 name
= fb_label_name ((int) number
, 0);
517 /* Seen before, or symbol is defined: OK. */
518 symbolP
= symbol_find (name
);
519 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
521 /* Local labels are never absolute. Don't waste time
522 checking absoluteness. */
523 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
525 expressionP
->X_op
= O_symbol
;
526 expressionP
->X_add_symbol
= symbolP
;
530 /* Either not seen or not defined. */
531 /* @@ Should print out the original string instead of
532 the parsed number. */
533 as_bad (_("backward ref to unknown label \"%d:\""),
535 expressionP
->X_op
= O_constant
;
538 expressionP
->X_add_number
= 0;
540 else if (LOCAL_LABELS_FB
&& c
== 'f')
542 /* Forward reference. Expect symbol to be undefined or
543 unknown. undefined: seen it before. unknown: never seen
546 Construct a local label name, then an undefined symbol.
547 Don't create a xseg frag for it: caller may do that.
548 Just return it as never seen before. */
549 name
= fb_label_name ((int) number
, 1);
550 symbolP
= symbol_find_or_make (name
);
551 /* We have no need to check symbol properties. */
552 #ifndef many_segments
553 /* Since "know" puts its arg into a "string", we
554 can't have newlines in the argument. */
555 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
557 expressionP
->X_op
= O_symbol
;
558 expressionP
->X_add_symbol
= symbolP
;
559 expressionP
->X_add_number
= 0;
561 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
563 /* If the dollar label is *currently* defined, then this is just
564 another reference to it. If it is not *currently* defined,
565 then this is a fresh instantiation of that number, so create
568 if (dollar_label_defined ((long) number
))
570 name
= dollar_label_name ((long) number
, 0);
571 symbolP
= symbol_find (name
);
572 know (symbolP
!= NULL
);
576 name
= dollar_label_name ((long) number
, 1);
577 symbolP
= symbol_find_or_make (name
);
580 expressionP
->X_op
= O_symbol
;
581 expressionP
->X_add_symbol
= symbolP
;
582 expressionP
->X_add_number
= 0;
586 expressionP
->X_op
= O_constant
;
587 expressionP
->X_add_number
= number
;
588 input_line_pointer
--; /* Restore following character. */
589 } /* Really just a number. */
593 /* Not a small number. */
594 expressionP
->X_op
= O_big
;
595 expressionP
->X_add_number
= number
; /* Number of littlenums. */
596 input_line_pointer
--; /* -> char following number. */
600 /* Parse an MRI multi character constant. */
603 mri_char_constant (expressionS
*expressionP
)
607 if (*input_line_pointer
== '\''
608 && input_line_pointer
[1] != '\'')
610 expressionP
->X_op
= O_constant
;
611 expressionP
->X_add_number
= 0;
615 /* In order to get the correct byte ordering, we must build the
616 number in reverse. */
617 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
621 generic_bignum
[i
] = 0;
622 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
624 if (*input_line_pointer
== '\'')
626 if (input_line_pointer
[1] != '\'')
628 ++input_line_pointer
;
630 generic_bignum
[i
] <<= 8;
631 generic_bignum
[i
] += *input_line_pointer
;
632 ++input_line_pointer
;
635 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
637 /* If there is more than one littlenum, left justify the
638 last one to make it match the earlier ones. If there is
639 only one, we can just use the value directly. */
640 for (; j
< CHARS_PER_LITTLENUM
; j
++)
641 generic_bignum
[i
] <<= 8;
644 if (*input_line_pointer
== '\''
645 && input_line_pointer
[1] != '\'')
651 as_bad (_("character constant too large"));
660 c
= SIZE_OF_LARGE_NUMBER
- i
;
661 for (j
= 0; j
< c
; j
++)
662 generic_bignum
[j
] = generic_bignum
[i
+ j
];
666 know (LITTLENUM_NUMBER_OF_BITS
== 16);
669 expressionP
->X_op
= O_big
;
670 expressionP
->X_add_number
= i
;
674 expressionP
->X_op
= O_constant
;
676 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
678 expressionP
->X_add_number
=
679 (((generic_bignum
[1] & LITTLENUM_MASK
)
680 << LITTLENUM_NUMBER_OF_BITS
)
681 | (generic_bignum
[0] & LITTLENUM_MASK
));
684 /* Skip the final closing quote. */
685 ++input_line_pointer
;
688 /* Return an expression representing the current location. This
689 handles the magic symbol `.'. */
692 current_location (expressionS
*expressionp
)
694 if (now_seg
== absolute_section
)
696 expressionp
->X_op
= O_constant
;
697 expressionp
->X_add_number
= abs_section_offset
;
701 expressionp
->X_op
= O_symbol
;
702 expressionp
->X_add_symbol
= symbol_temp_new_now ();
703 expressionp
->X_add_number
= 0;
707 /* In: Input_line_pointer points to 1st char of operand, which may
711 The operand may have been empty: in this case X_op == O_absent.
712 Input_line_pointer->(next non-blank) char after operand. */
715 operand (expressionS
*expressionP
, enum expr_mode mode
)
718 symbolS
*symbolP
; /* Points to symbol. */
719 char *name
; /* Points to name of symbol. */
722 /* All integers are regarded as unsigned unless they are negated.
723 This is because the only thing which cares whether a number is
724 unsigned is the code in emit_expr which extends constants into
725 bignums. It should only sign extend negative numbers, so that
726 something like ``.quad 0x80000000'' is not sign extended even
727 though it appears negative if valueT is 32 bits. */
728 expressionP
->X_unsigned
= 1;
730 /* Digits, assume it is a bignum. */
732 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
733 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
735 if (is_end_of_line
[(unsigned char) c
])
749 input_line_pointer
--;
751 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
756 #ifdef LITERAL_PREFIXDOLLAR_HEX
758 /* $L is the start of a local label, not a hex constant. */
759 if (* input_line_pointer
== 'L')
761 integer_constant (16, expressionP
);
765 #ifdef LITERAL_PREFIXPERCENT_BIN
767 integer_constant (2, expressionP
);
772 /* Non-decimal radix. */
774 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
778 /* Check for a hex or float constant. */
779 for (s
= input_line_pointer
; hex_p (*s
); s
++)
781 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
783 --input_line_pointer
;
784 integer_constant (0, expressionP
);
788 c
= *input_line_pointer
;
797 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
799 integer_constant (0, expressionP
);
805 if (c
&& strchr (FLT_CHARS
, c
))
807 input_line_pointer
++;
808 floating_constant (expressionP
);
809 expressionP
->X_add_number
= - TOLOWER (c
);
813 /* The string was only zero. */
814 expressionP
->X_op
= O_constant
;
815 expressionP
->X_add_number
= 0;
824 input_line_pointer
++;
825 integer_constant (16, expressionP
);
829 if (LOCAL_LABELS_FB
&& ! (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
))
831 /* This code used to check for '+' and '-' here, and, in
832 some conditions, fall through to call
833 integer_constant. However, that didn't make sense,
834 as integer_constant only accepts digits. */
835 /* Some of our code elsewhere does permit digits greater
836 than the expected base; for consistency, do the same
838 if (input_line_pointer
[1] < '0'
839 || input_line_pointer
[1] > '9')
841 /* Parse this as a back reference to label 0. */
842 input_line_pointer
--;
843 integer_constant (10, expressionP
);
846 /* Otherwise, parse this as a binary number. */
850 input_line_pointer
++;
851 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
853 integer_constant (2, expressionP
);
864 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
872 /* If it says "0f" and it could possibly be a floating point
873 number, make it one. Otherwise, make it a local label,
874 and try to deal with parsing the rest later. */
875 if (!input_line_pointer
[1]
876 || (is_end_of_line
[0xff & input_line_pointer
[1]])
877 || strchr (FLT_CHARS
, 'f') == NULL
)
880 char *cp
= input_line_pointer
+ 1;
881 int r
= atof_generic (&cp
, ".", EXP_CHARS
,
882 &generic_floating_point_number
);
886 case ERROR_EXPONENT_OVERFLOW
:
887 if (*cp
== 'f' || *cp
== 'b')
888 /* Looks like a difference expression. */
890 else if (cp
== input_line_pointer
+ 1)
891 /* No characters has been accepted -- looks like
897 as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
902 /* Okay, now we've sorted it out. We resume at one of these
903 two labels, depending on what we've decided we're probably
906 input_line_pointer
--;
907 integer_constant (10, expressionP
);
917 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
919 integer_constant (0, expressionP
);
929 input_line_pointer
++;
930 floating_constant (expressionP
);
931 expressionP
->X_add_number
= - TOLOWER (c
);
935 if (LOCAL_LABELS_DOLLAR
)
937 integer_constant (10, expressionP
);
947 #ifndef NEED_INDEX_OPERATOR
950 /* Didn't begin with digit & not a name. */
951 if (mode
!= expr_defer
)
952 segment
= expression (expressionP
);
954 segment
= deferred_expression (expressionP
);
955 /* expression () will pass trailing whitespace. */
956 if ((c
== '(' && *input_line_pointer
!= ')')
957 || (c
== '[' && *input_line_pointer
!= ']'))
958 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
960 input_line_pointer
++;
962 /* Here with input_line_pointer -> char after "(...)". */
967 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
969 as_bad (_("EBCDIC constants are not supported"));
972 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
974 ++input_line_pointer
;
980 /* Warning: to conform to other people's assemblers NO
981 ESCAPEMENT is permitted for a single quote. The next
982 character, parity errors and all, is taken as the value
983 of the operand. VERY KINKY. */
984 expressionP
->X_op
= O_constant
;
985 expressionP
->X_add_number
= *input_line_pointer
++;
989 mri_char_constant (expressionP
);
994 /* Double quote is the bitwise not operator in MRI mode. */
1000 /* '~' is permitted to start a label on the Delta. */
1001 if (is_name_beginner (c
))
1007 operand (expressionP
, mode
);
1008 if (expressionP
->X_op
== O_constant
)
1010 /* input_line_pointer -> char after operand. */
1013 expressionP
->X_add_number
= - expressionP
->X_add_number
;
1014 /* Notice: '-' may overflow: no warning is given.
1015 This is compatible with other people's
1016 assemblers. Sigh. */
1017 expressionP
->X_unsigned
= 0;
1019 else if (c
== '~' || c
== '"')
1020 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1022 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1024 else if (expressionP
->X_op
== O_big
1025 && expressionP
->X_add_number
<= 0
1027 && (generic_floating_point_number
.sign
== '+'
1028 || generic_floating_point_number
.sign
== 'P'))
1030 /* Negative flonum (eg, -1.000e0). */
1031 if (generic_floating_point_number
.sign
== '+')
1032 generic_floating_point_number
.sign
= '-';
1034 generic_floating_point_number
.sign
= 'N';
1036 else if (expressionP
->X_op
== O_big
1037 && expressionP
->X_add_number
> 0)
1041 if (c
== '~' || c
== '-')
1043 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1044 generic_bignum
[i
] = ~generic_bignum
[i
];
1046 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1048 generic_bignum
[i
] += 1;
1049 if (generic_bignum
[i
])
1056 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1058 if (generic_bignum
[i
])
1060 generic_bignum
[i
] = 0;
1062 generic_bignum
[0] = nonzero
;
1065 else if (expressionP
->X_op
!= O_illegal
1066 && expressionP
->X_op
!= O_absent
)
1070 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1072 expressionP
->X_op
= O_uminus
;
1073 else if (c
== '~' || c
== '"')
1074 expressionP
->X_op
= O_bit_not
;
1076 expressionP
->X_op
= O_logical_not
;
1077 expressionP
->X_add_number
= 0;
1081 as_warn (_("Unary operator %c ignored because bad operand follows"),
1086 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1088 /* '$' is the program counter when in MRI mode, or when
1089 DOLLAR_DOT is defined. */
1091 if (! flag_m68k_mri
)
1094 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1096 /* In MRI mode and on Z80, '$' is also used as the prefix
1097 for a hexadecimal constant. */
1098 integer_constant (16, expressionP
);
1102 if (is_part_of_name (*input_line_pointer
))
1105 current_location (expressionP
);
1110 if (!is_part_of_name (*input_line_pointer
))
1112 current_location (expressionP
);
1115 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1116 && ! is_part_of_name (input_line_pointer
[8]))
1117 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1118 && ! is_part_of_name (input_line_pointer
[7])))
1122 start
= (input_line_pointer
[1] == 't'
1123 || input_line_pointer
[1] == 'T');
1124 input_line_pointer
+= start
? 8 : 7;
1126 if (*input_line_pointer
!= '(')
1127 as_bad (_("syntax error in .startof. or .sizeof."));
1132 ++input_line_pointer
;
1134 name
= input_line_pointer
;
1135 c
= get_symbol_end ();
1137 buf
= (char *) xmalloc (strlen (name
) + 10);
1139 sprintf (buf
, ".startof.%s", name
);
1141 sprintf (buf
, ".sizeof.%s", name
);
1142 symbolP
= symbol_make (buf
);
1145 expressionP
->X_op
= O_symbol
;
1146 expressionP
->X_add_symbol
= symbolP
;
1147 expressionP
->X_add_number
= 0;
1149 *input_line_pointer
= c
;
1151 if (*input_line_pointer
!= ')')
1152 as_bad (_("syntax error in .startof. or .sizeof."));
1154 ++input_line_pointer
;
1165 /* Can't imagine any other kind of operand. */
1166 expressionP
->X_op
= O_absent
;
1167 input_line_pointer
--;
1172 if (! flag_m68k_mri
)
1174 integer_constant (2, expressionP
);
1178 if (! flag_m68k_mri
)
1180 integer_constant (8, expressionP
);
1184 if (! flag_m68k_mri
)
1187 /* In MRI mode, this is a floating point constant represented
1188 using hexadecimal digits. */
1190 ++input_line_pointer
;
1191 integer_constant (16, expressionP
);
1195 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1198 current_location (expressionP
);
1206 if (is_name_beginner (c
)) /* Here if did not begin with a digit. */
1208 /* Identifier begins here.
1209 This is kludged for speed, so code is repeated. */
1211 name
= --input_line_pointer
;
1212 c
= get_symbol_end ();
1214 #ifdef md_parse_name
1215 /* This is a hook for the backend to parse certain names
1216 specially in certain contexts. If a name always has a
1217 specific value, it can often be handled by simply
1218 entering it in the symbol table. */
1219 if (md_parse_name (name
, expressionP
, mode
, &c
))
1221 *input_line_pointer
= c
;
1227 /* The MRI i960 assembler permits
1229 FIXME: This should use md_parse_name. */
1231 && (strcasecmp (name
, "sizeof") == 0
1232 || strcasecmp (name
, "startof") == 0))
1237 start
= (name
[1] == 't'
1240 *input_line_pointer
= c
;
1243 name
= input_line_pointer
;
1244 c
= get_symbol_end ();
1246 buf
= (char *) xmalloc (strlen (name
) + 10);
1248 sprintf (buf
, ".startof.%s", name
);
1250 sprintf (buf
, ".sizeof.%s", name
);
1251 symbolP
= symbol_make (buf
);
1254 expressionP
->X_op
= O_symbol
;
1255 expressionP
->X_add_symbol
= symbolP
;
1256 expressionP
->X_add_number
= 0;
1258 *input_line_pointer
= c
;
1265 symbolP
= symbol_find_or_make (name
);
1267 /* If we have an absolute symbol or a reg, then we know its
1269 segment
= S_GET_SEGMENT (symbolP
);
1270 if (mode
!= expr_defer
&& segment
== absolute_section
)
1272 expressionP
->X_op
= O_constant
;
1273 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1275 else if (mode
!= expr_defer
&& segment
== reg_section
)
1277 expressionP
->X_op
= O_register
;
1278 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1282 expressionP
->X_op
= O_symbol
;
1283 expressionP
->X_add_symbol
= symbolP
;
1284 expressionP
->X_add_number
= 0;
1286 *input_line_pointer
= c
;
1290 /* Let the target try to parse it. Success is indicated by changing
1291 the X_op field to something other than O_absent and pointing
1292 input_line_pointer past the expression. If it can't parse the
1293 expression, X_op and input_line_pointer should be unchanged. */
1294 expressionP
->X_op
= O_absent
;
1295 --input_line_pointer
;
1296 md_operand (expressionP
);
1297 if (expressionP
->X_op
== O_absent
)
1299 ++input_line_pointer
;
1300 as_bad (_("bad expression"));
1301 expressionP
->X_op
= O_constant
;
1302 expressionP
->X_add_number
= 0;
1308 /* It is more 'efficient' to clean up the expressionS when they are
1309 created. Doing it here saves lines of code. */
1310 clean_up_expression (expressionP
);
1311 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1312 know (*input_line_pointer
!= ' ');
1314 /* The PA port needs this information. */
1315 if (expressionP
->X_add_symbol
)
1316 symbol_mark_used (expressionP
->X_add_symbol
);
1318 expressionP
->X_add_symbol
= symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1319 expressionP
->X_op_symbol
= symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1321 switch (expressionP
->X_op
)
1324 return absolute_section
;
1326 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1332 /* Internal. Simplify a struct expression for use by expr (). */
1334 /* In: address of an expressionS.
1335 The X_op field of the expressionS may only take certain values.
1336 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1338 Out: expressionS may have been modified:
1339 Unused fields zeroed to help expr (). */
1342 clean_up_expression (expressionS
*expressionP
)
1344 switch (expressionP
->X_op
)
1348 expressionP
->X_add_number
= 0;
1353 expressionP
->X_add_symbol
= NULL
;
1358 expressionP
->X_op_symbol
= NULL
;
1365 /* Expression parser. */
1367 /* We allow an empty expression, and just assume (absolute,0) silently.
1368 Unary operators and parenthetical expressions are treated as operands.
1369 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1371 We used to do an aho/ullman shift-reduce parser, but the logic got so
1372 warped that I flushed it and wrote a recursive-descent parser instead.
1373 Now things are stable, would anybody like to write a fast parser?
1374 Most expressions are either register (which does not even reach here)
1375 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1376 So I guess it doesn't really matter how inefficient more complex expressions
1379 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1380 Also, we have consumed any leading or trailing spaces (operand does that)
1381 and done all intervening operators.
1383 This returns the segment of the result, which will be
1384 absolute_section or the segment of a symbol. */
1387 #define __ O_illegal
1389 #define O_SINGLE_EQ O_illegal
1392 /* Maps ASCII -> operators. */
1393 static const operatorT op_encoding
[256] = {
1394 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1395 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1397 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1398 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1399 __
, __
, __
, __
, __
, __
, __
, __
,
1400 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1401 __
, __
, __
, __
, __
, __
, __
, __
,
1402 __
, __
, __
, __
, __
, __
, __
, __
,
1403 __
, __
, __
, __
, __
, __
, __
, __
,
1405 #ifdef NEED_INDEX_OPERATOR
1410 __
, __
, O_bit_exclusive_or
, __
,
1411 __
, __
, __
, __
, __
, __
, __
, __
,
1412 __
, __
, __
, __
, __
, __
, __
, __
,
1413 __
, __
, __
, __
, __
, __
, __
, __
,
1414 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1416 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1417 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1418 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1419 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1420 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1421 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1422 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1423 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1427 0 operand, (expression)
1432 5 used for * / % in MRI mode
1437 static operator_rankT op_rank
[] = {
1442 0, /* O_symbol_rva */
1447 9, /* O_logical_not */
1451 8, /* O_left_shift */
1452 8, /* O_right_shift */
1453 7, /* O_bit_inclusive_or */
1454 7, /* O_bit_or_not */
1455 7, /* O_bit_exclusive_or */
1465 3, /* O_logical_and */
1466 2, /* O_logical_or */
1486 /* Unfortunately, in MRI mode for the m68k, multiplication and
1487 division have lower precedence than the bit wise operators. This
1488 function sets the operator precedences correctly for the current
1489 mode. Also, MRI uses a different bit_not operator, and this fixes
1492 #define STANDARD_MUL_PRECEDENCE 8
1493 #define MRI_MUL_PRECEDENCE 6
1496 expr_set_precedence (void)
1500 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1501 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1502 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1506 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1507 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1508 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1512 /* Initialize the expression parser. */
1517 expr_set_precedence ();
1519 /* Verify that X_op field is wide enough. */
1523 assert (e
.X_op
== O_max
);
1527 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1528 sets NUM_CHARS to the number of characters in the operator.
1529 Does not advance INPUT_LINE_POINTER. */
1531 static inline operatorT
1532 operator (int *num_chars
)
1537 c
= *input_line_pointer
& 0xff;
1540 if (is_end_of_line
[c
])
1546 return op_encoding
[c
];
1550 return op_encoding
[c
];
1553 switch (input_line_pointer
[1])
1556 return op_encoding
[c
];
1571 if (input_line_pointer
[1] != '=')
1572 return op_encoding
[c
];
1578 switch (input_line_pointer
[1])
1581 return op_encoding
[c
];
1583 ret
= O_right_shift
;
1593 switch (input_line_pointer
[1])
1596 /* We accept !! as equivalent to ^ for MRI compatibility. */
1598 return O_bit_exclusive_or
;
1600 /* We accept != as equivalent to <>. */
1605 return O_bit_inclusive_or
;
1606 return op_encoding
[c
];
1610 if (input_line_pointer
[1] != '|')
1611 return op_encoding
[c
];
1614 return O_logical_or
;
1617 if (input_line_pointer
[1] != '&')
1618 return op_encoding
[c
];
1621 return O_logical_and
;
1627 /* Parse an expression. */
1630 expr (int rankarg
, /* Larger # is higher rank. */
1631 expressionS
*resultP
, /* Deliver result here. */
1632 enum expr_mode mode
/* Controls behavior. */)
1634 operator_rankT rank
= (operator_rankT
) rankarg
;
1641 know (rankarg
>= 0);
1643 /* Save the value of dot for the fixup code. */
1645 dot_value
= frag_now_fix ();
1647 retval
= operand (resultP
, mode
);
1649 /* operand () gobbles spaces. */
1650 know (*input_line_pointer
!= ' ');
1652 op_left
= operator (&op_chars
);
1653 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1658 input_line_pointer
+= op_chars
; /* -> after operator. */
1660 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1661 if (right
.X_op
== O_absent
)
1663 as_warn (_("missing operand; zero assumed"));
1664 right
.X_op
= O_constant
;
1665 right
.X_add_number
= 0;
1666 right
.X_add_symbol
= NULL
;
1667 right
.X_op_symbol
= NULL
;
1670 know (*input_line_pointer
!= ' ');
1672 if (op_left
== O_index
)
1674 if (*input_line_pointer
!= ']')
1675 as_bad ("missing right bracket");
1678 ++input_line_pointer
;
1683 op_right
= operator (&op_chars
);
1685 know (op_right
== O_illegal
1686 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1687 know ((int) op_left
>= (int) O_multiply
1688 && (int) op_left
<= (int) O_index
);
1690 /* input_line_pointer->after right-hand quantity. */
1691 /* left-hand quantity in resultP. */
1692 /* right-hand quantity in right. */
1693 /* operator in op_left. */
1695 if (resultP
->X_op
== O_big
)
1697 if (resultP
->X_add_number
> 0)
1698 as_warn (_("left operand is a bignum; integer 0 assumed"));
1700 as_warn (_("left operand is a float; integer 0 assumed"));
1701 resultP
->X_op
= O_constant
;
1702 resultP
->X_add_number
= 0;
1703 resultP
->X_add_symbol
= NULL
;
1704 resultP
->X_op_symbol
= NULL
;
1706 if (right
.X_op
== O_big
)
1708 if (right
.X_add_number
> 0)
1709 as_warn (_("right operand is a bignum; integer 0 assumed"));
1711 as_warn (_("right operand is a float; integer 0 assumed"));
1712 right
.X_op
= O_constant
;
1713 right
.X_add_number
= 0;
1714 right
.X_add_symbol
= NULL
;
1715 right
.X_op_symbol
= NULL
;
1718 /* Optimize common cases. */
1719 #ifdef md_optimize_expr
1720 if (md_optimize_expr (resultP
, op_left
, &right
))
1727 #ifndef md_register_arithmetic
1728 # define md_register_arithmetic 1
1730 if (op_left
== O_add
&& right
.X_op
== O_constant
1731 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1734 resultP
->X_add_number
+= right
.X_add_number
;
1736 /* This case comes up in PIC code. */
1737 else if (op_left
== O_subtract
1738 && right
.X_op
== O_symbol
1739 && resultP
->X_op
== O_symbol
1740 && retval
== rightseg
1741 #ifdef md_allow_local_subtract
1742 && md_allow_local_subtract (resultP
, & right
, rightseg
)
1744 && (SEG_NORMAL (rightseg
)
1745 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1746 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1747 symbol_get_frag (right
.X_add_symbol
),
1750 resultP
->X_add_number
-= right
.X_add_number
;
1751 resultP
->X_add_number
-= frag_off
/ OCTETS_PER_BYTE
;
1752 resultP
->X_add_number
+= (S_GET_VALUE (resultP
->X_add_symbol
)
1753 - S_GET_VALUE (right
.X_add_symbol
));
1754 resultP
->X_op
= O_constant
;
1755 resultP
->X_add_symbol
= 0;
1757 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
1758 && (md_register_arithmetic
|| resultP
->X_op
!= O_register
))
1761 resultP
->X_add_number
-= right
.X_add_number
;
1763 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
1764 && (md_register_arithmetic
|| right
.X_op
!= O_register
))
1767 resultP
->X_op
= right
.X_op
;
1768 resultP
->X_add_symbol
= right
.X_add_symbol
;
1769 resultP
->X_op_symbol
= right
.X_op_symbol
;
1770 resultP
->X_add_number
+= right
.X_add_number
;
1773 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1775 /* Constant OP constant. */
1776 offsetT v
= right
.X_add_number
;
1777 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1779 as_warn (_("division by zero"));
1785 case O_multiply
: resultP
->X_add_number
*= v
; break;
1786 case O_divide
: resultP
->X_add_number
/= v
; break;
1787 case O_modulus
: resultP
->X_add_number
%= v
; break;
1788 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1790 /* We always use unsigned shifts, to avoid relying on
1791 characteristics of the compiler used to compile gas. */
1792 resultP
->X_add_number
=
1793 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1795 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1796 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1797 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1798 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1799 /* Constant + constant (O_add) is handled by the
1800 previous if statement for constant + X, so is omitted
1802 case O_subtract
: resultP
->X_add_number
-= v
; break;
1804 resultP
->X_add_number
=
1805 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1808 resultP
->X_add_number
=
1809 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1812 resultP
->X_add_number
=
1813 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1816 resultP
->X_add_number
=
1817 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1820 resultP
->X_add_number
=
1821 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1824 resultP
->X_add_number
=
1825 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1828 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1831 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1835 else if (resultP
->X_op
== O_symbol
1836 && right
.X_op
== O_symbol
1837 && (op_left
== O_add
1838 || op_left
== O_subtract
1839 || (resultP
->X_add_number
== 0
1840 && right
.X_add_number
== 0)))
1842 /* Symbol OP symbol. */
1843 resultP
->X_op
= op_left
;
1844 resultP
->X_op_symbol
= right
.X_add_symbol
;
1845 if (op_left
== O_add
)
1846 resultP
->X_add_number
+= right
.X_add_number
;
1847 else if (op_left
== O_subtract
)
1849 resultP
->X_add_number
-= right
.X_add_number
;
1850 if (retval
== rightseg
&& SEG_NORMAL (retval
))
1852 retval
= absolute_section
;
1853 rightseg
= absolute_section
;
1859 /* The general case. */
1860 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
1861 resultP
->X_op_symbol
= make_expr_symbol (&right
);
1862 resultP
->X_op
= op_left
;
1863 resultP
->X_add_number
= 0;
1864 resultP
->X_unsigned
= 1;
1867 if (retval
!= rightseg
)
1869 if (! SEG_NORMAL (retval
))
1871 if (retval
!= undefined_section
|| SEG_NORMAL (rightseg
))
1874 else if (SEG_NORMAL (rightseg
)
1876 && op_left
!= O_subtract
1879 as_bad (_("operation combines symbols in different segments"));
1883 } /* While next operator is >= this rank. */
1885 /* The PA port needs this information. */
1886 if (resultP
->X_add_symbol
)
1887 symbol_mark_used (resultP
->X_add_symbol
);
1889 if (rank
== 0 && mode
== expr_evaluate
)
1890 resolve_expression (resultP
);
1892 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
1895 /* Resolve an expression without changing any symbols/sub-expressions
1899 resolve_expression (expressionS
*expressionP
)
1901 /* Help out with CSE. */
1902 valueT final_val
= expressionP
->X_add_number
;
1903 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
1904 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
1905 operatorT op
= expressionP
->X_op
;
1907 segT seg_left
, seg_right
;
1908 fragS
*frag_left
, *frag_right
;
1923 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1931 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1934 if (seg_left
!= absolute_section
)
1937 if (op
== O_logical_not
)
1939 else if (op
== O_uminus
)
1951 case O_bit_inclusive_or
:
1953 case O_bit_exclusive_or
:
1965 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
1966 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
1969 /* Simplify addition or subtraction of a constant by folding the
1970 constant into X_add_number. */
1973 if (seg_right
== absolute_section
)
1979 else if (seg_left
== absolute_section
)
1983 seg_left
= seg_right
;
1984 add_symbol
= op_symbol
;
1989 else if (op
== O_subtract
)
1991 if (seg_right
== absolute_section
)
1999 /* Equality and non-equality tests are permitted on anything.
2000 Subtraction, and other comparison operators are permitted if
2001 both operands are in the same section.
2002 Shifts by constant zero are permitted on anything.
2003 Multiplies, bit-ors, and bit-ands with constant zero are
2004 permitted on anything.
2005 Multiplies and divides by constant one are permitted on
2007 Binary operations with both operands being the same register
2008 or undefined symbol are permitted if the result doesn't depend
2010 Otherwise, both operands must be absolute. We already handled
2011 the case of addition or subtraction of a constant above. */
2013 if (!(seg_left
== absolute_section
2014 && seg_right
== absolute_section
)
2015 && !(op
== O_eq
|| op
== O_ne
)
2016 && !((op
== O_subtract
2017 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2018 && seg_left
== seg_right
2020 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
))
2021 && (seg_left
!= reg_section
|| left
== right
)
2022 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2024 if ((seg_left
== absolute_section
&& left
== 0)
2025 || (seg_right
== absolute_section
&& right
== 0))
2027 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2029 if (seg_right
!= absolute_section
|| right
!= 0)
2031 seg_left
= seg_right
;
2033 add_symbol
= op_symbol
;
2038 else if (op
== O_left_shift
|| op
== O_right_shift
)
2040 if (seg_left
!= absolute_section
|| left
!= 0)
2046 else if (op
!= O_multiply
2047 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2050 else if (op
== O_multiply
2051 && seg_left
== absolute_section
&& left
== 1)
2053 seg_left
= seg_right
;
2055 add_symbol
= op_symbol
;
2059 else if ((op
== O_multiply
|| op
== O_divide
)
2060 && seg_right
== absolute_section
&& right
== 1)
2065 else if (left
!= right
2066 || ((seg_left
!= reg_section
|| seg_right
!= reg_section
)
2067 && (seg_left
!= undefined_section
2068 || seg_right
!= undefined_section
2069 || add_symbol
!= op_symbol
)))
2071 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2076 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2080 right
+= frag_off
/ OCTETS_PER_BYTE
;
2083 case O_add
: left
+= right
; break;
2084 case O_subtract
: left
-= right
; break;
2085 case O_multiply
: left
*= right
; break;
2089 left
= (offsetT
) left
/ (offsetT
) right
;
2094 left
= (offsetT
) left
% (offsetT
) right
;
2096 case O_left_shift
: left
<<= right
; break;
2097 case O_right_shift
: left
>>= right
; break;
2098 case O_bit_inclusive_or
: left
|= right
; break;
2099 case O_bit_or_not
: left
|= ~right
; break;
2100 case O_bit_exclusive_or
: left
^= right
; break;
2101 case O_bit_and
: left
&= right
; break;
2104 left
= (left
== right
2105 && seg_left
== seg_right
2106 && (finalize_syms
|| frag_left
== frag_right
)
2107 && (seg_left
!= undefined_section
2108 || add_symbol
== op_symbol
)
2109 ? ~ (valueT
) 0 : 0);
2114 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2117 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2120 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2123 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2125 case O_logical_and
: left
= left
&& right
; break;
2126 case O_logical_or
: left
= left
|| right
; break;
2136 if (seg_left
== absolute_section
)
2138 else if (seg_left
== reg_section
&& final_val
== 0)
2140 else if (add_symbol
!= expressionP
->X_add_symbol
)
2142 expressionP
->X_add_symbol
= add_symbol
;
2144 expressionP
->X_op
= op
;
2146 if (op
== O_constant
|| op
== O_register
)
2148 expressionP
->X_add_number
= final_val
;
2153 /* This lives here because it belongs equally in expr.c & read.c.
2154 expr.c is just a branch office read.c anyway, and putting it
2155 here lessens the crowd at read.c.
2157 Assume input_line_pointer is at start of symbol name.
2158 Advance input_line_pointer past symbol name.
2159 Turn that character into a '\0', returning its former value.
2160 This allows a string compare (RMS wants symbol names to be strings)
2162 There will always be a char following symbol name, because all good
2163 lines end in end-of-line. */
2166 get_symbol_end (void)
2170 /* We accept \001 in a name in case this is being called with a
2171 constructed string. */
2172 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2174 while (is_part_of_name (c
= *input_line_pointer
++)
2177 if (is_name_ender (c
))
2178 c
= *input_line_pointer
++;
2180 *--input_line_pointer
= 0;
2185 get_single_number (void)
2188 operand (&exp
, expr_normal
);
2189 return exp
.X_add_number
;