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
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 2, 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. */
29 #define min(a, b) ((a) < (b) ? (a) : (b))
32 #include "safe-ctype.h"
35 static void floating_constant (expressionS
* expressionP
);
36 static valueT
generic_bignum_to_int32 (void);
38 static valueT
generic_bignum_to_int64 (void);
40 static void integer_constant (int radix
, expressionS
* expressionP
);
41 static void mri_char_constant (expressionS
*);
42 static void current_location (expressionS
*);
43 static void clean_up_expression (expressionS
* expressionP
);
44 static segT
operand (expressionS
*, enum expr_mode
);
45 static operatorT
operator (int *);
47 extern const char EXP_CHARS
[], FLT_CHARS
[];
49 /* We keep a mapping of expression symbols to file positions, so that
50 we can provide better error messages. */
52 struct expr_symbol_line
{
53 struct expr_symbol_line
*next
;
59 static struct expr_symbol_line
*expr_symbol_lines
;
61 /* Build a dummy symbol to hold a complex expression. This is how we
62 build expressions up out of other expressions. The symbol is put
63 into the fake section expr_section. */
66 make_expr_symbol (expressionS
*expressionP
)
70 struct expr_symbol_line
*n
;
72 if (expressionP
->X_op
== O_symbol
73 && expressionP
->X_add_number
== 0)
74 return expressionP
->X_add_symbol
;
76 if (expressionP
->X_op
== O_big
)
78 /* This won't work, because the actual value is stored in
79 generic_floating_point_number or generic_bignum, and we are
80 going to lose it if we haven't already. */
81 if (expressionP
->X_add_number
> 0)
82 as_bad (_("bignum invalid"));
84 as_bad (_("floating point number invalid"));
85 zero
.X_op
= O_constant
;
86 zero
.X_add_number
= 0;
88 clean_up_expression (&zero
);
92 /* Putting constant symbols in absolute_section rather than
93 expr_section is convenient for the old a.out code, for which
94 S_GET_SEGMENT does not always retrieve the value put in by
96 symbolP
= symbol_create (FAKE_LABEL_NAME
,
97 (expressionP
->X_op
== O_constant
100 0, &zero_address_frag
);
101 symbol_set_value_expression (symbolP
, expressionP
);
103 if (expressionP
->X_op
== O_constant
)
104 resolve_symbol_value (symbolP
);
106 n
= (struct expr_symbol_line
*) xmalloc (sizeof *n
);
108 as_where (&n
->file
, &n
->line
);
109 n
->next
= expr_symbol_lines
;
110 expr_symbol_lines
= n
;
115 /* Return the file and line number for an expr symbol. Return
116 non-zero if something was found, 0 if no information is known for
120 expr_symbol_where (symbolS
*sym
, char **pfile
, unsigned int *pline
)
122 register struct expr_symbol_line
*l
;
124 for (l
= expr_symbol_lines
; l
!= NULL
; l
= l
->next
)
137 /* Utilities for building expressions.
138 Since complex expressions are recorded as symbols for use in other
139 expressions these return a symbolS * and not an expressionS *.
140 These explicitly do not take an "add_number" argument. */
141 /* ??? For completeness' sake one might want expr_build_symbol.
142 It would just return its argument. */
144 /* Build an expression for an unsigned constant.
145 The corresponding one for signed constants is missing because
146 there's currently no need for it. One could add an unsigned_p flag
147 but that seems more clumsy. */
150 expr_build_uconstant (offsetT value
)
155 e
.X_add_number
= value
;
157 return make_expr_symbol (&e
);
160 /* Build an expression for the current location ('.'). */
163 expr_build_dot (void)
167 current_location (&e
);
168 return make_expr_symbol (&e
);
171 /* Build any floating-point literal here.
172 Also build any bignum literal here. */
174 /* Seems atof_machine can backscan through generic_bignum and hit whatever
175 happens to be loaded before it in memory. And its way too complicated
176 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
177 and never write into the early words, thus they'll always be zero.
178 I hate Dean's floating-point code. Bleh. */
179 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
181 FLONUM_TYPE generic_floating_point_number
= {
182 &generic_bignum
[6], /* low. (JF: Was 0) */
183 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high. JF: (added +6) */
191 floating_constant (expressionS
*expressionP
)
193 /* input_line_pointer -> floating-point constant. */
196 error_code
= atof_generic (&input_line_pointer
, ".", EXP_CHARS
,
197 &generic_floating_point_number
);
201 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
203 as_bad (_("bad floating-point constant: exponent overflow"));
207 as_bad (_("bad floating-point constant: unknown error code=%d"),
211 expressionP
->X_op
= O_big
;
212 /* input_line_pointer -> just after constant, which may point to
214 expressionP
->X_add_number
= -1;
218 generic_bignum_to_int32 (void)
221 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
222 | (generic_bignum
[0] & LITTLENUM_MASK
);
223 number
&= 0xffffffff;
229 generic_bignum_to_int64 (void)
232 ((((((((valueT
) generic_bignum
[3] & LITTLENUM_MASK
)
233 << LITTLENUM_NUMBER_OF_BITS
)
234 | ((valueT
) generic_bignum
[2] & LITTLENUM_MASK
))
235 << LITTLENUM_NUMBER_OF_BITS
)
236 | ((valueT
) generic_bignum
[1] & LITTLENUM_MASK
))
237 << LITTLENUM_NUMBER_OF_BITS
)
238 | ((valueT
) generic_bignum
[0] & LITTLENUM_MASK
));
244 integer_constant (int radix
, expressionS
*expressionP
)
246 char *start
; /* Start of number. */
249 valueT number
; /* Offset or (absolute) value. */
250 short int digit
; /* Value of next digit in current radix. */
251 short int maxdig
= 0; /* Highest permitted digit value. */
252 int too_many_digits
= 0; /* If we see >= this number of. */
253 char *name
; /* Points to name of symbol. */
254 symbolS
*symbolP
; /* Points to symbol. */
256 int small
; /* True if fits in 32 bits. */
258 /* May be bignum, or may fit in 32 bits. */
259 /* Most numbers fit into 32 bits, and we want this case to be fast.
260 so we pretend it will fit into 32 bits. If, after making up a 32
261 bit number, we realise that we have scanned more digits than
262 comfortably fit into 32 bits, we re-scan the digits coding them
263 into a bignum. For decimal and octal numbers we are
264 conservative: Some numbers may be assumed bignums when in fact
265 they do fit into 32 bits. Numbers of any radix can have excess
266 leading zeros: We strive to recognise this and cast them back
267 into 32 bits. We must check that the bignum really is more than
268 32 bits, and change it back to a 32-bit number if it fits. The
269 number we are looking for is expected to be positive, but if it
270 fits into 32 bits as an unsigned number, we let it be a 32-bit
271 number. The cavalier approach is for speed in ordinary cases. */
272 /* This has been extended for 64 bits. We blindly assume that if
273 you're compiling in 64-bit mode, the target is a 64-bit machine.
274 This should be cleaned up. */
278 #else /* includes non-bfd case, mostly */
282 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
) && radix
== 0)
286 /* In MRI mode, the number may have a suffix indicating the
287 radix. For that matter, it might actually be a floating
289 for (suffix
= input_line_pointer
; ISALNUM (*suffix
); suffix
++)
291 if (*suffix
== 'e' || *suffix
== 'E')
295 if (suffix
== input_line_pointer
)
304 /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
305 we distinguish between 'B' and 'b'. This is the case for
307 if ((NUMBERS_WITH_SUFFIX
&& LOCAL_LABELS_FB
? *suffix
: c
) == 'B')
311 else if (c
== 'O' || c
== 'Q')
315 else if (suffix
[1] == '.' || c
== 'E' || flt
)
317 floating_constant (expressionP
);
332 too_many_digits
= valuesize
+ 1;
336 too_many_digits
= (valuesize
+ 2) / 3 + 1;
340 too_many_digits
= (valuesize
+ 3) / 4 + 1;
344 too_many_digits
= (valuesize
+ 11) / 4; /* Very rough. */
347 start
= input_line_pointer
;
348 c
= *input_line_pointer
++;
350 (digit
= hex_value (c
)) < maxdig
;
351 c
= *input_line_pointer
++)
353 number
= number
* radix
+ digit
;
355 /* c contains character after number. */
356 /* input_line_pointer->char after c. */
357 small
= (input_line_pointer
- start
- 1) < too_many_digits
;
359 if (radix
== 16 && c
== '_')
361 /* This is literal of the form 0x333_0_12345678_1.
362 This example is equivalent to 0x00000333000000001234567800000001. */
364 int num_little_digits
= 0;
366 input_line_pointer
= start
; /* -> 1st digit. */
368 know (LITTLENUM_NUMBER_OF_BITS
== 16);
370 for (c
= '_'; c
== '_'; num_little_digits
+= 2)
373 /* Convert one 64-bit word. */
376 for (c
= *input_line_pointer
++;
377 (digit
= hex_value (c
)) < maxdig
;
378 c
= *(input_line_pointer
++))
380 number
= number
* radix
+ digit
;
384 /* Check for 8 digit per word max. */
386 as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
388 /* Add this chunk to the bignum.
389 Shift things down 2 little digits. */
390 know (LITTLENUM_NUMBER_OF_BITS
== 16);
391 for (i
= min (num_little_digits
+ 1, SIZE_OF_LARGE_NUMBER
- 1);
394 generic_bignum
[i
] = generic_bignum
[i
- 2];
396 /* Add the new digits as the least significant new ones. */
397 generic_bignum
[0] = number
& 0xffffffff;
398 generic_bignum
[1] = number
>> 16;
401 /* Again, c is char after number, input_line_pointer->after c. */
403 if (num_little_digits
> SIZE_OF_LARGE_NUMBER
- 1)
404 num_little_digits
= SIZE_OF_LARGE_NUMBER
- 1;
406 assert (num_little_digits
>= 4);
408 if (num_little_digits
!= 8)
409 as_bad (_("a bignum with underscores must have exactly 4 words"));
411 /* We might have some leading zeros. These can be trimmed to give
412 us a change to fit this constant into a small number. */
413 while (generic_bignum
[num_little_digits
- 1] == 0
414 && num_little_digits
> 1)
417 if (num_little_digits
<= 2)
419 /* will fit into 32 bits. */
420 number
= generic_bignum_to_int32 ();
424 else if (num_little_digits
<= 4)
426 /* Will fit into 64 bits. */
427 number
= generic_bignum_to_int64 ();
435 /* Number of littlenums in the bignum. */
436 number
= num_little_digits
;
441 /* We saw a lot of digits. manufacture a bignum the hard way. */
442 LITTLENUM_TYPE
*leader
; /* -> high order littlenum of the bignum. */
443 LITTLENUM_TYPE
*pointer
; /* -> littlenum we are frobbing now. */
446 leader
= generic_bignum
;
447 generic_bignum
[0] = 0;
448 generic_bignum
[1] = 0;
449 generic_bignum
[2] = 0;
450 generic_bignum
[3] = 0;
451 input_line_pointer
= start
; /* -> 1st digit. */
452 c
= *input_line_pointer
++;
453 for (; (carry
= hex_value (c
)) < maxdig
; c
= *input_line_pointer
++)
455 for (pointer
= generic_bignum
; pointer
<= leader
; pointer
++)
459 work
= carry
+ radix
* *pointer
;
460 *pointer
= work
& LITTLENUM_MASK
;
461 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
465 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
467 /* Room to grow a longer bignum. */
472 /* Again, c is char after number. */
473 /* input_line_pointer -> after c. */
474 know (LITTLENUM_NUMBER_OF_BITS
== 16);
475 if (leader
< generic_bignum
+ 2)
477 /* Will fit into 32 bits. */
478 number
= generic_bignum_to_int32 ();
482 else if (leader
< generic_bignum
+ 4)
484 /* Will fit into 64 bits. */
485 number
= generic_bignum_to_int64 ();
491 /* Number of littlenums in the bignum. */
492 number
= leader
- generic_bignum
+ 1;
496 if ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
498 && input_line_pointer
- 1 == suffix
)
499 c
= *input_line_pointer
++;
503 /* Here with number, in correct radix. c is the next char.
504 Note that unlike un*x, we allow "011f" "0x9f" to both mean
505 the same as the (conventional) "9f".
506 This is simply easier than checking for strict canonical
509 if (LOCAL_LABELS_FB
&& c
== 'b')
511 /* Backward ref to local label.
512 Because it is backward, expect it to be defined. */
513 /* Construct a local label. */
514 name
= fb_label_name ((int) number
, 0);
516 /* Seen before, or symbol is defined: OK. */
517 symbolP
= symbol_find (name
);
518 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
520 /* Local labels are never absolute. Don't waste time
521 checking absoluteness. */
522 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
524 expressionP
->X_op
= O_symbol
;
525 expressionP
->X_add_symbol
= symbolP
;
529 /* Either not seen or not defined. */
530 /* @@ Should print out the original string instead of
531 the parsed number. */
532 as_bad (_("backward ref to unknown label \"%d:\""),
534 expressionP
->X_op
= O_constant
;
537 expressionP
->X_add_number
= 0;
539 else if (LOCAL_LABELS_FB
&& c
== 'f')
541 /* Forward reference. Expect symbol to be undefined or
542 unknown. undefined: seen it before. unknown: never seen
545 Construct a local label name, then an undefined symbol.
546 Don't create a xseg frag for it: caller may do that.
547 Just return it as never seen before. */
548 name
= fb_label_name ((int) number
, 1);
549 symbolP
= symbol_find_or_make (name
);
550 /* We have no need to check symbol properties. */
551 #ifndef many_segments
552 /* Since "know" puts its arg into a "string", we
553 can't have newlines in the argument. */
554 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
556 expressionP
->X_op
= O_symbol
;
557 expressionP
->X_add_symbol
= symbolP
;
558 expressionP
->X_add_number
= 0;
560 else if (LOCAL_LABELS_DOLLAR
&& c
== '$')
562 /* If the dollar label is *currently* defined, then this is just
563 another reference to it. If it is not *currently* defined,
564 then this is a fresh instantiation of that number, so create
567 if (dollar_label_defined ((long) number
))
569 name
= dollar_label_name ((long) number
, 0);
570 symbolP
= symbol_find (name
);
571 know (symbolP
!= NULL
);
575 name
= dollar_label_name ((long) number
, 1);
576 symbolP
= symbol_find_or_make (name
);
579 expressionP
->X_op
= O_symbol
;
580 expressionP
->X_add_symbol
= symbolP
;
581 expressionP
->X_add_number
= 0;
585 expressionP
->X_op
= O_constant
;
586 expressionP
->X_add_number
= number
;
587 input_line_pointer
--; /* Restore following character. */
588 } /* Really just a number. */
592 /* Not a small number. */
593 expressionP
->X_op
= O_big
;
594 expressionP
->X_add_number
= number
; /* Number of littlenums. */
595 input_line_pointer
--; /* -> char following number. */
599 /* Parse an MRI multi character constant. */
602 mri_char_constant (expressionS
*expressionP
)
606 if (*input_line_pointer
== '\''
607 && input_line_pointer
[1] != '\'')
609 expressionP
->X_op
= O_constant
;
610 expressionP
->X_add_number
= 0;
614 /* In order to get the correct byte ordering, we must build the
615 number in reverse. */
616 for (i
= SIZE_OF_LARGE_NUMBER
- 1; i
>= 0; i
--)
620 generic_bignum
[i
] = 0;
621 for (j
= 0; j
< CHARS_PER_LITTLENUM
; j
++)
623 if (*input_line_pointer
== '\'')
625 if (input_line_pointer
[1] != '\'')
627 ++input_line_pointer
;
629 generic_bignum
[i
] <<= 8;
630 generic_bignum
[i
] += *input_line_pointer
;
631 ++input_line_pointer
;
634 if (i
< SIZE_OF_LARGE_NUMBER
- 1)
636 /* If there is more than one littlenum, left justify the
637 last one to make it match the earlier ones. If there is
638 only one, we can just use the value directly. */
639 for (; j
< CHARS_PER_LITTLENUM
; j
++)
640 generic_bignum
[i
] <<= 8;
643 if (*input_line_pointer
== '\''
644 && input_line_pointer
[1] != '\'')
650 as_bad (_("character constant too large"));
659 c
= SIZE_OF_LARGE_NUMBER
- i
;
660 for (j
= 0; j
< c
; j
++)
661 generic_bignum
[j
] = generic_bignum
[i
+ j
];
665 know (LITTLENUM_NUMBER_OF_BITS
== 16);
668 expressionP
->X_op
= O_big
;
669 expressionP
->X_add_number
= i
;
673 expressionP
->X_op
= O_constant
;
675 expressionP
->X_add_number
= generic_bignum
[0] & LITTLENUM_MASK
;
677 expressionP
->X_add_number
=
678 (((generic_bignum
[1] & LITTLENUM_MASK
)
679 << LITTLENUM_NUMBER_OF_BITS
)
680 | (generic_bignum
[0] & LITTLENUM_MASK
));
683 /* Skip the final closing quote. */
684 ++input_line_pointer
;
687 /* Return an expression representing the current location. This
688 handles the magic symbol `.'. */
691 current_location (expressionS
*expressionp
)
693 if (now_seg
== absolute_section
)
695 expressionp
->X_op
= O_constant
;
696 expressionp
->X_add_number
= abs_section_offset
;
700 expressionp
->X_op
= O_symbol
;
701 expressionp
->X_add_symbol
= symbol_temp_new_now ();
702 expressionp
->X_add_number
= 0;
706 /* In: Input_line_pointer points to 1st char of operand, which may
710 The operand may have been empty: in this case X_op == O_absent.
711 Input_line_pointer->(next non-blank) char after operand. */
714 operand (expressionS
*expressionP
, enum expr_mode mode
)
717 symbolS
*symbolP
; /* Points to symbol. */
718 char *name
; /* Points to name of symbol. */
721 /* All integers are regarded as unsigned unless they are negated.
722 This is because the only thing which cares whether a number is
723 unsigned is the code in emit_expr which extends constants into
724 bignums. It should only sign extend negative numbers, so that
725 something like ``.quad 0x80000000'' is not sign extended even
726 though it appears negative if valueT is 32 bits. */
727 expressionP
->X_unsigned
= 1;
729 /* Digits, assume it is a bignum. */
731 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
732 c
= *input_line_pointer
++; /* input_line_pointer -> past char in c. */
734 if (is_end_of_line
[(unsigned char) c
])
748 input_line_pointer
--;
750 integer_constant ((NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
755 #ifdef LITERAL_PREFIXDOLLAR_HEX
757 /* $L is the start of a local label, not a hex constant. */
758 if (* input_line_pointer
== 'L')
760 integer_constant (16, expressionP
);
764 #ifdef LITERAL_PREFIXPERCENT_BIN
766 integer_constant (2, expressionP
);
771 /* Non-decimal radix. */
773 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
777 /* Check for a hex or float constant. */
778 for (s
= input_line_pointer
; hex_p (*s
); s
++)
780 if (*s
== 'h' || *s
== 'H' || *input_line_pointer
== '.')
782 --input_line_pointer
;
783 integer_constant (0, expressionP
);
787 c
= *input_line_pointer
;
796 if (NUMBERS_WITH_SUFFIX
|| flag_m68k_mri
)
798 integer_constant (0, expressionP
);
804 if (c
&& strchr (FLT_CHARS
, c
))
806 input_line_pointer
++;
807 floating_constant (expressionP
);
808 expressionP
->X_add_number
= - TOLOWER (c
);
812 /* The string was only zero. */
813 expressionP
->X_op
= O_constant
;
814 expressionP
->X_add_number
= 0;
823 input_line_pointer
++;
824 integer_constant (16, expressionP
);
828 if (LOCAL_LABELS_FB
&& ! (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
))
830 /* This code used to check for '+' and '-' here, and, in
831 some conditions, fall through to call
832 integer_constant. However, that didn't make sense,
833 as integer_constant only accepts digits. */
834 /* Some of our code elsewhere does permit digits greater
835 than the expected base; for consistency, do the same
837 if (input_line_pointer
[1] < '0'
838 || input_line_pointer
[1] > '9')
840 /* Parse this as a back reference to label 0. */
841 input_line_pointer
--;
842 integer_constant (10, expressionP
);
845 /* Otherwise, parse this as a binary number. */
849 input_line_pointer
++;
850 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
852 integer_constant (2, expressionP
);
863 integer_constant ((flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
871 /* If it says "0f" and it could possibly be a floating point
872 number, make it one. Otherwise, make it a local label,
873 and try to deal with parsing the rest later. */
874 if (!input_line_pointer
[1]
875 || (is_end_of_line
[0xff & input_line_pointer
[1]])
876 || strchr (FLT_CHARS
, 'f') == NULL
)
879 char *cp
= input_line_pointer
+ 1;
880 int r
= atof_generic (&cp
, ".", EXP_CHARS
,
881 &generic_floating_point_number
);
885 case ERROR_EXPONENT_OVERFLOW
:
886 if (*cp
== 'f' || *cp
== 'b')
887 /* Looks like a difference expression. */
889 else if (cp
== input_line_pointer
+ 1)
890 /* No characters has been accepted -- looks like
896 as_fatal (_("expr.c(operand): bad atof_generic return val %d"),
901 /* Okay, now we've sorted it out. We resume at one of these
902 two labels, depending on what we've decided we're probably
905 input_line_pointer
--;
906 integer_constant (10, expressionP
);
916 if (flag_m68k_mri
|| NUMBERS_WITH_SUFFIX
)
918 integer_constant (0, expressionP
);
928 input_line_pointer
++;
929 floating_constant (expressionP
);
930 expressionP
->X_add_number
= - TOLOWER (c
);
934 if (LOCAL_LABELS_DOLLAR
)
936 integer_constant (10, expressionP
);
946 #ifndef NEED_INDEX_OPERATOR
949 /* Didn't begin with digit & not a name. */
950 if (mode
!= expr_defer
)
951 segment
= expression (expressionP
);
953 segment
= deferred_expression (expressionP
);
954 /* expression () will pass trailing whitespace. */
955 if ((c
== '(' && *input_line_pointer
!= ')')
956 || (c
== '[' && *input_line_pointer
!= ']'))
957 as_bad (_("missing '%c'"), c
== '(' ? ')' : ']');
959 input_line_pointer
++;
961 /* Here with input_line_pointer -> char after "(...)". */
966 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
968 as_bad (_("EBCDIC constants are not supported"));
971 if (! flag_m68k_mri
|| *input_line_pointer
!= '\'')
973 ++input_line_pointer
;
979 /* Warning: to conform to other people's assemblers NO
980 ESCAPEMENT is permitted for a single quote. The next
981 character, parity errors and all, is taken as the value
982 of the operand. VERY KINKY. */
983 expressionP
->X_op
= O_constant
;
984 expressionP
->X_add_number
= *input_line_pointer
++;
988 mri_char_constant (expressionP
);
993 /* Double quote is the bitwise not operator in MRI mode. */
999 /* '~' is permitted to start a label on the Delta. */
1000 if (is_name_beginner (c
))
1006 /* Do not accept ++e or --e as +(+e) or -(-e)
1007 Disabled, since the preprocessor removes whitespace. */
1008 if (0 && (c
== '-' || c
== '+') && *input_line_pointer
== c
)
1011 operand (expressionP
, mode
);
1012 if (expressionP
->X_op
== O_constant
)
1014 /* input_line_pointer -> char after operand. */
1017 expressionP
->X_add_number
= - expressionP
->X_add_number
;
1018 /* Notice: '-' may overflow: no warning is given.
1019 This is compatible with other people's
1020 assemblers. Sigh. */
1021 expressionP
->X_unsigned
= 0;
1023 else if (c
== '~' || c
== '"')
1024 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
1026 expressionP
->X_add_number
= ! expressionP
->X_add_number
;
1028 else if (expressionP
->X_op
== O_big
1029 && expressionP
->X_add_number
<= 0
1031 && (generic_floating_point_number
.sign
== '+'
1032 || generic_floating_point_number
.sign
== 'P'))
1034 /* Negative flonum (eg, -1.000e0). */
1035 if (generic_floating_point_number
.sign
== '+')
1036 generic_floating_point_number
.sign
= '-';
1038 generic_floating_point_number
.sign
= 'N';
1040 else if (expressionP
->X_op
== O_big
1041 && expressionP
->X_add_number
> 0)
1045 if (c
== '~' || c
== '-')
1047 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1048 generic_bignum
[i
] = ~generic_bignum
[i
];
1050 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1052 generic_bignum
[i
] += 1;
1053 if (generic_bignum
[i
])
1060 for (i
= 0; i
< expressionP
->X_add_number
; ++i
)
1062 if (generic_bignum
[i
])
1064 generic_bignum
[i
] = 0;
1066 generic_bignum
[0] = nonzero
;
1069 else if (expressionP
->X_op
!= O_illegal
1070 && expressionP
->X_op
!= O_absent
)
1074 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
1076 expressionP
->X_op
= O_uminus
;
1077 else if (c
== '~' || c
== '"')
1078 expressionP
->X_op
= O_bit_not
;
1080 expressionP
->X_op
= O_logical_not
;
1081 expressionP
->X_add_number
= 0;
1085 as_warn (_("Unary operator %c ignored because bad operand follows"),
1090 #if defined (DOLLAR_DOT) || defined (TC_M68K)
1092 /* '$' is the program counter when in MRI mode, or when
1093 DOLLAR_DOT is defined. */
1095 if (! flag_m68k_mri
)
1098 if (DOLLAR_AMBIGU
&& hex_p (*input_line_pointer
))
1100 /* In MRI mode and on Z80, '$' is also used as the prefix
1101 for a hexadecimal constant. */
1102 integer_constant (16, expressionP
);
1106 if (is_part_of_name (*input_line_pointer
))
1109 current_location (expressionP
);
1114 if (!is_part_of_name (*input_line_pointer
))
1116 current_location (expressionP
);
1119 else if ((strncasecmp (input_line_pointer
, "startof.", 8) == 0
1120 && ! is_part_of_name (input_line_pointer
[8]))
1121 || (strncasecmp (input_line_pointer
, "sizeof.", 7) == 0
1122 && ! is_part_of_name (input_line_pointer
[7])))
1126 start
= (input_line_pointer
[1] == 't'
1127 || input_line_pointer
[1] == 'T');
1128 input_line_pointer
+= start
? 8 : 7;
1130 if (*input_line_pointer
!= '(')
1131 as_bad (_("syntax error in .startof. or .sizeof."));
1136 ++input_line_pointer
;
1138 name
= input_line_pointer
;
1139 c
= get_symbol_end ();
1141 buf
= (char *) xmalloc (strlen (name
) + 10);
1143 sprintf (buf
, ".startof.%s", name
);
1145 sprintf (buf
, ".sizeof.%s", name
);
1146 symbolP
= symbol_make (buf
);
1149 expressionP
->X_op
= O_symbol
;
1150 expressionP
->X_add_symbol
= symbolP
;
1151 expressionP
->X_add_number
= 0;
1153 *input_line_pointer
= c
;
1155 if (*input_line_pointer
!= ')')
1156 as_bad (_("syntax error in .startof. or .sizeof."));
1158 ++input_line_pointer
;
1169 /* Can't imagine any other kind of operand. */
1170 expressionP
->X_op
= O_absent
;
1171 input_line_pointer
--;
1176 if (! flag_m68k_mri
)
1178 integer_constant (2, expressionP
);
1182 if (! flag_m68k_mri
)
1184 integer_constant (8, expressionP
);
1188 if (! flag_m68k_mri
)
1191 /* In MRI mode, this is a floating point constant represented
1192 using hexadecimal digits. */
1194 ++input_line_pointer
;
1195 integer_constant (16, expressionP
);
1199 if (! flag_m68k_mri
|| is_part_of_name (*input_line_pointer
))
1202 current_location (expressionP
);
1210 if (is_name_beginner (c
)) /* Here if did not begin with a digit. */
1212 /* Identifier begins here.
1213 This is kludged for speed, so code is repeated. */
1215 name
= --input_line_pointer
;
1216 c
= get_symbol_end ();
1218 #ifdef md_parse_name
1219 /* This is a hook for the backend to parse certain names
1220 specially in certain contexts. If a name always has a
1221 specific value, it can often be handled by simply
1222 entering it in the symbol table. */
1223 if (md_parse_name (name
, expressionP
, mode
, &c
))
1225 *input_line_pointer
= c
;
1231 /* The MRI i960 assembler permits
1233 FIXME: This should use md_parse_name. */
1235 && (strcasecmp (name
, "sizeof") == 0
1236 || strcasecmp (name
, "startof") == 0))
1241 start
= (name
[1] == 't'
1244 *input_line_pointer
= c
;
1247 name
= input_line_pointer
;
1248 c
= get_symbol_end ();
1250 buf
= (char *) xmalloc (strlen (name
) + 10);
1252 sprintf (buf
, ".startof.%s", name
);
1254 sprintf (buf
, ".sizeof.%s", name
);
1255 symbolP
= symbol_make (buf
);
1258 expressionP
->X_op
= O_symbol
;
1259 expressionP
->X_add_symbol
= symbolP
;
1260 expressionP
->X_add_number
= 0;
1262 *input_line_pointer
= c
;
1269 symbolP
= symbol_find_or_make (name
);
1271 /* If we have an absolute symbol or a reg, then we know its
1273 segment
= S_GET_SEGMENT (symbolP
);
1274 if (mode
!= expr_defer
&& segment
== absolute_section
)
1276 expressionP
->X_op
= O_constant
;
1277 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1279 else if (mode
!= expr_defer
&& segment
== reg_section
)
1281 expressionP
->X_op
= O_register
;
1282 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
1286 expressionP
->X_op
= O_symbol
;
1287 expressionP
->X_add_symbol
= symbolP
;
1288 expressionP
->X_add_number
= 0;
1290 *input_line_pointer
= c
;
1295 /* Let the target try to parse it. Success is indicated by changing
1296 the X_op field to something other than O_absent and pointing
1297 input_line_pointer past the expression. If it can't parse the
1298 expression, X_op and input_line_pointer should be unchanged. */
1299 expressionP
->X_op
= O_absent
;
1300 --input_line_pointer
;
1301 md_operand (expressionP
);
1302 if (expressionP
->X_op
== O_absent
)
1304 ++input_line_pointer
;
1305 as_bad (_("bad expression"));
1306 expressionP
->X_op
= O_constant
;
1307 expressionP
->X_add_number
= 0;
1313 /* It is more 'efficient' to clean up the expressionS when they are
1314 created. Doing it here saves lines of code. */
1315 clean_up_expression (expressionP
);
1316 SKIP_WHITESPACE (); /* -> 1st char after operand. */
1317 know (*input_line_pointer
!= ' ');
1319 /* The PA port needs this information. */
1320 if (expressionP
->X_add_symbol
)
1321 symbol_mark_used (expressionP
->X_add_symbol
);
1323 expressionP
->X_add_symbol
= symbol_clone_if_forward_ref (expressionP
->X_add_symbol
);
1324 expressionP
->X_op_symbol
= symbol_clone_if_forward_ref (expressionP
->X_op_symbol
);
1326 switch (expressionP
->X_op
)
1329 return absolute_section
;
1331 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
1337 /* Internal. Simplify a struct expression for use by expr (). */
1339 /* In: address of an expressionS.
1340 The X_op field of the expressionS may only take certain values.
1341 Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1343 Out: expressionS may have been modified:
1344 Unused fields zeroed to help expr (). */
1347 clean_up_expression (expressionS
*expressionP
)
1349 switch (expressionP
->X_op
)
1353 expressionP
->X_add_number
= 0;
1358 expressionP
->X_add_symbol
= NULL
;
1363 expressionP
->X_op_symbol
= NULL
;
1370 /* Expression parser. */
1372 /* We allow an empty expression, and just assume (absolute,0) silently.
1373 Unary operators and parenthetical expressions are treated as operands.
1374 As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1376 We used to do an aho/ullman shift-reduce parser, but the logic got so
1377 warped that I flushed it and wrote a recursive-descent parser instead.
1378 Now things are stable, would anybody like to write a fast parser?
1379 Most expressions are either register (which does not even reach here)
1380 or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1381 So I guess it doesn't really matter how inefficient more complex expressions
1384 After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1385 Also, we have consumed any leading or trailing spaces (operand does that)
1386 and done all intervening operators.
1388 This returns the segment of the result, which will be
1389 absolute_section or the segment of a symbol. */
1392 #define __ O_illegal
1394 #define O_SINGLE_EQ O_illegal
1397 /* Maps ASCII -> operators. */
1398 static const operatorT op_encoding
[256] = {
1399 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1400 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1402 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
1403 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
1404 __
, __
, __
, __
, __
, __
, __
, __
,
1405 __
, __
, __
, __
, O_lt
, O_SINGLE_EQ
, O_gt
, __
,
1406 __
, __
, __
, __
, __
, __
, __
, __
,
1407 __
, __
, __
, __
, __
, __
, __
, __
,
1408 __
, __
, __
, __
, __
, __
, __
, __
,
1410 #ifdef NEED_INDEX_OPERATOR
1415 __
, __
, O_bit_exclusive_or
, __
,
1416 __
, __
, __
, __
, __
, __
, __
, __
,
1417 __
, __
, __
, __
, __
, __
, __
, __
,
1418 __
, __
, __
, __
, __
, __
, __
, __
,
1419 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
1421 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1422 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1423 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1424 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1425 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1426 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1427 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
1428 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
1432 0 operand, (expression)
1437 5 used for * / % in MRI mode
1442 static operator_rankT op_rank
[] = {
1447 0, /* O_symbol_rva */
1452 9, /* O_logical_not */
1456 8, /* O_left_shift */
1457 8, /* O_right_shift */
1458 7, /* O_bit_inclusive_or */
1459 7, /* O_bit_or_not */
1460 7, /* O_bit_exclusive_or */
1470 3, /* O_logical_and */
1471 2, /* O_logical_or */
1491 /* Unfortunately, in MRI mode for the m68k, multiplication and
1492 division have lower precedence than the bit wise operators. This
1493 function sets the operator precedences correctly for the current
1494 mode. Also, MRI uses a different bit_not operator, and this fixes
1497 #define STANDARD_MUL_PRECEDENCE 8
1498 #define MRI_MUL_PRECEDENCE 6
1501 expr_set_precedence (void)
1505 op_rank
[O_multiply
] = MRI_MUL_PRECEDENCE
;
1506 op_rank
[O_divide
] = MRI_MUL_PRECEDENCE
;
1507 op_rank
[O_modulus
] = MRI_MUL_PRECEDENCE
;
1511 op_rank
[O_multiply
] = STANDARD_MUL_PRECEDENCE
;
1512 op_rank
[O_divide
] = STANDARD_MUL_PRECEDENCE
;
1513 op_rank
[O_modulus
] = STANDARD_MUL_PRECEDENCE
;
1517 /* Initialize the expression parser. */
1522 expr_set_precedence ();
1524 /* Verify that X_op field is wide enough. */
1528 assert (e
.X_op
== O_max
);
1532 /* Return the encoding for the operator at INPUT_LINE_POINTER, and
1533 sets NUM_CHARS to the number of characters in the operator.
1534 Does not advance INPUT_LINE_POINTER. */
1536 static inline operatorT
1537 operator (int *num_chars
)
1542 c
= *input_line_pointer
& 0xff;
1545 if (is_end_of_line
[c
])
1551 return op_encoding
[c
];
1555 /* Do not allow a++b and a--b to be a + (+b) and a - (-b)
1556 Disabled, since the preprocessor removes whitespace. */
1557 if (1 || input_line_pointer
[1] != c
)
1558 return op_encoding
[c
];
1562 switch (input_line_pointer
[1])
1565 return op_encoding
[c
];
1580 if (input_line_pointer
[1] != '=')
1581 return op_encoding
[c
];
1587 switch (input_line_pointer
[1])
1590 return op_encoding
[c
];
1592 ret
= O_right_shift
;
1602 switch (input_line_pointer
[1])
1605 /* We accept !! as equivalent to ^ for MRI compatibility. */
1607 return O_bit_exclusive_or
;
1609 /* We accept != as equivalent to <>. */
1614 return O_bit_inclusive_or
;
1615 return op_encoding
[c
];
1619 if (input_line_pointer
[1] != '|')
1620 return op_encoding
[c
];
1623 return O_logical_or
;
1626 if (input_line_pointer
[1] != '&')
1627 return op_encoding
[c
];
1630 return O_logical_and
;
1636 /* Parse an expression. */
1639 expr (int rankarg
, /* Larger # is higher rank. */
1640 expressionS
*resultP
, /* Deliver result here. */
1641 enum expr_mode mode
/* Controls behavior. */)
1643 operator_rankT rank
= (operator_rankT
) rankarg
;
1652 /* Save the value of dot for the fixup code. */
1654 dot_value
= frag_now_fix ();
1656 retval
= operand (resultP
, mode
);
1658 /* operand () gobbles spaces. */
1659 know (*input_line_pointer
!= ' ');
1661 op_left
= operator (&op_chars
);
1662 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
1666 input_line_pointer
+= op_chars
; /* -> after operator. */
1668 rightseg
= expr (op_rank
[(int) op_left
], &right
, mode
);
1669 if (right
.X_op
== O_absent
)
1671 as_warn (_("missing operand; zero assumed"));
1672 right
.X_op
= O_constant
;
1673 right
.X_add_number
= 0;
1674 right
.X_add_symbol
= NULL
;
1675 right
.X_op_symbol
= NULL
;
1678 know (*input_line_pointer
!= ' ');
1680 if (op_left
== O_index
)
1682 if (*input_line_pointer
!= ']')
1683 as_bad ("missing right bracket");
1686 ++input_line_pointer
;
1691 op_right
= operator (&op_chars
);
1693 know (op_right
== O_illegal
1694 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
1695 know ((int) op_left
>= (int) O_multiply
1696 && (int) op_left
<= (int) O_index
);
1698 /* input_line_pointer->after right-hand quantity. */
1699 /* left-hand quantity in resultP. */
1700 /* right-hand quantity in right. */
1701 /* operator in op_left. */
1703 if (resultP
->X_op
== O_big
)
1705 if (resultP
->X_add_number
> 0)
1706 as_warn (_("left operand is a bignum; integer 0 assumed"));
1708 as_warn (_("left operand is a float; integer 0 assumed"));
1709 resultP
->X_op
= O_constant
;
1710 resultP
->X_add_number
= 0;
1711 resultP
->X_add_symbol
= NULL
;
1712 resultP
->X_op_symbol
= NULL
;
1714 if (right
.X_op
== O_big
)
1716 if (right
.X_add_number
> 0)
1717 as_warn (_("right operand is a bignum; integer 0 assumed"));
1719 as_warn (_("right operand is a float; integer 0 assumed"));
1720 right
.X_op
= O_constant
;
1721 right
.X_add_number
= 0;
1722 right
.X_add_symbol
= NULL
;
1723 right
.X_op_symbol
= NULL
;
1726 /* Optimize common cases. */
1727 #ifdef md_optimize_expr
1728 if (md_optimize_expr (resultP
, op_left
, &right
))
1735 if (op_left
== O_add
&& right
.X_op
== O_constant
)
1738 resultP
->X_add_number
+= right
.X_add_number
;
1740 /* This case comes up in PIC code. */
1741 else if (op_left
== O_subtract
1742 && right
.X_op
== O_symbol
1743 && resultP
->X_op
== O_symbol
1744 && (symbol_get_frag (right
.X_add_symbol
)
1745 == symbol_get_frag (resultP
->X_add_symbol
))
1746 && (SEG_NORMAL (rightseg
)
1747 || right
.X_add_symbol
== resultP
->X_add_symbol
))
1749 resultP
->X_add_number
-= right
.X_add_number
;
1750 resultP
->X_add_number
+= (S_GET_VALUE (resultP
->X_add_symbol
)
1751 - S_GET_VALUE (right
.X_add_symbol
));
1752 resultP
->X_op
= O_constant
;
1753 resultP
->X_add_symbol
= 0;
1755 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
)
1758 resultP
->X_add_number
-= right
.X_add_number
;
1760 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
)
1763 resultP
->X_op
= right
.X_op
;
1764 resultP
->X_add_symbol
= right
.X_add_symbol
;
1765 resultP
->X_op_symbol
= right
.X_op_symbol
;
1766 resultP
->X_add_number
+= right
.X_add_number
;
1769 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
1771 /* Constant OP constant. */
1772 offsetT v
= right
.X_add_number
;
1773 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
1775 as_warn (_("division by zero"));
1781 case O_multiply
: resultP
->X_add_number
*= v
; break;
1782 case O_divide
: resultP
->X_add_number
/= v
; break;
1783 case O_modulus
: resultP
->X_add_number
%= v
; break;
1784 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
1786 /* We always use unsigned shifts, to avoid relying on
1787 characteristics of the compiler used to compile gas. */
1788 resultP
->X_add_number
=
1789 (offsetT
) ((valueT
) resultP
->X_add_number
>> (valueT
) v
);
1791 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
1792 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
1793 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
1794 case O_bit_and
: resultP
->X_add_number
&= v
; break;
1795 case O_add
: resultP
->X_add_number
+= v
; break;
1796 case O_subtract
: resultP
->X_add_number
-= v
; break;
1798 resultP
->X_add_number
=
1799 resultP
->X_add_number
== v
? ~ (offsetT
) 0 : 0;
1802 resultP
->X_add_number
=
1803 resultP
->X_add_number
!= v
? ~ (offsetT
) 0 : 0;
1806 resultP
->X_add_number
=
1807 resultP
->X_add_number
< v
? ~ (offsetT
) 0 : 0;
1810 resultP
->X_add_number
=
1811 resultP
->X_add_number
<= v
? ~ (offsetT
) 0 : 0;
1814 resultP
->X_add_number
=
1815 resultP
->X_add_number
>= v
? ~ (offsetT
) 0 : 0;
1818 resultP
->X_add_number
=
1819 resultP
->X_add_number
> v
? ~ (offsetT
) 0 : 0;
1822 resultP
->X_add_number
= resultP
->X_add_number
&& v
;
1825 resultP
->X_add_number
= resultP
->X_add_number
|| v
;
1829 else if (resultP
->X_op
== O_symbol
1830 && right
.X_op
== O_symbol
1831 && (op_left
== O_add
1832 || op_left
== O_subtract
1833 || (resultP
->X_add_number
== 0
1834 && right
.X_add_number
== 0)))
1836 /* Symbol OP symbol. */
1837 resultP
->X_op
= op_left
;
1838 resultP
->X_op_symbol
= right
.X_add_symbol
;
1839 if (op_left
== O_add
)
1840 resultP
->X_add_number
+= right
.X_add_number
;
1841 else if (op_left
== O_subtract
)
1843 resultP
->X_add_number
-= right
.X_add_number
;
1844 if (retval
== rightseg
&& SEG_NORMAL (retval
))
1846 retval
= absolute_section
;
1847 rightseg
= absolute_section
;
1853 /* The general case. */
1854 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
1855 resultP
->X_op_symbol
= make_expr_symbol (&right
);
1856 resultP
->X_op
= op_left
;
1857 resultP
->X_add_number
= 0;
1858 resultP
->X_unsigned
= 1;
1861 if (retval
!= rightseg
)
1863 if (! SEG_NORMAL (retval
))
1865 if (retval
!= undefined_section
|| SEG_NORMAL (rightseg
))
1868 else if (SEG_NORMAL (rightseg
)
1870 && op_left
!= O_subtract
1873 as_bad (_("operation combines symbols in different segments"));
1877 } /* While next operator is >= this rank. */
1879 /* The PA port needs this information. */
1880 if (resultP
->X_add_symbol
)
1881 symbol_mark_used (resultP
->X_add_symbol
);
1883 if (rank
== 0 && mode
== expr_evaluate
)
1884 resolve_expression (resultP
);
1886 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
1889 /* Resolve an expression without changing any symbols/sub-expressions
1893 resolve_expression (expressionS
*expressionP
)
1895 /* Help out with CSE. */
1896 valueT final_val
= expressionP
->X_add_number
;
1897 symbolS
*add_symbol
= expressionP
->X_add_symbol
;
1898 symbolS
*op_symbol
= expressionP
->X_op_symbol
;
1899 operatorT op
= expressionP
->X_op
;
1901 segT seg_left
, seg_right
;
1902 fragS
*frag_left
, *frag_right
;
1916 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1924 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
))
1927 if (seg_left
!= absolute_section
)
1930 if (op
== O_logical_not
)
1932 else if (op
== O_uminus
)
1944 case O_bit_inclusive_or
:
1946 case O_bit_exclusive_or
:
1958 if (!snapshot_symbol (&add_symbol
, &left
, &seg_left
, &frag_left
)
1959 || !snapshot_symbol (&op_symbol
, &right
, &seg_right
, &frag_right
))
1962 /* Simplify addition or subtraction of a constant by folding the
1963 constant into X_add_number. */
1966 if (seg_right
== absolute_section
)
1972 else if (seg_left
== absolute_section
)
1976 seg_left
= seg_right
;
1977 add_symbol
= op_symbol
;
1982 else if (op
== O_subtract
)
1984 if (seg_right
== absolute_section
)
1992 /* Equality and non-equality tests are permitted on anything.
1993 Subtraction, and other comparison operators are permitted if
1994 both operands are in the same section.
1995 Shifts by constant zero are permitted on anything.
1996 Multiplies, bit-ors, and bit-ands with constant zero are
1997 permitted on anything.
1998 Multiplies and divides by constant one are permitted on
2000 Binary operations with both operands being the same register
2001 or undefined symbol are permitted if the result doesn't depend
2003 Otherwise, both operands must be absolute. We already handled
2004 the case of addition or subtraction of a constant above. */
2005 if (!(seg_left
== absolute_section
2006 && seg_right
== absolute_section
)
2007 && !(op
== O_eq
|| op
== O_ne
)
2008 && !((op
== O_subtract
2009 || op
== O_lt
|| op
== O_le
|| op
== O_ge
|| op
== O_gt
)
2010 && seg_left
== seg_right
2011 && (finalize_syms
|| frag_left
== frag_right
)
2012 && (seg_left
!= reg_section
|| left
== right
)
2013 && (seg_left
!= undefined_section
|| add_symbol
== op_symbol
)))
2015 if ((seg_left
== absolute_section
&& left
== 0)
2016 || (seg_right
== absolute_section
&& right
== 0))
2018 if (op
== O_bit_exclusive_or
|| op
== O_bit_inclusive_or
)
2020 if (seg_right
!= absolute_section
|| right
!= 0)
2022 seg_left
= seg_right
;
2024 add_symbol
= op_symbol
;
2029 else if (op
== O_left_shift
|| op
== O_right_shift
)
2031 if (seg_left
!= absolute_section
|| left
!= 0)
2037 else if (op
!= O_multiply
2038 && op
!= O_bit_or_not
&& op
!= O_bit_and
)
2041 else if (op
== O_multiply
2042 && seg_left
== absolute_section
&& left
== 1)
2044 seg_left
= seg_right
;
2046 add_symbol
= op_symbol
;
2050 else if ((op
== O_multiply
|| op
== O_divide
)
2051 && seg_right
== absolute_section
&& right
== 1)
2056 else if (left
!= right
2057 || ((seg_left
!= reg_section
|| seg_right
!= reg_section
)
2058 && (seg_left
!= undefined_section
2059 || seg_right
!= undefined_section
2060 || add_symbol
!= op_symbol
)))
2062 else if (op
== O_bit_and
|| op
== O_bit_inclusive_or
)
2067 else if (op
!= O_bit_exclusive_or
&& op
!= O_bit_or_not
)
2073 case O_add
: left
+= right
; break;
2074 case O_subtract
: left
-= right
; break;
2075 case O_multiply
: left
*= right
; break;
2079 left
= (offsetT
) left
/ (offsetT
) right
;
2084 left
= (offsetT
) left
% (offsetT
) right
;
2086 case O_left_shift
: left
<<= right
; break;
2087 case O_right_shift
: left
>>= right
; break;
2088 case O_bit_inclusive_or
: left
|= right
; break;
2089 case O_bit_or_not
: left
|= ~right
; break;
2090 case O_bit_exclusive_or
: left
^= right
; break;
2091 case O_bit_and
: left
&= right
; break;
2094 left
= (left
== right
2095 && seg_left
== seg_right
2096 && (finalize_syms
|| frag_left
== frag_right
)
2097 && (seg_left
!= undefined_section
2098 || add_symbol
== op_symbol
)
2099 ? ~ (valueT
) 0 : 0);
2104 left
= (offsetT
) left
< (offsetT
) right
? ~ (valueT
) 0 : 0;
2107 left
= (offsetT
) left
<= (offsetT
) right
? ~ (valueT
) 0 : 0;
2110 left
= (offsetT
) left
>= (offsetT
) right
? ~ (valueT
) 0 : 0;
2113 left
= (offsetT
) left
> (offsetT
) right
? ~ (valueT
) 0 : 0;
2115 case O_logical_and
: left
= left
&& right
; break;
2116 case O_logical_or
: left
= left
|| right
; break;
2126 if (seg_left
== absolute_section
)
2128 else if (seg_left
== reg_section
&& final_val
== 0)
2130 else if (add_symbol
!= expressionP
->X_add_symbol
)
2132 expressionP
->X_add_symbol
= add_symbol
;
2134 expressionP
->X_op
= op
;
2136 if (op
== O_constant
|| op
== O_register
)
2138 expressionP
->X_add_number
= final_val
;
2143 /* This lives here because it belongs equally in expr.c & read.c.
2144 expr.c is just a branch office read.c anyway, and putting it
2145 here lessens the crowd at read.c.
2147 Assume input_line_pointer is at start of symbol name.
2148 Advance input_line_pointer past symbol name.
2149 Turn that character into a '\0', returning its former value.
2150 This allows a string compare (RMS wants symbol names to be strings)
2152 There will always be a char following symbol name, because all good
2153 lines end in end-of-line. */
2156 get_symbol_end (void)
2160 /* We accept \001 in a name in case this is being called with a
2161 constructed string. */
2162 if (is_name_beginner (c
= *input_line_pointer
++) || c
== '\001')
2164 while (is_part_of_name (c
= *input_line_pointer
++)
2167 if (is_name_ender (c
))
2168 c
= *input_line_pointer
++;
2170 *--input_line_pointer
= 0;
2175 get_single_number (void)
2178 operand (&exp
, expr_normal
);
2179 return exp
.X_add_number
;