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