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
99 0, &zero_address_frag
);
100 symbol_set_value_expression (symbolP
, expressionP
);
102 if (expressionP
->X_op
== O_constant
)
103 resolve_symbol_value (symbolP
);
105 n
= (struct expr_symbol_line
*) xmalloc (sizeof *n
);
107 as_where (&n
->file
, &n
->line
);
108 n
->next
= expr_symbol_lines
;
109 expr_symbol_lines
= n
;
114 /* Return the file and line number for an expr symbol. Return
115 non-zero if something was found, 0 if no information is known for
119 expr_symbol_where (symbolS
*sym
, char **pfile
, unsigned int *pline
)
121 register struct expr_symbol_line
*l
;
123 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
136 /* Utilities for building expressions.
137 Since complex expressions are recorded as symbols for use in other
138 expressions these return a symbolS * and not an expressionS *.
139 These explicitly do not take an "add_number" argument. */
140 /* ??? For completeness' sake one might want expr_build_symbol.
141 It would just return its argument. */
143 /* Build an expression for an unsigned constant.
144 The corresponding one for signed constants is missing because
145 there's currently no need for it. One could add an unsigned_p flag
146 but that seems more clumsy. */
149 expr_build_uconstant (offsetT value
)
154 e
.X_add_number
= value
;
156 return make_expr_symbol (&e
);
159 /* Build an expression for the current location ('.'). */
162 expr_build_dot (void)
166 current_location (&e
);
167 return make_expr_symbol (&e
);
170 /* Build any floating-point literal here.
171 Also build any bignum literal here. */
173 /* Seems atof_machine can backscan through generic_bignum and hit whatever
174 happens to be loaded before it in memory. And its way too complicated
175 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
176 and never write into the early words, thus they'll always be zero.
177 I hate Dean's floating-point code. Bleh. */
178 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
180 FLONUM_TYPE generic_floating_point_number
= {
181 &generic_bignum
[6], /* low. (JF: Was 0) */
182 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
190 floating_constant (expressionS
*expressionP
)
192 /* input_line_pointer -> floating-point constant. */
195 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
196 &generic_floating_point_number
);
200 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
202 as_bad (_("bad floating-point constant: exponent overflow"));
206 as_bad (_("bad floating-point constant: unknown error code=%d"),
210 expressionP
->X_op
= O_big
;
211 /* input_line_pointer -> just after constant, which may point to
213 expressionP
->X_add_number
= -1;
217 generic_bignum_to_int32 (void)
220 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
221 | (generic_bignum
[0] & LITTLENUM_MASK
);
222 number
&= 0xffffffff;
228 generic_bignum_to_int64 (void)
231 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
232 << LITTLENUM_NUMBER_OF_BITS
)
233 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
234 << LITTLENUM_NUMBER_OF_BITS
)
235 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
236 << LITTLENUM_NUMBER_OF_BITS
)
237 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
243 integer_constant (int radix
, expressionS
*expressionP
)
245 char *start
; /* Start of number. */
248 valueT number
; /* Offset or (absolute) value. */
249 short int digit
; /* Value of next digit in current radix. */
250 short int maxdig
= 0; /* Highest permitted digit value. */
251 int too_many_digits
= 0; /* If we see >= this number of. */
252 char *name
; /* Points to name of symbol. */
253 symbolS
*symbolP
; /* Points to symbol. */
255 int small
; /* True if fits in 32 bits. */
257 /* May be bignum, or may fit in 32 bits. */
258 /* Most numbers fit into 32 bits, and we want this case to be fast.
259 so we pretend it will fit into 32 bits. If, after making up a 32
260 bit number, we realise that we have scanned more digits than
261 comfortably fit into 32 bits, we re-scan the digits coding them
262 into a bignum. For decimal and octal numbers we are
263 conservative: Some numbers may be assumed bignums when in fact
264 they do fit into 32 bits. Numbers of any radix can have excess
265 leading zeros: We strive to recognise this and cast them back
266 into 32 bits. We must check that the bignum really is more than
267 32 bits, and change it back to a 32-bit number if it fits. The
268 number we are looking for is expected to be positive, but if it
269 fits into 32 bits as an unsigned number, we let it be a 32-bit
270 number. The cavalier approach is for speed in ordinary cases. */
271 /* This has been extended for 64 bits. We blindly assume that if
272 you're compiling in 64-bit mode, the target is a 64-bit machine.
273 This should be cleaned up. */
277 #else /* includes non-bfd case, mostly */
281 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
285 /* In MRI mode, the number may have a suffix indicating the
286 radix. For that matter, it might actually be a floating
288 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
290 if (*suffix
== 'e' || *suffix
== 'E')
294 if (suffix
== input_line_pointer
)
303 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
304 we distinguish between 'B' and 'b'. This is the case for
306 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
310 else if (c
== 'O' || c
== 'Q')
314 else if (suffix
[1] == '.' || c
== 'E' || flt
)
316 floating_constant (expressionP
);
331 too_many_digits
= valuesize
+ 1;
335 too_many_digits
= (valuesize
+ 2) / 3 + 1;
339 too_many_digits
= (valuesize
+ 3) / 4 + 1;
343 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
346 start
= input_line_pointer
;
347 c
= *input_line_pointer
++;
349 (digit
= hex_value (c
)) < maxdig
;
350 c
= *input_line_pointer
++)
352 number
= number
* radix
+ digit
;
354 /* c contains character after number. */
355 /* input_line_pointer->char after c. */
356 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
358 if (radix
== 16 && c
== '_')
360 /* This is literal of the form 0x333_0_12345678_1.
361 This example is equivalent to 0x00000333000000001234567800000001. */
363 int num_little_digits
= 0;
365 input_line_pointer
= start
; /* -> 1st digit. */
367 know (LITTLENUM_NUMBER_OF_BITS
== 16);
369 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
372 /* Convert one 64-bit word. */
375 for (c
= *input_line_pointer
++;
376 (digit
= hex_value (c
)) < maxdig
;
377 c
= *(input_line_pointer
++))
379 number
= number
* radix
+ digit
;
383 /* Check for 8 digit per word max. */
385 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
387 /* Add this chunk to the bignum.
388 Shift things down 2 little digits. */
389 know (LITTLENUM_NUMBER_OF_BITS
== 16);
390 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
393 generic_bignum
[i
] = generic_bignum
[i
- 2];
395 /* Add the new digits as the least significant new ones. */
396 generic_bignum
[0] = number
& 0xffffffff;
397 generic_bignum
[1] = number
>> 16;
400 /* Again, c is char after number, input_line_pointer->after c. */
402 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
403 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
405 assert (num_little_digits
>= 4);
407 if (num_little_digits
!= 8)
408 as_bad (_("a bignum with underscores must have exactly 4 words"));
410 /* We might have some leading zeros. These can be trimmed to give
411 us a change to fit this constant into a small number. */
412 while (generic_bignum
[num_little_digits
- 1] == 0
413 && num_little_digits
> 1)
416 if (num_little_digits
<= 2)
418 /* will fit into 32 bits. */
419 number
= generic_bignum_to_int32 ();
423 else if (num_little_digits
<= 4)
425 /* Will fit into 64 bits. */
426 number
= generic_bignum_to_int64 ();
434 /* Number of littlenums in the bignum. */
435 number
= num_little_digits
;
440 /* We saw a lot of digits. manufacture a bignum the hard way. */
441 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
442 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
445 leader
= generic_bignum
;
446 generic_bignum
[0] = 0;
447 generic_bignum
[1] = 0;
448 generic_bignum
[2] = 0;
449 generic_bignum
[3] = 0;
450 input_line_pointer
= start
; /* -> 1st digit. */
451 c
= *input_line_pointer
++;
452 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
454 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
458 work
= carry
+ radix
* *pointer
;
459 *pointer
= work
& LITTLENUM_MASK
;
460 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
464 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
466 /* Room to grow a longer bignum. */
471 /* Again, c is char after number. */
472 /* input_line_pointer -> after c. */
473 know (LITTLENUM_NUMBER_OF_BITS
== 16);
474 if (leader
< generic_bignum
+ 2)
476 /* Will fit into 32 bits. */
477 number
= generic_bignum_to_int32 ();
481 else if (leader
< generic_bignum
+ 4)
483 /* Will fit into 64 bits. */
484 number
= generic_bignum_to_int64 ();
490 /* Number of littlenums in the bignum. */
491 number
= leader
- generic_bignum
+ 1;
495 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
497 && input_line_pointer
- 1 == suffix
)
498 c
= *input_line_pointer
++;
502 /* Here with number, in correct radix. c is the next char.
503 Note that unlike un*x, we allow "011f" "0x9f" to both mean
504 the same as the (conventional) "9f".
505 This is simply easier than checking for strict canonical
508 if (LOCAL_LABELS_FB
&& c
== 'b')
510 /* Backward ref to local label.
511 Because it is backward, expect it to be defined. */
512 /* Construct a local label. */
513 name
= fb_label_name ((int) number
, 0);
515 /* Seen before, or symbol is defined: OK. */
516 symbolP
= symbol_find (name
);
517 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
519 /* Local labels are never absolute. Don't waste time
520 checking absoluteness. */
521 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
523 expressionP
->X_op
= O_symbol
;
524 expressionP
->X_add_symbol
= symbolP
;
528 /* Either not seen or not defined. */
529 /* @@ Should print out the original string instead of
530 the parsed number. */
531 as_bad (_("backward ref to unknown label \"%d:\""),
533 expressionP
->X_op
= O_constant
;
536 expressionP
->X_add_number
= 0;
538 else if (LOCAL_LABELS_FB
&& c
== 'f')
540 /* Forward reference. Expect symbol to be undefined or
541 unknown. undefined: seen it before. unknown: never seen
544 Construct a local label name, then an undefined symbol.
545 Don't create a xseg frag for it: caller may do that.
546 Just return it as never seen before. */
547 name
= fb_label_name ((int) number
, 1);
548 symbolP
= symbol_find_or_make (name
);
549 /* We have no need to check symbol properties. */
550 #ifndef many_segments
551 /* Since "know" puts its arg into a "string", we
552 can't have newlines in the argument. */
553 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
555 expressionP
->X_op
= O_symbol
;
556 expressionP
->X_add_symbol
= symbolP
;
557 expressionP
->X_add_number
= 0;
559 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
561 /* If the dollar label is *currently* defined, then this is just
562 another reference to it. If it is not *currently* defined,
563 then this is a fresh instantiation of that number, so create
566 if (dollar_label_defined ((long) number
))
568 name
= dollar_label_name ((long) number
, 0);
569 symbolP
= symbol_find (name
);
570 know (symbolP
!= NULL
);
574 name
= dollar_label_name ((long) number
, 1);
575 symbolP
= symbol_find_or_make (name
);
578 expressionP
->X_op
= O_symbol
;
579 expressionP
->X_add_symbol
= symbolP
;
580 expressionP
->X_add_number
= 0;
584 expressionP
->X_op
= O_constant
;
585 expressionP
->X_add_number
= number
;
586 input_line_pointer
--; /* Restore following character. */
587 } /* Really just a number. */
591 /* Not a small number. */
592 expressionP
->X_op
= O_big
;
593 expressionP
->X_add_number
= number
; /* Number of littlenums. */
594 input_line_pointer
--; /* -> char following number. */
598 /* Parse an MRI multi character constant. */
601 mri_char_constant (expressionS
*expressionP
)
605 if (*input_line_pointer
== '\''
606 && input_line_pointer
[1] != '\'')
608 expressionP
->X_op
= O_constant
;
609 expressionP
->X_add_number
= 0;
613 /* In order to get the correct byte ordering, we must build the
614 number in reverse. */
615 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
619 generic_bignum
[i
] = 0;
620 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
622 if (*input_line_pointer
== '\'')
624 if (input_line_pointer
[1] != '\'')
626 ++input_line_pointer
;
628 generic_bignum
[i
] <<= 8;
629 generic_bignum
[i
] += *input_line_pointer
;
630 ++input_line_pointer
;
633 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
635 /* If there is more than one littlenum, left justify the
636 last one to make it match the earlier ones. If there is
637 only one, we can just use the value directly. */
638 for (; j
< CHARS_PER_LITTLENUM
; j
++)
639 generic_bignum
[i
] <<= 8;
642 if (*input_line_pointer
== '\''
643 && input_line_pointer
[1] != '\'')
649 as_bad (_("character constant too large"));
658 c
= SIZE_OF_LARGE_NUMBER
- i
;
659 for (j
= 0; j
< c
; j
++)
660 generic_bignum
[j
] = generic_bignum
[i
+ j
];
664 know (LITTLENUM_NUMBER_OF_BITS
== 16);
667 expressionP
->X_op
= O_big
;
668 expressionP
->X_add_number
= i
;
672 expressionP
->X_op
= O_constant
;
674 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
676 expressionP
->X_add_number
=
677 (((generic_bignum
[1] & LITTLENUM_MASK
)
678 << LITTLENUM_NUMBER_OF_BITS
)
679 | (generic_bignum
[0] & LITTLENUM_MASK
));
682 /* Skip the final closing quote. */
683 ++input_line_pointer
;
686 /* Return an expression representing the current location. This
687 handles the magic symbol `.'. */
690 current_location (expressionS
*expressionp
)
692 if (now_seg
== absolute_section
)
694 expressionp
->X_op
= O_constant
;
695 expressionp
->X_add_number
= abs_section_offset
;
699 expressionp
->X_op
= O_symbol
;
700 expressionp
->X_add_symbol
= symbol_temp_new_now ();
701 expressionp
->X_add_number
= 0;
705 /* In: Input_line_pointer points to 1st char of operand, which may
709 The operand may have been empty: in this case X_op == O_absent.
710 Input_line_pointer->(next non-blank) char after operand. */
713 operand (expressionS
*expressionP
, enum expr_mode mode
)
716 symbolS
*symbolP
; /* Points to symbol. */
717 char *name
; /* Points to name of symbol. */
720 /* All integers are regarded as unsigned unless they are negated.
721 This is because the only thing which cares whether a number is
722 unsigned is the code in emit_expr which extends constants into
723 bignums. It should only sign extend negative numbers, so that
724 something like ``.quad 0x80000000'' is not sign extended even
725 though it appears negative if valueT is 32 bits. */
726 expressionP
->X_unsigned
= 1;
728 /* Digits, assume it is a bignum. */
730 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
731 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
733 if (is_end_of_line
[(unsigned char) c
])
747 input_line_pointer
--;
749 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
754 #ifdef LITERAL_PREFIXDOLLAR_HEX
756 /* $L is the start of a local label, not a hex constant. */
757 if (* input_line_pointer
== 'L')
759 integer_constant (16, expressionP
);
763 #ifdef LITERAL_PREFIXPERCENT_BIN
765 integer_constant (2, expressionP
);
770 /* Non-decimal radix. */
772 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
776 /* Check for a hex or float constant. */
777 for (s
= input_line_pointer
; hex_p (*s
); s
++)
779 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
781 --input_line_pointer
;
782 integer_constant (0, expressionP
);
786 c
= *input_line_pointer
;
795 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
797 integer_constant (0, expressionP
);
803 if (c
&& strchr (FLT_CHARS
, c
))
805 input_line_pointer
++;
806 floating_constant (expressionP
);
807 expressionP
->X_add_number
= - TOLOWER (c
);
811 /* The string was only zero. */
812 expressionP
->X_op
= O_constant
;
813 expressionP
->X_add_number
= 0;
822 input_line_pointer
++;
823 integer_constant (16, expressionP
);
827 if (LOCAL_LABELS_FB
&& ! (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
))
829 /* This code used to check for '+' and '-' here, and, in
830 some conditions, fall through to call
831 integer_constant. However, that didn't make sense,
832 as integer_constant only accepts digits. */
833 /* Some of our code elsewhere does permit digits greater
834 than the expected base; for consistency, do the same
836 if (input_line_pointer
[1] < '0'
837 || input_line_pointer
[1] > '9')
839 /* Parse this as a back reference to label 0. */
840 input_line_pointer
--;
841 integer_constant (10, expressionP
);
844 /* Otherwise, parse this as a binary number. */
848 input_line_pointer
++;
849 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
851 integer_constant (2, expressionP
);
862 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
870 /* If it says "0f" and it could possibly be a floating point
871 number, make it one. Otherwise, make it a local label,
872 and try to deal with parsing the rest later. */
873 if (!input_line_pointer
[1]
874 || (is_end_of_line
[0xff & input_line_pointer
[1]])
875 || strchr (FLT_CHARS
, 'f') == NULL
)
878 char *cp
= input_line_pointer
+ 1;
879 int r
= atof_generic (&cp
, ".", EXP_CHARS
,
880 &generic_floating_point_number
);
884 case ERROR_EXPONENT_OVERFLOW
:
885 if (*cp
== 'f' || *cp
== 'b')
886 /* Looks like a difference expression. */
888 else if (cp
== input_line_pointer
+ 1)
889 /* No characters has been accepted -- looks like
895 as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
900 /* Okay, now we've sorted it out. We resume at one of these
901 two labels, depending on what we've decided we're probably
904 input_line_pointer
--;
905 integer_constant (10, expressionP
);
915 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
917 integer_constant (0, expressionP
);
927 input_line_pointer
++;
928 floating_constant (expressionP
);
929 expressionP
->X_add_number
= - TOLOWER (c
);
933 if (LOCAL_LABELS_DOLLAR
)
935 integer_constant (10, expressionP
);
945 #ifndef NEED_INDEX_OPERATOR
948 /* Didn't begin with digit & not a name. */
949 if (mode
!= expr_defer
)
950 segment
= expression (expressionP
);
952 segment
= deferred_expression (expressionP
);
953 /* expression () will pass trailing whitespace. */
954 if ((c
== '(' && *input_line_pointer
!= ')')
955 || (c
== '[' && *input_line_pointer
!= ']'))
956 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
958 input_line_pointer
++;
960 /* Here with input_line_pointer -> char after "(...)". */
965 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
967 as_bad (_("EBCDIC constants are not supported"));
970 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
972 ++input_line_pointer
;
978 /* Warning: to conform to other people's assemblers NO
979 ESCAPEMENT is permitted for a single quote. The next
980 character, parity errors and all, is taken as the value
981 of the operand. VERY KINKY. */
982 expressionP
->X_op
= O_constant
;
983 expressionP
->X_add_number
= *input_line_pointer
++;
987 mri_char_constant (expressionP
);
992 /* Double quote is the bitwise not operator in MRI mode. */
998 /* '~' is permitted to start a label on the Delta. */
999 if (is_name_beginner (c
))
1005 operand (expressionP
, mode
);
1006 if (expressionP
->X_op
== O_constant
)
1008 /* input_line_pointer -> char after operand. */
1011 expressionP
->X_add_number
= - expressionP
->X_add_number
;
1012 /* Notice: '-' may overflow: no warning is given.
1013 This is compatible with other people's
1014 assemblers. Sigh. */
1015 expressionP
->X_unsigned
= 0;
1017 else if (c
== '~' || c
== '"')
1018 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1020 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1022 else if (expressionP
->X_op
== O_big
1023 && expressionP
->X_add_number
<= 0
1025 && (generic_floating_point_number
.sign
== '+'
1026 || generic_floating_point_number
.sign
== 'P'))
1028 /* Negative flonum (eg, -1.000e0). */
1029 if (generic_floating_point_number
.sign
== '+')
1030 generic_floating_point_number
.sign
= '-';
1032 generic_floating_point_number
.sign
= 'N';
1034 else if (expressionP
->X_op
== O_big
1035 && expressionP
->X_add_number
> 0)
1039 if (c
== '~' || c
== '-')
1041 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1042 generic_bignum
[i
] = ~generic_bignum
[i
];
1044 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1046 generic_bignum
[i
] += 1;
1047 if (generic_bignum
[i
])
1054 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1056 if (generic_bignum
[i
])
1058 generic_bignum
[i
] = 0;
1060 generic_bignum
[0] = nonzero
;
1063 else if (expressionP
->X_op
!= O_illegal
1064 && expressionP
->X_op
!= O_absent
)
1068 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1070 expressionP
->X_op
= O_uminus
;
1071 else if (c
== '~' || c
== '"')
1072 expressionP
->X_op
= O_bit_not
;
1074 expressionP
->X_op
= O_logical_not
;
1075 expressionP
->X_add_number
= 0;
1079 as_warn (_("Unary operator %c ignored because bad operand follows"),
1084 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1086 /* '$' is the program counter when in MRI mode, or when
1087 DOLLAR_DOT is defined. */
1089 if (! flag_m68k_mri
)
1092 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1094 /* In MRI mode and on Z80, '$' is also used as the prefix
1095 for a hexadecimal constant. */
1096 integer_constant (16, expressionP
);
1100 if (is_part_of_name (*input_line_pointer
))
1103 current_location (expressionP
);
1108 if (!is_part_of_name (*input_line_pointer
))
1110 current_location (expressionP
);
1113 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1114 && ! is_part_of_name (input_line_pointer
[8]))
1115 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1116 && ! is_part_of_name (input_line_pointer
[7])))
1120 start
= (input_line_pointer
[1] == 't'
1121 || input_line_pointer
[1] == 'T');
1122 input_line_pointer
+= start
? 8 : 7;
1124 if (*input_line_pointer
!= '(')
1125 as_bad (_("syntax error in .startof. or .sizeof."));
1130 ++input_line_pointer
;
1132 name
= input_line_pointer
;
1133 c
= get_symbol_end ();
1135 buf
= (char *) xmalloc (strlen (name
) + 10);
1137 sprintf (buf
, ".startof.%s", name
);
1139 sprintf (buf
, ".sizeof.%s", name
);
1140 symbolP
= symbol_make (buf
);
1143 expressionP
->X_op
= O_symbol
;
1144 expressionP
->X_add_symbol
= symbolP
;
1145 expressionP
->X_add_number
= 0;
1147 *input_line_pointer
= c
;
1149 if (*input_line_pointer
!= ')')
1150 as_bad (_("syntax error in .startof. or .sizeof."));
1152 ++input_line_pointer
;
1163 /* Can't imagine any other kind of operand. */
1164 expressionP
->X_op
= O_absent
;
1165 input_line_pointer
--;
1170 if (! flag_m68k_mri
)
1172 integer_constant (2, expressionP
);
1176 if (! flag_m68k_mri
)
1178 integer_constant (8, expressionP
);
1182 if (! flag_m68k_mri
)
1185 /* In MRI mode, this is a floating point constant represented
1186 using hexadecimal digits. */
1188 ++input_line_pointer
;
1189 integer_constant (16, expressionP
);
1193 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1196 current_location (expressionP
);
1204 if (is_name_beginner (c
)) /* Here if did not begin with a digit. */
1206 /* Identifier begins here.
1207 This is kludged for speed, so code is repeated. */
1209 name
= --input_line_pointer
;
1210 c
= get_symbol_end ();
1212 #ifdef md_parse_name
1213 /* This is a hook for the backend to parse certain names
1214 specially in certain contexts. If a name always has a
1215 specific value, it can often be handled by simply
1216 entering it in the symbol table. */
1217 if (md_parse_name (name
, expressionP
, mode
, &c
))
1219 *input_line_pointer
= c
;
1225 /* The MRI i960 assembler permits
1227 FIXME: This should use md_parse_name. */
1229 && (strcasecmp (name
, "sizeof") == 0
1230 || strcasecmp (name
, "startof") == 0))
1235 start
= (name
[1] == 't'
1238 *input_line_pointer
= c
;
1241 name
= input_line_pointer
;
1242 c
= get_symbol_end ();
1244 buf
= (char *) xmalloc (strlen (name
) + 10);
1246 sprintf (buf
, ".startof.%s", name
);
1248 sprintf (buf
, ".sizeof.%s", name
);
1249 symbolP
= symbol_make (buf
);
1252 expressionP
->X_op
= O_symbol
;
1253 expressionP
->X_add_symbol
= symbolP
;
1254 expressionP
->X_add_number
= 0;
1256 *input_line_pointer
= c
;
1263 symbolP
= symbol_find_or_make (name
);
1265 /* If we have an absolute symbol or a reg, then we know its
1267 segment
= S_GET_SEGMENT (symbolP
);
1268 if (mode
!= expr_defer
&& segment
== absolute_section
)
1270 expressionP
->X_op
= O_constant
;
1271 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1273 else if (mode
!= expr_defer
&& segment
== reg_section
)
1275 expressionP
->X_op
= O_register
;
1276 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1280 expressionP
->X_op
= O_symbol
;
1281 expressionP
->X_add_symbol
= symbolP
;
1282 expressionP
->X_add_number
= 0;
1284 *input_line_pointer
= c
;
1288 /* Let the target try to parse it. Success is indicated by changing
1289 the X_op field to something other than O_absent and pointing
1290 input_line_pointer past the expression. If it can't parse the
1291 expression, X_op and input_line_pointer should be unchanged. */
1292 expressionP
->X_op
= O_absent
;
1293 --input_line_pointer
;
1294 md_operand (expressionP
);
1295 if (expressionP
->X_op
== O_absent
)
1297 ++input_line_pointer
;
1298 as_bad (_("bad expression"));
1299 expressionP
->X_op
= O_constant
;
1300 expressionP
->X_add_number
= 0;
1306 /* It is more 'efficient' to clean up the expressionS when they are
1307 created. Doing it here saves lines of code. */
1308 clean_up_expression (expressionP
);
1309 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1310 know (*input_line_pointer
!= ' ');
1312 /* The PA port needs this information. */
1313 if (expressionP
->X_add_symbol
)
1314 symbol_mark_used (expressionP
->X_add_symbol
);
1316 expressionP
->X_add_symbol
= symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1317 expressionP
->X_op_symbol
= symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1319 switch (expressionP
->X_op
)
1322 return absolute_section
;
1324 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1330 /* Internal. Simplify a struct expression for use by expr (). */
1332 /* In: address of an expressionS.
1333 The X_op field of the expressionS may only take certain values.
1334 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1336 Out: expressionS may have been modified:
1337 Unused fields zeroed to help expr (). */
1340 clean_up_expression (expressionS
*expressionP
)
1342 switch (expressionP
->X_op
)
1346 expressionP
->X_add_number
= 0;
1351 expressionP
->X_add_symbol
= NULL
;
1356 expressionP
->X_op_symbol
= NULL
;
1363 /* Expression parser. */
1365 /* We allow an empty expression, and just assume (absolute,0) silently.
1366 Unary operators and parenthetical expressions are treated as operands.
1367 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1369 We used to do an aho/ullman shift-reduce parser, but the logic got so
1370 warped that I flushed it and wrote a recursive-descent parser instead.
1371 Now things are stable, would anybody like to write a fast parser?
1372 Most expressions are either register (which does not even reach here)
1373 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1374 So I guess it doesn't really matter how inefficient more complex expressions
1377 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1378 Also, we have consumed any leading or trailing spaces (operand does that)
1379 and done all intervening operators.
1381 This returns the segment of the result, which will be
1382 absolute_section or the segment of a symbol. */
1385 #define __ O_illegal
1387 #define O_SINGLE_EQ O_illegal
1390 /* Maps ASCII -> operators. */
1391 static const operatorT op_encoding
[256] = {
1392 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1393 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1395 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1396 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1397 __
, __
, __
, __
, __
, __
, __
, __
,
1398 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1399 __
, __
, __
, __
, __
, __
, __
, __
,
1400 __
, __
, __
, __
, __
, __
, __
, __
,
1401 __
, __
, __
, __
, __
, __
, __
, __
,
1403 #ifdef NEED_INDEX_OPERATOR
1408 __
, __
, O_bit_exclusive_or
, __
,
1409 __
, __
, __
, __
, __
, __
, __
, __
,
1410 __
, __
, __
, __
, __
, __
, __
, __
,
1411 __
, __
, __
, __
, __
, __
, __
, __
,
1412 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1414 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1415 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1416 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1417 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1418 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1419 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1420 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1421 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1425 0 operand, (expression)
1430 5 used for * / % in MRI mode
1435 static operator_rankT op_rank
[] = {
1440 0, /* O_symbol_rva */
1445 9, /* O_logical_not */
1449 8, /* O_left_shift */
1450 8, /* O_right_shift */
1451 7, /* O_bit_inclusive_or */
1452 7, /* O_bit_or_not */
1453 7, /* O_bit_exclusive_or */
1463 3, /* O_logical_and */
1464 2, /* O_logical_or */
1484 /* Unfortunately, in MRI mode for the m68k, multiplication and
1485 division have lower precedence than the bit wise operators. This
1486 function sets the operator precedences correctly for the current
1487 mode. Also, MRI uses a different bit_not operator, and this fixes
1490 #define STANDARD_MUL_PRECEDENCE 8
1491 #define MRI_MUL_PRECEDENCE 6
1494 expr_set_precedence (void)
1498 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1499 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1500 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1504 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1505 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1506 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1510 /* Initialize the expression parser. */
1515 expr_set_precedence ();
1517 /* Verify that X_op field is wide enough. */
1521 assert (e
.X_op
== O_max
);
1525 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1526 sets NUM_CHARS to the number of characters in the operator.
1527 Does not advance INPUT_LINE_POINTER. */
1529 static inline operatorT
1530 operator (int *num_chars
)
1535 c
= *input_line_pointer
& 0xff;
1538 if (is_end_of_line
[c
])
1544 return op_encoding
[c
];
1548 return op_encoding
[c
];
1551 switch (input_line_pointer
[1])
1554 return op_encoding
[c
];
1569 if (input_line_pointer
[1] != '=')
1570 return op_encoding
[c
];
1576 switch (input_line_pointer
[1])
1579 return op_encoding
[c
];
1581 ret
= O_right_shift
;
1591 switch (input_line_pointer
[1])
1594 /* We accept !! as equivalent to ^ for MRI compatibility. */
1596 return O_bit_exclusive_or
;
1598 /* We accept != as equivalent to <>. */
1603 return O_bit_inclusive_or
;
1604 return op_encoding
[c
];
1608 if (input_line_pointer
[1] != '|')
1609 return op_encoding
[c
];
1612 return O_logical_or
;
1615 if (input_line_pointer
[1] != '&')
1616 return op_encoding
[c
];
1619 return O_logical_and
;
1625 /* Parse an expression. */
1628 expr (int rankarg
, /* Larger # is higher rank. */
1629 expressionS
*resultP
, /* Deliver result here. */
1630 enum expr_mode mode
/* Controls behavior. */)
1632 operator_rankT rank
= (operator_rankT
) rankarg
;
1639 know (rankarg
>= 0);
1641 /* Save the value of dot for the fixup code. */
1643 dot_value
= frag_now_fix ();
1645 retval
= operand (resultP
, mode
);
1647 /* operand () gobbles spaces. */
1648 know (*input_line_pointer
!= ' ');
1650 op_left
= operator (&op_chars
);
1651 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1656 input_line_pointer
+= op_chars
; /* -> after operator. */
1658 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1659 if (right
.X_op
== O_absent
)
1661 as_warn (_("missing operand; zero assumed"));
1662 right
.X_op
= O_constant
;
1663 right
.X_add_number
= 0;
1664 right
.X_add_symbol
= NULL
;
1665 right
.X_op_symbol
= NULL
;
1668 know (*input_line_pointer
!= ' ');
1670 if (op_left
== O_index
)
1672 if (*input_line_pointer
!= ']')
1673 as_bad ("missing right bracket");
1676 ++input_line_pointer
;
1681 op_right
= operator (&op_chars
);
1683 know (op_right
== O_illegal
1684 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1685 know ((int) op_left
>= (int) O_multiply
1686 && (int) op_left
<= (int) O_index
);
1688 /* input_line_pointer->after right-hand quantity. */
1689 /* left-hand quantity in resultP. */
1690 /* right-hand quantity in right. */
1691 /* operator in op_left. */
1693 if (resultP
->X_op
== O_big
)
1695 if (resultP
->X_add_number
> 0)
1696 as_warn (_("left operand is a bignum; integer 0 assumed"));
1698 as_warn (_("left operand is a float; integer 0 assumed"));
1699 resultP
->X_op
= O_constant
;
1700 resultP
->X_add_number
= 0;
1701 resultP
->X_add_symbol
= NULL
;
1702 resultP
->X_op_symbol
= NULL
;
1704 if (right
.X_op
== O_big
)
1706 if (right
.X_add_number
> 0)
1707 as_warn (_("right operand is a bignum; integer 0 assumed"));
1709 as_warn (_("right operand is a float; integer 0 assumed"));
1710 right
.X_op
= O_constant
;
1711 right
.X_add_number
= 0;
1712 right
.X_add_symbol
= NULL
;
1713 right
.X_op_symbol
= NULL
;
1716 /* Optimize common cases. */
1717 #ifdef md_optimize_expr
1718 if (md_optimize_expr (resultP
, op_left
, &right
))
1725 if (op_left
== O_add
&& right
.X_op
== O_constant
)
1728 resultP
->X_add_number
+= right
.X_add_number
;
1730 /* This case comes up in PIC code. */
1731 else if (op_left
== O_subtract
1732 && right
.X_op
== O_symbol
1733 && resultP
->X_op
== O_symbol
1734 && retval
== rightseg
1735 && (SEG_NORMAL (rightseg
)
1736 || right
.X_add_symbol
== resultP
->X_add_symbol
)
1737 && frag_offset_fixed_p (symbol_get_frag (resultP
->X_add_symbol
),
1738 symbol_get_frag (right
.X_add_symbol
),
1741 resultP
->X_add_number
-= right
.X_add_number
;
1742 resultP
->X_add_number
-= frag_off
/ OCTETS_PER_BYTE
;
1743 resultP
->X_add_number
+= (S_GET_VALUE (resultP
->X_add_symbol
)
1744 - S_GET_VALUE (right
.X_add_symbol
));
1745 resultP
->X_op
= O_constant
;
1746 resultP
->X_add_symbol
= 0;
1748 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
)
1751 resultP
->X_add_number
-= right
.X_add_number
;
1753 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
)
1756 resultP
->X_op
= right
.X_op
;
1757 resultP
->X_add_symbol
= right
.X_add_symbol
;
1758 resultP
->X_op_symbol
= right
.X_op_symbol
;
1759 resultP
->X_add_number
+= right
.X_add_number
;
1762 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1764 /* Constant OP constant. */
1765 offsetT v
= right
.X_add_number
;
1766 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1768 as_warn (_("division by zero"));
1774 case O_multiply
: resultP
->X_add_number
*= v
; break;
1775 case O_divide
: resultP
->X_add_number
/= v
; break;
1776 case O_modulus
: resultP
->X_add_number
%= v
; break;
1777 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1779 /* We always use unsigned shifts, to avoid relying on
1780 characteristics of the compiler used to compile gas. */
1781 resultP
->X_add_number
=
1782 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1784 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1785 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1786 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1787 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1788 /* Constant + constant (O_add) is handled by the
1789 previous if statement for constant + X, so is omitted
1791 case O_subtract
: resultP
->X_add_number
-= v
; break;
1793 resultP
->X_add_number
=
1794 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1797 resultP
->X_add_number
=
1798 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1801 resultP
->X_add_number
=
1802 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1805 resultP
->X_add_number
=
1806 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1809 resultP
->X_add_number
=
1810 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1813 resultP
->X_add_number
=
1814 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1817 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1820 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1824 else if (resultP
->X_op
== O_symbol
1825 && right
.X_op
== O_symbol
1826 && (op_left
== O_add
1827 || op_left
== O_subtract
1828 || (resultP
->X_add_number
== 0
1829 && right
.X_add_number
== 0)))
1831 /* Symbol OP symbol. */
1832 resultP
->X_op
= op_left
;
1833 resultP
->X_op_symbol
= right
.X_add_symbol
;
1834 if (op_left
== O_add
)
1835 resultP
->X_add_number
+= right
.X_add_number
;
1836 else if (op_left
== O_subtract
)
1838 resultP
->X_add_number
-= right
.X_add_number
;
1839 if (retval
== rightseg
&& SEG_NORMAL (retval
))
1841 retval
= absolute_section
;
1842 rightseg
= absolute_section
;
1848 /* The general case. */
1849 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
1850 resultP
->X_op_symbol
= make_expr_symbol (&right
);
1851 resultP
->X_op
= op_left
;
1852 resultP
->X_add_number
= 0;
1853 resultP
->X_unsigned
= 1;
1856 if (retval
!= rightseg
)
1858 if (! SEG_NORMAL (retval
))
1860 if (retval
!= undefined_section
|| SEG_NORMAL (rightseg
))
1863 else if (SEG_NORMAL (rightseg
)
1865 && op_left
!= O_subtract
1868 as_bad (_("operation combines symbols in different segments"));
1872 } /* While next operator is >= this rank. */
1874 /* The PA port needs this information. */
1875 if (resultP
->X_add_symbol
)
1876 symbol_mark_used (resultP
->X_add_symbol
);
1878 if (rank
== 0 && mode
== expr_evaluate
)
1879 resolve_expression (resultP
);
1881 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
1884 /* Resolve an expression without changing any symbols/sub-expressions
1888 resolve_expression (expressionS
*expressionP
)
1890 /* Help out with CSE. */
1891 valueT final_val
= expressionP
->X_add_number
;
1892 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
1893 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
1894 operatorT op
= expressionP
->X_op
;
1896 segT seg_left
, seg_right
;
1897 fragS
*frag_left
, *frag_right
;
1912 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1920 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1923 if (seg_left
!= absolute_section
)
1926 if (op
== O_logical_not
)
1928 else if (op
== O_uminus
)
1940 case O_bit_inclusive_or
:
1942 case O_bit_exclusive_or
:
1954 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
1955 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
1958 /* Simplify addition or subtraction of a constant by folding the
1959 constant into X_add_number. */
1962 if (seg_right
== absolute_section
)
1968 else if (seg_left
== absolute_section
)
1972 seg_left
= seg_right
;
1973 add_symbol
= op_symbol
;
1978 else if (op
== O_subtract
)
1980 if (seg_right
== absolute_section
)
1988 /* Equality and non-equality tests are permitted on anything.
1989 Subtraction, and other comparison operators are permitted if
1990 both operands are in the same section.
1991 Shifts by constant zero are permitted on anything.
1992 Multiplies, bit-ors, and bit-ands with constant zero are
1993 permitted on anything.
1994 Multiplies and divides by constant one are permitted on
1996 Binary operations with both operands being the same register
1997 or undefined symbol are permitted if the result doesn't depend
1999 Otherwise, both operands must be absolute. We already handled
2000 the case of addition or subtraction of a constant above. */
2002 if (!(seg_left
== absolute_section
2003 && seg_right
== absolute_section
)
2004 && !(op
== O_eq
|| op
== O_ne
)
2005 && !((op
== O_subtract
2006 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2007 && seg_left
== seg_right
2009 || frag_offset_fixed_p (frag_left
, frag_right
, &frag_off
))
2010 && (seg_left
!= reg_section
|| left
== right
)
2011 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2013 if ((seg_left
== absolute_section
&& left
== 0)
2014 || (seg_right
== absolute_section
&& right
== 0))
2016 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2018 if (seg_right
!= absolute_section
|| right
!= 0)
2020 seg_left
= seg_right
;
2022 add_symbol
= op_symbol
;
2027 else if (op
== O_left_shift
|| op
== O_right_shift
)
2029 if (seg_left
!= absolute_section
|| left
!= 0)
2035 else if (op
!= O_multiply
2036 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2039 else if (op
== O_multiply
2040 && seg_left
== absolute_section
&& left
== 1)
2042 seg_left
= seg_right
;
2044 add_symbol
= op_symbol
;
2048 else if ((op
== O_multiply
|| op
== O_divide
)
2049 && seg_right
== absolute_section
&& right
== 1)
2054 else if (left
!= right
2055 || ((seg_left
!= reg_section
|| seg_right
!= reg_section
)
2056 && (seg_left
!= undefined_section
2057 || seg_right
!= undefined_section
2058 || add_symbol
!= op_symbol
)))
2060 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2065 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2069 right
+= frag_off
/ OCTETS_PER_BYTE
;
2072 case O_add
: left
+= right
; break;
2073 case O_subtract
: left
-= right
; break;
2074 case O_multiply
: left
*= right
; break;
2078 left
= (offsetT
) left
/ (offsetT
) right
;
2083 left
= (offsetT
) left
% (offsetT
) right
;
2085 case O_left_shift
: left
<<= right
; break;
2086 case O_right_shift
: left
>>= right
; break;
2087 case O_bit_inclusive_or
: left
|= right
; break;
2088 case O_bit_or_not
: left
|= ~right
; break;
2089 case O_bit_exclusive_or
: left
^= right
; break;
2090 case O_bit_and
: left
&= right
; break;
2093 left
= (left
== right
2094 && seg_left
== seg_right
2095 && (finalize_syms
|| frag_left
== frag_right
)
2096 && (seg_left
!= undefined_section
2097 || add_symbol
== op_symbol
)
2098 ? ~ (valueT
) 0 : 0);
2103 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2106 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2109 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2112 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2114 case O_logical_and
: left
= left
&& right
; break;
2115 case O_logical_or
: left
= left
|| right
; break;
2125 if (seg_left
== absolute_section
)
2127 else if (seg_left
== reg_section
&& final_val
== 0)
2129 else if (add_symbol
!= expressionP
->X_add_symbol
)
2131 expressionP
->X_add_symbol
= add_symbol
;
2133 expressionP
->X_op
= op
;
2135 if (op
== O_constant
|| op
== O_register
)
2137 expressionP
->X_add_number
= final_val
;
2142 /* This lives here because it belongs equally in expr.c & read.c.
2143 expr.c is just a branch office read.c anyway, and putting it
2144 here lessens the crowd at read.c.
2146 Assume input_line_pointer is at start of symbol name.
2147 Advance input_line_pointer past symbol name.
2148 Turn that character into a '\0', returning its former value.
2149 This allows a string compare (RMS wants symbol names to be strings)
2151 There will always be a char following symbol name, because all good
2152 lines end in end-of-line. */
2155 get_symbol_end (void)
2159 /* We accept \001 in a name in case this is being called with a
2160 constructed string. */
2161 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2163 while (is_part_of_name (c
= *input_line_pointer
++)
2166 if (is_name_ender (c
))
2167 c
= *input_line_pointer
++;
2169 *--input_line_pointer
= 0;
2174 get_single_number (void)
2177 operand (&exp
, expr_normal
);
2178 return exp
.X_add_number
;