1 /* expr.c -operands, expressions-
2 Copyright (C) 1987, 1990, 1991, 1992 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.
35 static void clean_up_expression (expressionS
* expressionP
);
37 static void clean_up_expression (); /* Internal. */
38 #endif /* not __STDC__ */
39 extern const char EXP_CHARS
[]; /* JF hide MD floating pt stuff all the same place */
40 extern const char FLT_CHARS
[];
43 * Build any floating-point literal here.
44 * Also build any bignum literal here.
47 /* LITTLENUM_TYPE generic_buffer [6]; *//* JF this is a hack */
48 /* Seems atof_machine can backscan through generic_bignum and hit whatever
49 happens to be loaded before it in memory. And its way too complicated
50 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
51 and never write into the early words, thus they'll always be zero.
52 I hate Dean's floating-point code. Bleh.
54 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6];
55 FLONUM_TYPE generic_floating_point_number
=
57 &generic_bignum
[6], /* low (JF: Was 0) */
58 &generic_bignum
[SIZE_OF_LARGE_NUMBER
+ 6 - 1], /* high JF: (added +6) */
63 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
64 int generic_floating_point_magic
;
66 floating_constant (expressionP
)
67 expressionS
*expressionP
;
69 /* input_line_pointer->*/
70 /* floating-point constant. */
73 error_code
= atof_generic
74 (&input_line_pointer
, ".", EXP_CHARS
,
75 &generic_floating_point_number
);
79 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
81 as_bad ("bad floating-point constant: exponent overflow, probably assembling junk");
85 as_bad ("bad floating-point constant: unknown error code=%d.", error_code
);
88 expressionP
->X_seg
= SEG_BIG
;
89 /* input_line_pointer->just after constant, */
90 /* which may point to whitespace. */
91 expressionP
->X_add_number
= -1;
96 integer_constant (radix
, expressionP
)
98 expressionS
*expressionP
;
100 register char *digit_2
; /*->2nd digit of number. */
103 register valueT number
; /* offset or (absolute) value */
104 register short int digit
; /* value of next digit in current radix */
105 register short int maxdig
= 0;/* highest permitted digit value. */
106 register int too_many_digits
= 0; /* if we see >= this number of */
107 register char *name
; /* points to name of symbol */
108 register symbolS
*symbolP
; /* points to symbol */
110 int small
; /* true if fits in 32 bits. */
111 extern char hex_value
[]; /* in hex_value.c */
113 /* may be bignum, or may fit in 32 bits. */
115 * most numbers fit into 32 bits, and we want this case to be fast.
116 * so we pretend it will fit into 32 bits. if, after making up a 32
117 * bit number, we realise that we have scanned more digits than
118 * comfortably fit into 32 bits, we re-scan the digits coding
119 * them into a bignum. for decimal and octal numbers we are conservative: some
120 * numbers may be assumed bignums when in fact they do fit into 32 bits.
121 * numbers of any radix can have excess leading zeros: we strive
122 * to recognise this and cast them back into 32 bits.
123 * we must check that the bignum really is more than 32
124 * bits, and change it back to a 32-bit number if it fits.
125 * the number we are looking for is expected to be positive, but
126 * if it fits into 32 bits as an unsigned number, we let it be a 32-bit
127 * number. the cavalier approach is for speed in ordinary cases.
135 too_many_digits
= 33;
139 too_many_digits
= 11;
149 too_many_digits
= 11;
151 c
= *input_line_pointer
;
152 input_line_pointer
++;
153 digit_2
= input_line_pointer
;
154 for (number
= 0; (digit
= hex_value
[c
]) < maxdig
; c
= *input_line_pointer
++)
156 number
= number
* radix
+ digit
;
158 /* c contains character after number. */
159 /* input_line_pointer->char after c. */
160 small
= input_line_pointer
- digit_2
< too_many_digits
;
164 * we saw a lot of digits. manufacture a bignum the hard way.
166 LITTLENUM_TYPE
*leader
; /*->high order littlenum of the bignum. */
167 LITTLENUM_TYPE
*pointer
; /*->littlenum we are frobbing now. */
170 leader
= generic_bignum
;
171 generic_bignum
[0] = 0;
172 generic_bignum
[1] = 0;
173 /* we could just use digit_2, but lets be mnemonic. */
174 input_line_pointer
= --digit_2
; /*->1st digit. */
175 c
= *input_line_pointer
++;
176 for (; (carry
= hex_value
[c
]) < maxdig
; c
= *input_line_pointer
++)
178 for (pointer
= generic_bignum
;
184 work
= carry
+ radix
* *pointer
;
185 *pointer
= work
& LITTLENUM_MASK
;
186 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
190 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
191 { /* room to grow a longer bignum. */
196 /* again, c is char after number, */
197 /* input_line_pointer->after c. */
198 know (sizeof (int) * 8 == 32);
199 know (LITTLENUM_NUMBER_OF_BITS
== 16);
200 /* hence the constant "2" in the next line. */
201 if (leader
< generic_bignum
+ 2)
202 { /* will fit into 32 bits. */
204 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
205 | (generic_bignum
[0] & LITTLENUM_MASK
);
210 number
= leader
- generic_bignum
+ 1; /* number of littlenums in the bignum. */
216 * here with number, in correct radix. c is the next char.
217 * note that unlike un*x, we allow "011f" "0x9f" to
218 * both mean the same as the (conventional) "9f". this is simply easier
219 * than checking for strict canonical form. syntax sux!
225 #ifdef LOCAL_LABELS_FB
229 * backward ref to local label.
230 * because it is backward, expect it to be defined.
232 /* Construct a local label. */
233 name
= fb_label_name ((int) number
, 0);
235 /* seen before, or symbol is defined: ok */
236 symbolP
= symbol_find (name
);
237 if ((symbolP
!= NULL
) && (S_IS_DEFINED (symbolP
)))
240 /* local labels are never absolute. don't waste time
241 checking absoluteness. */
242 know (SEG_NORMAL (S_GET_SEGMENT (symbolP
)));
244 expressionP
->X_add_symbol
= symbolP
;
245 expressionP
->X_seg
= S_GET_SEGMENT (symbolP
);
249 { /* either not seen or not defined. */
250 as_bad ("backw. ref to unknown label \"%d:\", 0 assumed.", number
);
251 expressionP
->X_seg
= SEG_ABSOLUTE
;
254 expressionP
->X_add_number
= 0;
261 * forward reference. expect symbol to be undefined or
262 * unknown. undefined: seen it before. unknown: never seen
264 * construct a local label name, then an undefined symbol.
265 * don't create a xseg frag for it: caller may do that.
266 * just return it as never seen before.
268 name
= fb_label_name ((int) number
, 1);
269 symbolP
= symbol_find_or_make (name
);
270 /* we have no need to check symbol properties. */
271 #ifndef many_segments
272 /* since "know" puts its arg into a "string", we
273 can't have newlines in the argument. */
274 know (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
|| S_GET_SEGMENT (symbolP
) == SEG_TEXT
|| S_GET_SEGMENT (symbolP
) == SEG_DATA
);
276 expressionP
->X_add_symbol
= symbolP
;
277 expressionP
->X_seg
= SEG_UNKNOWN
;
278 expressionP
->X_subtract_symbol
= NULL
;
279 expressionP
->X_add_number
= 0;
284 #endif /* LOCAL_LABELS_FB */
286 #ifdef LOCAL_LABELS_DOLLAR
291 /* If the dollar label is *currently* defined, then this is just
292 another reference to it. If it is not *currently* defined,
293 then this is a fresh instantiation of that number, so create
296 if (dollar_label_defined (number
))
298 name
= dollar_label_name (number
, 0);
299 symbolP
= symbol_find (name
);
300 know (symbolP
!= NULL
);
304 name
= dollar_label_name (number
, 1);
305 symbolP
= symbol_find_or_make (name
);
308 expressionP
->X_add_symbol
= symbolP
;
309 expressionP
->X_add_number
= 0;
310 expressionP
->X_seg
= S_GET_SEGMENT (symbolP
);
315 #endif /* LOCAL_LABELS_DOLLAR */
319 expressionP
->X_add_number
= number
;
320 expressionP
->X_seg
= SEG_ABSOLUTE
;
321 input_line_pointer
--; /* restore following character. */
323 } /* really just a number */
325 } /* switch on char following the number */
330 { /* not a small number */
331 expressionP
->X_add_number
= number
;
332 expressionP
->X_seg
= SEG_BIG
;
333 input_line_pointer
--; /*->char following number. */
335 } /* integer_constant() */
339 * Summary of operand().
341 * in: Input_line_pointer points to 1st char of operand, which may
344 * out: A expressionS. X_seg determines how to understand the rest of the
346 * The operand may have been empty: in this case X_seg == SEG_ABSENT.
347 * Input_line_pointer->(next non-blank) char after operand.
354 operand (expressionP
)
355 register expressionS
*expressionP
;
358 register symbolS
*symbolP
; /* points to symbol */
359 register char *name
; /* points to name of symbol */
360 /* invented for humans only, hope */
361 /* optimising compiler flushes it! */
362 register short int radix
; /* 2, 8, 10 or 16, 0 when floating */
363 /* 0 means we saw start of a floating- */
364 /* point constant. */
366 /* digits, assume it is a bignum. */
371 SKIP_WHITESPACE (); /* leading whitespace is part of operand. */
372 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
378 integer_constant (2, expressionP
);
381 integer_constant (8, expressionP
);
384 integer_constant (16, expressionP
);
396 input_line_pointer
--;
398 integer_constant (10, expressionP
);
402 /* non-decimal radix */
405 c
= *input_line_pointer
;
410 if (c
&& strchr (FLT_CHARS
, c
))
412 input_line_pointer
++;
413 floating_constant (expressionP
);
417 /* The string was only zero */
418 expressionP
->X_add_symbol
= 0;
419 expressionP
->X_add_number
= 0;
420 expressionP
->X_seg
= SEG_ABSOLUTE
;
427 input_line_pointer
++;
428 integer_constant (16, expressionP
);
432 #ifdef LOCAL_LABELS_FB
433 if (!*input_line_pointer
434 || (!strchr ("+-.0123456789", *input_line_pointer
)
435 && !strchr (EXP_CHARS
, *input_line_pointer
)))
437 input_line_pointer
--;
438 integer_constant (10, expressionP
);
443 input_line_pointer
++;
444 integer_constant (2, expressionP
);
455 integer_constant (8, expressionP
);
459 #ifdef LOCAL_LABELS_FB
460 /* if it says '0f' and the line ends or it doesn't look like
461 a floating point #, its a local label ref. dtrt */
462 /* likewise for the b's. xoxorich. */
464 && (!*input_line_pointer
||
465 (!strchr ("+-.0123456789", *input_line_pointer
) &&
466 !strchr (EXP_CHARS
, *input_line_pointer
))))
468 input_line_pointer
-= 1;
469 integer_constant (10, expressionP
);
483 input_line_pointer
++;
484 floating_constant (expressionP
);
487 #ifdef LOCAL_LABELS_DOLLAR
489 integer_constant (10, expressionP
);
496 /* didn't begin with digit & not a name */
498 (void) expression (expressionP
);
499 /* Expression() will pass trailing whitespace */
500 if (*input_line_pointer
++ != ')')
502 as_bad ("Missing ')' assumed");
503 input_line_pointer
--;
505 /* here with input_line_pointer->char after "(...)" */
507 return expressionP
->X_seg
;
512 * Warning: to conform to other people's assemblers NO ESCAPEMENT is permitted
513 * for a single quote. The next character, parity errors and all, is taken
514 * as the value of the operand. VERY KINKY.
516 expressionP
->X_add_number
= *input_line_pointer
++;
517 expressionP
->X_seg
= SEG_ABSOLUTE
;
525 /* unary operator: hope for SEG_ABSOLUTE */
526 switch (operand (expressionP
))
529 /* input_line_pointer -> char after operand */
532 expressionP
->X_add_number
= -expressionP
->X_add_number
;
534 * Notice: '-' may overflow: no warning is given. This is compatible
535 * with other people's assemblers. Sigh.
540 expressionP
->X_add_number
= ~expressionP
->X_add_number
;
550 { /* JF I hope this hack works */
551 expressionP
->X_subtract_symbol
= expressionP
->X_add_symbol
;
552 expressionP
->X_add_symbol
= 0;
553 expressionP
->X_seg
= SEG_DIFFERENCE
;
556 default: /* unary on non-absolute is unsuported */
557 as_warn ("Unary operator %c ignored because bad operand follows", c
);
559 /* Expression undisturbed from operand(). */
568 if (!is_part_of_name (*input_line_pointer
))
571 extern struct obstack frags
;
573 /* JF: '.' is pseudo symbol with value of current location
574 in current segment. */
575 #ifdef DOT_LABEL_PREFIX
580 symbolP
= symbol_new (fake
,
582 (valueT
) (obstack_next_free (&frags
) - frag_now
->fr_literal
),
585 expressionP
->X_add_number
= 0;
586 expressionP
->X_add_symbol
= symbolP
;
587 expressionP
->X_seg
= now_seg
;
599 /* can't imagine any other kind of operand */
600 expressionP
->X_seg
= SEG_ABSENT
;
601 input_line_pointer
--;
602 md_operand (expressionP
);
606 if (is_name_beginner (c
)) /* here if did not begin with a digit */
609 * Identifier begins here.
610 * This is kludged for speed, so code is repeated.
613 name
= --input_line_pointer
;
614 c
= get_symbol_end ();
615 symbolP
= symbol_find_or_make (name
);
617 * If we have an absolute symbol or a reg, then we know its value now.
619 expressionP
->X_seg
= S_GET_SEGMENT (symbolP
);
620 switch (expressionP
->X_seg
)
624 expressionP
->X_add_number
= S_GET_VALUE (symbolP
);
628 expressionP
->X_add_number
= 0;
629 expressionP
->X_add_symbol
= symbolP
;
631 *input_line_pointer
= c
;
632 expressionP
->X_subtract_symbol
= NULL
;
636 as_bad ("Bad expression");
637 expressionP
->X_add_number
= 0;
638 expressionP
->X_seg
= SEG_ABSOLUTE
;
651 * It is more 'efficient' to clean up the expressionS when they are created.
652 * Doing it here saves lines of code.
654 clean_up_expression (expressionP
);
655 SKIP_WHITESPACE (); /*->1st char after operand. */
656 know (*input_line_pointer
!= ' ');
657 return (expressionP
->X_seg
);
661 /* Internal. Simplify a struct expression for use by expr() */
664 * In: address of a expressionS.
665 * The X_seg field of the expressionS may only take certain values.
666 * Now, we permit SEG_PASS1 to make code smaller & faster.
667 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
668 * Out: expressionS may have been modified:
669 * 'foo-foo' symbol references cancelled to 0,
670 * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE;
671 * Unused fields zeroed to help expr().
675 clean_up_expression (expressionP
)
676 register expressionS
*expressionP
;
678 switch (expressionP
->X_seg
)
682 expressionP
->X_add_symbol
= NULL
;
683 expressionP
->X_subtract_symbol
= NULL
;
684 expressionP
->X_add_number
= 0;
689 expressionP
->X_subtract_symbol
= NULL
;
690 expressionP
->X_add_symbol
= NULL
;
694 expressionP
->X_subtract_symbol
= NULL
;
699 * It does not hurt to 'cancel' NULL==NULL
700 * when comparing symbols for 'eq'ness.
701 * It is faster to re-cancel them to NULL
702 * than to check for this special case.
704 if (expressionP
->X_subtract_symbol
== expressionP
->X_add_symbol
705 || (expressionP
->X_subtract_symbol
706 && expressionP
->X_add_symbol
707 && expressionP
->X_subtract_symbol
->sy_frag
== expressionP
->X_add_symbol
->sy_frag
708 && S_GET_VALUE (expressionP
->X_subtract_symbol
) == S_GET_VALUE (expressionP
->X_add_symbol
)))
710 expressionP
->X_subtract_symbol
= NULL
;
711 expressionP
->X_add_symbol
= NULL
;
712 expressionP
->X_seg
= SEG_ABSOLUTE
;
717 expressionP
->X_add_symbol
= NULL
;
718 expressionP
->X_subtract_symbol
= NULL
;
722 if (SEG_NORMAL (expressionP
->X_seg
))
724 expressionP
->X_subtract_symbol
= NULL
;
728 BAD_CASE (expressionP
->X_seg
);
732 } /* clean_up_expression() */
737 * Internal. Made a function because this code is used in 2 places.
738 * Generate error or correct X_?????_symbol of expressionS.
742 * symbol_1 += symbol_2 ... well ... sort of.
746 expr_part (symbol_1_PP
, symbol_2_P
)
747 symbolS
**symbol_1_PP
;
751 #ifndef MANY_SEGMENTS
752 know ((*symbol_1_PP
) == NULL
|| (S_GET_SEGMENT (*symbol_1_PP
) == SEG_TEXT
) || (S_GET_SEGMENT (*symbol_1_PP
) == SEG_DATA
) || (S_GET_SEGMENT (*symbol_1_PP
) == SEG_BSS
) || (!S_IS_DEFINED (*symbol_1_PP
)));
753 know (symbol_2_P
== NULL
|| (S_GET_SEGMENT (symbol_2_P
) == SEG_TEXT
) || (S_GET_SEGMENT (symbol_2_P
) == SEG_DATA
) || (S_GET_SEGMENT (symbol_2_P
) == SEG_BSS
) || (!S_IS_DEFINED (symbol_2_P
)));
757 if (!S_IS_DEFINED (*symbol_1_PP
))
761 return_value
= SEG_PASS1
;
766 know (!S_IS_DEFINED (*symbol_1_PP
));
767 return_value
= SEG_UNKNOWN
;
774 if (!S_IS_DEFINED (symbol_2_P
))
777 return_value
= SEG_PASS1
;
781 /* {seg1} - {seg2} */
782 as_bad ("Expression too complex, 2 symbolS forgotten: \"%s\" \"%s\"",
783 S_GET_NAME (*symbol_1_PP
), S_GET_NAME (symbol_2_P
));
785 return_value
= SEG_ABSOLUTE
;
790 return_value
= S_GET_SEGMENT (*symbol_1_PP
);
795 { /* (* symbol_1_PP) == NULL */
798 *symbol_1_PP
= symbol_2_P
;
799 return_value
= S_GET_SEGMENT (symbol_2_P
);
804 return_value
= SEG_ABSOLUTE
;
807 #ifndef MANY_SEGMENTS
808 know (return_value
== SEG_ABSOLUTE
|| return_value
== SEG_TEXT
|| return_value
== SEG_DATA
|| return_value
== SEG_BSS
|| return_value
== SEG_UNKNOWN
|| return_value
== SEG_PASS1
);
810 know ((*symbol_1_PP
) == NULL
|| (S_GET_SEGMENT (*symbol_1_PP
) == return_value
));
811 return (return_value
);
814 /* Expression parser. */
817 * We allow an empty expression, and just assume (absolute,0) silently.
818 * Unary operators and parenthetical expressions are treated as operands.
819 * As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
821 * We used to do a aho/ullman shift-reduce parser, but the logic got so
822 * warped that I flushed it and wrote a recursive-descent parser instead.
823 * Now things are stable, would anybody like to write a fast parser?
824 * Most expressions are either register (which does not even reach here)
825 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
826 * So I guess it doesn't really matter how inefficient more complex expressions
829 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
830 * Also, we have consumed any leading or trailing spaces (operand does that)
831 * and done all intervening operators.
836 O_illegal
, /* (0) what we get for illegal op */
838 O_multiply
, /* (1) * */
839 O_divide
, /* (2) / */
840 O_modulus
, /* (3) % */
841 O_left_shift
, /* (4) < */
842 O_right_shift
, /* (5) > */
843 O_bit_inclusive_or
, /* (6) | */
844 O_bit_or_not
, /* (7) ! */
845 O_bit_exclusive_or
, /* (8) ^ */
846 O_bit_and
, /* (9) & */
848 O_subtract
/* (11) - */
855 static const operatorT op_encoding
[256] =
856 { /* maps ASCII->operators */
858 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
859 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
861 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
862 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
863 __
, __
, __
, __
, __
, __
, __
, __
,
864 __
, __
, __
, __
, O_left_shift
, __
, O_right_shift
, __
,
865 __
, __
, __
, __
, __
, __
, __
, __
,
866 __
, __
, __
, __
, __
, __
, __
, __
,
867 __
, __
, __
, __
, __
, __
, __
, __
,
868 __
, __
, __
, __
, __
, __
, O_bit_exclusive_or
, __
,
869 __
, __
, __
, __
, __
, __
, __
, __
,
870 __
, __
, __
, __
, __
, __
, __
, __
,
871 __
, __
, __
, __
, __
, __
, __
, __
,
872 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
874 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
875 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
876 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
877 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
878 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
879 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
880 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
881 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
887 * 0 operand, (expression)
892 static const operator_rankT
894 {0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1};
896 /* Return resultP->X_seg. */
899 register operator_rankT rank
; /* Larger # is higher rank. */
900 register expressionS
*resultP
; /* Deliver result here. */
903 register operatorT op_left
;
904 register char c_left
; /* 1st operator character. */
905 register operatorT op_right
;
906 register char c_right
;
909 (void) operand (resultP
);
910 know (*input_line_pointer
!= ' '); /* Operand() gobbles spaces. */
911 c_left
= *input_line_pointer
; /* Potential operator character. */
912 op_left
= op_encoding
[c_left
];
913 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
915 input_line_pointer
++; /*->after 1st character of operator. */
916 /* Operators "<<" and ">>" have 2 characters. */
917 if (*input_line_pointer
== c_left
&& (c_left
== '<' || c_left
== '>'))
919 input_line_pointer
++;
920 } /*->after operator. */
921 if (SEG_ABSENT
== expr (op_rank
[(int) op_left
], &right
))
923 as_warn ("Missing operand value assumed absolute 0.");
924 resultP
->X_add_number
= 0;
925 resultP
->X_subtract_symbol
= NULL
;
926 resultP
->X_add_symbol
= NULL
;
927 resultP
->X_seg
= SEG_ABSOLUTE
;
929 know (*input_line_pointer
!= ' ');
930 c_right
= *input_line_pointer
;
931 op_right
= op_encoding
[c_right
];
932 if (*input_line_pointer
== c_right
&& (c_right
== '<' || c_right
== '>'))
934 input_line_pointer
++;
935 } /*->after operator. */
936 know ((int) op_right
== 0 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
937 /* input_line_pointer->after right-hand quantity. */
938 /* left-hand quantity in resultP */
939 /* right-hand quantity in right. */
940 /* operator in op_left. */
941 if (resultP
->X_seg
== SEG_PASS1
|| right
.X_seg
== SEG_PASS1
)
943 resultP
->X_seg
= SEG_PASS1
;
947 if (resultP
->X_seg
== SEG_BIG
)
949 as_warn ("Left operand of %c is a %s. Integer 0 assumed.",
950 c_left
, resultP
->X_add_number
> 0 ? "bignum" : "float");
951 resultP
->X_seg
= SEG_ABSOLUTE
;
952 resultP
->X_add_symbol
= 0;
953 resultP
->X_subtract_symbol
= 0;
954 resultP
->X_add_number
= 0;
956 if (right
.X_seg
== SEG_BIG
)
958 as_warn ("Right operand of %c is a %s. Integer 0 assumed.",
959 c_left
, right
.X_add_number
> 0 ? "bignum" : "float");
960 right
.X_seg
= SEG_ABSOLUTE
;
961 right
.X_add_symbol
= 0;
962 right
.X_subtract_symbol
= 0;
963 right
.X_add_number
= 0;
965 if (op_left
== O_subtract
)
968 * Convert - into + by exchanging symbolS and negating number.
969 * I know -infinity can't be negated in 2's complement:
970 * but then it can't be subtracted either. This trick
971 * does not cause any further inaccuracy.
974 register symbolS
*symbolP
;
976 right
.X_add_number
= -right
.X_add_number
;
977 symbolP
= right
.X_add_symbol
;
978 right
.X_add_symbol
= right
.X_subtract_symbol
;
979 right
.X_subtract_symbol
= symbolP
;
982 right
.X_seg
= SEG_DIFFERENCE
;
987 if (op_left
== O_add
)
991 #ifndef MANY_SEGMENTS
993 know (resultP
->X_seg
== SEG_DATA
|| resultP
->X_seg
== SEG_TEXT
|| resultP
->X_seg
== SEG_BSS
|| resultP
->X_seg
== SEG_UNKNOWN
|| resultP
->X_seg
== SEG_DIFFERENCE
|| resultP
->X_seg
== SEG_ABSOLUTE
|| resultP
->X_seg
== SEG_PASS1
|| resultP
->X_seg
== SEG_REGISTER
);
995 know (right
.X_seg
== SEG_DATA
|| right
.X_seg
== SEG_TEXT
|| right
.X_seg
== SEG_BSS
|| right
.X_seg
== SEG_UNKNOWN
|| right
.X_seg
== SEG_DIFFERENCE
|| right
.X_seg
== SEG_ABSOLUTE
|| right
.X_seg
== SEG_PASS1
);
997 clean_up_expression (&right
);
998 clean_up_expression (resultP
);
1000 seg1
= expr_part (&resultP
->X_add_symbol
, right
.X_add_symbol
);
1001 seg2
= expr_part (&resultP
->X_subtract_symbol
, right
.X_subtract_symbol
);
1002 if (seg1
== SEG_PASS1
|| seg2
== SEG_PASS1
)
1005 resultP
->X_seg
= SEG_PASS1
;
1007 else if (seg2
== SEG_ABSOLUTE
)
1008 resultP
->X_seg
= seg1
;
1009 else if (seg1
!= SEG_UNKNOWN
1010 && seg1
!= SEG_ABSOLUTE
1011 && seg2
!= SEG_UNKNOWN
1014 know (seg2
!= SEG_ABSOLUTE
);
1015 know (resultP
->X_subtract_symbol
);
1016 #ifndef MANY_SEGMENTS
1017 know (seg1
== SEG_TEXT
|| seg1
== SEG_DATA
|| seg1
== SEG_BSS
);
1018 know (seg2
== SEG_TEXT
|| seg2
== SEG_DATA
|| seg2
== SEG_BSS
);
1020 know (resultP
->X_add_symbol
);
1021 know (resultP
->X_subtract_symbol
);
1022 as_bad ("Expression too complex: forgetting %s - %s",
1023 S_GET_NAME (resultP
->X_add_symbol
),
1024 S_GET_NAME (resultP
->X_subtract_symbol
));
1025 resultP
->X_seg
= SEG_ABSOLUTE
;
1026 /* Clean_up_expression() will do the rest. */
1029 resultP
->X_seg
= SEG_DIFFERENCE
;
1031 resultP
->X_add_number
+= right
.X_add_number
;
1032 clean_up_expression (resultP
);
1036 if (resultP
->X_seg
== SEG_UNKNOWN
|| right
.X_seg
== SEG_UNKNOWN
)
1038 resultP
->X_seg
= SEG_PASS1
;
1043 resultP
->X_subtract_symbol
= NULL
;
1044 resultP
->X_add_symbol
= NULL
;
1045 /* Will be SEG_ABSOLUTE. */
1046 if (resultP
->X_seg
!= SEG_ABSOLUTE
|| right
.X_seg
!= SEG_ABSOLUTE
)
1048 as_bad ("Relocation error. Absolute 0 assumed.");
1049 resultP
->X_seg
= SEG_ABSOLUTE
;
1050 resultP
->X_add_number
= 0;
1056 case O_bit_inclusive_or
:
1057 resultP
->X_add_number
|= right
.X_add_number
;
1061 if (right
.X_add_number
)
1063 resultP
->X_add_number
%= right
.X_add_number
;
1067 as_warn ("Division by 0. 0 assumed.");
1068 resultP
->X_add_number
= 0;
1073 resultP
->X_add_number
&= right
.X_add_number
;
1077 resultP
->X_add_number
*= right
.X_add_number
;
1081 if (right
.X_add_number
)
1083 resultP
->X_add_number
/= right
.X_add_number
;
1087 as_warn ("Division by 0. 0 assumed.");
1088 resultP
->X_add_number
= 0;
1093 resultP
->X_add_number
<<= right
.X_add_number
;
1097 resultP
->X_add_number
>>= right
.X_add_number
;
1100 case O_bit_exclusive_or
:
1101 resultP
->X_add_number
^= right
.X_add_number
;
1105 resultP
->X_add_number
|= ~right
.X_add_number
;
1111 } /* switch(operator) */
1113 } /* If we have to force need_pass_2. */
1114 } /* If operator was +. */
1115 } /* If we didn't set need_pass_2. */
1117 } /* While next operator is >= this rank. */
1118 return (resultP
->X_seg
);
1124 * This lives here because it belongs equally in expr.c & read.c.
1125 * Expr.c is just a branch office read.c anyway, and putting it
1126 * here lessens the crowd at read.c.
1128 * Assume input_line_pointer is at start of symbol name.
1129 * Advance input_line_pointer past symbol name.
1130 * Turn that character into a '\0', returning its former value.
1131 * This allows a string compare (RMS wants symbol names to be strings)
1132 * of the symbol name.
1133 * There will always be a char following symbol name, because all good
1134 * lines end in end-of-line.
1141 while (is_part_of_name (c
= *input_line_pointer
++))
1143 *--input_line_pointer
= 0;
1149 get_single_number ()
1153 return exp
.X_add_number
;