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.
26 * $FreeBSD: src/gnu/usr.bin/as/expr.c,v 1.8 1999/08/27 23:34:14 peter Exp $
27 * $DragonFly: src/gnu/usr.bin/as/Attic/expr.c,v 1.2 2003/06/17 04:25:44 dillon Exp $
38 static void clean_up_expression(expressionS *expressionP);
40 static void clean_up_expression(); /* Internal. */
41 #endif /* not __STDC__ */
42 extern const char EXP_CHARS[]; /* JF hide MD floating pt stuff all the same place */
43 extern const char FLT_CHARS[];
45 #ifdef LOCAL_LABELS_DOLLAR
46 extern int local_label_defined[];
50 * Build any floating-point literal here.
51 * Also build any bignum literal here.
54 /* LITTLENUM_TYPE generic_buffer[6]; */ /* JF this is a hack */
55 /* Seems atof_machine can backscan through generic_bignum and hit whatever
56 happens to be loaded before it in memory. And its way too complicated
57 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
58 and never write into the early words, thus they'll always be zero.
59 I hate Dean's floating-point code. Bleh.
61 LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER+6];
62 FLONUM_TYPE generic_floating_point_number =
64 &generic_bignum[6], /* low (JF: Was 0) */
65 &generic_bignum[SIZE_OF_LARGE_NUMBER+6 - 1], /* high JF: (added +6) */
70 /* If nonzero, we've been asked to assemble nan, +inf or -inf */
71 int generic_floating_point_magic;
74 * Summary of operand().
76 * in: Input_line_pointer points to 1st char of operand, which may
79 * out: A expressionS. X_seg determines how to understand the rest of the
81 * The operand may have been empty: in this case X_seg == SEG_ABSENT.
82 * Input_line_pointer->(next non-blank) char after operand.
88 register expressionS * expressionP;
91 register char *name; /* points to name of symbol */
92 register symbolS * symbolP; /* Points to symbol */
94 extern const char hex_value[]; /* In hex_value.c */
97 /* XXX */ expressionP->X_got_symbol = 0;
99 SKIP_WHITESPACE(); /* Leading whitespace is part of operand. */
100 c = * input_line_pointer ++; /* Input_line_pointer->past char in c. */
101 if (isdigit(c) || (c == 'H' && input_line_pointer[0] == '\''))
103 register valueT number; /* offset or (absolute) value */
104 register short int digit; /* value of next digit in current radix */
105 /* invented for humans only, hope */
106 /* optimising compiler flushes it! */
107 register short int radix; /* 2, 8, 10 or 16 */
108 /* 0 means we saw start of a floating- */
109 /* point constant. */
110 register short int maxdig = 0;/* Highest permitted digit value. */
111 register int too_many_digits = 0; /* If we see >= this number of */
112 /* digits, assume it is a bignum. */
113 register char * digit_2; /*->2nd digit of number. */
114 int small; /* TRUE if fits in 32 bits. */
117 if (c == 'H' || c == '0') { /* non-decimal radix */
118 if ((c = *input_line_pointer ++) == 'x' || c == 'X' || c == '\'') {
119 c = *input_line_pointer ++; /* read past "0x" or "0X" or H' */
123 /* If it says '0f' and the line ends or it DOESN'T look like
124 a floating point #, its a local label ref. DTRT */
125 /* likewise for the b's. xoxorich. */
126 if ((c == 'f' || c == 'b' || c == 'B')
127 && (!*input_line_pointer ||
128 (!strchr("+-.0123456789iInN",*input_line_pointer) &&
129 !strchr(EXP_CHARS,*input_line_pointer)))) {
131 too_many_digits = 11;
133 input_line_pointer -= 2;
135 } else if (c == 'b' || c == 'B') {
136 c = *input_line_pointer++;
138 too_many_digits = 33;
140 } else if (c && strchr(FLT_CHARS,c)) {
141 radix = 0; /* Start of floating-point constant. */
142 /* input_line_pointer->1st char of number. */
143 expressionP->X_add_number = -(isupper(c) ? tolower(c) : c);
145 } else { /* By elimination, assume octal radix. */
147 too_many_digits = 11;
149 } /* c == char after "0" or "0x" or "0X" or "0e" etc. */
152 too_many_digits = 11;
153 } /* if operand starts with a zero */
155 if (radix) { /* Fixed-point integer constant. */
156 /* May be bignum, or may fit in 32 bits. */
158 * Most numbers fit into 32 bits, and we want this case to be fast.
159 * So we pretend it will fit into 32 bits. If, after making up a 32
160 * bit number, we realise that we have scanned more digits than
161 * comfortably fit into 32 bits, we re-scan the digits coding
162 * them into a bignum. For decimal and octal numbers we are conservative: some
163 * numbers may be assumed bignums when in fact they do fit into 32 bits.
164 * Numbers of any radix can have excess leading zeros: we strive
165 * to recognise this and cast them back into 32 bits.
166 * We must check that the bignum really is more than 32
167 * bits, and change it back to a 32-bit number if it fits.
168 * The number we are looking for is expected to be positive, but
169 * if it fits into 32 bits as an unsigned number, we let it be a 32-bit
170 * number. The cavalier approach is for speed in ordinary cases.
172 digit_2 = input_line_pointer;
173 for (number=0; (digit=hex_value[c])<maxdig; c = * input_line_pointer ++)
175 number = number * radix + digit;
177 /* C contains character after number. */
178 /* Input_line_pointer->char after C. */
179 small = input_line_pointer - digit_2 < too_many_digits;
183 * We saw a lot of digits. Manufacture a bignum the hard way.
185 LITTLENUM_TYPE *leader; /*->high order littlenum of the bignum. */
186 LITTLENUM_TYPE *pointer; /*->littlenum we are frobbing now. */
189 leader = generic_bignum;
190 generic_bignum[0] = 0;
191 generic_bignum[1] = 0;
192 /* We could just use digit_2, but lets be mnemonic. */
193 input_line_pointer = --digit_2; /*->1st digit. */
194 c = *input_line_pointer++;
195 for (; (carry = hex_value[c]) < maxdig; c = *input_line_pointer++)
197 for (pointer = generic_bignum;
203 work = carry + radix * *pointer;
204 *pointer = work & LITTLENUM_MASK;
205 carry = work >> LITTLENUM_NUMBER_OF_BITS;
209 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
210 { /* Room to grow a longer bignum. */
215 /* Again, C is char after number, */
216 /* input_line_pointer->after C. */
217 know(sizeof (int) * 8 == 32);
218 know(LITTLENUM_NUMBER_OF_BITS == 16);
219 /* Hence the constant "2" in the next line. */
220 if (leader < generic_bignum + 2)
221 { /* Will fit into 32 bits. */
223 ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
224 | (generic_bignum[0] & LITTLENUM_MASK);
229 number = leader - generic_bignum + 1; /* Number of littlenums in the bignum. */
235 * Here with number, in correct radix. c is the next char.
236 * Note that unlike Un*x, we allow "011f" "0x9f" to
237 * both mean the same as the (conventional) "9f". This is simply easier
238 * than checking for strict canonical form. Syntax sux!
243 #ifdef LOCAL_LABELS_FB
246 #ifdef LOCAL_LABELS_DOLLAR
247 || (c == '$' && local_label_defined[number])
252 * Backward ref to local label.
253 * Because it is backward, expect it to be DEFINED.
256 * Construct a local label.
258 name = local_label_name ((int)number, 0);
259 if (((symbolP = symbol_find(name)) != NULL) /* seen before */
260 && (S_IS_DEFINED(symbolP))) /* symbol is defined: OK */
261 { /* Expected path: symbol defined. */
262 /* Local labels are never absolute. Don't waste time checking absoluteness. */
263 know(SEG_NORMAL(S_GET_SEGMENT(symbolP)));
265 expressionP->X_add_symbol = symbolP;
266 expressionP->X_add_number = 0;
267 expressionP->X_seg = S_GET_SEGMENT(symbolP);
270 { /* Either not seen or not defined. */
271 as_bad("Backw. ref to unknown label \"%d:\", 0 assumed.",
273 expressionP->X_add_number = 0;
274 expressionP->X_seg = SEG_ABSOLUTE;
280 #ifdef LOCAL_LABELS_FB
283 #ifdef LOCAL_LABELS_DOLLAR
284 || (c == '$' && !local_label_defined[number])
289 * Forward reference. Expect symbol to be undefined or
290 * unknown. Undefined: seen it before. Unknown: never seen
292 * Construct a local label name, then an undefined symbol.
293 * Don't create a XSEG frag for it: caller may do that.
294 * Just return it as never seen before.
296 name = local_label_name((int)number, 1);
297 symbolP = symbol_find_or_make(name);
298 /* We have no need to check symbol properties. */
299 #ifndef MANY_SEGMENTS
300 /* Since "know" puts its arg into a "string", we
301 can't have newlines in the argument. */
302 know(S_GET_SEGMENT(symbolP) == SEG_UNKNOWN || S_GET_SEGMENT(symbolP) == SEG_TEXT || S_GET_SEGMENT(symbolP) == SEG_DATA);
304 expressionP->X_add_symbol = symbolP;
305 expressionP->X_seg = SEG_UNKNOWN;
306 expressionP->X_subtract_symbol = NULL;
307 expressionP->X_add_number = 0;
310 { /* Really a number, not a local label. */
311 expressionP->X_add_number = number;
312 expressionP->X_seg = SEG_ABSOLUTE;
313 input_line_pointer--; /* Restore following character. */
314 } /* if (c == 'f') */
315 } /* if (c == 'b') */
318 { /* Really a number. */
319 expressionP->X_add_number = number;
320 expressionP->X_seg = SEG_ABSOLUTE;
321 input_line_pointer--; /* Restore following character. */
322 } /* if (number<10) */
326 expressionP->X_add_number = number;
327 expressionP->X_seg = SEG_BIG;
328 input_line_pointer --; /*->char following number. */
330 } /* (If integer constant) */
332 { /* input_line_pointer->*/
333 /* floating-point constant. */
336 error_code = atof_generic
337 (& input_line_pointer, ".", EXP_CHARS,
338 & generic_floating_point_number);
342 if (error_code == ERROR_EXPONENT_OVERFLOW)
344 as_bad("Bad floating-point constant: exponent overflow, probably assembling junk");
348 as_bad("Bad floating-point constant: unknown error code=%d.", error_code);
351 expressionP->X_seg = SEG_BIG;
352 /* input_line_pointer->just after constant, */
353 /* which may point to whitespace. */
354 know(expressionP->X_add_number < 0); /* < 0 means "floating point". */
355 } /* if (not floating-point constant) */
357 else if (c == '.' && !is_part_of_name(*input_line_pointer)) {
358 extern struct obstack frags;
361 JF: '.' is pseudo symbol with value of current location in current
364 symbolP = symbol_new("\001L0",
366 (valueT)(obstack_next_free(&frags)-frag_now->fr_literal),
369 expressionP->X_add_number=0;
370 expressionP->X_add_symbol=symbolP;
371 expressionP->X_seg = now_seg;
373 } else if (is_name_beginner(c)) { /* here if did not begin with a digit */
376 * Identifier begins here.
377 * This is kludged for speed, so code is repeated.
379 name = input_line_pointer - 1;
380 c = get_symbol_end();
381 symbolP = symbol_find_or_make(name);
383 * If we have an absolute symbol or a reg, then we know its value now.
385 expressionP->X_seg = S_GET_SEGMENT(symbolP);
386 switch (expressionP->X_seg)
390 expressionP->X_add_number = S_GET_VALUE(symbolP);
394 expressionP->X_add_number = 0;
396 if (symbolP == GOT_symbol) {
397 expressionP->X_got_symbol = symbolP;
401 expressionP->X_add_symbol = symbolP;
403 *input_line_pointer = c;
404 expressionP->X_subtract_symbol = NULL;
405 } else if (c == '(' || c == '[') {/* didn't begin with digit & not a name */
406 (void)expression(expressionP);
407 /* Expression() will pass trailing whitespace */
408 if (c == '(' && *input_line_pointer++ != ')' ||
409 c == '[' && *input_line_pointer++ != ']') {
410 as_bad("Missing ')' assumed");
411 input_line_pointer--;
413 /* here with input_line_pointer->char after "(...)" */
414 } else if (c == '~' || c == '-' || c == '+') {
415 /* unary operator: hope for SEG_ABSOLUTE */
416 switch (operand (expressionP)) {
418 /* input_line_pointer->char after operand */
420 expressionP->X_add_number = - expressionP->X_add_number;
422 * Notice: '-' may overflow: no warning is given. This is compatible
423 * with other people's assemblers. Sigh.
425 } else if (c == '~') {
426 expressionP->X_add_number = ~ expressionP->X_add_number;
427 } else if (c != '+') {
429 } /* switch on unary operator */
432 default: /* unary on non-absolute is unsuported */
433 if (!SEG_NORMAL(operand(expressionP)))
435 as_bad("Unary operator %c ignored because bad operand follows", c);
438 /* Fall through for normal segments ****/
441 if (c == '-') { /* JF I hope this hack works */
442 expressionP->X_subtract_symbol=expressionP->X_add_symbol;
443 expressionP->X_add_symbol=0;
444 expressionP->X_seg=SEG_DIFFERENCE;
447 /* Expression undisturbed from operand(). */
453 * Warning: to conform to other people's assemblers NO ESCAPEMENT is permitted
454 * for a single quote. The next character, parity errors and all, is taken
455 * as the value of the operand. VERY KINKY.
457 expressionP->X_add_number = * input_line_pointer ++;
458 expressionP->X_seg = SEG_ABSOLUTE;
462 /* can't imagine any other kind of operand */
463 expressionP->X_seg = SEG_ABSENT;
464 input_line_pointer --;
465 md_operand (expressionP);
468 * It is more 'efficient' to clean up the expressions when they are created.
469 * Doing it here saves lines of code.
471 clean_up_expression(expressionP);
472 SKIP_WHITESPACE(); /*->1st char after operand. */
473 know(*input_line_pointer != ' ');
474 return(expressionP->X_seg);
477 /* Internal. Simplify a struct expression for use by expr() */
480 * In: address of a expressionS.
481 * The X_seg field of the expressionS may only take certain values.
482 * Now, we permit SEG_PASS1 to make code smaller & faster.
483 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
484 * Out: expressionS may have been modified:
485 * 'foo-foo' symbol references cancelled to 0,
486 * which changes X_seg from SEG_DIFFERENCE to SEG_ABSOLUTE;
487 * Unused fields zeroed to help expr().
491 clean_up_expression (expressionP)
492 register expressionS *expressionP;
494 switch (expressionP->X_seg) {
497 expressionP->X_add_symbol = NULL;
498 expressionP->X_subtract_symbol = NULL;
499 expressionP->X_add_number = 0;
504 expressionP->X_subtract_symbol = NULL;
505 expressionP->X_add_symbol = NULL;
509 expressionP->X_subtract_symbol = NULL;
514 * It does not hurt to 'cancel' NULL == NULL
515 * when comparing symbols for 'eq'ness.
516 * It is faster to re-cancel them to NULL
517 * than to check for this special case.
519 if (expressionP->X_subtract_symbol == expressionP->X_add_symbol
520 || (expressionP->X_subtract_symbol
521 && expressionP->X_add_symbol
522 && expressionP->X_subtract_symbol->sy_frag == expressionP->X_add_symbol->sy_frag
523 && S_GET_VALUE(expressionP->X_subtract_symbol) == S_GET_VALUE(expressionP->X_add_symbol))) {
524 expressionP->X_subtract_symbol = NULL;
525 expressionP->X_add_symbol = NULL;
526 expressionP->X_seg = SEG_ABSOLUTE;
531 expressionP->X_add_symbol = NULL;
532 expressionP->X_subtract_symbol = NULL;
536 if (SEG_NORMAL(expressionP->X_seg)) {
537 expressionP->X_subtract_symbol = NULL;
540 BAD_CASE (expressionP->X_seg);
544 } /* clean_up_expression() */
549 * Internal. Made a function because this code is used in 2 places.
550 * Generate error or correct X_?????_symbol of expressionS.
554 * symbol_1 += symbol_2 ... well ... sort of.
558 expr_part (symbol_1_PP, symbol_2_P)
559 symbolS ** symbol_1_PP;
560 symbolS * symbol_2_P;
563 #ifndef MANY_SEGMENTS
564 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)));
565 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)));
569 if (!S_IS_DEFINED(* symbol_1_PP))
573 return_value = SEG_PASS1;
574 * symbol_1_PP = NULL;
578 know(!S_IS_DEFINED(* symbol_1_PP));
579 return_value = SEG_UNKNOWN;
586 if (!S_IS_DEFINED(symbol_2_P))
588 * symbol_1_PP = NULL;
589 return_value = SEG_PASS1;
593 /* {seg1} - {seg2} */
594 as_bad("Expression too complex, 2 symbols forgotten: \"%s\" \"%s\"",
595 S_GET_NAME(* symbol_1_PP), S_GET_NAME(symbol_2_P));
596 * symbol_1_PP = NULL;
597 return_value = SEG_ABSOLUTE;
602 return_value = S_GET_SEGMENT(* symbol_1_PP);
607 { /* (* symbol_1_PP) == NULL */
610 * symbol_1_PP = symbol_2_P;
611 return_value = S_GET_SEGMENT(symbol_2_P);
615 * symbol_1_PP = NULL;
616 return_value = SEG_ABSOLUTE;
619 #ifndef MANY_SEGMENTS
620 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);
622 know((*symbol_1_PP) == NULL || (S_GET_SEGMENT(*symbol_1_PP) == return_value));
623 return (return_value);
629 fprintf (stdout, "%s type %s%s",
631 S_IS_EXTERNAL(s) ? "EXTERNAL " : "",
632 segment_name(S_GET_SEGMENT(s)));
637 fprintf (stdout, " segment %s\n", segment_name (e->X_seg));
638 fprintf (stdout, " add_number %ld (%lx)\n",
639 e->X_add_number, e->X_add_number);
640 if (e->X_add_symbol) {
641 fprintf (stdout, " add_symbol ");
642 ps (e->X_add_symbol);
643 fprintf (stdout, "\n");
645 if (e->X_subtract_symbol) {
646 fprintf (stdout, " sub_symbol ");
647 ps (e->X_subtract_symbol);
648 fprintf (stdout, "\n");
652 /* Expression parser. */
655 * We allow an empty expression, and just assume (absolute,0) silently.
656 * Unary operators and parenthetical expressions are treated as operands.
657 * As usual, Q == quantity == operand, O == operator, X == expression mnemonics.
659 * We used to do a aho/ullman shift-reduce parser, but the logic got so
660 * warped that I flushed it and wrote a recursive-descent parser instead.
661 * Now things are stable, would anybody like to write a fast parser?
662 * Most expressions are either register (which does not even reach here)
663 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
664 * So I guess it doesn't really matter how inefficient more complex expressions
667 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
668 * Also, we have consumed any leading or trailing spaces (operand does that)
669 * and done all intervening operators.
674 O_illegal, /* (0) what we get for illegal op */
676 O_multiply, /* (1) * */
677 O_divide, /* (2) / */
678 O_modulus, /* (3) % */
679 O_left_shift, /* (4) < */
680 O_right_shift, /* (5) > */
681 O_bit_inclusive_or, /* (6) | */
682 O_bit_or_not, /* (7) ! */
683 O_bit_exclusive_or, /* (8) ^ */
684 O_bit_and, /* (9) & */
686 O_subtract /* (11) - */
692 static const operatorT op_encoding[256] = { /* maps ASCII->operators */
694 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
695 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
697 __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
698 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
699 __, __, __, __, __, __, __, __,
700 __, __, __, __, O_left_shift, __, O_right_shift, __,
701 __, __, __, __, __, __, __, __,
702 __, __, __, __, __, __, __, __,
703 __, __, __, __, __, __, __, __,
704 __, __, __, __, __, __, O_bit_exclusive_or, __,
705 __, __, __, __, __, __, __, __,
706 __, __, __, __, __, __, __, __,
707 __, __, __, __, __, __, __, __,
708 __, __, __, __, O_bit_inclusive_or, __, __, __,
710 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
711 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
712 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
713 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
714 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
715 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
716 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
717 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
723 * 0 operand, (expression)
728 static const operator_rankT
729 op_rank[] = { 0, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1 };
731 /* Return resultP->X_seg. */
732 segT expr(rank, resultP)
733 register operator_rankT rank; /* Larger # is higher rank. */
734 register expressionS *resultP; /* Deliver result here. */
737 register operatorT op_left;
738 register char c_left; /* 1st operator character. */
739 register operatorT op_right;
740 register char c_right;
743 (void) operand(resultP);
744 know(*input_line_pointer != ' '); /* Operand() gobbles spaces. */
745 c_left = *input_line_pointer; /* Potential operator character. */
746 op_left = op_encoding[c_left];
748 while (op_left != O_illegal && op_rank[(int) op_left] > rank) {
749 input_line_pointer++; /*->after 1st character of operator. */
751 /* Operators "<<" and ">>" have 2 characters. */
752 if (*input_line_pointer == c_left && (c_left == '<' || c_left == '>')) {
753 input_line_pointer ++;
754 } /*->after operator. */
755 if (SEG_ABSENT == expr (op_rank[(int) op_left], &right)) {
756 as_warn("Missing operand value assumed absolute 0.");
757 resultP->X_add_number = 0;
758 resultP->X_subtract_symbol = NULL;
759 resultP->X_add_symbol = NULL;
760 resultP->X_seg = SEG_ABSOLUTE;
763 know(*input_line_pointer != ' ');
764 c_right = *input_line_pointer;
765 op_right = op_encoding[c_right];
767 if (*input_line_pointer == c_right && (c_right == '<' || c_right == '>')) {
768 input_line_pointer ++;
769 } /*->after operator. */
771 know((int) op_right == 0 || op_rank[(int) op_right] <= op_rank[(int) op_left]);
772 /* input_line_pointer->after right-hand quantity. */
773 /* left-hand quantity in resultP */
774 /* right-hand quantity in right. */
775 /* operator in op_left. */
776 if (resultP->X_seg == SEG_PASS1 || right.X_seg == SEG_PASS1) {
777 resultP->X_seg = SEG_PASS1;
779 if (resultP->X_seg == SEG_BIG) {
780 as_warn("Left operand of %c is a %s. Integer 0 assumed.",
781 c_left, resultP->X_add_number > 0 ? "bignum" : "float");
782 resultP->X_seg = SEG_ABSOLUTE;
783 resultP->X_add_symbol = 0;
784 resultP->X_subtract_symbol = 0;
785 resultP->X_add_number = 0;
787 if (right.X_seg == SEG_BIG) {
788 as_warn("Right operand of %c is a %s. Integer 0 assumed.",
789 c_left, right.X_add_number > 0 ? "bignum" : "float");
790 right.X_seg = SEG_ABSOLUTE;
791 right.X_add_symbol = 0;
792 right.X_subtract_symbol = 0;
793 right.X_add_number = 0;
795 if (op_left == O_subtract) {
797 * Convert - into + by exchanging symbols and negating number.
798 * I know -infinity can't be negated in 2's complement:
799 * but then it can't be subtracted either. This trick
800 * does not cause any further inaccuracy.
803 register symbolS * symbolP;
805 right.X_add_number = - right.X_add_number;
806 symbolP = right.X_add_symbol;
807 right.X_add_symbol = right.X_subtract_symbol;
808 right.X_subtract_symbol = symbolP;
810 right.X_seg = SEG_DIFFERENCE;
815 if (op_left == O_add) {
818 #ifndef MANY_SEGMENTS
819 know(resultP->X_seg == SEG_DATA
820 || resultP->X_seg == SEG_TEXT
821 || resultP->X_seg == SEG_BSS
822 || resultP->X_seg == SEG_UNKNOWN
823 || resultP->X_seg == SEG_DIFFERENCE
824 || resultP->X_seg == SEG_ABSOLUTE
825 || resultP->X_seg == SEG_PASS1);
826 know(right.X_seg == SEG_DATA
827 || right.X_seg == SEG_TEXT
828 || right.X_seg == SEG_BSS
829 || right.X_seg == SEG_UNKNOWN
830 || right.X_seg == SEG_DIFFERENCE
831 || right.X_seg == SEG_ABSOLUTE
832 || right.X_seg == SEG_PASS1);
834 clean_up_expression(& right);
835 clean_up_expression(resultP);
838 /* XXX - kludge here to accomodate "_GLOBAL_OFFSET_TABLE + (x - y)"
839 * expressions: this only works for this special case, the
840 * _GLOBAL_OFFSET_TABLE thing *must* be the left operand, the whole
841 * expression is given the segment of right expression (always a DIFFERENCE,
842 * which should get resolved by fixup_segment())
844 if (resultP->X_got_symbol) {
845 resultP->X_add_symbol = right.X_add_symbol;
846 resultP->X_subtract_symbol = right.X_subtract_symbol;
847 seg1 = S_GET_SEGMENT(right.X_add_symbol);
848 seg2 = S_GET_SEGMENT(right.X_subtract_symbol);
849 resultP->X_seg = right.X_seg;
852 seg1 = expr_part(&resultP->X_add_symbol, right.X_add_symbol);
853 seg2 = expr_part(&resultP->X_subtract_symbol, right.X_subtract_symbol);
857 if (seg1 == SEG_PASS1 || seg2 == SEG_PASS1) {
859 resultP->X_seg = SEG_PASS1;
860 } else if (seg2 == SEG_ABSOLUTE)
861 resultP->X_seg = seg1;
862 else if (seg1 != SEG_UNKNOWN
863 && seg1 != SEG_ABSOLUTE
864 && seg2 != SEG_UNKNOWN
866 know(seg2 != SEG_ABSOLUTE);
867 know(resultP->X_subtract_symbol);
868 #ifndef MANY_SEGMENTS
869 know(seg1 == SEG_TEXT || seg1 == SEG_DATA || seg1 == SEG_BSS);
870 know(seg2 == SEG_TEXT || seg2 == SEG_DATA || seg2 == SEG_BSS);
872 know(resultP->X_add_symbol);
873 know(resultP->X_subtract_symbol);
874 as_bad("Expression too complex: forgetting %s - %s",
875 S_GET_NAME(resultP->X_add_symbol),
876 S_GET_NAME(resultP->X_subtract_symbol));
877 resultP->X_seg = SEG_ABSOLUTE;
878 /* Clean_up_expression() will do the rest. */
880 resultP->X_seg = SEG_DIFFERENCE;
882 resultP->X_add_number += right.X_add_number;
883 clean_up_expression(resultP);
884 } else { /* Not +. */
885 if (resultP->X_seg == SEG_UNKNOWN || right.X_seg == SEG_UNKNOWN) {
886 resultP->X_seg = SEG_PASS1;
889 resultP->X_subtract_symbol = NULL;
890 resultP->X_add_symbol = NULL;
892 /* Will be SEG_ABSOLUTE. */
893 if (resultP->X_seg != SEG_ABSOLUTE || right.X_seg != SEG_ABSOLUTE) {
894 as_bad("Relocation error. Absolute 0 assumed.");
895 resultP->X_seg = SEG_ABSOLUTE;
896 resultP->X_add_number = 0;
899 case O_bit_inclusive_or:
900 resultP->X_add_number |= right.X_add_number;
904 if (right.X_add_number) {
905 resultP->X_add_number %= right.X_add_number;
907 as_warn("Division by 0. 0 assumed.");
908 resultP->X_add_number = 0;
913 resultP->X_add_number &= right.X_add_number;
917 resultP->X_add_number *= right.X_add_number;
921 if (right.X_add_number) {
922 resultP->X_add_number /= right.X_add_number;
924 as_warn("Division by 0. 0 assumed.");
925 resultP->X_add_number = 0;
930 resultP->X_add_number <<= right.X_add_number;
934 resultP->X_add_number >>= right.X_add_number;
937 case O_bit_exclusive_or:
938 resultP->X_add_number ^= right.X_add_number;
942 resultP->X_add_number |= ~ right.X_add_number;
948 } /* switch (operator) */
950 } /* If we have to force need_pass_2. */
951 } /* If operator was +. */
952 } /* If we didn't set need_pass_2. */
954 } /* While next operator is >= this rank. */
956 return(resultP->X_seg);
962 * This lives here because it belongs equally in expr.c & read.c.
963 * Expr.c is just a branch office read.c anyway, and putting it
964 * here lessens the crowd at read.c.
966 * Assume input_line_pointer is at start of symbol name.
967 * Advance input_line_pointer past symbol name.
968 * Turn that character into a '\0', returning its former value.
969 * This allows a string compare (RMS wants symbol names to be strings)
970 * of the symbol name.
971 * There will always be a char following symbol name, because all good
972 * lines end in end-of-line.
979 while (is_part_of_name(c = *input_line_pointer++)) ;;
980 *--input_line_pointer = 0;
985 unsigned int get_single_number()
989 return exp.X_add_number;