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.
28 static char rcsid[] = "$Id: expr.c,v 1.6 1997/02/22 15:43:31 peter Exp $";
39 static void clean_up_expression(expressionS *expressionP);
41 static void clean_up_expression(); /* Internal. */
42 #endif /* not __STDC__ */
43 extern const char EXP_CHARS[]; /* JF hide MD floating pt stuff all the same place */
44 extern const char FLT_CHARS[];
46 #ifdef LOCAL_LABELS_DOLLAR
47 extern int local_label_defined[];
51 * Build any floating-point literal here.
52 * Also build any bignum literal here.
55 /* LITTLENUM_TYPE generic_buffer[6]; */ /* JF this is a hack */
56 /* Seems atof_machine can backscan through generic_bignum and hit whatever
57 happens to be loaded before it in memory. And its way too complicated
58 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
59 and never write into the early words, thus they'll always be zero.
60 I hate Dean's floating-point code. Bleh.
62 LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER+6];
63 FLONUM_TYPE generic_floating_point_number =
65 &generic_bignum[6], /* low (JF: Was 0) */
66 &generic_bignum[SIZE_OF_LARGE_NUMBER+6 - 1], /* high JF: (added +6) */
71 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
72 int generic_floating_point_magic;
75 * Summary of operand().
77 * in: Input_line_pointer points to 1st char of operand, which may
80 * out: A expressionS. X_seg determines how to understand the rest of the
82 * The operand may have been empty: in this case X_seg == SEG_ABSENT.
83 * Input_line_pointer->(next non-blank) char after operand.
89 register expressionS * expressionP;
92 register char *name; /* points to name of symbol */
93 register symbolS * symbolP; /* Points to symbol */
95 extern const char hex_value[]; /* In hex_value.c */
98 /* XXX */ expressionP->X_got_symbol = 0;
100 SKIP_WHITESPACE(); /* Leading whitespace is part of operand. */
101 c = * input_line_pointer ++; /* Input_line_pointer->past char in c. */
102 if (isdigit(c) || (c == 'H' && input_line_pointer[0] == '\''))
104 register valueT number; /* offset or (absolute) value */
105 register short int digit; /* value of next digit in current radix */
106 /* invented for humans only, hope */
107 /* optimising compiler flushes it! */
108 register short int radix; /* 2, 8, 10 or 16 */
109 /* 0 means we saw start of a floating- */
110 /* point constant. */
111 register short int maxdig = 0;/* Highest permitted digit value. */
112 register int too_many_digits = 0; /* If we see >= this number of */
113 /* digits, assume it is a bignum. */
114 register char * digit_2; /*->2nd digit of number. */
115 int small; /* TRUE if fits in 32 bits. */
118 if (c == 'H' || c == '0') { /* non-decimal radix */
119 if ((c = *input_line_pointer ++) == 'x' || c == 'X' || c == '\'') {
120 c = *input_line_pointer ++; /* read past "0x" or "0X" or H' */
124 /* If it says '0f' and the line ends or it DOESN'T look like
125 a floating point #, its a local label ref. DTRT */
126 /* likewise for the b's. xoxorich. */
127 if ((c == 'f' || c == 'b' || c == 'B')
128 && (!*input_line_pointer ||
129 (!strchr("+-.0123456789iInN",*input_line_pointer) &&
130 !strchr(EXP_CHARS,*input_line_pointer)))) {
132 too_many_digits = 11;
134 input_line_pointer -= 2;
136 } else if (c == 'b' || c == 'B') {
137 c = *input_line_pointer++;
139 too_many_digits = 33;
141 } else if (c && strchr(FLT_CHARS,c)) {
142 radix = 0; /* Start of floating-point constant. */
143 /* input_line_pointer->1st char of number. */
144 expressionP->X_add_number = -(isupper(c) ? tolower(c) : c);
146 } else { /* By elimination, assume octal radix. */
148 too_many_digits = 11;
150 } /* c == char after "0" or "0x" or "0X" or "0e" etc. */
153 too_many_digits = 11;
154 } /* if operand starts with a zero */
156 if (radix) { /* Fixed-point integer constant. */
157 /* May be bignum, or may fit in 32 bits. */
159 * Most numbers fit into 32 bits, and we want this case to be fast.
160 * So we pretend it will fit into 32 bits. If, after making up a 32
161 * bit number, we realise that we have scanned more digits than
162 * comfortably fit into 32 bits, we re-scan the digits coding
163 * them into a bignum. For decimal and octal numbers we are conservative: some
164 * numbers may be assumed bignums when in fact they do fit into 32 bits.
165 * Numbers of any radix can have excess leading zeros: we strive
166 * to recognise this and cast them back into 32 bits.
167 * We must check that the bignum really is more than 32
168 * bits, and change it back to a 32-bit number if it fits.
169 * The number we are looking for is expected to be positive, but
170 * if it fits into 32 bits as an unsigned number, we let it be a 32-bit
171 * number. The cavalier approach is for speed in ordinary cases.
173 digit_2 = input_line_pointer;
174 for (number=0; (digit=hex_value[c])<maxdig; c = * input_line_pointer ++)
176 number = number * radix + digit;
178 /* C contains character after number. */
179 /* Input_line_pointer->char after C. */
180 small = input_line_pointer - digit_2 < too_many_digits;
184 * We saw a lot of digits. Manufacture a bignum the hard way.
186 LITTLENUM_TYPE *leader; /*->high order littlenum of the bignum. */
187 LITTLENUM_TYPE *pointer; /*->littlenum we are frobbing now. */
190 leader = generic_bignum;
191 generic_bignum[0] = 0;
192 generic_bignum[1] = 0;
193 /* We could just use digit_2, but lets be mnemonic. */
194 input_line_pointer = --digit_2; /*->1st digit. */
195 c = *input_line_pointer++;
196 for (; (carry = hex_value[c]) < maxdig; c = *input_line_pointer++)
198 for (pointer = generic_bignum;
204 work = carry + radix * *pointer;
205 *pointer = work & LITTLENUM_MASK;
206 carry = work >> LITTLENUM_NUMBER_OF_BITS;
210 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
211 { /* Room to grow a longer bignum. */
216 /* Again, C is char after number, */
217 /* input_line_pointer->after C. */
218 know(sizeof (int) * 8 == 32);
219 know(LITTLENUM_NUMBER_OF_BITS == 16);
220 /* Hence the constant "2" in the next line. */
221 if (leader < generic_bignum + 2)
222 { /* Will fit into 32 bits. */
224 ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
225 | (generic_bignum[0] & LITTLENUM_MASK);
230 number = leader - generic_bignum + 1; /* Number of littlenums in the bignum. */
236 * Here with number, in correct radix. c is the next char.
237 * Note that unlike Un*x, we allow "011f" "0x9f" to
238 * both mean the same as the (conventional) "9f". This is simply easier
239 * than checking for strict canonical form. Syntax sux!
244 #ifdef LOCAL_LABELS_FB
247 #ifdef LOCAL_LABELS_DOLLAR
248 || (c == '$' && local_label_defined[number])
253 * Backward ref to local label.
254 * Because it is backward, expect it to be DEFINED.
257 * Construct a local label.
259 name = local_label_name ((int)number, 0);
260 if (((symbolP = symbol_find(name)) != NULL) /* seen before */
261 && (S_IS_DEFINED(symbolP))) /* symbol is defined: OK */
262 { /* Expected path: symbol defined. */
263 /* Local labels are never absolute. Don't waste time checking absoluteness. */
264 know(SEG_NORMAL(S_GET_SEGMENT(symbolP)));
266 expressionP->X_add_symbol = symbolP;
267 expressionP->X_add_number = 0;
268 expressionP->X_seg = S_GET_SEGMENT(symbolP);
271 { /* Either not seen or not defined. */
272 as_bad("Backw. ref to unknown label \"%d:\", 0 assumed.",
274 expressionP->X_add_number = 0;
275 expressionP->X_seg = SEG_ABSOLUTE;
281 #ifdef LOCAL_LABELS_FB
284 #ifdef LOCAL_LABELS_DOLLAR
285 || (c == '$' && !local_label_defined[number])
290 * Forward reference. Expect symbol to be undefined or
291 * unknown. Undefined: seen it before. Unknown: never seen
293 * Construct a local label name, then an undefined symbol.
294 * Don't create a XSEG frag for it: caller may do that.
295 * Just return it as never seen before.
297 name = local_label_name((int)number, 1);
298 symbolP = symbol_find_or_make(name);
299 /* We have no need to check symbol properties. */
300 #ifndef MANY_SEGMENTS
301 /* Since "know" puts its arg into a "string", we
302 can't have newlines in the argument. */
303 know(S_GET_SEGMENT(symbolP) == SEG_UNKNOWN || S_GET_SEGMENT(symbolP) == SEG_TEXT || S_GET_SEGMENT(symbolP) == SEG_DATA);
305 expressionP->X_add_symbol = symbolP;
306 expressionP->X_seg = SEG_UNKNOWN;
307 expressionP->X_subtract_symbol = NULL;
308 expressionP->X_add_number = 0;
311 { /* Really a number, not a local label. */
312 expressionP->X_add_number = number;
313 expressionP->X_seg = SEG_ABSOLUTE;
314 input_line_pointer--; /* Restore following character. */
315 } /* if (c == 'f') */
316 } /* if (c == 'b') */
319 { /* Really a number. */
320 expressionP->X_add_number = number;
321 expressionP->X_seg = SEG_ABSOLUTE;
322 input_line_pointer--; /* Restore following character. */
323 } /* if (number<10) */
327 expressionP->X_add_number = number;
328 expressionP->X_seg = SEG_BIG;
329 input_line_pointer --; /*->char following number. */
331 } /* (If integer constant) */
333 { /* input_line_pointer->*/
334 /* floating-point constant. */
337 error_code = atof_generic
338 (& input_line_pointer, ".", EXP_CHARS,
339 & generic_floating_point_number);
343 if (error_code == ERROR_EXPONENT_OVERFLOW)
345 as_bad("Bad floating-point constant: exponent overflow, probably assembling junk");
349 as_bad("Bad floating-point constant: unknown error code=%d.", error_code);
352 expressionP->X_seg = SEG_BIG;
353 /* input_line_pointer->just after constant, */
354 /* which may point to whitespace. */
355 know(expressionP->X_add_number < 0); /* < 0 means "floating point". */
356 } /* if (not floating-point constant) */
358 else if (c == '.' && !is_part_of_name(*input_line_pointer)) {
359 extern struct obstack frags;
362 JF: '.' is pseudo symbol with value of current location in current
365 symbolP = symbol_new("\001L0",
367 (valueT)(obstack_next_free(&frags)-frag_now->fr_literal),
370 expressionP->X_add_number=0;
371 expressionP->X_add_symbol=symbolP;
372 expressionP->X_seg = now_seg;
374 } else if (is_name_beginner(c)) { /* here if did not begin with a digit */
377 * Identifier begins here.
378 * This is kludged for speed, so code is repeated.
380 name = input_line_pointer - 1;
381 c = get_symbol_end();
382 symbolP = symbol_find_or_make(name);
384 * If we have an absolute symbol or a reg, then we know its value now.
386 expressionP->X_seg = S_GET_SEGMENT(symbolP);
387 switch (expressionP->X_seg)
391 expressionP->X_add_number = S_GET_VALUE(symbolP);
395 expressionP->X_add_number = 0;
397 if (symbolP == GOT_symbol) {
398 expressionP->X_got_symbol = symbolP;
402 expressionP->X_add_symbol = symbolP;
404 *input_line_pointer = c;
405 expressionP->X_subtract_symbol = NULL;
406 } else if (c == '(' || c == '[') {/* didn't begin with digit & not a name */
407 (void)expression(expressionP);
408 /* Expression() will pass trailing whitespace */
409 if (c == '(' && *input_line_pointer++ != ')' ||
410 c == '[' && *input_line_pointer++ != ']') {
411 as_bad("Missing ')' assumed");
412 input_line_pointer--;
414 /* here with input_line_pointer->char after "(...)" */
415 } else if (c == '~' || c == '-' || c == '+') {
416 /* unary operator: hope for SEG_ABSOLUTE */
417 switch (operand (expressionP)) {
419 /* input_line_pointer->char after operand */
421 expressionP->X_add_number = - expressionP->X_add_number;
423 * Notice: '-' may overflow: no warning is given. This is compatible
424 * with other people's assemblers. Sigh.
426 } else if (c == '~') {
427 expressionP->X_add_number = ~ expressionP->X_add_number;
428 } else if (c != '+') {
430 } /* switch on unary operator */
433 default: /* unary on non-absolute is unsuported */
434 if (!SEG_NORMAL(operand(expressionP)))
436 as_bad("Unary operator %c ignored because bad operand follows", c);
439 /* Fall through for normal segments ****/
442 if (c == '-') { /* JF I hope this hack works */
443 expressionP->X_subtract_symbol=expressionP->X_add_symbol;
444 expressionP->X_add_symbol=0;
445 expressionP->X_seg=SEG_DIFFERENCE;
448 /* Expression undisturbed from operand(). */
454 * Warning: to conform to other people's assemblers NO ESCAPEMENT is permitted
455 * for a single quote. The next character, parity errors and all, is taken
456 * as the value of the operand. VERY KINKY.
458 expressionP->X_add_number = * input_line_pointer ++;
459 expressionP->X_seg = SEG_ABSOLUTE;
463 /* can't imagine any other kind of operand */
464 expressionP->X_seg = SEG_ABSENT;
465 input_line_pointer --;
466 md_operand (expressionP);
469 * It is more 'efficient' to clean up the expressions when they are created.
470 * Doing it here saves lines of code.
472 clean_up_expression(expressionP);
473 SKIP_WHITESPACE(); /*->1st char after operand. */
474 know(*input_line_pointer != ' ');
475 return(expressionP->X_seg);
478 /* Internal. Simplify a struct expression for use by expr() */
481 * In: address of a expressionS.
482 * The X_seg field of the expressionS may only take certain values.
483 * Now, we permit SEG_PASS1 to make code smaller & faster.
484 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
485 * Out: expressionS may have been modified:
486 * 'foo-foo' symbol references cancelled to 0,
487 * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE;
488 * Unused fields zeroed to help expr().
492 clean_up_expression (expressionP)
493 register expressionS *expressionP;
495 switch (expressionP->X_seg) {
498 expressionP->X_add_symbol = NULL;
499 expressionP->X_subtract_symbol = NULL;
500 expressionP->X_add_number = 0;
505 expressionP->X_subtract_symbol = NULL;
506 expressionP->X_add_symbol = NULL;
510 expressionP->X_subtract_symbol = NULL;
515 * It does not hurt to 'cancel' NULL == NULL
516 * when comparing symbols for 'eq'ness.
517 * It is faster to re-cancel them to NULL
518 * than to check for this special case.
520 if (expressionP->X_subtract_symbol == expressionP->X_add_symbol
521 || (expressionP->X_subtract_symbol
522 && expressionP->X_add_symbol
523 && expressionP->X_subtract_symbol->sy_frag == expressionP->X_add_symbol->sy_frag
524 && S_GET_VALUE(expressionP->X_subtract_symbol) == S_GET_VALUE(expressionP->X_add_symbol))) {
525 expressionP->X_subtract_symbol = NULL;
526 expressionP->X_add_symbol = NULL;
527 expressionP->X_seg = SEG_ABSOLUTE;
532 expressionP->X_add_symbol = NULL;
533 expressionP->X_subtract_symbol = NULL;
537 if (SEG_NORMAL(expressionP->X_seg)) {
538 expressionP->X_subtract_symbol = NULL;
541 BAD_CASE (expressionP->X_seg);
545 } /* clean_up_expression() */
550 * Internal. Made a function because this code is used in 2 places.
551 * Generate error or correct X_?????_symbol of expressionS.
555 * symbol_1 += symbol_2 ... well ... sort of.
559 expr_part (symbol_1_PP, symbol_2_P)
560 symbolS ** symbol_1_PP;
561 symbolS * symbol_2_P;
564 #ifndef MANY_SEGMENTS
565 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)));
566 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)));
570 if (!S_IS_DEFINED(* symbol_1_PP))
574 return_value = SEG_PASS1;
575 * symbol_1_PP = NULL;
579 know(!S_IS_DEFINED(* symbol_1_PP));
580 return_value = SEG_UNKNOWN;
587 if (!S_IS_DEFINED(symbol_2_P))
589 * symbol_1_PP = NULL;
590 return_value = SEG_PASS1;
594 /* {seg1} - {seg2} */
595 as_bad("Expression too complex, 2 symbols forgotten: \"%s\" \"%s\"",
596 S_GET_NAME(* symbol_1_PP), S_GET_NAME(symbol_2_P));
597 * symbol_1_PP = NULL;
598 return_value = SEG_ABSOLUTE;
603 return_value = S_GET_SEGMENT(* symbol_1_PP);
608 { /* (* symbol_1_PP) == NULL */
611 * symbol_1_PP = symbol_2_P;
612 return_value = S_GET_SEGMENT(symbol_2_P);
616 * symbol_1_PP = NULL;
617 return_value = SEG_ABSOLUTE;
620 #ifndef MANY_SEGMENTS
621 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);
623 know((*symbol_1_PP) == NULL || (S_GET_SEGMENT(*symbol_1_PP) == return_value));
624 return (return_value);
630 fprintf (stdout, "%s type %s%s",
632 S_IS_EXTERNAL(s) ? "EXTERNAL " : "",
633 segment_name(S_GET_SEGMENT(s)));
638 fprintf (stdout, " segment %s\n", segment_name (e->X_seg));
639 fprintf (stdout, " add_number %ld (%lx)\n",
640 e->X_add_number, e->X_add_number);
641 if (e->X_add_symbol) {
642 fprintf (stdout, " add_symbol ");
643 ps (e->X_add_symbol);
644 fprintf (stdout, "\n");
646 if (e->X_subtract_symbol) {
647 fprintf (stdout, " sub_symbol ");
648 ps (e->X_subtract_symbol);
649 fprintf (stdout, "\n");
653 /* Expression parser. */
656 * We allow an empty expression, and just assume (absolute,0) silently.
657 * Unary operators and parenthetical expressions are treated as operands.
658 * As usual, Q == quantity == operand, O == operator, X == expression mnemonics.
660 * We used to do a aho/ullman shift-reduce parser, but the logic got so
661 * warped that I flushed it and wrote a recursive-descent parser instead.
662 * Now things are stable, would anybody like to write a fast parser?
663 * Most expressions are either register (which does not even reach here)
664 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
665 * So I guess it doesn't really matter how inefficient more complex expressions
668 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
669 * Also, we have consumed any leading or trailing spaces (operand does that)
670 * and done all intervening operators.
675 O_illegal, /* (0) what we get for illegal op */
677 O_multiply, /* (1) * */
678 O_divide, /* (2) / */
679 O_modulus, /* (3) % */
680 O_left_shift, /* (4) < */
681 O_right_shift, /* (5) > */
682 O_bit_inclusive_or, /* (6) | */
683 O_bit_or_not, /* (7) ! */
684 O_bit_exclusive_or, /* (8) ^ */
685 O_bit_and, /* (9) & */
687 O_subtract /* (11) - */
693 static const operatorT op_encoding[256] = { /* maps ASCII->operators */
695 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
696 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
698 __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
699 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
700 __, __, __, __, __, __, __, __,
701 __, __, __, __, O_left_shift, __, O_right_shift, __,
702 __, __, __, __, __, __, __, __,
703 __, __, __, __, __, __, __, __,
704 __, __, __, __, __, __, __, __,
705 __, __, __, __, __, __, O_bit_exclusive_or, __,
706 __, __, __, __, __, __, __, __,
707 __, __, __, __, __, __, __, __,
708 __, __, __, __, __, __, __, __,
709 __, __, __, __, O_bit_inclusive_or, __, __, __,
711 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
712 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
713 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
714 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
715 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
716 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
717 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
718 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
724 * 0 operand, (expression)
729 static const operator_rankT
730 op_rank[] = { 0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1 };
732 /* Return resultP->X_seg. */
733 segT expr(rank, resultP)
734 register operator_rankT rank; /* Larger # is higher rank. */
735 register expressionS *resultP; /* Deliver result here. */
738 register operatorT op_left;
739 register char c_left; /* 1st operator character. */
740 register operatorT op_right;
741 register char c_right;
744 (void) operand(resultP);
745 know(*input_line_pointer != ' '); /* Operand() gobbles spaces. */
746 c_left = *input_line_pointer; /* Potential operator character. */
747 op_left = op_encoding[c_left];
749 while (op_left != O_illegal && op_rank[(int) op_left] > rank) {
750 input_line_pointer++; /*->after 1st character of operator. */
752 /* Operators "<<" and ">>" have 2 characters. */
753 if (*input_line_pointer == c_left && (c_left == '<' || c_left == '>')) {
754 input_line_pointer ++;
755 } /*->after operator. */
756 if (SEG_ABSENT == expr (op_rank[(int) op_left], &right)) {
757 as_warn("Missing operand value assumed absolute 0.");
758 resultP->X_add_number = 0;
759 resultP->X_subtract_symbol = NULL;
760 resultP->X_add_symbol = NULL;
761 resultP->X_seg = SEG_ABSOLUTE;
764 know(*input_line_pointer != ' ');
765 c_right = *input_line_pointer;
766 op_right = op_encoding[c_right];
768 if (*input_line_pointer == c_right && (c_right == '<' || c_right == '>')) {
769 input_line_pointer ++;
770 } /*->after operator. */
772 know((int) op_right == 0 || op_rank[(int) op_right] <= op_rank[(int) op_left]);
773 /* input_line_pointer->after right-hand quantity. */
774 /* left-hand quantity in resultP */
775 /* right-hand quantity in right. */
776 /* operator in op_left. */
777 if (resultP->X_seg == SEG_PASS1 || right.X_seg == SEG_PASS1) {
778 resultP->X_seg = SEG_PASS1;
780 if (resultP->X_seg == SEG_BIG) {
781 as_warn("Left operand of %c is a %s. Integer 0 assumed.",
782 c_left, resultP->X_add_number > 0 ? "bignum" : "float");
783 resultP->X_seg = SEG_ABSOLUTE;
784 resultP->X_add_symbol = 0;
785 resultP->X_subtract_symbol = 0;
786 resultP->X_add_number = 0;
788 if (right.X_seg == SEG_BIG) {
789 as_warn("Right operand of %c is a %s. Integer 0 assumed.",
790 c_left, right.X_add_number > 0 ? "bignum" : "float");
791 right.X_seg = SEG_ABSOLUTE;
792 right.X_add_symbol = 0;
793 right.X_subtract_symbol = 0;
794 right.X_add_number = 0;
796 if (op_left == O_subtract) {
798 * Convert - into + by exchanging symbols and negating number.
799 * I know -infinity can't be negated in 2's complement:
800 * but then it can't be subtracted either. This trick
801 * does not cause any further inaccuracy.
804 register symbolS * symbolP;
806 right.X_add_number = - right.X_add_number;
807 symbolP = right.X_add_symbol;
808 right.X_add_symbol = right.X_subtract_symbol;
809 right.X_subtract_symbol = symbolP;
811 right.X_seg = SEG_DIFFERENCE;
816 if (op_left == O_add) {
819 #ifndef MANY_SEGMENTS
820 know(resultP->X_seg == SEG_DATA
821 || resultP->X_seg == SEG_TEXT
822 || resultP->X_seg == SEG_BSS
823 || resultP->X_seg == SEG_UNKNOWN
824 || resultP->X_seg == SEG_DIFFERENCE
825 || resultP->X_seg == SEG_ABSOLUTE
826 || resultP->X_seg == SEG_PASS1);
827 know(right.X_seg == SEG_DATA
828 || right.X_seg == SEG_TEXT
829 || right.X_seg == SEG_BSS
830 || right.X_seg == SEG_UNKNOWN
831 || right.X_seg == SEG_DIFFERENCE
832 || right.X_seg == SEG_ABSOLUTE
833 || right.X_seg == SEG_PASS1);
835 clean_up_expression(& right);
836 clean_up_expression(resultP);
839 /* XXX - kludge here to accomodate "_GLOBAL_OFFSET_TABLE + (x - y)"
840 * expressions: this only works for this special case, the
841 * _GLOBAL_OFFSET_TABLE thing *must* be the left operand, the whole
842 * expression is given the segment of right expression (always a DIFFERENCE,
843 * which should get resolved by fixup_segment())
845 if (resultP->X_got_symbol) {
846 resultP->X_add_symbol = right.X_add_symbol;
847 resultP->X_subtract_symbol = right.X_subtract_symbol;
848 seg1 = S_GET_SEGMENT(right.X_add_symbol);
849 seg2 = S_GET_SEGMENT(right.X_subtract_symbol);
850 resultP->X_seg = right.X_seg;
853 seg1 = expr_part(&resultP->X_add_symbol, right.X_add_symbol);
854 seg2 = expr_part(&resultP->X_subtract_symbol, right.X_subtract_symbol);
858 if (seg1 == SEG_PASS1 || seg2 == SEG_PASS1) {
860 resultP->X_seg = SEG_PASS1;
861 } else if (seg2 == SEG_ABSOLUTE)
862 resultP->X_seg = seg1;
863 else if (seg1 != SEG_UNKNOWN
864 && seg1 != SEG_ABSOLUTE
865 && seg2 != SEG_UNKNOWN
867 know(seg2 != SEG_ABSOLUTE);
868 know(resultP->X_subtract_symbol);
869 #ifndef MANY_SEGMENTS
870 know(seg1 == SEG_TEXT || seg1 == SEG_DATA || seg1 == SEG_BSS);
871 know(seg2 == SEG_TEXT || seg2 == SEG_DATA || seg2 == SEG_BSS);
873 know(resultP->X_add_symbol);
874 know(resultP->X_subtract_symbol);
875 as_bad("Expression too complex: forgetting %s - %s",
876 S_GET_NAME(resultP->X_add_symbol),
877 S_GET_NAME(resultP->X_subtract_symbol));
878 resultP->X_seg = SEG_ABSOLUTE;
879 /* Clean_up_expression() will do the rest. */
881 resultP->X_seg = SEG_DIFFERENCE;
883 resultP->X_add_number += right.X_add_number;
884 clean_up_expression(resultP);
885 } else { /* Not +. */
886 if (resultP->X_seg == SEG_UNKNOWN || right.X_seg == SEG_UNKNOWN) {
887 resultP->X_seg = SEG_PASS1;
890 resultP->X_subtract_symbol = NULL;
891 resultP->X_add_symbol = NULL;
893 /* Will be SEG_ABSOLUTE. */
894 if (resultP->X_seg != SEG_ABSOLUTE || right.X_seg != SEG_ABSOLUTE) {
895 as_bad("Relocation error. Absolute 0 assumed.");
896 resultP->X_seg = SEG_ABSOLUTE;
897 resultP->X_add_number = 0;
900 case O_bit_inclusive_or:
901 resultP->X_add_number |= right.X_add_number;
905 if (right.X_add_number) {
906 resultP->X_add_number %= right.X_add_number;
908 as_warn("Division by 0. 0 assumed.");
909 resultP->X_add_number = 0;
914 resultP->X_add_number &= right.X_add_number;
918 resultP->X_add_number *= right.X_add_number;
922 if (right.X_add_number) {
923 resultP->X_add_number /= right.X_add_number;
925 as_warn("Division by 0. 0 assumed.");
926 resultP->X_add_number = 0;
931 resultP->X_add_number <<= right.X_add_number;
935 resultP->X_add_number >>= right.X_add_number;
938 case O_bit_exclusive_or:
939 resultP->X_add_number ^= right.X_add_number;
943 resultP->X_add_number |= ~ right.X_add_number;
949 } /* switch (operator) */
951 } /* If we have to force need_pass_2. */
952 } /* If operator was +. */
953 } /* If we didn't set need_pass_2. */
955 } /* While next operator is >= this rank. */
957 return(resultP->X_seg);
963 * This lives here because it belongs equally in expr.c & read.c.
964 * Expr.c is just a branch office read.c anyway, and putting it
965 * here lessens the crowd at read.c.
967 * Assume input_line_pointer is at start of symbol name.
968 * Advance input_line_pointer past symbol name.
969 * Turn that character into a '\0', returning its former value.
970 * This allows a string compare (RMS wants symbol names to be strings)
971 * of the symbol name.
972 * There will always be a char following symbol name, because all good
973 * lines end in end-of-line.
980 while (is_part_of_name(c = *input_line_pointer++)) ;;
981 *--input_line_pointer = 0;
986 unsigned int get_single_number()
990 return exp.X_add_number;