1 /* expr.c -operands, expressions-
2 Copyright (C) 1987, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 * This is really a branch office of as-read.c. I split it out to clearly
22 * distinguish the world of expressions from the world of statements.
23 * (It also gives smaller files to re-compile.)
24 * Here, "operand"s are of expressions, not instructions.
34 static void floating_constant
PARAMS ((expressionS
* expressionP
));
35 static void integer_constant
PARAMS ((int radix
, expressionS
* expressionP
));
36 static void clean_up_expression
PARAMS ((expressionS
* expressionP
));
37 static symbolS
*make_expr_symbol
PARAMS ((expressionS
* expressionP
));
39 extern const char EXP_CHARS
[], FLT_CHARS
[];
41 /* Build a dummy symbol to hold a complex expression. This is how we
42 build expressions up out of other expressions. The symbol is put
43 into the fake section expr_section. */
46 make_expr_symbol (expressionP
)
47 expressionS
*expressionP
;
52 /* FIXME: This should be something which decode_local_label_name
54 fake
= FAKE_LABEL_NAME
;
56 /* Putting constant symbols in absolute_section rather than
57 expr_section is convenient for the old a.out code, for which
58 S_GET_SEGMENT does not always retrieve the value put in by
60 symbolP
= symbol_new (fake
,
61 (expressionP
->X_op
== O_constant
64 0, &zero_address_frag
);
65 symbolP
->sy_value
= *expressionP
;
70 * Build any floating-point literal here.
71 * Also build any bignum literal here.
74 /* Seems atof_machine can backscan through generic_bignum and hit whatever
75 happens to be loaded before it in memory. And its way too complicated
76 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
77 and never write into the early words, thus they'll always be zero.
78 I hate Dean's floating-point code. Bleh. */
79 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
80 FLONUM_TYPE generic_floating_point_number
=
82 &generic_bignum
[6], /* low (JF: Was 0) */
83 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high JF: (added +6) */
88 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
89 int generic_floating_point_magic
;
92 floating_constant (expressionP
)
93 expressionS
*expressionP
;
95 /* input_line_pointer->*/
96 /* floating-point constant. */
99 error_code
= atof_generic
100 (&input_line_pointer
, ".", EXP_CHARS
,
101 &generic_floating_point_number
);
105 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
107 as_bad ("bad floating-point constant: exponent overflow, probably assembling junk");
111 as_bad ("bad floating-point constant: unknown error code=%d.", error_code
);
114 expressionP
->X_op
= O_big
;
115 /* input_line_pointer->just after constant, */
116 /* which may point to whitespace. */
117 expressionP
->X_add_number
= -1;
121 integer_constant (radix
, expressionP
)
123 expressionS
*expressionP
;
125 char *digit_2
; /*->2nd digit of number. */
128 valueT number
; /* offset or (absolute) value */
129 short int digit
; /* value of next digit in current radix */
130 short int maxdig
= 0;/* highest permitted digit value. */
131 int too_many_digits
= 0; /* if we see >= this number of */
132 char *name
; /* points to name of symbol */
133 symbolS
*symbolP
; /* points to symbol */
135 int small
; /* true if fits in 32 bits. */
136 extern const char hex_value
[]; /* in hex_value.c */
138 /* May be bignum, or may fit in 32 bits. */
139 /* Most numbers fit into 32 bits, and we want this case to be fast.
140 so we pretend it will fit into 32 bits. If, after making up a 32
141 bit number, we realise that we have scanned more digits than
142 comfortably fit into 32 bits, we re-scan the digits coding them
143 into a bignum. For decimal and octal numbers we are
144 conservative: Some numbers may be assumed bignums when in fact
145 they do fit into 32 bits. Numbers of any radix can have excess
146 leading zeros: We strive to recognise this and cast them back
147 into 32 bits. We must check that the bignum really is more than
148 32 bits, and change it back to a 32-bit number if it fits. The
149 number we are looking for is expected to be positive, but if it
150 fits into 32 bits as an unsigned number, we let it be a 32-bit
151 number. The cavalier approach is for speed in ordinary cases. */
152 /* This has been extended for 64 bits. We blindly assume that if
153 you're compiling in 64-bit mode, the target is a 64-bit machine.
154 This should be cleaned up. */
158 #else /* includes non-bfd case, mostly */
166 too_many_digits
= valuesize
+ 1;
170 too_many_digits
= (valuesize
+ 2) / 3;
174 too_many_digits
= (valuesize
+ 3) / 4;
178 too_many_digits
= (valuesize
+ 12) / 4; /* very rough */
181 c
= *input_line_pointer
;
182 input_line_pointer
++;
183 digit_2
= input_line_pointer
;
185 (digit
= hex_value
[(unsigned char) c
]) < maxdig
;
186 c
= *input_line_pointer
++)
188 number
= number
* radix
+ digit
;
190 /* c contains character after number. */
191 /* input_line_pointer->char after c. */
192 small
= input_line_pointer
- digit_2
< too_many_digits
;
196 * we saw a lot of digits. manufacture a bignum the hard way.
198 LITTLENUM_TYPE
*leader
; /*->high order littlenum of the bignum. */
199 LITTLENUM_TYPE
*pointer
; /*->littlenum we are frobbing now. */
202 leader
= generic_bignum
;
203 generic_bignum
[0] = 0;
204 generic_bignum
[1] = 0;
205 /* we could just use digit_2, but lets be mnemonic. */
206 input_line_pointer
= --digit_2
; /*->1st digit. */
207 c
= *input_line_pointer
++;
209 (carry
= hex_value
[(unsigned char) c
]) < maxdig
;
210 c
= *input_line_pointer
++)
212 for (pointer
= generic_bignum
;
218 work
= carry
+ radix
* *pointer
;
219 *pointer
= work
& LITTLENUM_MASK
;
220 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
224 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
225 { /* room to grow a longer bignum. */
230 /* again, c is char after number, */
231 /* input_line_pointer->after c. */
232 know (LITTLENUM_NUMBER_OF_BITS
== 16);
233 if (leader
< generic_bignum
+ sizeof (valueT
) / 2)
234 { /* will fit into 32 bits. */
236 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
237 | (generic_bignum
[0] & LITTLENUM_MASK
);
242 number
= leader
- generic_bignum
+ 1; /* number of littlenums in the bignum. */
248 * here with number, in correct radix. c is the next char.
249 * note that unlike un*x, we allow "011f" "0x9f" to
250 * both mean the same as the (conventional) "9f". this is simply easier
251 * than checking for strict canonical form. syntax sux!
257 #ifdef LOCAL_LABELS_FB
261 * backward ref to local label.
262 * because it is backward, expect it to be defined.
264 /* Construct a local label. */
265 name
= fb_label_name ((int) number
, 0);
267 /* seen before, or symbol is defined: ok */
268 symbolP
= symbol_find (name
);
269 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
272 /* local labels are never absolute. don't waste time
273 checking absoluteness. */
274 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
276 expressionP
->X_op
= O_symbol
;
277 expressionP
->X_add_symbol
= symbolP
;
282 /* either not seen or not defined. */
283 /* @@ Should print out the original string instead of
284 the parsed number. */
285 as_bad ("backw. ref to unknown label \"%d:\", 0 assumed.",
287 expressionP
->X_op
= O_constant
;
290 expressionP
->X_add_number
= 0;
297 * forward reference. expect symbol to be undefined or
298 * unknown. undefined: seen it before. unknown: never seen
300 * construct a local label name, then an undefined symbol.
301 * don't create a xseg frag for it: caller may do that.
302 * just return it as never seen before.
304 name
= fb_label_name ((int) number
, 1);
305 symbolP
= symbol_find_or_make (name
);
306 /* we have no need to check symbol properties. */
307 #ifndef many_segments
308 /* since "know" puts its arg into a "string", we
309 can't have newlines in the argument. */
310 know (S_GET_SEGMENT (symbolP
) == undefined_section
|| S_GET_SEGMENT (symbolP
) == text_section
|| S_GET_SEGMENT (symbolP
) == data_section
);
312 expressionP
->X_op
= O_symbol
;
313 expressionP
->X_add_symbol
= symbolP
;
314 expressionP
->X_add_number
= 0;
319 #endif /* LOCAL_LABELS_FB */
321 #ifdef LOCAL_LABELS_DOLLAR
326 /* If the dollar label is *currently* defined, then this is just
327 another reference to it. If it is not *currently* defined,
328 then this is a fresh instantiation of that number, so create
331 if (dollar_label_defined ((long) number
))
333 name
= dollar_label_name ((long) number
, 0);
334 symbolP
= symbol_find (name
);
335 know (symbolP
!= NULL
);
339 name
= dollar_label_name ((long) number
, 1);
340 symbolP
= symbol_find_or_make (name
);
343 expressionP
->X_op
= O_symbol
;
344 expressionP
->X_add_symbol
= symbolP
;
345 expressionP
->X_add_number
= 0;
350 #endif /* LOCAL_LABELS_DOLLAR */
354 expressionP
->X_op
= O_constant
;
355 expressionP
->X_add_number
= number
;
356 input_line_pointer
--; /* restore following character. */
358 } /* really just a number */
360 } /* switch on char following the number */
366 /* not a small number */
367 expressionP
->X_op
= O_big
;
368 expressionP
->X_add_number
= number
;
369 input_line_pointer
--; /*->char following number. */
375 * Summary of operand().
377 * in: Input_line_pointer points to 1st char of operand, which may
380 * out: A expressionS.
381 * The operand may have been empty: in this case X_op == O_absent.
382 * Input_line_pointer->(next non-blank) char after operand.
386 operand (expressionP
)
387 expressionS
*expressionP
;
390 symbolS
*symbolP
; /* points to symbol */
391 char *name
; /* points to name of symbol */
394 /* All integers are regarded as unsigned unless they are negated.
395 This is because the only thing which cares whether a number is
396 unsigned is the code in emit_expr which extends constants into
397 bignums. It should only sign extend negative numbers, so that
398 something like ``.quad 0x80000000'' is not sign extended even
399 though it appears negative if valueT is 32 bits. */
400 expressionP
->X_unsigned
= 1;
402 /* digits, assume it is a bignum. */
404 SKIP_WHITESPACE (); /* leading whitespace is part of operand. */
405 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
411 integer_constant (2, expressionP
);
414 integer_constant (8, expressionP
);
417 integer_constant (16, expressionP
);
429 input_line_pointer
--;
431 integer_constant (10, expressionP
);
435 /* non-decimal radix */
437 c
= *input_line_pointer
;
442 if (c
&& strchr (FLT_CHARS
, c
))
444 input_line_pointer
++;
445 floating_constant (expressionP
);
449 /* The string was only zero */
450 expressionP
->X_op
= O_constant
;
451 expressionP
->X_add_number
= 0;
458 input_line_pointer
++;
459 integer_constant (16, expressionP
);
463 #ifdef LOCAL_LABELS_FB
464 /* FIXME: This seems to be nonsense. At this point we know
465 for sure that *input_line_pointer is 'b'. So why are we
466 checking it? What is this code supposed to do? */
467 if (!*input_line_pointer
468 || (!strchr ("+-.0123456789", *input_line_pointer
)
469 && !strchr (EXP_CHARS
, *input_line_pointer
)))
471 input_line_pointer
--;
472 integer_constant (10, expressionP
);
477 input_line_pointer
++;
478 integer_constant (2, expressionP
);
489 integer_constant (8, expressionP
);
493 #ifdef LOCAL_LABELS_FB
494 /* if it says '0f' and the line ends or it doesn't look like
495 a floating point #, its a local label ref. dtrt */
496 /* likewise for the b's. xoxorich. */
497 /* FIXME: As in the 'b' case, we know that the
498 *input_line_pointer is 'f'. What is this code really
501 && (!*input_line_pointer
||
502 (!strchr ("+-.0123456789", *input_line_pointer
) &&
503 !strchr (EXP_CHARS
, *input_line_pointer
))))
505 input_line_pointer
-= 1;
506 integer_constant (10, expressionP
);
520 input_line_pointer
++;
521 floating_constant (expressionP
);
522 expressionP
->X_add_number
= -(isupper (c
) ? tolower (c
) : c
);
525 #ifdef LOCAL_LABELS_DOLLAR
527 integer_constant (10, expressionP
);
535 /* didn't begin with digit & not a name */
536 segment
= expression (expressionP
);
537 /* Expression() will pass trailing whitespace */
538 if (*input_line_pointer
++ != ')')
540 as_bad ("Missing ')' assumed");
541 input_line_pointer
--;
543 /* here with input_line_pointer->char after "(...)" */
547 /* Warning: to conform to other people's assemblers NO ESCAPEMENT is
548 permitted for a single quote. The next character, parity errors and
549 all, is taken as the value of the operand. VERY KINKY. */
550 expressionP
->X_op
= O_constant
;
551 expressionP
->X_add_number
= *input_line_pointer
++;
555 (void) operand (expressionP
);
561 operand (expressionP
);
562 if (expressionP
->X_op
== O_constant
)
564 /* input_line_pointer -> char after operand */
567 expressionP
->X_add_number
= - expressionP
->X_add_number
;
568 /* Notice: '-' may overflow: no warning is given. This is
569 compatible with other people's assemblers. Sigh. */
570 expressionP
->X_unsigned
= 0;
573 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
575 else if (expressionP
->X_op
!= O_illegal
576 && expressionP
->X_op
!= O_absent
)
578 expressionP
->X_add_symbol
= make_expr_symbol (expressionP
);
580 expressionP
->X_op
= O_uminus
;
582 expressionP
->X_op
= O_bit_not
;
583 expressionP
->X_add_number
= 0;
586 as_warn ("Unary operator %c ignored because bad operand follows",
592 if (!is_part_of_name (*input_line_pointer
))
596 /* JF: '.' is pseudo symbol with value of current location
597 in current segment. */
598 fake
= FAKE_LABEL_NAME
;
599 symbolP
= symbol_new (fake
,
601 (valueT
) frag_now_fix (),
604 expressionP
->X_op
= O_symbol
;
605 expressionP
->X_add_symbol
= symbolP
;
606 expressionP
->X_add_number
= 0;
617 /* can't imagine any other kind of operand */
618 expressionP
->X_op
= O_absent
;
619 input_line_pointer
--;
620 md_operand (expressionP
);
624 if (is_end_of_line
[(unsigned char) c
])
626 if (is_name_beginner (c
)) /* here if did not begin with a digit */
629 * Identifier begins here.
630 * This is kludged for speed, so code is repeated.
633 name
= --input_line_pointer
;
634 c
= get_symbol_end ();
635 symbolP
= symbol_find_or_make (name
);
637 /* If we have an absolute symbol or a reg, then we know its
639 segment
= S_GET_SEGMENT (symbolP
);
640 if (segment
== absolute_section
)
642 expressionP
->X_op
= O_constant
;
643 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
645 else if (segment
== reg_section
)
647 expressionP
->X_op
= O_register
;
648 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
652 expressionP
->X_op
= O_symbol
;
653 expressionP
->X_add_symbol
= symbolP
;
654 expressionP
->X_add_number
= 0;
656 *input_line_pointer
= c
;
660 as_bad ("Bad expression");
661 expressionP
->X_op
= O_constant
;
662 expressionP
->X_add_number
= 0;
667 * It is more 'efficient' to clean up the expressionS when they are created.
668 * Doing it here saves lines of code.
670 clean_up_expression (expressionP
);
671 SKIP_WHITESPACE (); /*->1st char after operand. */
672 know (*input_line_pointer
!= ' ');
674 switch (expressionP
->X_op
)
677 return absolute_section
;
679 return S_GET_SEGMENT (expressionP
->X_add_symbol
);
685 /* Internal. Simplify a struct expression for use by expr() */
688 * In: address of a expressionS.
689 * The X_op field of the expressionS may only take certain values.
690 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
691 * Out: expressionS may have been modified:
692 * 'foo-foo' symbol references cancelled to 0,
693 * which changes X_op from O_subtract to O_constant.
694 * Unused fields zeroed to help expr().
698 clean_up_expression (expressionP
)
699 expressionS
*expressionP
;
701 switch (expressionP
->X_op
)
705 expressionP
->X_add_number
= 0;
710 expressionP
->X_add_symbol
= NULL
;
715 expressionP
->X_op_symbol
= NULL
;
718 if (expressionP
->X_op_symbol
== expressionP
->X_add_symbol
719 || ((expressionP
->X_op_symbol
->sy_frag
720 == expressionP
->X_add_symbol
->sy_frag
)
721 && SEG_NORMAL (S_GET_SEGMENT (expressionP
->X_add_symbol
))
722 && (S_GET_VALUE (expressionP
->X_op_symbol
)
723 == S_GET_VALUE (expressionP
->X_add_symbol
))))
725 expressionP
->X_op
= O_constant
;
726 expressionP
->X_add_symbol
= NULL
;
727 expressionP
->X_op_symbol
= NULL
;
735 /* Expression parser. */
738 * We allow an empty expression, and just assume (absolute,0) silently.
739 * Unary operators and parenthetical expressions are treated as operands.
740 * As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
742 * We used to do a aho/ullman shift-reduce parser, but the logic got so
743 * warped that I flushed it and wrote a recursive-descent parser instead.
744 * Now things are stable, would anybody like to write a fast parser?
745 * Most expressions are either register (which does not even reach here)
746 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
747 * So I guess it doesn't really matter how inefficient more complex expressions
750 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
751 * Also, we have consumed any leading or trailing spaces (operand does that)
752 * and done all intervening operators.
754 * This returns the segment of the result, which will be
755 * absolute_section or the segment of a symbol.
761 static const operatorT op_encoding
[256] =
762 { /* maps ASCII->operators */
764 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
765 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
767 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
768 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
769 __
, __
, __
, __
, __
, __
, __
, __
,
770 __
, __
, __
, __
, O_left_shift
, __
, O_right_shift
, __
,
771 __
, __
, __
, __
, __
, __
, __
, __
,
772 __
, __
, __
, __
, __
, __
, __
, __
,
773 __
, __
, __
, __
, __
, __
, __
, __
,
774 __
, __
, __
, __
, __
, __
, O_bit_exclusive_or
, __
,
775 __
, __
, __
, __
, __
, __
, __
, __
,
776 __
, __
, __
, __
, __
, __
, __
, __
,
777 __
, __
, __
, __
, __
, __
, __
, __
,
778 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
780 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
781 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
782 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
783 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
784 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
785 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
786 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
787 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
793 * 0 operand, (expression)
799 static const operator_rankT op_rank
[] =
812 3, /* O_left_shift */
813 3, /* O_right_shift */
814 2, /* O_bit_inclusive_or */
815 2, /* O_bit_or_not */
816 2, /* O_bit_exclusive_or */
824 operator_rankT rank
; /* Larger # is higher rank. */
825 expressionS
*resultP
; /* Deliver result here. */
830 char c_left
; /* 1st operator character. */
836 retval
= operand (resultP
);
838 know (*input_line_pointer
!= ' '); /* Operand() gobbles spaces. */
840 c_left
= *input_line_pointer
; /* Potential operator character. */
841 op_left
= op_encoding
[(unsigned char) c_left
];
842 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
846 input_line_pointer
++; /*->after 1st character of operator. */
847 /* Operators "<<" and ">>" have 2 characters. */
848 if (*input_line_pointer
== c_left
&& (c_left
== '<' || c_left
== '>'))
849 ++input_line_pointer
;
851 rightseg
= expr (op_rank
[(int) op_left
], &right
);
852 if (right
.X_op
== O_absent
)
854 as_warn ("missing operand; zero assumed");
855 right
.X_op
= O_constant
;
856 right
.X_add_number
= 0;
857 right
.X_add_symbol
= NULL
;
858 right
.X_op_symbol
= NULL
;
861 know (*input_line_pointer
!= ' ');
863 if (retval
== undefined_section
)
865 if (SEG_NORMAL (rightseg
))
868 else if (! SEG_NORMAL (retval
))
870 else if (SEG_NORMAL (rightseg
)
871 && retval
!= rightseg
873 && op_left
!= O_subtract
876 as_bad ("operation combines symbols in different segments");
878 c_right
= *input_line_pointer
;
879 op_right
= op_encoding
[(unsigned char) c_right
];
880 if (*input_line_pointer
== c_right
&& (c_right
== '<' || c_right
== '>'))
881 ++input_line_pointer
;
883 know (op_right
== O_illegal
|| op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
884 know ((int) op_left
>= (int) O_multiply
&& (int) op_left
<= (int) O_subtract
);
886 /* input_line_pointer->after right-hand quantity. */
887 /* left-hand quantity in resultP */
888 /* right-hand quantity in right. */
889 /* operator in op_left. */
891 if (resultP
->X_op
== O_big
)
893 as_warn ("left operand of %c is a %s; integer 0 assumed",
894 c_left
, resultP
->X_add_number
> 0 ? "bignum" : "float");
895 resultP
->X_op
= O_constant
;
896 resultP
->X_add_number
= 0;
897 resultP
->X_add_symbol
= NULL
;
898 resultP
->X_op_symbol
= NULL
;
900 if (right
.X_op
== O_big
)
902 as_warn ("right operand of %c is a %s; integer 0 assumed",
903 c_left
, right
.X_add_number
> 0 ? "bignum" : "float");
904 right
.X_op
= O_constant
;
905 right
.X_add_number
= 0;
906 right
.X_add_symbol
= NULL
;
907 right
.X_op_symbol
= NULL
;
910 /* Optimize common cases. */
911 if (op_left
== O_add
&& right
.X_op
== O_constant
)
914 resultP
->X_add_number
+= right
.X_add_number
;
916 else if (op_left
== O_subtract
&& right
.X_op
== O_constant
)
919 resultP
->X_add_number
-= right
.X_add_number
;
921 else if (op_left
== O_add
&& resultP
->X_op
== O_constant
)
924 resultP
->X_op
= right
.X_op
;
925 resultP
->X_add_symbol
= right
.X_add_symbol
;
926 resultP
->X_op_symbol
= right
.X_op_symbol
;
927 resultP
->X_add_number
+= right
.X_add_number
;
930 else if (resultP
->X_op
== O_constant
&& right
.X_op
== O_constant
)
932 /* Constant OP constant. */
933 offsetT v
= right
.X_add_number
;
934 if (v
== 0 && (op_left
== O_divide
|| op_left
== O_modulus
))
936 as_warn ("division by zero");
941 case O_multiply
: resultP
->X_add_number
*= v
; break;
942 case O_divide
: resultP
->X_add_number
/= v
; break;
943 case O_modulus
: resultP
->X_add_number
%= v
; break;
944 case O_left_shift
: resultP
->X_add_number
<<= v
; break;
945 case O_right_shift
: resultP
->X_add_number
>>= v
; break;
946 case O_bit_inclusive_or
: resultP
->X_add_number
|= v
; break;
947 case O_bit_or_not
: resultP
->X_add_number
|= ~v
; break;
948 case O_bit_exclusive_or
: resultP
->X_add_number
^= v
; break;
949 case O_bit_and
: resultP
->X_add_number
&= v
; break;
950 case O_add
: resultP
->X_add_number
+= v
; break;
951 case O_subtract
: resultP
->X_add_number
-= v
; break;
955 else if (resultP
->X_op
== O_symbol
956 && right
.X_op
== O_symbol
958 || op_left
== O_subtract
959 || (resultP
->X_add_number
== 0
960 && right
.X_add_number
== 0)))
962 /* Symbol OP symbol. */
963 resultP
->X_op
= op_left
;
964 resultP
->X_op_symbol
= right
.X_add_symbol
;
965 if (op_left
== O_add
)
966 resultP
->X_add_number
+= right
.X_add_number
;
967 else if (op_left
== O_subtract
)
968 resultP
->X_add_number
-= right
.X_add_number
;
972 /* The general case. */
973 resultP
->X_add_symbol
= make_expr_symbol (resultP
);
974 resultP
->X_op_symbol
= make_expr_symbol (&right
);
975 resultP
->X_op
= op_left
;
976 resultP
->X_add_number
= 0;
977 resultP
->X_unsigned
= 1;
981 } /* While next operator is >= this rank. */
983 return resultP
->X_op
== O_constant
? absolute_section
: retval
;
989 * This lives here because it belongs equally in expr.c & read.c.
990 * Expr.c is just a branch office read.c anyway, and putting it
991 * here lessens the crowd at read.c.
993 * Assume input_line_pointer is at start of symbol name.
994 * Advance input_line_pointer past symbol name.
995 * Turn that character into a '\0', returning its former value.
996 * This allows a string compare (RMS wants symbol names to be strings)
997 * of the symbol name.
998 * There will always be a char following symbol name, because all good
999 * lines end in end-of-line.
1006 while (is_part_of_name (c
= *input_line_pointer
++))
1008 *--input_line_pointer
= 0;
1014 get_single_number ()
1018 return exp
.X_add_number
;