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
[];
42 #ifdef LOCAL_LABELS_DOLLAR
43 extern int local_label_defined
[];
47 * Build any floating-point literal here.
48 * Also build any bignum literal here.
51 /* LITTLENUM_TYPE generic_buffer [6]; */ /* JF this is a hack */
52 /* Seems atof_machine can backscan through generic_bignum and hit whatever
53 happens to be loaded before it in memory. And its way too complicated
54 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
55 and never write into the early words, thus they'll always be zero.
56 I hate Dean's floating-point code. Bleh.
58 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+6];
59 FLONUM_TYPE generic_floating_point_number
=
61 & generic_bignum
[6], /* low (JF: Was 0) */
62 & generic_bignum
[SIZE_OF_LARGE_NUMBER
+6 - 1], /* high JF: (added +6) */
67 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
68 int generic_floating_point_magic
;
70 floating_constant(expressionP
)
71 expressionS
*expressionP
;
73 /* input_line_pointer->*/
74 /* floating-point constant. */
77 error_code
= atof_generic
78 (& input_line_pointer
, ".", EXP_CHARS
,
79 & generic_floating_point_number
);
83 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
85 as_bad("bad floating-point constant: exponent overflow, probably assembling junk");
89 as_bad("bad floating-point constant: unknown error code=%d.", error_code
);
92 expressionP
->X_seg
= SEG_BIG
;
93 /* input_line_pointer->just after constant, */
94 /* which may point to whitespace. */
95 expressionP
->X_add_number
=-1;
101 integer_constant(radix
, expressionP
)
103 expressionS
*expressionP
;
107 register char * digit_2
; /*->2nd digit of number. */
110 register valueT number
; /* offset or (absolute) value */
111 register short int digit
; /* value of next digit in current radix */
112 register short int maxdig
= 0; /* highest permitted digit value. */
113 register int too_many_digits
= 0; /* if we see >= this number of */
114 register char *name
; /* points to name of symbol */
115 register symbolS
* symbolP
; /* points to symbol */
117 int small
; /* true if fits in 32 bits. */
118 extern char hex_value
[]; /* in hex_value.c */
120 /* may be bignum, or may fit in 32 bits. */
122 * most numbers fit into 32 bits, and we want this case to be fast.
123 * so we pretend it will fit into 32 bits. if, after making up a 32
124 * bit number, we realise that we have scanned more digits than
125 * comfortably fit into 32 bits, we re-scan the digits coding
126 * them into a bignum. for decimal and octal numbers we are conservative: some
127 * numbers may be assumed bignums when in fact they do fit into 32 bits.
128 * numbers of any radix can have excess leading zeros: we strive
129 * to recognise this and cast them back into 32 bits.
130 * we must check that the bignum really is more than 32
131 * bits, and change it back to a 32-bit number if it fits.
132 * the number we are looking for is expected to be positive, but
133 * if it fits into 32 bits as an unsigned number, we let it be a 32-bit
134 * number. the cavalier approach is for speed in ordinary cases.
142 too_many_digits
= 33;
146 too_many_digits
= 11;
156 too_many_digits
= 11;
158 c
= *input_line_pointer
;
159 input_line_pointer
++;
160 digit_2
= input_line_pointer
;
161 for (number
=0; (digit
=hex_value
[c
])<maxdig
; c
= * input_line_pointer
++)
163 number
= number
* radix
+ digit
;
165 /* c contains character after number. */
166 /* input_line_pointer->char after c. */
167 small
= input_line_pointer
- digit_2
< too_many_digits
;
171 * we saw a lot of digits. manufacture a bignum the hard way.
173 LITTLENUM_TYPE
* leader
; /*->high order littlenum of the bignum. */
174 LITTLENUM_TYPE
* pointer
; /*->littlenum we are frobbing now. */
177 leader
= generic_bignum
;
178 generic_bignum
[0] = 0;
179 generic_bignum
[1] = 0;
180 /* we could just use digit_2, but lets be mnemonic. */
181 input_line_pointer
= -- digit_2
; /*->1st digit. */
182 c
= *input_line_pointer
++;
183 for (; (carry
= hex_value
[c
]) < maxdig
; c
= * input_line_pointer
++)
185 for (pointer
= generic_bignum
;
191 work
= carry
+ radix
* * pointer
;
192 * pointer
= work
& LITTLENUM_MASK
;
193 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
197 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
198 { /* room to grow a longer bignum. */
203 /* again, c is char after number, */
204 /* input_line_pointer->after c. */
205 know(sizeof (int) * 8 == 32);
206 know(LITTLENUM_NUMBER_OF_BITS
== 16);
207 /* hence the constant "2" in the next line. */
208 if (leader
< generic_bignum
+ 2)
209 { /* will fit into 32 bits. */
211 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
212 | (generic_bignum
[0] & LITTLENUM_MASK
);
217 number
= leader
- generic_bignum
+ 1; /* number of littlenums in the bignum. */
223 * here with number, in correct radix. c is the next char.
224 * note that unlike un*x, we allow "011f" "0x9f" to
225 * both mean the same as the (conventional) "9f". this is simply easier
226 * than checking for strict canonical form. syntax sux!
231 #ifdef LOCAL_LABELS_FB
234 #ifdef LOCAL_LABELS_DOLLAR
235 || (c
=='$' && local_label_defined
[number
])
240 * backward ref to local label.
241 * because it is backward, expect it to be defined.
244 * construct a local label.
246 name
= local_label_name ((int)number
, 0);
247 if (((symbolP
= symbol_find(name
)) != NULL
) /* seen before */
248 && (S_IS_DEFINED(symbolP
))) /* symbol is defined: ok */
249 { /* expected path: symbol defined. */
250 /* local labels are never absolute. don't waste time checking absoluteness. */
251 know(SEG_NORMAL(S_GET_SEGMENT(symbolP
)));
253 expressionP
->X_add_symbol
= symbolP
;
254 expressionP
->X_add_number
= 0;
255 expressionP
->X_seg
= S_GET_SEGMENT(symbolP
);
258 { /* either not seen or not defined. */
259 as_bad("backw. ref to unknown label \"%d:\", 0 assumed.",
261 expressionP
->X_add_number
= 0;
262 expressionP
->X_seg
= SEG_ABSOLUTE
;
268 #ifdef LOCAL_LABELS_FB
271 #ifdef LOCAL_LABELS_DOLLAR
272 || (c
=='$' && !local_label_defined
[number
])
277 * forward reference. expect symbol to be undefined or
278 * unknown. undefined: seen it before. unknown: never seen
280 * construct a local label name, then an undefined symbol.
281 * don't create a xseg frag for it: caller may do that.
282 * just return it as never seen before.
284 name
= local_label_name((int)number
, 1);
285 symbolP
= symbol_find_or_make(name
);
286 /* we have no need to check symbol properties. */
287 #ifndef many_segments
288 /* since "know" puts its arg into a "string", we
289 can't have newlines in the argument. */
290 know(S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
|| S_GET_SEGMENT(symbolP
) == SEG_TEXT
|| S_GET_SEGMENT(symbolP
) == SEG_DATA
);
292 expressionP
->X_add_symbol
= symbolP
;
293 expressionP
->X_seg
= SEG_UNKNOWN
;
294 expressionP
->X_subtract_symbol
= NULL
;
295 expressionP
->X_add_number
= 0;
298 { /* really a number, not a local label. */
299 expressionP
->X_add_number
= number
;
300 expressionP
->X_seg
= SEG_ABSOLUTE
;
301 input_line_pointer
--; /* restore following character. */
306 { /* really a number. */
307 expressionP
->X_add_number
= number
;
308 expressionP
->X_seg
= SEG_ABSOLUTE
;
309 input_line_pointer
--; /* restore following character. */
310 } /* if (number<10) */
314 expressionP
->X_add_number
= number
;
315 expressionP
->X_seg
= SEG_BIG
;
316 input_line_pointer
--; /*->char following number. */
322 * Summary of operand().
324 * in: Input_line_pointer points to 1st char of operand, which may
327 * out: A expressionS. X_seg determines how to understand the rest of the
329 * The operand may have been empty: in this case X_seg == SEG_ABSENT.
330 * Input_line_pointer->(next non-blank) char after operand.
337 operand (expressionP
)
338 register expressionS
* expressionP
;
341 register symbolS
* symbolP
; /* points to symbol */
342 register char *name
; /* points to name of symbol */
343 /* invented for humans only, hope */
344 /* optimising compiler flushes it! */
345 register short int radix
; /* 2, 8, 10 or 16, 0 when floating */
346 /* 0 means we saw start of a floating- */
347 /* point constant. */
349 /* digits, assume it is a bignum. */
354 SKIP_WHITESPACE(); /* leading whitespace is part of operand. */
355 c
= * input_line_pointer
++; /* input_line_pointer->past char in c. */
361 integer_constant(2, expressionP
);
364 integer_constant(8, expressionP
);
367 integer_constant(16, expressionP
);
379 input_line_pointer
--;
381 integer_constant(10, expressionP
);
385 /* non-decimal radix */
388 c
= *input_line_pointer
;
393 /* The string was only zero */
394 expressionP
->X_add_symbol
= 0;
395 expressionP
->X_add_number
= 0;
396 expressionP
->X_seg
= SEG_ABSOLUTE
;
401 input_line_pointer
++;
402 integer_constant(16, expressionP
);
406 input_line_pointer
++;
407 integer_constant(2, expressionP
);
418 integer_constant(8, expressionP
);
422 /* if it says '0f' and the line ends or it doesn't look like
423 a floating point #, its a local label ref. dtrt */
424 /* likewise for the b's. xoxorich. */
425 if ((c
== 'f' || c
== 'b' || c
== 'b')
426 && (!*input_line_pointer
||
427 (!strchr("+-.0123456789",*input_line_pointer
) &&
428 !strchr(EXP_CHARS
,*input_line_pointer
))))
430 input_line_pointer
-= 2;
431 integer_constant(10, expressionP
);
444 input_line_pointer
++;
445 floating_constant(expressionP
);
451 /* didn't begin with digit & not a name */
453 (void)expression(expressionP
);
454 /* Expression() will pass trailing whitespace */
455 if (* input_line_pointer
++ != ')')
457 as_bad("Missing ')' assumed");
458 input_line_pointer
--;
460 /* here with input_line_pointer->char after "(...)" */
467 * Warning: to conform to other people's assemblers NO ESCAPEMENT is permitted
468 * for a single quote. The next character, parity errors and all, is taken
469 * as the value of the operand. VERY KINKY.
471 expressionP
->X_add_number
= * input_line_pointer
++;
472 expressionP
->X_seg
= SEG_ABSOLUTE
;
480 /* unary operator: hope for SEG_ABSOLUTE */
481 switch(operand (expressionP
)) {
483 /* input_line_pointer -> char after operand */
486 expressionP
-> X_add_number
= - expressionP
-> X_add_number
;
488 * Notice: '-' may overflow: no warning is given. This is compatible
489 * with other people's assemblers. Sigh.
494 expressionP
-> X_add_number
= ~ expressionP
-> X_add_number
;
503 if(c
=='-') { /* JF I hope this hack works */
504 expressionP
->X_subtract_symbol
=expressionP
->X_add_symbol
;
505 expressionP
->X_add_symbol
=0;
506 expressionP
->X_seg
=SEG_DIFFERENCE
;
509 default: /* unary on non-absolute is unsuported */
510 as_warn("Unary operator %c ignored because bad operand follows", c
);
512 /* Expression undisturbed from operand(). */
521 if( !is_part_of_name(*input_line_pointer
))
523 extern struct obstack frags
;
526 JF: '.' is pseudo symbol with value of current location in current
529 symbolP
= symbol_new("L0\001",
531 (valueT
)(obstack_next_free(&frags
)-frag_now
->fr_literal
),
534 expressionP
->X_add_number
=0;
535 expressionP
->X_add_symbol
=symbolP
;
536 expressionP
->X_seg
= now_seg
;
548 /* can't imagine any other kind of operand */
549 expressionP
->X_seg
= SEG_ABSENT
;
550 input_line_pointer
--;
551 md_operand (expressionP
);
555 if (is_name_beginner(c
)) /* here if did not begin with a digit */
558 * Identifier begins here.
559 * This is kludged for speed, so code is repeated.
562 name
= -- input_line_pointer
;
563 c
= get_symbol_end();
564 symbolP
= symbol_find_or_make(name
);
566 * If we have an absolute symbol or a reg, then we know its value now.
568 expressionP
->X_seg
= S_GET_SEGMENT(symbolP
);
569 switch (expressionP
->X_seg
)
573 expressionP
->X_add_number
= S_GET_VALUE(symbolP
);
577 expressionP
->X_add_number
= 0;
578 expressionP
->X_add_symbol
= symbolP
;
580 * input_line_pointer
= c
;
581 expressionP
->X_subtract_symbol
= NULL
;
585 as_bad("Bad expression");
586 expressionP
->X_add_number
= 0;
587 expressionP
->X_seg
= SEG_ABSOLUTE
;
600 * It is more 'efficient' to clean up the expressionS when they are created.
601 * Doing it here saves lines of code.
603 clean_up_expression (expressionP
);
604 SKIP_WHITESPACE(); /*->1st char after operand. */
605 know(* input_line_pointer
!= ' ');
606 return (expressionP
->X_seg
);
610 /* Internal. Simplify a struct expression for use by expr() */
613 * In: address of a expressionS.
614 * The X_seg field of the expressionS may only take certain values.
615 * Now, we permit SEG_PASS1 to make code smaller & faster.
616 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
617 * Out: expressionS may have been modified:
618 * 'foo-foo' symbol references cancelled to 0,
619 * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE;
620 * Unused fields zeroed to help expr().
624 clean_up_expression (expressionP
)
625 register expressionS
* expressionP
;
627 switch (expressionP
->X_seg
)
631 expressionP
->X_add_symbol
= NULL
;
632 expressionP
->X_subtract_symbol
= NULL
;
633 expressionP
->X_add_number
= 0;
638 expressionP
->X_subtract_symbol
= NULL
;
639 expressionP
->X_add_symbol
= NULL
;
643 expressionP
->X_subtract_symbol
= NULL
;
648 * It does not hurt to 'cancel' NULL==NULL
649 * when comparing symbols for 'eq'ness.
650 * It is faster to re-cancel them to NULL
651 * than to check for this special case.
653 if (expressionP
->X_subtract_symbol
== expressionP
->X_add_symbol
654 || (expressionP
->X_subtract_symbol
655 && expressionP
->X_add_symbol
656 && expressionP
->X_subtract_symbol
->sy_frag
==expressionP
->X_add_symbol
->sy_frag
657 && S_GET_VALUE(expressionP
->X_subtract_symbol
) == S_GET_VALUE(expressionP
->X_add_symbol
))) {
658 expressionP
->X_subtract_symbol
= NULL
;
659 expressionP
->X_add_symbol
= NULL
;
660 expressionP
->X_seg
= SEG_ABSOLUTE
;
665 expressionP
->X_add_symbol
= NULL
;
666 expressionP
->X_subtract_symbol
= NULL
;
670 if (SEG_NORMAL(expressionP
->X_seg
)) {
671 expressionP
->X_subtract_symbol
= NULL
;
674 BAD_CASE (expressionP
->X_seg
);
678 } /* clean_up_expression() */
683 * Internal. Made a function because this code is used in 2 places.
684 * Generate error or correct X_?????_symbol of expressionS.
688 * symbol_1 += symbol_2 ... well ... sort of.
692 expr_part (symbol_1_PP
, symbol_2_P
)
693 symbolS
** symbol_1_PP
;
694 symbolS
* symbol_2_P
;
697 #ifndef MANY_SEGMENTS
698 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
)));
699 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
)));
703 if (!S_IS_DEFINED(* symbol_1_PP
))
707 return_value
= SEG_PASS1
;
708 * symbol_1_PP
= NULL
;
712 know(!S_IS_DEFINED(* symbol_1_PP
));
713 return_value
= SEG_UNKNOWN
;
720 if (!S_IS_DEFINED(symbol_2_P
))
722 * symbol_1_PP
= NULL
;
723 return_value
= SEG_PASS1
;
727 /* {seg1} - {seg2} */
728 as_bad("Expression too complex, 2 symbolS forgotten: \"%s\" \"%s\"",
729 S_GET_NAME(* symbol_1_PP
), S_GET_NAME(symbol_2_P
));
730 * symbol_1_PP
= NULL
;
731 return_value
= SEG_ABSOLUTE
;
736 return_value
= S_GET_SEGMENT(* symbol_1_PP
);
741 { /* (* symbol_1_PP) == NULL */
744 * symbol_1_PP
= symbol_2_P
;
745 return_value
= S_GET_SEGMENT(symbol_2_P
);
749 * symbol_1_PP
= NULL
;
750 return_value
= SEG_ABSOLUTE
;
753 #ifndef MANY_SEGMENTS
754 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
);
756 know((*symbol_1_PP
) == NULL
|| (S_GET_SEGMENT(*symbol_1_PP
) == return_value
));
757 return (return_value
);
760 /* Expression parser. */
763 * We allow an empty expression, and just assume (absolute,0) silently.
764 * Unary operators and parenthetical expressions are treated as operands.
765 * As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
767 * We used to do a aho/ullman shift-reduce parser, but the logic got so
768 * warped that I flushed it and wrote a recursive-descent parser instead.
769 * Now things are stable, would anybody like to write a fast parser?
770 * Most expressions are either register (which does not even reach here)
771 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
772 * So I guess it doesn't really matter how inefficient more complex expressions
775 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
776 * Also, we have consumed any leading or trailing spaces (operand does that)
777 * and done all intervening operators.
782 O_illegal
, /* (0) what we get for illegal op */
784 O_multiply
, /* (1) * */
785 O_divide
, /* (2) / */
786 O_modulus
, /* (3) % */
787 O_left_shift
, /* (4) < */
788 O_right_shift
, /* (5) > */
789 O_bit_inclusive_or
, /* (6) | */
790 O_bit_or_not
, /* (7) ! */
791 O_bit_exclusive_or
, /* (8) ^ */
792 O_bit_and
, /* (9) & */
794 O_subtract
/* (11) - */
800 static const operatorT op_encoding
[256] = { /* maps ASCII->operators */
802 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
803 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
805 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
806 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
807 __
, __
, __
, __
, __
, __
, __
, __
,
808 __
, __
, __
, __
, O_left_shift
, __
, O_right_shift
, __
,
809 __
, __
, __
, __
, __
, __
, __
, __
,
810 __
, __
, __
, __
, __
, __
, __
, __
,
811 __
, __
, __
, __
, __
, __
, __
, __
,
812 __
, __
, __
, __
, __
, __
, O_bit_exclusive_or
, __
,
813 __
, __
, __
, __
, __
, __
, __
, __
,
814 __
, __
, __
, __
, __
, __
, __
, __
,
815 __
, __
, __
, __
, __
, __
, __
, __
,
816 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
818 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
819 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
820 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
821 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
822 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
823 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
824 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
825 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
831 * 0 operand, (expression)
836 static const operator_rankT
837 op_rank
[] = { 0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1 };
839 /* Return resultP->X_seg. */
840 segT
expr(rank
, resultP
)
841 register operator_rankT rank
; /* Larger # is higher rank. */
842 register expressionS
*resultP
; /* Deliver result here. */
845 register operatorT op_left
;
846 register char c_left
; /* 1st operator character. */
847 register operatorT op_right
;
848 register char c_right
;
851 (void)operand (resultP
);
852 know(* input_line_pointer
!= ' '); /* Operand() gobbles spaces. */
853 c_left
= * input_line_pointer
; /* Potential operator character. */
854 op_left
= op_encoding
[c_left
];
855 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
857 input_line_pointer
++; /*->after 1st character of operator. */
858 /* Operators "<<" and ">>" have 2 characters. */
859 if (* input_line_pointer
== c_left
&& (c_left
== '<' || c_left
== '>'))
861 input_line_pointer
++;
862 } /*->after operator. */
863 if (SEG_ABSENT
== expr (op_rank
[(int) op_left
], &right
))
865 as_warn("Missing operand value assumed absolute 0.");
866 resultP
->X_add_number
= 0;
867 resultP
->X_subtract_symbol
= NULL
;
868 resultP
->X_add_symbol
= NULL
;
869 resultP
->X_seg
= SEG_ABSOLUTE
;
871 know(* input_line_pointer
!= ' ');
872 c_right
= * input_line_pointer
;
873 op_right
= op_encoding
[c_right
];
874 if (* input_line_pointer
== c_right
&& (c_right
== '<' || c_right
== '>'))
876 input_line_pointer
++;
877 } /*->after operator. */
878 know((int) op_right
== 0 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
879 /* input_line_pointer->after right-hand quantity. */
880 /* left-hand quantity in resultP */
881 /* right-hand quantity in right. */
882 /* operator in op_left. */
883 if (resultP
->X_seg
== SEG_PASS1
|| right
. X_seg
== SEG_PASS1
)
885 resultP
->X_seg
= SEG_PASS1
;
889 if (resultP
->X_seg
== SEG_BIG
)
891 as_warn("Left operand of %c is a %s. Integer 0 assumed.",
892 c_left
, resultP
->X_add_number
> 0 ? "bignum" : "float");
893 resultP
->X_seg
= SEG_ABSOLUTE
;
894 resultP
->X_add_symbol
= 0;
895 resultP
->X_subtract_symbol
= 0;
896 resultP
->X_add_number
= 0;
898 if (right
. X_seg
== SEG_BIG
)
900 as_warn("Right operand of %c is a %s. Integer 0 assumed.",
901 c_left
, right
. X_add_number
> 0 ? "bignum" : "float");
902 right
. X_seg
= SEG_ABSOLUTE
;
903 right
. X_add_symbol
= 0;
904 right
. X_subtract_symbol
= 0;
905 right
. X_add_number
= 0;
907 if (op_left
== O_subtract
)
910 * Convert - into + by exchanging symbolS and negating number.
911 * I know -infinity can't be negated in 2's complement:
912 * but then it can't be subtracted either. This trick
913 * does not cause any further inaccuracy.
916 register symbolS
* symbolP
;
918 right
. X_add_number
= - right
. X_add_number
;
919 symbolP
= right
. X_add_symbol
;
920 right
. X_add_symbol
= right
. X_subtract_symbol
;
921 right
. X_subtract_symbol
= symbolP
;
924 right
. X_seg
= SEG_DIFFERENCE
;
929 if (op_left
== O_add
)
933 #ifndef MANY_SEGMENTS
934 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
);
935 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
);
937 clean_up_expression (& right
);
938 clean_up_expression (resultP
);
940 seg1
= expr_part (& resultP
->X_add_symbol
, right
. X_add_symbol
);
941 seg2
= expr_part (& resultP
->X_subtract_symbol
, right
. X_subtract_symbol
);
942 if (seg1
== SEG_PASS1
|| seg2
== SEG_PASS1
) {
944 resultP
->X_seg
= SEG_PASS1
;
945 } else if (seg2
== SEG_ABSOLUTE
)
946 resultP
->X_seg
= seg1
;
947 else if (seg1
!= SEG_UNKNOWN
948 && seg1
!= SEG_ABSOLUTE
949 && seg2
!= SEG_UNKNOWN
951 know(seg2
!= SEG_ABSOLUTE
);
952 know(resultP
->X_subtract_symbol
);
953 #ifndef MANY_SEGMENTS
954 know(seg1
== SEG_TEXT
|| seg1
== SEG_DATA
|| seg1
== SEG_BSS
);
955 know(seg2
== SEG_TEXT
|| seg2
== SEG_DATA
|| seg2
== SEG_BSS
);
957 know(resultP
->X_add_symbol
);
958 know(resultP
->X_subtract_symbol
);
959 as_bad("Expression too complex: forgetting %s - %s",
960 S_GET_NAME(resultP
->X_add_symbol
),
961 S_GET_NAME(resultP
->X_subtract_symbol
));
962 resultP
->X_seg
= SEG_ABSOLUTE
;
963 /* Clean_up_expression() will do the rest. */
965 resultP
->X_seg
= SEG_DIFFERENCE
;
967 resultP
->X_add_number
+= right
. X_add_number
;
968 clean_up_expression (resultP
);
972 if (resultP
->X_seg
== SEG_UNKNOWN
|| right
. X_seg
== SEG_UNKNOWN
)
974 resultP
->X_seg
= SEG_PASS1
;
979 resultP
->X_subtract_symbol
= NULL
;
980 resultP
->X_add_symbol
= NULL
;
981 /* Will be SEG_ABSOLUTE. */
982 if (resultP
->X_seg
!= SEG_ABSOLUTE
|| right
. X_seg
!= SEG_ABSOLUTE
)
984 as_bad("Relocation error. Absolute 0 assumed.");
985 resultP
->X_seg
= SEG_ABSOLUTE
;
986 resultP
->X_add_number
= 0;
992 case O_bit_inclusive_or
:
993 resultP
->X_add_number
|= right
. X_add_number
;
997 if (right
. X_add_number
)
999 resultP
->X_add_number
%= right
. X_add_number
;
1003 as_warn("Division by 0. 0 assumed.");
1004 resultP
->X_add_number
= 0;
1009 resultP
->X_add_number
&= right
. X_add_number
;
1013 resultP
->X_add_number
*= right
. X_add_number
;
1017 if (right
. X_add_number
)
1019 resultP
->X_add_number
/= right
. X_add_number
;
1023 as_warn("Division by 0. 0 assumed.");
1024 resultP
->X_add_number
= 0;
1029 resultP
->X_add_number
<<= right
. X_add_number
;
1033 resultP
->X_add_number
>>= right
. X_add_number
;
1036 case O_bit_exclusive_or
:
1037 resultP
->X_add_number
^= right
. X_add_number
;
1041 resultP
->X_add_number
|= ~ right
. X_add_number
;
1047 } /* switch(operator) */
1049 } /* If we have to force need_pass_2. */
1050 } /* If operator was +. */
1051 } /* If we didn't set need_pass_2. */
1053 } /* While next operator is >= this rank. */
1054 return (resultP
->X_seg
);
1060 * This lives here because it belongs equally in expr.c & read.c.
1061 * Expr.c is just a branch office read.c anyway, and putting it
1062 * here lessens the crowd at read.c.
1064 * Assume input_line_pointer is at start of symbol name.
1065 * Advance input_line_pointer past symbol name.
1066 * Turn that character into a '\0', returning its former value.
1067 * This allows a string compare (RMS wants symbol names to be strings)
1068 * of the symbol name.
1069 * There will always be a char following symbol name, because all good
1070 * lines end in end-of-line.
1077 while (is_part_of_name(c
= * input_line_pointer
++))
1079 * -- input_line_pointer
= 0;
1084 unsigned int get_single_number()
1088 return exp
.X_add_number
;