1 /* expr.c -operands, expressions-
2 Copyright (C) 1987, 1990, 1991 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 1, 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. */
20 /* static const char rcsid[] = "$Id$"; */
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.
37 static void clean_up_expression(expressionS
*expressionP
);
39 static void clean_up_expression(); /* Internal. */
41 extern const char EXP_CHARS
[]; /* JF hide MD floating pt stuff all the same place */
42 extern const char FLT_CHARS
[];
44 #ifdef LOCAL_LABELS_DOLLAR
45 extern int local_label_defined
[];
49 * Build any floating-point literal here.
50 * Also build any bignum literal here.
53 /* LITTLENUM_TYPE generic_buffer [6]; */ /* JF this is a hack */
54 /* Seems atof_machine can backscan through generic_bignum and hit whatever
55 happens to be loaded before it in memory. And its way too complicated
56 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
57 and never write into the early words, thus they'll always be zero.
58 I hate Dean's floating-point code. Bleh.
60 LITTLENUM_TYPE generic_bignum
[SIZE_OF_LARGE_NUMBER
+6];
61 FLONUM_TYPE generic_floating_point_number
=
63 & generic_bignum
[6], /* low (JF: Was 0) */
64 & generic_bignum
[SIZE_OF_LARGE_NUMBER
+6 - 1], /* high JF: (added +6) */
69 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
70 int generic_floating_point_magic
;
73 * Summary of operand().
75 * in: Input_line_pointer points to 1st char of operand, which may
78 * out: A expressionS. X_seg determines how to understand the rest of the
80 * The operand may have been empty: in this case X_seg == SEG_ABSENT.
81 * Input_line_pointer->(next non-blank) char after operand.
87 register expressionS
* expressionP
;
90 register char *name
; /* points to name of symbol */
91 register symbolS
* symbolP
; /* Points to symbol */
93 extern char hex_value
[]; /* In hex_value.c */
95 SKIP_WHITESPACE(); /* Leading whitespace is part of operand. */
96 c
= * input_line_pointer
++; /* Input_line_pointer->past char in c. */
99 register valueT number
; /* offset or (absolute) value */
100 register short int digit
; /* value of next digit in current radix */
101 /* invented for humans only, hope */
102 /* optimising compiler flushes it! */
103 register short int radix
; /* 2, 8, 10 or 16 */
104 /* 0 means we saw start of a floating- */
105 /* point constant. */
106 register short int maxdig
= 0;/* Highest permitted digit value. */
107 register int too_many_digits
= 0; /* If we see >= this number of */
108 /* digits, assume it is a bignum. */
109 register char * digit_2
; /*->2nd digit of number. */
110 int small
; /* TRUE if fits in 32 bits. */
112 if (c
== '0') { /* non-decimal radix */
113 if ((c
= *input_line_pointer
++)=='x' || c
=='X') {
114 c
= *input_line_pointer
++; /* read past "0x" or "0X" */
118 /* If it says '0f' and the line ends or it DOESN'T look like
119 a floating point #, its a local label ref. DTRT */
120 /* likewise for the b's. xoxorich. */
121 if ((c
== 'f' || c
== 'b' || c
== 'B')
122 && (!*input_line_pointer
||
123 (!strchr("+-.0123456789",*input_line_pointer
) &&
124 !strchr(EXP_CHARS
,*input_line_pointer
)))) {
126 too_many_digits
= 11;
128 input_line_pointer
-= 2;
130 } else if (c
== 'b' || c
== 'B') {
131 c
= *input_line_pointer
++;
133 too_many_digits
= 33;
135 } else if (c
&& strchr(FLT_CHARS
,c
)) {
136 radix
= 0; /* Start of floating-point constant. */
137 /* input_line_pointer->1st char of number. */
138 expressionP
->X_add_number
= -(isupper(c
) ? tolower(c
) : c
);
140 } else { /* By elimination, assume octal radix. */
142 too_many_digits
= 11;
144 } /* c == char after "0" or "0x" or "0X" or "0e" etc. */
147 too_many_digits
= 11;
148 } /* if operand starts with a zero */
150 if (radix
) { /* Fixed-point integer constant. */
151 /* May be bignum, or may fit in 32 bits. */
153 * Most numbers fit into 32 bits, and we want this case to be fast.
154 * So we pretend it will fit into 32 bits. If, after making up a 32
155 * bit number, we realise that we have scanned more digits than
156 * comfortably fit into 32 bits, we re-scan the digits coding
157 * them into a bignum. For decimal and octal numbers we are conservative: some
158 * numbers may be assumed bignums when in fact they do fit into 32 bits.
159 * Numbers of any radix can have excess leading zeros: we strive
160 * to recognise this and cast them back into 32 bits.
161 * We must check that the bignum really is more than 32
162 * bits, and change it back to a 32-bit number if it fits.
163 * The number we are looking for is expected to be positive, but
164 * if it fits into 32 bits as an unsigned number, we let it be a 32-bit
165 * number. The cavalier approach is for speed in ordinary cases.
167 digit_2
= input_line_pointer
;
168 for (number
=0; (digit
=hex_value
[c
])<maxdig
; c
= * input_line_pointer
++)
170 number
= number
* radix
+ digit
;
172 /* C contains character after number. */
173 /* Input_line_pointer->char after C. */
174 small
= input_line_pointer
- digit_2
< too_many_digits
;
178 * We saw a lot of digits. Manufacture a bignum the hard way.
180 LITTLENUM_TYPE
* leader
; /*->high order littlenum of the bignum. */
181 LITTLENUM_TYPE
* pointer
; /*->littlenum we are frobbing now. */
184 leader
= generic_bignum
;
185 generic_bignum
[0] = 0;
186 generic_bignum
[1] = 0;
187 /* We could just use digit_2, but lets be mnemonic. */
188 input_line_pointer
= -- digit_2
; /*->1st digit. */
189 c
= *input_line_pointer
++;
190 for (; (carry
= hex_value
[c
]) < maxdig
; c
= * input_line_pointer
++)
192 for (pointer
= generic_bignum
;
198 work
= carry
+ radix
* * pointer
;
199 * pointer
= work
& LITTLENUM_MASK
;
200 carry
= work
>> LITTLENUM_NUMBER_OF_BITS
;
204 if (leader
< generic_bignum
+ SIZE_OF_LARGE_NUMBER
- 1)
205 { /* Room to grow a longer bignum. */
210 /* Again, C is char after number, */
211 /* input_line_pointer->after C. */
212 know(sizeof (int) * 8 == 32);
213 know(LITTLENUM_NUMBER_OF_BITS
== 16);
214 /* Hence the constant "2" in the next line. */
215 if (leader
< generic_bignum
+ 2)
216 { /* Will fit into 32 bits. */
218 ((generic_bignum
[1] & LITTLENUM_MASK
) << LITTLENUM_NUMBER_OF_BITS
)
219 | (generic_bignum
[0] & LITTLENUM_MASK
);
224 number
= leader
- generic_bignum
+ 1; /* Number of littlenums in the bignum. */
230 * Here with number, in correct radix. c is the next char.
231 * Note that unlike Un*x, we allow "011f" "0x9f" to
232 * both mean the same as the (conventional) "9f". This is simply easier
233 * than checking for strict canonical form. Syntax sux!
238 #ifdef LOCAL_LABELS_FB
241 #ifdef LOCAL_LABELS_DOLLAR
242 || (c
=='$' && local_label_defined
[number
])
247 * Backward ref to local label.
248 * Because it is backward, expect it to be DEFINED.
251 * Construct a local label.
253 name
= local_label_name ((int)number
, 0);
254 if (((symbolP
= symbol_find(name
)) != NULL
) /* seen before */
255 && (S_IS_DEFINED(symbolP
))) /* symbol is defined: OK */
256 { /* Expected path: symbol defined. */
257 /* Local labels are never absolute. Don't waste time checking absoluteness. */
258 know((S_GET_SEGMENT(symbolP
) == SEG_DATA
) || (S_GET_SEGMENT(symbolP
) == SEG_TEXT
));
259 expressionP
->X_add_symbol
= symbolP
;
260 expressionP
->X_add_number
= 0;
261 expressionP
->X_seg
= S_GET_SEGMENT(symbolP
);
264 { /* Either not seen or not defined. */
265 as_bad("Backw. ref to unknown label \"%d:\", 0 assumed.",
267 expressionP
->X_add_number
= 0;
268 expressionP
->X_seg
= SEG_ABSOLUTE
;
274 #ifdef LOCAL_LABELS_FB
277 #ifdef LOCAL_LABELS_DOLLAR
278 || (c
=='$' && !local_label_defined
[number
])
283 * Forward reference. Expect symbol to be undefined or
284 * unknown. Undefined: seen it before. Unknown: never seen
286 * Construct a local label name, then an undefined symbol.
287 * Don't create a XSEG frag for it: caller may do that.
288 * Just return it as never seen before.
290 name
= local_label_name((int)number
, 1);
291 symbolP
= symbol_find_or_make(name
);
292 /* We have no need to check symbol properties. */
293 know(S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
294 || S_GET_SEGMENT(symbolP
) == SEG_TEXT
295 || S_GET_SEGMENT(symbolP
) == SEG_DATA
);
296 expressionP
->X_add_symbol
= symbolP
;
297 expressionP
->X_seg
= SEG_UNKNOWN
;
298 expressionP
->X_subtract_symbol
= NULL
;
299 expressionP
->X_add_number
= 0;
302 { /* Really a number, not a local label. */
303 expressionP
->X_add_number
= number
;
304 expressionP
->X_seg
= SEG_ABSOLUTE
;
305 input_line_pointer
--; /* Restore following character. */
310 { /* Really a number. */
311 expressionP
->X_add_number
= number
;
312 expressionP
->X_seg
= SEG_ABSOLUTE
;
313 input_line_pointer
--; /* Restore following character. */
314 } /* if (number<10) */
318 expressionP
->X_add_number
= number
;
319 expressionP
->X_seg
= SEG_BIG
;
320 input_line_pointer
--; /*->char following number. */
322 } /* (If integer constant) */
324 { /* input_line_pointer->*/
325 /* floating-point constant. */
328 error_code
= atof_generic
329 (& input_line_pointer
, ".", EXP_CHARS
,
330 & generic_floating_point_number
);
334 if (error_code
== ERROR_EXPONENT_OVERFLOW
)
336 as_bad("Bad floating-point constant: exponent overflow, probably assembling junk");
340 as_bad("Bad floating-point constant: unknown error code=%d.", error_code
);
343 expressionP
->X_seg
= SEG_BIG
;
344 /* input_line_pointer->just after constant, */
345 /* which may point to whitespace. */
346 know(expressionP
->X_add_number
< 0); /* < 0 means "floating point". */
347 } /* if (not floating-point constant) */
349 else if(c
=='.' && !is_part_of_name(*input_line_pointer
)) {
350 extern struct obstack frags
;
353 JF: '.' is pseudo symbol with value of current location in current
356 symbolP
= symbol_new("L0\001",
358 (valueT
)(obstack_next_free(&frags
)-frag_now
->fr_literal
),
361 expressionP
->X_add_number
=0;
362 expressionP
->X_add_symbol
=symbolP
;
363 expressionP
->X_seg
= now_seg
;
365 } else if (is_name_beginner(c
)) /* here if did not begin with a digit */
368 * Identifier begins here.
369 * This is kludged for speed, so code is repeated.
371 name
= -- input_line_pointer
;
372 c
= get_symbol_end();
373 symbolP
= symbol_find_or_make(name
);
375 * If we have an absolute symbol or a reg, then we know its value now.
377 expressionP
->X_seg
= S_GET_SEGMENT(symbolP
);
378 switch (expressionP
->X_seg
)
382 expressionP
->X_add_number
= S_GET_VALUE(symbolP
);
386 expressionP
->X_add_number
= 0;
387 expressionP
->X_add_symbol
= symbolP
;
389 * input_line_pointer
= c
;
390 expressionP
->X_subtract_symbol
= NULL
;
392 else if (c
=='(')/* didn't begin with digit & not a name */
394 (void)expression(expressionP
);
395 /* Expression() will pass trailing whitespace */
396 if (* input_line_pointer
++ != ')')
398 as_bad("Missing ')' assumed");
399 input_line_pointer
--;
401 /* here with input_line_pointer->char after "(...)" */
403 else if (c
== '~' || c
== '-' || c
== '+') {
404 /* unary operator: hope for SEG_ABSOLUTE */
405 switch (operand (expressionP
)) {
407 /* input_line_pointer->char after operand */
409 expressionP
->X_add_number
= - expressionP
->X_add_number
;
411 * Notice: '-' may overflow: no warning is given. This is compatible
412 * with other people's assemblers. Sigh.
414 } else if (c
== '~') {
415 expressionP
->X_add_number
= ~ expressionP
->X_add_number
;
416 } else if (c
!= '+') {
418 } /* switch on unary operator */
426 if(c
=='-') { /* JF I hope this hack works */
427 expressionP
->X_subtract_symbol
=expressionP
->X_add_symbol
;
428 expressionP
->X_add_symbol
=0;
429 expressionP
->X_seg
=SEG_DIFFERENCE
;
432 default: /* unary on non-absolute is unsuported */
433 as_bad("Unary operator %c ignored because bad operand follows", c
);
435 /* Expression undisturbed from operand(). */
441 * Warning: to conform to other people's assemblers NO ESCAPEMENT is permitted
442 * for a single quote. The next character, parity errors and all, is taken
443 * as the value of the operand. VERY KINKY.
445 expressionP
->X_add_number
= * input_line_pointer
++;
446 expressionP
->X_seg
= SEG_ABSOLUTE
;
450 /* can't imagine any other kind of operand */
451 expressionP
->X_seg
= SEG_ABSENT
;
452 input_line_pointer
--;
453 md_operand (expressionP
);
456 * It is more 'efficient' to clean up the expressions when they are created.
457 * Doing it here saves lines of code.
459 clean_up_expression (expressionP
);
460 SKIP_WHITESPACE(); /*->1st char after operand. */
461 know(* input_line_pointer
!= ' ');
462 return (expressionP
->X_seg
);
465 /* Internal. Simplify a struct expression for use by expr() */
468 * In: address of a expressionS.
469 * The X_seg field of the expressionS may only take certain values.
470 * Now, we permit SEG_PASS1 to make code smaller & faster.
471 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
472 * Out: expressionS may have been modified:
473 * 'foo-foo' symbol references cancelled to 0,
474 * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE;
475 * Unused fields zeroed to help expr().
479 clean_up_expression (expressionP
)
480 register expressionS
* expressionP
;
482 switch (expressionP
->X_seg
)
486 expressionP
->X_add_symbol
= NULL
;
487 expressionP
->X_subtract_symbol
= NULL
;
488 expressionP
->X_add_number
= 0;
493 expressionP
->X_subtract_symbol
= NULL
;
494 expressionP
->X_add_symbol
= NULL
;
501 expressionP
->X_subtract_symbol
= NULL
;
506 * It does not hurt to 'cancel' NULL==NULL
507 * when comparing symbols for 'eq'ness.
508 * It is faster to re-cancel them to NULL
509 * than to check for this special case.
511 if (expressionP
->X_subtract_symbol
== expressionP
->X_add_symbol
512 || (expressionP
->X_subtract_symbol
513 && expressionP
->X_add_symbol
514 && expressionP
->X_subtract_symbol
->sy_frag
==expressionP
->X_add_symbol
->sy_frag
515 && S_GET_VALUE(expressionP
->X_subtract_symbol
) == S_GET_VALUE(expressionP
->X_add_symbol
))) {
516 expressionP
->X_subtract_symbol
= NULL
;
517 expressionP
->X_add_symbol
= NULL
;
518 expressionP
->X_seg
= SEG_ABSOLUTE
;
523 expressionP
->X_add_symbol
= NULL
;
524 expressionP
->X_subtract_symbol
= NULL
;
528 BAD_CASE (expressionP
->X_seg
);
531 } /* clean_up_expression() */
536 * Internal. Made a function because this code is used in 2 places.
537 * Generate error or correct X_?????_symbol of expressionS.
541 * symbol_1 += symbol_2 ... well ... sort of.
545 expr_part (symbol_1_PP
, symbol_2_P
)
546 symbolS
** symbol_1_PP
;
547 symbolS
* symbol_2_P
;
551 know((* symbol_1_PP
) == NULL
552 || (S_GET_SEGMENT(*symbol_1_PP
) == SEG_TEXT
)
553 || (S_GET_SEGMENT(*symbol_1_PP
) == SEG_DATA
)
554 || (S_GET_SEGMENT(*symbol_1_PP
) == SEG_BSS
)
555 || (!S_IS_DEFINED(* symbol_1_PP
)));
556 know(symbol_2_P
== NULL
557 || (S_GET_SEGMENT(symbol_2_P
) == SEG_TEXT
)
558 || (S_GET_SEGMENT(symbol_2_P
) == SEG_DATA
)
559 || (S_GET_SEGMENT(symbol_2_P
) == SEG_BSS
)
560 || (!S_IS_DEFINED(symbol_2_P
)));
563 if (!S_IS_DEFINED(* symbol_1_PP
))
567 return_value
= SEG_PASS1
;
568 * symbol_1_PP
= NULL
;
572 know(!S_IS_DEFINED(* symbol_1_PP
));
573 return_value
= SEG_UNKNOWN
;
580 if (!S_IS_DEFINED(symbol_2_P
))
582 * symbol_1_PP
= NULL
;
583 return_value
= SEG_PASS1
;
587 /* {seg1} - {seg2} */
588 as_bad("Expression too complex, 2 symbols forgotten: \"%s\" \"%s\"",
589 S_GET_NAME(* symbol_1_PP
), S_GET_NAME(symbol_2_P
));
590 * symbol_1_PP
= NULL
;
591 return_value
= SEG_ABSOLUTE
;
596 return_value
= S_GET_SEGMENT(* symbol_1_PP
);
601 { /* (* symbol_1_PP) == NULL */
604 * symbol_1_PP
= symbol_2_P
;
605 return_value
= S_GET_SEGMENT(symbol_2_P
);
609 * symbol_1_PP
= NULL
;
610 return_value
= SEG_ABSOLUTE
;
613 know(return_value
== SEG_ABSOLUTE
614 || return_value
== SEG_TEXT
615 || return_value
== SEG_DATA
616 || return_value
== SEG_BSS
617 || return_value
== SEG_UNKNOWN
618 || return_value
== SEG_PASS1
);
619 know((* symbol_1_PP
) == NULL
620 || (S_GET_SEGMENT(* symbol_1_PP
) == return_value
));
621 return (return_value
);
624 /* Expression parser. */
627 * We allow an empty expression, and just assume (absolute,0) silently.
628 * Unary operators and parenthetical expressions are treated as operands.
629 * As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
631 * We used to do a aho/ullman shift-reduce parser, but the logic got so
632 * warped that I flushed it and wrote a recursive-descent parser instead.
633 * Now things are stable, would anybody like to write a fast parser?
634 * Most expressions are either register (which does not even reach here)
635 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
636 * So I guess it doesn't really matter how inefficient more complex expressions
639 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
640 * Also, we have consumed any leading or trailing spaces (operand does that)
641 * and done all intervening operators.
646 O_illegal
, /* (0) what we get for illegal op */
648 O_multiply
, /* (1) * */
649 O_divide
, /* (2) / */
650 O_modulus
, /* (3) % */
651 O_left_shift
, /* (4) < */
652 O_right_shift
, /* (5) > */
653 O_bit_inclusive_or
, /* (6) | */
654 O_bit_or_not
, /* (7) ! */
655 O_bit_exclusive_or
, /* (8) ^ */
656 O_bit_and
, /* (9) & */
658 O_subtract
/* (11) - */
664 static const operatorT op_encoding
[256] = { /* maps ASCII->operators */
666 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
667 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
669 __
, O_bit_or_not
, __
, __
, __
, O_modulus
, O_bit_and
, __
,
670 __
, __
, O_multiply
, O_add
, __
, O_subtract
, __
, O_divide
,
671 __
, __
, __
, __
, __
, __
, __
, __
,
672 __
, __
, __
, __
, O_left_shift
, __
, O_right_shift
, __
,
673 __
, __
, __
, __
, __
, __
, __
, __
,
674 __
, __
, __
, __
, __
, __
, __
, __
,
675 __
, __
, __
, __
, __
, __
, __
, __
,
676 __
, __
, __
, __
, __
, __
, O_bit_exclusive_or
, __
,
677 __
, __
, __
, __
, __
, __
, __
, __
,
678 __
, __
, __
, __
, __
, __
, __
, __
,
679 __
, __
, __
, __
, __
, __
, __
, __
,
680 __
, __
, __
, __
, O_bit_inclusive_or
, __
, __
, __
,
682 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
683 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
684 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
685 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
686 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
687 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
688 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
,
689 __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
, __
695 * 0 operand, (expression)
700 static const operator_rankT
701 op_rank
[] = { 0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1 };
703 /* Return resultP->X_seg. */
704 segT
expr(rank
, resultP
)
705 register operator_rankT rank
; /* Larger # is higher rank. */
706 register expressionS
*resultP
; /* Deliver result here. */
709 register operatorT op_left
;
710 register char c_left
; /* 1st operator character. */
711 register operatorT op_right
;
712 register char c_right
;
715 (void)operand (resultP
);
716 know(* input_line_pointer
!= ' '); /* Operand() gobbles spaces. */
717 c_left
= * input_line_pointer
; /* Potential operator character. */
718 op_left
= op_encoding
[c_left
];
719 while (op_left
!= O_illegal
&& op_rank
[(int) op_left
] > rank
)
721 input_line_pointer
++; /*->after 1st character of operator. */
722 /* Operators "<<" and ">>" have 2 characters. */
723 if (* input_line_pointer
== c_left
&& (c_left
== '<' || c_left
== '>'))
725 input_line_pointer
++;
726 } /*->after operator. */
727 if (SEG_ABSENT
== expr (op_rank
[(int) op_left
], &right
))
729 as_warn("Missing operand value assumed absolute 0.");
730 resultP
->X_add_number
= 0;
731 resultP
->X_subtract_symbol
= NULL
;
732 resultP
->X_add_symbol
= NULL
;
733 resultP
->X_seg
= SEG_ABSOLUTE
;
735 know(* input_line_pointer
!= ' ');
736 c_right
= * input_line_pointer
;
737 op_right
= op_encoding
[c_right
];
738 if (* input_line_pointer
== c_right
&& (c_right
== '<' || c_right
== '>'))
740 input_line_pointer
++;
741 } /*->after operator. */
742 know((int) op_right
== 0
743 || op_rank
[(int) op_right
] <= op_rank
[(int) op_left
]);
744 /* input_line_pointer->after right-hand quantity. */
745 /* left-hand quantity in resultP */
746 /* right-hand quantity in right. */
747 /* operator in op_left. */
748 if (resultP
->X_seg
== SEG_PASS1
|| right
. X_seg
== SEG_PASS1
)
750 resultP
->X_seg
= SEG_PASS1
;
754 if (resultP
->X_seg
== SEG_BIG
)
756 as_warn("Left operand of %c is a %s. Integer 0 assumed.",
757 c_left
, resultP
->X_add_number
> 0 ? "bignum" : "float");
758 resultP
->X_seg
= SEG_ABSOLUTE
;
759 resultP
->X_add_symbol
= 0;
760 resultP
->X_subtract_symbol
= 0;
761 resultP
->X_add_number
= 0;
763 if (right
. X_seg
== SEG_BIG
)
765 as_warn("Right operand of %c is a %s. Integer 0 assumed.",
766 c_left
, right
. X_add_number
> 0 ? "bignum" : "float");
767 right
. X_seg
= SEG_ABSOLUTE
;
768 right
. X_add_symbol
= 0;
769 right
. X_subtract_symbol
= 0;
770 right
. X_add_number
= 0;
772 if (op_left
== O_subtract
)
775 * Convert - into + by exchanging symbols and negating number.
776 * I know -infinity can't be negated in 2's complement:
777 * but then it can't be subtracted either. This trick
778 * does not cause any further inaccuracy.
781 register symbolS
* symbolP
;
783 right
. X_add_number
= - right
. X_add_number
;
784 symbolP
= right
. X_add_symbol
;
785 right
. X_add_symbol
= right
. X_subtract_symbol
;
786 right
. X_subtract_symbol
= symbolP
;
789 right
. X_seg
= SEG_DIFFERENCE
;
794 if (op_left
== O_add
)
799 know(resultP
->X_seg
== SEG_DATA
800 || resultP
->X_seg
== SEG_TEXT
801 || resultP
->X_seg
== SEG_BSS
802 || resultP
->X_seg
== SEG_UNKNOWN
803 || resultP
->X_seg
== SEG_DIFFERENCE
804 || resultP
->X_seg
== SEG_ABSOLUTE
805 || resultP
->X_seg
== SEG_PASS1
);
806 know(right
. X_seg
== SEG_DATA
807 || right
. X_seg
== SEG_TEXT
808 || right
. X_seg
== SEG_BSS
809 || right
. X_seg
== SEG_UNKNOWN
810 || right
. X_seg
== SEG_DIFFERENCE
811 || right
. X_seg
== SEG_ABSOLUTE
812 || right
. X_seg
== SEG_PASS1
);
814 clean_up_expression (& right
);
815 clean_up_expression (resultP
);
817 seg1
= expr_part (& resultP
->X_add_symbol
, right
. X_add_symbol
);
818 seg2
= expr_part (& resultP
->X_subtract_symbol
, right
. X_subtract_symbol
);
819 if (seg1
== SEG_PASS1
|| seg2
== SEG_PASS1
) {
821 resultP
->X_seg
= SEG_PASS1
;
822 } else if (seg2
== SEG_ABSOLUTE
)
823 resultP
->X_seg
= seg1
;
824 else if (seg1
!= SEG_UNKNOWN
825 && seg1
!= SEG_ABSOLUTE
826 && seg2
!= SEG_UNKNOWN
828 know(seg2
!= SEG_ABSOLUTE
);
829 know(resultP
->X_subtract_symbol
);
831 know(seg1
== SEG_TEXT
|| seg1
== SEG_DATA
|| seg1
== SEG_BSS
);
832 know(seg2
== SEG_TEXT
|| seg2
== SEG_DATA
|| seg2
== SEG_BSS
);
833 know(resultP
->X_add_symbol
);
834 know(resultP
->X_subtract_symbol
);
835 as_bad("Expression too complex: forgetting %s - %s",
836 S_GET_NAME(resultP
->X_add_symbol
),
837 S_GET_NAME(resultP
->X_subtract_symbol
));
838 resultP
->X_seg
= SEG_ABSOLUTE
;
839 /* Clean_up_expression() will do the rest. */
841 resultP
->X_seg
= SEG_DIFFERENCE
;
843 resultP
->X_add_number
+= right
. X_add_number
;
844 clean_up_expression (resultP
);
848 if (resultP
->X_seg
== SEG_UNKNOWN
|| right
. X_seg
== SEG_UNKNOWN
)
850 resultP
->X_seg
= SEG_PASS1
;
855 resultP
->X_subtract_symbol
= NULL
;
856 resultP
->X_add_symbol
= NULL
;
857 /* Will be SEG_ABSOLUTE. */
858 if (resultP
->X_seg
!= SEG_ABSOLUTE
|| right
. X_seg
!= SEG_ABSOLUTE
)
860 as_bad("Relocation error. Absolute 0 assumed.");
861 resultP
->X_seg
= SEG_ABSOLUTE
;
862 resultP
->X_add_number
= 0;
868 case O_bit_inclusive_or
:
869 resultP
->X_add_number
|= right
. X_add_number
;
873 if (right
. X_add_number
)
875 resultP
->X_add_number
%= right
. X_add_number
;
879 as_warn("Division by 0. 0 assumed.");
880 resultP
->X_add_number
= 0;
885 resultP
->X_add_number
&= right
. X_add_number
;
889 resultP
->X_add_number
*= right
. X_add_number
;
893 if (right
. X_add_number
)
895 resultP
->X_add_number
/= right
. X_add_number
;
899 as_warn("Division by 0. 0 assumed.");
900 resultP
->X_add_number
= 0;
905 resultP
->X_add_number
<<= right
. X_add_number
;
909 resultP
->X_add_number
>>= right
. X_add_number
;
912 case O_bit_exclusive_or
:
913 resultP
->X_add_number
^= right
. X_add_number
;
917 resultP
->X_add_number
|= ~ right
. X_add_number
;
923 } /* switch(operator) */
925 } /* If we have to force need_pass_2. */
926 } /* If operator was +. */
927 } /* If we didn't set need_pass_2. */
929 } /* While next operator is >= this rank. */
930 return (resultP
->X_seg
);
936 * This lives here because it belongs equally in expr.c & read.c.
937 * Expr.c is just a branch office read.c anyway, and putting it
938 * here lessens the crowd at read.c.
940 * Assume input_line_pointer is at start of symbol name.
941 * Advance input_line_pointer past symbol name.
942 * Turn that character into a '\0', returning its former value.
943 * This allows a string compare (RMS wants symbol names to be strings)
944 * of the symbol name.
945 * There will always be a char following symbol name, because all good
946 * lines end in end-of-line.
953 while (is_part_of_name(c
= * input_line_pointer
++))
955 * -- input_line_pointer
= 0;