* hppa-tdep.c (frame_saved_pc): Don't try to dig a return pointer
[deliverable/binutils-gdb.git] / gas / expr.c
CommitLineData
fecd2382 1/* expr.c -operands, expressions-
d90f530b 2 Copyright (C) 1987, 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
2ed83a59 3
a39116f1 4 This file is part of GAS, the GNU Assembler.
2ed83a59 5
a39116f1
RP
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)
9 any later version.
2ed83a59 10
a39116f1
RP
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.
2ed83a59 15
a39116f1
RP
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
219deb70 18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
fecd2382
RP
19
20/*
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.
25 */
26
27#include <ctype.h>
28#include <string.h>
29
30#include "as.h"
3a762a0b 31#include "libiberty.h"
fecd2382
RP
32#include "obstack.h"
33
d4c8cbd8
JL
34static void floating_constant PARAMS ((expressionS * expressionP));
35static void integer_constant PARAMS ((int radix, expressionS * expressionP));
219deb70 36static void mri_char_constant PARAMS ((expressionS *));
f2f7d044 37static void clean_up_expression PARAMS ((expressionS * expressionP));
5ac34ac3 38
f2f7d044 39extern const char EXP_CHARS[], FLT_CHARS[];
5ac34ac3
ILT
40\f
41/* Build a dummy symbol to hold a complex expression. This is how we
42 build expressions up out of other expressions. The symbol is put
43 into the fake section expr_section. */
44
3a762a0b 45symbolS *
5ac34ac3
ILT
46make_expr_symbol (expressionP)
47 expressionS *expressionP;
48{
49 const char *fake;
50 symbolS *symbolP;
fecd2382 51
d90f530b
KR
52 if (expressionP->X_op == O_symbol
53 && expressionP->X_add_number == 0)
54 return expressionP->X_add_symbol;
55
5ac34ac3
ILT
56 /* FIXME: This should be something which decode_local_label_name
57 will handle. */
d4c8cbd8
JL
58 fake = FAKE_LABEL_NAME;
59
5ac34ac3
ILT
60 /* Putting constant symbols in absolute_section rather than
61 expr_section is convenient for the old a.out code, for which
62 S_GET_SEGMENT does not always retrieve the value put in by
63 S_SET_SEGMENT. */
3a762a0b
KR
64 symbolP = symbol_create (fake,
65 (expressionP->X_op == O_constant
66 ? absolute_section
67 : expr_section),
68 0, &zero_address_frag);
5ac34ac3 69 symbolP->sy_value = *expressionP;
d90f530b
KR
70
71 if (expressionP->X_op == O_constant)
72 resolve_symbol_value (symbolP);
73
5ac34ac3
ILT
74 return symbolP;
75}
76\f
fecd2382
RP
77/*
78 * Build any floating-point literal here.
79 * Also build any bignum literal here.
80 */
81
fecd2382
RP
82/* Seems atof_machine can backscan through generic_bignum and hit whatever
83 happens to be loaded before it in memory. And its way too complicated
84 for me to fix right. Thus a hack. JF: Just make generic_bignum bigger,
85 and never write into the early words, thus they'll always be zero.
f2f7d044 86 I hate Dean's floating-point code. Bleh. */
2ed83a59
KR
87LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
88FLONUM_TYPE generic_floating_point_number =
fecd2382 89{
2ed83a59 90 &generic_bignum[6], /* low (JF: Was 0) */
351878df 91 &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high JF: (added +6) */
2ed83a59
KR
92 0, /* leader */
93 0, /* exponent */
94 0 /* sign */
95};
fecd2382
RP
96/* If nonzero, we've been asked to assemble nan, +inf or -inf */
97int generic_floating_point_magic;
98\f
d4c8cbd8 99static void
2ed83a59
KR
100floating_constant (expressionP)
101 expressionS *expressionP;
c593cf41
SC
102{
103 /* input_line_pointer->*/
104 /* floating-point constant. */
105 int error_code;
106
351878df
KR
107 error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
108 &generic_floating_point_number);
c593cf41
SC
109
110 if (error_code)
c593cf41 111 {
2ed83a59
KR
112 if (error_code == ERROR_EXPONENT_OVERFLOW)
113 {
114 as_bad ("bad floating-point constant: exponent overflow, probably assembling junk");
115 }
116 else
117 {
118 as_bad ("bad floating-point constant: unknown error code=%d.", error_code);
119 }
c593cf41 120 }
5ac34ac3 121 expressionP->X_op = O_big;
c593cf41
SC
122 /* input_line_pointer->just after constant, */
123 /* which may point to whitespace. */
2ed83a59 124 expressionP->X_add_number = -1;
c593cf41
SC
125}
126
d4c8cbd8 127static void
2ed83a59
KR
128integer_constant (radix, expressionP)
129 int radix;
130 expressionS *expressionP;
c593cf41 131{
7691379e 132 char *start; /* start of number. */
219deb70 133 char *suffix = NULL;
c593cf41 134 char c;
dae92eab
KR
135 valueT number; /* offset or (absolute) value */
136 short int digit; /* value of next digit in current radix */
137 short int maxdig = 0;/* highest permitted digit value. */
138 int too_many_digits = 0; /* if we see >= this number of */
139 char *name; /* points to name of symbol */
140 symbolS *symbolP; /* points to symbol */
2ed83a59
KR
141
142 int small; /* true if fits in 32 bits. */
2ed83a59 143
dae92eab
KR
144 /* May be bignum, or may fit in 32 bits. */
145 /* Most numbers fit into 32 bits, and we want this case to be fast.
146 so we pretend it will fit into 32 bits. If, after making up a 32
147 bit number, we realise that we have scanned more digits than
148 comfortably fit into 32 bits, we re-scan the digits coding them
149 into a bignum. For decimal and octal numbers we are
150 conservative: Some numbers may be assumed bignums when in fact
151 they do fit into 32 bits. Numbers of any radix can have excess
152 leading zeros: We strive to recognise this and cast them back
153 into 32 bits. We must check that the bignum really is more than
154 32 bits, and change it back to a 32-bit number if it fits. The
155 number we are looking for is expected to be positive, but if it
156 fits into 32 bits as an unsigned number, we let it be a 32-bit
157 number. The cavalier approach is for speed in ordinary cases. */
58d4951d
ILT
158 /* This has been extended for 64 bits. We blindly assume that if
159 you're compiling in 64-bit mode, the target is a 64-bit machine.
160 This should be cleaned up. */
161
162#ifdef BFD64
163#define valuesize 64
164#else /* includes non-bfd case, mostly */
165#define valuesize 32
166#endif
2ed83a59 167
219deb70
ILT
168 if (flag_mri && radix == 0)
169 {
170 int flt = 0;
171
172 /* In MRI mode, the number may have a suffix indicating the
173 radix. For that matter, it might actually be a floating
174 point constant. */
175 for (suffix = input_line_pointer; isalnum (*suffix); suffix++)
176 {
177 if (*suffix == 'e' || *suffix == 'E')
178 flt = 1;
179 }
180
181 if (suffix == input_line_pointer)
182 {
183 radix = 10;
184 suffix = NULL;
185 }
186 else
187 {
188 c = *--suffix;
189 if (islower (c))
190 c = toupper (c);
191 if (c == 'B')
192 radix = 2;
193 else if (c == 'D')
194 radix = 10;
195 else if (c == 'O' || c == 'Q')
196 radix = 8;
197 else if (c == 'H')
198 radix = 16;
199 else if (suffix[1] == '.' || c == 'E' || flt)
200 {
201 floating_constant (expressionP);
202 return;
203 }
204 else
205 {
206 radix = 10;
207 suffix = NULL;
208 }
209 }
210 }
211
2ed83a59 212 switch (radix)
f8701a3f 213 {
f8701a3f
SC
214 case 2:
215 maxdig = 2;
58d4951d 216 too_many_digits = valuesize + 1;
f8701a3f
SC
217 break;
218 case 8:
219 maxdig = radix = 8;
7691379e 220 too_many_digits = (valuesize + 2) / 3 + 1;
f8701a3f
SC
221 break;
222 case 16:
f8701a3f 223 maxdig = radix = 16;
7691379e 224 too_many_digits = (valuesize + 3) / 4 + 1;
f8701a3f
SC
225 break;
226 case 10:
227 maxdig = radix = 10;
58d4951d 228 too_many_digits = (valuesize + 12) / 4; /* very rough */
f8701a3f 229 }
58d4951d 230#undef valuesize
7691379e
KR
231 start = input_line_pointer;
232 c = *input_line_pointer++;
58d4951d 233 for (number = 0;
3a762a0b 234 (digit = hex_value (c)) < maxdig;
58d4951d 235 c = *input_line_pointer++)
f8701a3f
SC
236 {
237 number = number * radix + digit;
238 }
c593cf41
SC
239 /* c contains character after number. */
240 /* input_line_pointer->char after c. */
7691379e 241 small = (input_line_pointer - start - 1) < too_many_digits;
2ed83a59 242 if (!small)
c593cf41 243 {
f8701a3f
SC
244 /*
245 * we saw a lot of digits. manufacture a bignum the hard way.
246 */
2ed83a59
KR
247 LITTLENUM_TYPE *leader; /*->high order littlenum of the bignum. */
248 LITTLENUM_TYPE *pointer; /*->littlenum we are frobbing now. */
f8701a3f 249 long carry;
2ed83a59 250
f8701a3f 251 leader = generic_bignum;
2ed83a59
KR
252 generic_bignum[0] = 0;
253 generic_bignum[1] = 0;
7691379e 254 input_line_pointer = start; /*->1st digit. */
f8701a3f 255 c = *input_line_pointer++;
58d4951d 256 for (;
3a762a0b 257 (carry = hex_value (c)) < maxdig;
58d4951d 258 c = *input_line_pointer++)
f8701a3f
SC
259 {
260 for (pointer = generic_bignum;
261 pointer <= leader;
262 pointer++)
263 {
264 long work;
2ed83a59
KR
265
266 work = carry + radix * *pointer;
f8701a3f
SC
267 *pointer = work & LITTLENUM_MASK;
268 carry = work >> LITTLENUM_NUMBER_OF_BITS;
269 }
270 if (carry)
271 {
272 if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
351878df
KR
273 {
274 /* room to grow a longer bignum. */
f8701a3f
SC
275 *++leader = carry;
276 }
277 }
278 }
279 /* again, c is char after number, */
280 /* input_line_pointer->after c. */
2ed83a59 281 know (LITTLENUM_NUMBER_OF_BITS == 16);
7691379e 282 if (leader < generic_bignum + 2)
351878df
KR
283 {
284 /* will fit into 32 bits. */
f8701a3f 285 number =
2ed83a59
KR
286 ((generic_bignum[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
287 | (generic_bignum[0] & LITTLENUM_MASK);
f8701a3f
SC
288 small = 1;
289 }
290 else
291 {
2ed83a59 292 number = leader - generic_bignum + 1; /* number of littlenums in the bignum. */
c593cf41 293 }
c593cf41 294 }
219deb70
ILT
295
296 if (flag_mri && suffix != NULL && input_line_pointer - 1 == suffix)
297 c = *input_line_pointer++;
298
2ed83a59
KR
299 if (small)
300 {
f8701a3f 301 /*
2ed83a59
KR
302 * here with number, in correct radix. c is the next char.
303 * note that unlike un*x, we allow "011f" "0x9f" to
304 * both mean the same as the (conventional) "9f". this is simply easier
305 * than checking for strict canonical form. syntax sux!
f8701a3f 306 */
2ed83a59 307
219deb70 308 if (LOCAL_LABELS_FB && c == 'b')
2ed83a59 309 {
219deb70
ILT
310 /*
311 * backward ref to local label.
312 * because it is backward, expect it to be defined.
313 */
314 /* Construct a local label. */
315 name = fb_label_name ((int) number, 0);
2ed83a59 316
219deb70
ILT
317 /* seen before, or symbol is defined: ok */
318 symbolP = symbol_find (name);
319 if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
320 {
321 /* local labels are never absolute. don't waste time
322 checking absoluteness. */
323 know (SEG_NORMAL (S_GET_SEGMENT (symbolP)));
2ed83a59 324
219deb70
ILT
325 expressionP->X_op = O_symbol;
326 expressionP->X_add_symbol = symbolP;
327 }
328 else
329 {
330 /* either not seen or not defined. */
331 /* @@ Should print out the original string instead of
332 the parsed number. */
333 as_bad ("backw. ref to unknown label \"%d:\", 0 assumed.",
334 (int) number);
335 expressionP->X_op = O_constant;
336 }
2ed83a59 337
219deb70
ILT
338 expressionP->X_add_number = 0;
339 } /* case 'b' */
340 else if (LOCAL_LABELS_FB && c == 'f')
341 {
342 /*
343 * forward reference. expect symbol to be undefined or
344 * unknown. undefined: seen it before. unknown: never seen
345 * it before.
346 * construct a local label name, then an undefined symbol.
347 * don't create a xseg frag for it: caller may do that.
348 * just return it as never seen before.
349 */
350 name = fb_label_name ((int) number, 1);
351 symbolP = symbol_find_or_make (name);
352 /* we have no need to check symbol properties. */
c593cf41 353#ifndef many_segments
219deb70
ILT
354 /* since "know" puts its arg into a "string", we
355 can't have newlines in the argument. */
356 know (S_GET_SEGMENT (symbolP) == undefined_section || S_GET_SEGMENT (symbolP) == text_section || S_GET_SEGMENT (symbolP) == data_section);
c593cf41 357#endif
219deb70
ILT
358 expressionP->X_op = O_symbol;
359 expressionP->X_add_symbol = symbolP;
360 expressionP->X_add_number = 0;
361 } /* case 'f' */
362 else if (LOCAL_LABELS_DOLLAR && c == '$')
363 {
364 /* If the dollar label is *currently* defined, then this is just
365 another reference to it. If it is not *currently* defined,
366 then this is a fresh instantiation of that number, so create
367 it. */
2ed83a59 368
219deb70
ILT
369 if (dollar_label_defined ((long) number))
370 {
371 name = dollar_label_name ((long) number, 0);
372 symbolP = symbol_find (name);
373 know (symbolP != NULL);
374 }
375 else
376 {
377 name = dollar_label_name ((long) number, 1);
378 symbolP = symbol_find_or_make (name);
379 }
2ed83a59 380
219deb70
ILT
381 expressionP->X_op = O_symbol;
382 expressionP->X_add_symbol = symbolP;
383 expressionP->X_add_number = 0;
384 } /* case '$' */
385 else
386 {
387 expressionP->X_op = O_constant;
388#ifdef TARGET_WORD_SIZE
389 /* Sign extend NUMBER. */
390 number |= (-(number >> (TARGET_WORD_SIZE - 1))) << (TARGET_WORD_SIZE - 1);
391#endif
392 expressionP->X_add_number = number;
393 input_line_pointer--; /* restore following character. */
394 } /* really just a number */
395 }
396 else
397 {
398 /* not a small number */
399 expressionP->X_op = O_big;
400 expressionP->X_add_number = number; /* number of littlenums */
401 input_line_pointer--; /*->char following number. */
402 }
403}
2ed83a59 404
219deb70 405/* Parse an MRI multi character constant. */
f8701a3f 406
219deb70
ILT
407static void
408mri_char_constant (expressionP)
409 expressionS *expressionP;
410{
411 int i;
2ed83a59 412
219deb70
ILT
413 if (*input_line_pointer == '\''
414 && input_line_pointer[1] != '\'')
415 {
416 expressionP->X_op = O_constant;
417 expressionP->X_add_number = 0;
418 return;
419 }
2ed83a59 420
219deb70
ILT
421 /* In order to get the correct byte ordering, we must build the
422 number in reverse. */
423 for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
424 {
425 int j;
2ed83a59 426
219deb70
ILT
427 generic_bignum[i] = 0;
428 for (j = 0; j < CHARS_PER_LITTLENUM; j++)
429 {
430 if (*input_line_pointer == '\'')
431 {
432 if (input_line_pointer[1] != '\'')
433 break;
434 ++input_line_pointer;
435 }
436 generic_bignum[i] <<= 8;
437 generic_bignum[i] += *input_line_pointer;
438 ++input_line_pointer;
439 }
2ed83a59 440
219deb70
ILT
441 if (i < SIZE_OF_LARGE_NUMBER - 1)
442 {
443 /* If there is more than one littlenum, left justify the
444 last one to make it match the earlier ones. If there is
445 only one, we can just use the value directly. */
446 for (; j < CHARS_PER_LITTLENUM; j++)
447 generic_bignum[i] <<= 8;
448 }
2ed83a59 449
219deb70
ILT
450 if (*input_line_pointer == '\''
451 && input_line_pointer[1] != '\'')
452 break;
453 }
2ed83a59 454
219deb70
ILT
455 if (i < 0)
456 {
457 as_bad ("Character constant too large");
458 i = 0;
459 }
2ed83a59 460
219deb70
ILT
461 if (i > 0)
462 {
463 int c;
464 int j;
2ed83a59 465
219deb70
ILT
466 c = SIZE_OF_LARGE_NUMBER - i;
467 for (j = 0; j < c; j++)
468 generic_bignum[j] = generic_bignum[i + j];
469 i = c;
2ed83a59 470 }
219deb70
ILT
471
472 know (LITTLENUM_NUMBER_OF_BITS == 16);
473 if (i > 2)
dae92eab 474 {
5ac34ac3 475 expressionP->X_op = O_big;
219deb70
ILT
476 expressionP->X_add_number = i;
477 }
478 else
479 {
480 expressionP->X_op = O_constant;
481 if (i < 2)
482 expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
483 else
484 expressionP->X_add_number =
485 (((generic_bignum[1] & LITTLENUM_MASK)
486 << LITTLENUM_NUMBER_OF_BITS)
487 | (generic_bignum[0] & LITTLENUM_MASK));
dae92eab 488 }
c593cf41 489
219deb70
ILT
490 /* Skip the final closing quote. */
491 ++input_line_pointer;
492}
c593cf41 493
fecd2382
RP
494/*
495 * Summary of operand().
496 *
497 * in: Input_line_pointer points to 1st char of operand, which may
498 * be a space.
499 *
5ac34ac3
ILT
500 * out: A expressionS.
501 * The operand may have been empty: in this case X_op == O_absent.
fecd2382 502 * Input_line_pointer->(next non-blank) char after operand.
fecd2382 503 */
c593cf41 504
fecd2382 505static segT
c593cf41 506operand (expressionP)
dae92eab 507 expressionS *expressionP;
fecd2382 508{
dae92eab
KR
509 char c;
510 symbolS *symbolP; /* points to symbol */
511 char *name; /* points to name of symbol */
58d4951d 512 segT segment;
c593cf41 513
d4c8cbd8
JL
514 /* All integers are regarded as unsigned unless they are negated.
515 This is because the only thing which cares whether a number is
516 unsigned is the code in emit_expr which extends constants into
517 bignums. It should only sign extend negative numbers, so that
518 something like ``.quad 0x80000000'' is not sign extended even
519 though it appears negative if valueT is 32 bits. */
520 expressionP->X_unsigned = 1;
521
c593cf41
SC
522 /* digits, assume it is a bignum. */
523
2ed83a59
KR
524 SKIP_WHITESPACE (); /* leading whitespace is part of operand. */
525 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
c593cf41
SC
526
527 switch (c)
fecd2382 528 {
c593cf41
SC
529 case '1':
530 case '2':
531 case '3':
532 case '4':
533 case '5':
534 case '6':
535 case '7':
2ed83a59
KR
536 case '8':
537 case '9':
538 input_line_pointer--;
539
219deb70 540 integer_constant (flag_mri ? 0 : 10, expressionP);
c593cf41
SC
541 break;
542
2ed83a59
KR
543 case '0':
544 /* non-decimal radix */
545
219deb70
ILT
546 if (flag_mri)
547 {
548 char *s;
549
550 /* Check for a hex constant. */
551 for (s = input_line_pointer; hex_p (*s); s++)
552 ;
553 if (*s == 'h' || *s == 'H')
554 {
555 --input_line_pointer;
556 integer_constant (0, expressionP);
557 break;
558 }
559 }
560
2ed83a59
KR
561 c = *input_line_pointer;
562 switch (c)
563 {
2ed83a59 564 default:
219deb70 565 default_case:
2ed83a59
KR
566 if (c && strchr (FLT_CHARS, c))
567 {
568 input_line_pointer++;
569 floating_constant (expressionP);
7691379e 570 expressionP->X_add_number = -(isupper (c) ? tolower (c) : c);
2ed83a59
KR
571 }
572 else
573 {
574 /* The string was only zero */
5ac34ac3 575 expressionP->X_op = O_constant;
2ed83a59 576 expressionP->X_add_number = 0;
2ed83a59
KR
577 }
578
579 break;
580
581 case 'x':
582 case 'X':
219deb70
ILT
583 if (flag_mri)
584 goto default_case;
2ed83a59
KR
585 input_line_pointer++;
586 integer_constant (16, expressionP);
587 break;
588
589 case 'b':
219deb70 590 if (LOCAL_LABELS_FB)
2ed83a59 591 {
219deb70
ILT
592 switch (input_line_pointer[1])
593 {
594 case '+':
595 case '-':
596 /* If unambiguously a difference expression, treat
597 it as one by indicating a label; otherwise, it's
598 always a binary number. */
599 {
600 char *cp = input_line_pointer + 1;
601 while (strchr ("0123456789", *++cp))
602 ;
603 if (*cp == 'b' || *cp == 'f')
604 goto is_0b_label;
605 }
606 goto is_0b_binary;
607 case '0': case '1':
608 /* Some of our code elsewhere does permit digits
609 greater than the expected base; for consistency,
610 do the same here. */
611 case '2': case '3': case '4': case '5':
612 case '6': case '7': case '8': case '9':
613 goto is_0b_binary;
614 case 0:
d90f530b 615 goto is_0b_label;
219deb70
ILT
616 default:
617 goto is_0b_label;
618 }
619 is_0b_label:
620 input_line_pointer--;
621 integer_constant (10, expressionP);
622 break;
623 is_0b_binary:
624 ;
2ed83a59 625 }
2ed83a59
KR
626 case 'B':
627 input_line_pointer++;
219deb70
ILT
628 if (flag_mri)
629 goto default_case;
2ed83a59
KR
630 integer_constant (2, expressionP);
631 break;
632
633 case '0':
634 case '1':
635 case '2':
636 case '3':
637 case '4':
638 case '5':
639 case '6':
640 case '7':
219deb70 641 integer_constant (flag_mri ? 0 : 8, expressionP);
2ed83a59
KR
642 break;
643
644 case 'f':
219deb70
ILT
645 if (LOCAL_LABELS_FB)
646 {
647 /* If it says "0f" and it could possibly be a floating point
648 number, make it one. Otherwise, make it a local label,
649 and try to deal with parsing the rest later. */
650 if (!input_line_pointer[1]
651 || (is_end_of_line[0xff & input_line_pointer[1]]))
652 goto is_0f_label;
d90f530b 653 {
219deb70
ILT
654 char *cp = input_line_pointer + 1;
655 int r = atof_generic (&cp, ".", EXP_CHARS,
656 &generic_floating_point_number);
657 switch (r)
658 {
659 case 0:
660 case ERROR_EXPONENT_OVERFLOW:
661 if (*cp == 'f' || *cp == 'b')
662 /* looks like a difference expression */
663 goto is_0f_label;
664 else
665 goto is_0f_float;
666 default:
667 as_fatal ("expr.c(operand): bad atof_generic return val %d",
668 r);
669 }
d90f530b 670 }
d90f530b 671
219deb70
ILT
672 /* Okay, now we've sorted it out. We resume at one of these
673 two labels, depending on what we've decided we're probably
674 looking at. */
675 is_0f_label:
676 input_line_pointer--;
677 integer_constant (10, expressionP);
678 break;
679
680 is_0f_float:
681 /* fall through */
682 ;
683 }
2ed83a59
KR
684
685 case 'd':
686 case 'D':
687 case 'F':
688 case 'r':
689 case 'e':
690 case 'E':
691 case 'g':
692 case 'G':
2ed83a59
KR
693 input_line_pointer++;
694 floating_constant (expressionP);
f2f7d044 695 expressionP->X_add_number = -(isupper (c) ? tolower (c) : c);
2ed83a59
KR
696 break;
697
2ed83a59 698 case '$':
219deb70
ILT
699 if (LOCAL_LABELS_DOLLAR)
700 {
701 integer_constant (10, expressionP);
702 break;
703 }
704 else
705 goto default_case;
2ed83a59
KR
706 }
707
c593cf41 708 break;
5ac34ac3 709
2ed83a59 710 case '(':
d90f530b 711 case '[':
2ed83a59 712 /* didn't begin with digit & not a name */
58d4951d 713 segment = expression (expressionP);
5ac34ac3 714 /* Expression() will pass trailing whitespace */
219deb70
ILT
715 if ((c == '(' && *input_line_pointer++ != ')')
716 || (c == '[' && *input_line_pointer++ != ']'))
5ac34ac3
ILT
717 {
718 as_bad ("Missing ')' assumed");
719 input_line_pointer--;
720 }
721 /* here with input_line_pointer->char after "(...)" */
58d4951d 722 return segment;
c593cf41 723
219deb70
ILT
724 case 'E':
725 if (! flag_mri || *input_line_pointer != '\'')
726 goto de_fault;
727 as_bad ("EBCDIC constants are not supported");
728 /* Fall through. */
729 case 'A':
730 if (! flag_mri || *input_line_pointer != '\'')
731 goto de_fault;
732 ++input_line_pointer;
733 /* Fall through. */
2ed83a59 734 case '\'':
219deb70
ILT
735 if (! flag_mri)
736 {
737 /* Warning: to conform to other people's assemblers NO
738 ESCAPEMENT is permitted for a single quote. The next
739 character, parity errors and all, is taken as the value
740 of the operand. VERY KINKY. */
741 expressionP->X_op = O_constant;
742 expressionP->X_add_number = *input_line_pointer++;
743 break;
744 }
745
746 mri_char_constant (expressionP);
2ed83a59
KR
747 break;
748
49864cfa 749 case '+':
58d4951d 750 (void) operand (expressionP);
49864cfa
KR
751 break;
752
219deb70
ILT
753 case '"':
754 /* Double quote is the logical not operator in MRI mode. */
755 if (! flag_mri)
756 goto de_fault;
757 /* Fall through. */
2ed83a59
KR
758 case '~':
759 case '-':
2ed83a59 760 {
5ac34ac3
ILT
761 operand (expressionP);
762 if (expressionP->X_op == O_constant)
2ed83a59 763 {
2ed83a59
KR
764 /* input_line_pointer -> char after operand */
765 if (c == '-')
766 {
5ac34ac3 767 expressionP->X_add_number = - expressionP->X_add_number;
d841bc49
KR
768 /* Notice: '-' may overflow: no warning is given. This is
769 compatible with other people's assemblers. Sigh. */
d4c8cbd8 770 expressionP->X_unsigned = 0;
2ed83a59
KR
771 }
772 else
5ac34ac3 773 expressionP->X_add_number = ~ expressionP->X_add_number;
f2f7d044 774 }
5ac34ac3
ILT
775 else if (expressionP->X_op != O_illegal
776 && expressionP->X_op != O_absent)
f2f7d044 777 {
5ac34ac3 778 expressionP->X_add_symbol = make_expr_symbol (expressionP);
2ed83a59 779 if (c == '-')
5ac34ac3 780 expressionP->X_op = O_uminus;
f2f7d044 781 else
5ac34ac3
ILT
782 expressionP->X_op = O_bit_not;
783 expressionP->X_add_number = 0;
c593cf41 784 }
f2f7d044 785 else
5ac34ac3
ILT
786 as_warn ("Unary operator %c ignored because bad operand follows",
787 c);
c593cf41 788 }
2ed83a59
KR
789 break;
790
d90f530b 791 case '$':
219deb70
ILT
792 /* $ is the program counter when in MRI mode, or when DOLLAR_DOT
793 is defined. */
794#ifndef DOLLAR_DOT
795 if (! flag_mri)
796 goto de_fault;
d90f530b 797#endif
219deb70
ILT
798 if (flag_mri && hex_p (*input_line_pointer))
799 {
800 /* In MRI mode, $ is also used as the prefix for a
801 hexadecimal constant. */
802 integer_constant (16, expressionP);
803 break;
804 }
805 /* Fall through. */
806 case '.':
2ed83a59
KR
807 if (!is_part_of_name (*input_line_pointer))
808 {
5ac34ac3 809 const char *fake;
2ed83a59 810
85825401
ILT
811 /* JF: '.' is pseudo symbol with value of current location
812 in current segment. */
d4c8cbd8 813 fake = FAKE_LABEL_NAME;
85825401 814 symbolP = symbol_new (fake,
2ed83a59 815 now_seg,
5ac34ac3 816 (valueT) frag_now_fix (),
2ed83a59 817 frag_now);
c593cf41 818
5ac34ac3 819 expressionP->X_op = O_symbol;
2ed83a59 820 expressionP->X_add_symbol = symbolP;
5ac34ac3 821 expressionP->X_add_number = 0;
2ed83a59 822 break;
2ed83a59
KR
823 }
824 else
825 {
826 goto isname;
2ed83a59
KR
827 }
828 case ',':
829 case '\n':
f2f7d044 830 case '\0':
0bd77bc4 831 eol:
2ed83a59 832 /* can't imagine any other kind of operand */
5ac34ac3 833 expressionP->X_op = O_absent;
2ed83a59 834 input_line_pointer--;
219deb70
ILT
835 break;
836
837 case '%':
838 if (! flag_mri)
839 goto de_fault;
840 integer_constant (2, expressionP);
841 break;
842
843 case '@':
844 if (! flag_mri)
845 goto de_fault;
846 integer_constant (8, expressionP);
847 break;
848
849 case ':':
850 if (! flag_mri)
851 goto de_fault;
852
853 /* In MRI mode, this is a floating point constant represented
854 using hexadecimal digits. */
855
856 ++input_line_pointer;
857 integer_constant (16, expressionP);
2ed83a59 858 break;
0bd77bc4 859
2ed83a59 860 default:
219deb70 861 de_fault:
58d4951d 862 if (is_end_of_line[(unsigned char) c])
0bd77bc4 863 goto eol;
2ed83a59
KR
864 if (is_name_beginner (c)) /* here if did not begin with a digit */
865 {
866 /*
d841bc49
KR
867 * Identifier begins here.
868 * This is kludged for speed, so code is repeated.
869 */
2ed83a59
KR
870 isname:
871 name = --input_line_pointer;
872 c = get_symbol_end ();
873 symbolP = symbol_find_or_make (name);
5ac34ac3
ILT
874
875 /* If we have an absolute symbol or a reg, then we know its
876 value now. */
58d4951d
ILT
877 segment = S_GET_SEGMENT (symbolP);
878 if (segment == absolute_section)
5ac34ac3
ILT
879 {
880 expressionP->X_op = O_constant;
881 expressionP->X_add_number = S_GET_VALUE (symbolP);
882 }
58d4951d 883 else if (segment == reg_section)
5ac34ac3
ILT
884 {
885 expressionP->X_op = O_register;
886 expressionP->X_add_number = S_GET_VALUE (symbolP);
887 }
f2f7d044 888 else
2ed83a59 889 {
5ac34ac3 890 expressionP->X_op = O_symbol;
2ed83a59 891 expressionP->X_add_symbol = symbolP;
5ac34ac3 892 expressionP->X_add_number = 0;
2ed83a59
KR
893 }
894 *input_line_pointer = c;
2ed83a59
KR
895 }
896 else
897 {
219deb70
ILT
898 /* Let the target try to parse it. Success is indicated by changing
899 the X_op field to something other than O_absent and pointing
900 input_line_pointer passed the expression. If it can't parse the
901 expression, X_op and input_line_pointer should be unchanged. */
902 expressionP->X_op = O_absent;
903 --input_line_pointer;
904 md_operand (expressionP);
905 if (expressionP->X_op == O_absent)
906 {
907 ++input_line_pointer;
908 as_bad ("Bad expression");
909 expressionP->X_op = O_constant;
910 expressionP->X_add_number = 0;
911 }
2ed83a59 912 }
219deb70 913 break;
c593cf41 914 }
c593cf41 915
c593cf41
SC
916 /*
917 * It is more 'efficient' to clean up the expressionS when they are created.
918 * Doing it here saves lines of code.
919 */
920 clean_up_expression (expressionP);
2ed83a59
KR
921 SKIP_WHITESPACE (); /*->1st char after operand. */
922 know (*input_line_pointer != ' ');
58d4951d 923
009dc5e1
JL
924 /* The PA port needs this information. */
925 if (expressionP->X_add_symbol)
926 expressionP->X_add_symbol->sy_used = 1;
927
58d4951d
ILT
928 switch (expressionP->X_op)
929 {
930 default:
931 return absolute_section;
932 case O_symbol:
933 return S_GET_SEGMENT (expressionP->X_add_symbol);
934 case O_register:
935 return reg_section;
936 }
2ed83a59 937} /* operand() */
fecd2382
RP
938\f
939/* Internal. Simplify a struct expression for use by expr() */
940
941/*
942 * In: address of a expressionS.
5ac34ac3 943 * The X_op field of the expressionS may only take certain values.
fecd2382
RP
944 * Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
945 * Out: expressionS may have been modified:
946 * 'foo-foo' symbol references cancelled to 0,
5ac34ac3 947 * which changes X_op from O_subtract to O_constant.
fecd2382
RP
948 * Unused fields zeroed to help expr().
949 */
950
951static void
c593cf41 952clean_up_expression (expressionP)
dae92eab 953 expressionS *expressionP;
fecd2382 954{
5ac34ac3 955 switch (expressionP->X_op)
2ed83a59 956 {
5ac34ac3
ILT
957 case O_illegal:
958 case O_absent:
2ed83a59 959 expressionP->X_add_number = 0;
5ac34ac3
ILT
960 /* Fall through. */
961 case O_big:
962 case O_constant:
963 case O_register:
2ed83a59 964 expressionP->X_add_symbol = NULL;
5ac34ac3
ILT
965 /* Fall through. */
966 case O_symbol:
967 case O_uminus:
968 case O_bit_not:
969 expressionP->X_op_symbol = NULL;
970 break;
971 case O_subtract:
972 if (expressionP->X_op_symbol == expressionP->X_add_symbol
973 || ((expressionP->X_op_symbol->sy_frag
974 == expressionP->X_add_symbol->sy_frag)
ffffc8fb 975 && SEG_NORMAL (S_GET_SEGMENT (expressionP->X_add_symbol))
5ac34ac3 976 && (S_GET_VALUE (expressionP->X_op_symbol)
49864cfa 977 == S_GET_VALUE (expressionP->X_add_symbol))))
2ed83a59 978 {
3a762a0b
KR
979 addressT diff = (S_GET_VALUE (expressionP->X_add_symbol)
980 - S_GET_VALUE (expressionP->X_op_symbol));
d90f530b 981
5ac34ac3 982 expressionP->X_op = O_constant;
2ed83a59 983 expressionP->X_add_symbol = NULL;
5ac34ac3 984 expressionP->X_op_symbol = NULL;
d90f530b 985 expressionP->X_add_number += diff;
fecd2382 986 }
5ac34ac3
ILT
987 break;
988 default:
989 break;
fecd2382 990 }
f2f7d044 991}
fecd2382
RP
992\f
993/* Expression parser. */
994
995/*
996 * We allow an empty expression, and just assume (absolute,0) silently.
997 * Unary operators and parenthetical expressions are treated as operands.
998 * As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
999 *
1000 * We used to do a aho/ullman shift-reduce parser, but the logic got so
1001 * warped that I flushed it and wrote a recursive-descent parser instead.
1002 * Now things are stable, would anybody like to write a fast parser?
1003 * Most expressions are either register (which does not even reach here)
1004 * or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1005 * So I guess it doesn't really matter how inefficient more complex expressions
1006 * are parsed.
1007 *
1008 * After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1009 * Also, we have consumed any leading or trailing spaces (operand does that)
1010 * and done all intervening operators.
5ac34ac3
ILT
1011 *
1012 * This returns the segment of the result, which will be
1013 * absolute_section or the segment of a symbol.
fecd2382
RP
1014 */
1015
49864cfa 1016#undef __
fecd2382
RP
1017#define __ O_illegal
1018
2ed83a59
KR
1019static const operatorT op_encoding[256] =
1020{ /* maps ASCII->operators */
1021
1022 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1023 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1024
219deb70 1025 __, O_bit_or_not, O_bit_not, __, __, O_modulus, O_bit_and, __,
2ed83a59
KR
1026 __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1027 __, __, __, __, __, __, __, __,
219deb70 1028 __, __, __, __, O_lt, __, O_gt, __,
2ed83a59
KR
1029 __, __, __, __, __, __, __, __,
1030 __, __, __, __, __, __, __, __,
1031 __, __, __, __, __, __, __, __,
1032 __, __, __, __, __, __, O_bit_exclusive_or, __,
1033 __, __, __, __, __, __, __, __,
1034 __, __, __, __, __, __, __, __,
1035 __, __, __, __, __, __, __, __,
1036 __, __, __, __, O_bit_inclusive_or, __, __, __,
1037
1038 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1039 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1040 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1041 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1042 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1043 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1044 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1045 __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1046};
fecd2382
RP
1047
1048
1049/*
1050 * Rank Examples
1051 * 0 operand, (expression)
219deb70
ILT
1052 * 1 = <> < <= >= >
1053 * 2 + -
1054 * 3 used for * / % in MRI mode
1055 * 4 & ^ ! |
1056 * 5 * / % << >>
1057 * 6 unary - unary ~
fecd2382 1058 */
219deb70 1059static operator_rankT op_rank[] =
5ac34ac3
ILT
1060{
1061 0, /* O_illegal */
1062 0, /* O_absent */
1063 0, /* O_constant */
1064 0, /* O_symbol */
1065 0, /* O_register */
1066 0, /* O_bit */
219deb70
ILT
1067 6, /* O_uminus */
1068 6, /* O_bit_not */
1069 5, /* O_multiply */
1070 5, /* O_divide */
1071 5, /* O_modulus */
1072 5, /* O_left_shift */
1073 5, /* O_right_shift */
1074 4, /* O_bit_inclusive_or */
1075 4, /* O_bit_or_not */
1076 4, /* O_bit_exclusive_or */
1077 4, /* O_bit_and */
1078 2, /* O_add */
1079 2, /* O_subtract */
1080 1, /* O_eq */
1081 1, /* O_ne */
1082 1, /* O_lt */
1083 1, /* O_le */
1084 1, /* O_ge */
1085 1 /* O_gt */
5ac34ac3 1086};
219deb70
ILT
1087
1088/* Initialize the expression parser. */
1089
1090void
1091expr_begin ()
1092{
1093 /* In MRI mode, multiplication and division have lower precedence
1094 than the bit wise operators. */
1095 if (flag_mri)
1096 {
1097 op_rank[O_multiply] = 3;
1098 op_rank[O_divide] = 3;
1099 op_rank[O_modulus] = 3;
1100 }
1101}
fecd2382 1102\f
219deb70
ILT
1103/* Return the encoding for the operator at INPUT_LINE_POINTER.
1104 Advance INPUT_LINE_POINTER to the last character in the operator
1105 (i.e., don't change it for a single character operator). */
1106
1107static inline operatorT
1108operator ()
1109{
1110 int c;
1111 operatorT ret;
1112
1113 c = *input_line_pointer;
1114
1115 switch (c)
1116 {
1117 default:
1118 return op_encoding[c];
1119
1120 case '<':
1121 switch (input_line_pointer[1])
1122 {
1123 default:
1124 return op_encoding[c];
1125 case '<':
1126 ret = O_left_shift;
1127 break;
1128 case '>':
1129 ret = O_ne;
1130 break;
1131 case '=':
1132 ret = O_le;
1133 break;
1134 }
1135 ++input_line_pointer;
1136 return ret;
1137
1138 case '>':
1139 switch (input_line_pointer[1])
1140 {
1141 default:
1142 return op_encoding[c];
1143 case '>':
1144 ret = O_right_shift;
1145 break;
1146 case '=':
1147 ret = O_ge;
1148 break;
1149 }
1150 ++input_line_pointer;
1151 return ret;
1152
1153 case '!':
1154 /* We accept !! as equivalent to ^ for MRI compatibility. */
1155 if (input_line_pointer[1] != '!')
1156 {
1157 if (flag_mri)
1158 return O_bit_inclusive_or;
1159 return op_encoding[c];
1160 }
1161 ++input_line_pointer;
1162 return O_bit_exclusive_or;
1163 }
1164
1165 /*NOTREACHED*/
1166}
1167
1168/* Parse an expression. */
1169
5ac34ac3 1170segT
2ed83a59 1171expr (rank, resultP)
dae92eab
KR
1172 operator_rankT rank; /* Larger # is higher rank. */
1173 expressionS *resultP; /* Deliver result here. */
fecd2382 1174{
5ac34ac3 1175 segT retval;
2ed83a59 1176 expressionS right;
dae92eab 1177 operatorT op_left;
dae92eab 1178 operatorT op_right;
c593cf41 1179
2ed83a59 1180 know (rank >= 0);
5ac34ac3
ILT
1181
1182 retval = operand (resultP);
1183
2ed83a59 1184 know (*input_line_pointer != ' '); /* Operand() gobbles spaces. */
5ac34ac3 1185
219deb70 1186 op_left = operator ();
2ed83a59 1187 while (op_left != O_illegal && op_rank[(int) op_left] > rank)
fecd2382 1188 {
5ac34ac3
ILT
1189 segT rightseg;
1190
2ed83a59 1191 input_line_pointer++; /*->after 1st character of operator. */
5ac34ac3
ILT
1192
1193 rightseg = expr (op_rank[(int) op_left], &right);
1194 if (right.X_op == O_absent)
fecd2382 1195 {
5ac34ac3
ILT
1196 as_warn ("missing operand; zero assumed");
1197 right.X_op = O_constant;
1198 right.X_add_number = 0;
d4c8cbd8
JL
1199 right.X_add_symbol = NULL;
1200 right.X_op_symbol = NULL;
fecd2382 1201 }
5ac34ac3 1202
2ed83a59 1203 know (*input_line_pointer != ' ');
5ac34ac3 1204
58d4951d
ILT
1205 if (retval == undefined_section)
1206 {
1207 if (SEG_NORMAL (rightseg))
1208 retval = rightseg;
1209 }
1210 else if (! SEG_NORMAL (retval))
5ac34ac3
ILT
1211 retval = rightseg;
1212 else if (SEG_NORMAL (rightseg)
d4c8cbd8
JL
1213 && retval != rightseg
1214#ifdef DIFF_EXPR_OK
1215 && op_left != O_subtract
1216#endif
1217 )
5ac34ac3
ILT
1218 as_bad ("operation combines symbols in different segments");
1219
219deb70 1220 op_right = operator ();
5ac34ac3
ILT
1221
1222 know (op_right == O_illegal || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1223 know ((int) op_left >= (int) O_multiply && (int) op_left <= (int) O_subtract);
1224
c593cf41
SC
1225 /* input_line_pointer->after right-hand quantity. */
1226 /* left-hand quantity in resultP */
1227 /* right-hand quantity in right. */
1228 /* operator in op_left. */
5ac34ac3
ILT
1229
1230 if (resultP->X_op == O_big)
fecd2382 1231 {
219deb70
ILT
1232 as_warn ("left operand is a %s; integer 0 assumed",
1233 resultP->X_add_number > 0 ? "bignum" : "float");
5ac34ac3
ILT
1234 resultP->X_op = O_constant;
1235 resultP->X_add_number = 0;
1236 resultP->X_add_symbol = NULL;
1237 resultP->X_op_symbol = NULL;
fecd2382 1238 }
5ac34ac3 1239 if (right.X_op == O_big)
fecd2382 1240 {
219deb70
ILT
1241 as_warn ("right operand is a %s; integer 0 assumed",
1242 right.X_add_number > 0 ? "bignum" : "float");
5ac34ac3
ILT
1243 right.X_op = O_constant;
1244 right.X_add_number = 0;
1245 right.X_add_symbol = NULL;
1246 right.X_op_symbol = NULL;
1247 }
1248
1249 /* Optimize common cases. */
219deb70 1250 if (op_left == O_add && right.X_op == O_constant)
5ac34ac3
ILT
1251 {
1252 /* X + constant. */
1253 resultP->X_add_number += right.X_add_number;
1254 }
d90f530b
KR
1255 /* This case comes up in PIC code. */
1256 else if (op_left == O_subtract
1257 && right.X_op == O_symbol
1258 && resultP->X_op == O_symbol
1259 && (right.X_add_symbol->sy_frag
fcacfef6
JL
1260 == resultP->X_add_symbol->sy_frag)
1261 && SEG_NORMAL (S_GET_SEGMENT (right.X_add_symbol)))
1262
d90f530b
KR
1263 {
1264 resultP->X_add_number += right.X_add_number;
1265 resultP->X_add_number += (S_GET_VALUE (resultP->X_add_symbol)
1266 - S_GET_VALUE (right.X_add_symbol));
1267 resultP->X_op = O_constant;
1268 resultP->X_add_symbol = 0;
1269 }
5ac34ac3
ILT
1270 else if (op_left == O_subtract && right.X_op == O_constant)
1271 {
1272 /* X - constant. */
1273 resultP->X_add_number -= right.X_add_number;
1274 }
1275 else if (op_left == O_add && resultP->X_op == O_constant)
1276 {
1277 /* Constant + X. */
1278 resultP->X_op = right.X_op;
1279 resultP->X_add_symbol = right.X_add_symbol;
1280 resultP->X_op_symbol = right.X_op_symbol;
1281 resultP->X_add_number += right.X_add_number;
1282 retval = rightseg;
1283 }
1284 else if (resultP->X_op == O_constant && right.X_op == O_constant)
1285 {
1286 /* Constant OP constant. */
1287 offsetT v = right.X_add_number;
1288 if (v == 0 && (op_left == O_divide || op_left == O_modulus))
fecd2382 1289 {
5ac34ac3
ILT
1290 as_warn ("division by zero");
1291 v = 1;
fecd2382 1292 }
5ac34ac3 1293 switch (op_left)
fecd2382 1294 {
219deb70 1295 default: abort ();
5ac34ac3
ILT
1296 case O_multiply: resultP->X_add_number *= v; break;
1297 case O_divide: resultP->X_add_number /= v; break;
1298 case O_modulus: resultP->X_add_number %= v; break;
1299 case O_left_shift: resultP->X_add_number <<= v; break;
1300 case O_right_shift: resultP->X_add_number >>= v; break;
1301 case O_bit_inclusive_or: resultP->X_add_number |= v; break;
1302 case O_bit_or_not: resultP->X_add_number |= ~v; break;
1303 case O_bit_exclusive_or: resultP->X_add_number ^= v; break;
1304 case O_bit_and: resultP->X_add_number &= v; break;
1305 case O_add: resultP->X_add_number += v; break;
1306 case O_subtract: resultP->X_add_number -= v; break;
219deb70
ILT
1307 case O_eq:
1308 resultP->X_add_number =
1309 resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
1310 break;
1311 case O_ne:
1312 resultP->X_add_number =
1313 resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
1314 break;
1315 case O_lt:
1316 resultP->X_add_number =
1317 resultP->X_add_number < v ? ~ (offsetT) 0 : 0;
1318 break;
1319 case O_le:
1320 resultP->X_add_number =
1321 resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
1322 break;
1323 case O_ge:
1324 resultP->X_add_number =
1325 resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
1326 break;
1327 case O_gt:
1328 resultP->X_add_number =
1329 resultP->X_add_number > v ? ~ (offsetT) 0 : 0;
1330 break;
fecd2382 1331 }
5ac34ac3
ILT
1332 }
1333 else if (resultP->X_op == O_symbol
1334 && right.X_op == O_symbol
1335 && (op_left == O_add
1336 || op_left == O_subtract
1337 || (resultP->X_add_number == 0
1338 && right.X_add_number == 0)))
1339 {
1340 /* Symbol OP symbol. */
1341 resultP->X_op = op_left;
1342 resultP->X_op_symbol = right.X_add_symbol;
c593cf41 1343 if (op_left == O_add)
5ac34ac3
ILT
1344 resultP->X_add_number += right.X_add_number;
1345 else if (op_left == O_subtract)
1346 resultP->X_add_number -= right.X_add_number;
1347 }
1348 else
1349 {
1350 /* The general case. */
1351 resultP->X_add_symbol = make_expr_symbol (resultP);
1352 resultP->X_op_symbol = make_expr_symbol (&right);
1353 resultP->X_op = op_left;
1354 resultP->X_add_number = 0;
d4c8cbd8 1355 resultP->X_unsigned = 1;
5ac34ac3 1356 }
351878df 1357
2ed83a59 1358 op_left = op_right;
fecd2382 1359 } /* While next operator is >= this rank. */
5ac34ac3 1360
009dc5e1
JL
1361 /* The PA port needs this information. */
1362 if (resultP->X_add_symbol)
1363 resultP->X_add_symbol->sy_used = 1;
1364
5ac34ac3 1365 return resultP->X_op == O_constant ? absolute_section : retval;
fecd2382
RP
1366}
1367\f
1368/*
1369 * get_symbol_end()
1370 *
1371 * This lives here because it belongs equally in expr.c & read.c.
1372 * Expr.c is just a branch office read.c anyway, and putting it
1373 * here lessens the crowd at read.c.
1374 *
1375 * Assume input_line_pointer is at start of symbol name.
1376 * Advance input_line_pointer past symbol name.
1377 * Turn that character into a '\0', returning its former value.
1378 * This allows a string compare (RMS wants symbol names to be strings)
1379 * of the symbol name.
1380 * There will always be a char following symbol name, because all good
1381 * lines end in end-of-line.
1382 */
1383char
2ed83a59 1384get_symbol_end ()
fecd2382 1385{
dae92eab 1386 char c;
2ed83a59
KR
1387
1388 while (is_part_of_name (c = *input_line_pointer++))
1389 ;
1390 *--input_line_pointer = 0;
1391 return (c);
fecd2382
RP
1392}
1393
a39116f1 1394
351878df 1395unsigned int
2ed83a59 1396get_single_number ()
a39116f1 1397{
2ed83a59
KR
1398 expressionS exp;
1399 operand (&exp);
1400 return exp.X_add_number;
1401
a39116f1 1402}
2ed83a59 1403
8b228fe9 1404/* end of expr.c */
This page took 0.209543 seconds and 4 git commands to generate.