Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/gas/expr.c
Line
Count
Source (jump to first uncovered line)
1
/* expr.c -operands, expressions-
2
   Copyright (C) 1987-2025 Free Software Foundation, Inc.
3
4
   This file is part of GAS, the GNU Assembler.
5
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 3, or (at your option)
9
   any later version.
10
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.
15
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 the Free
18
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19
   02110-1301, USA.  */
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
236
#define min(a, b)       ((a) < (b) ? (a) : (b))
27
28
#include "as.h"
29
#include "safe-ctype.h"
30
31
#include <limits.h>
32
#ifndef CHAR_BIT
33
#define CHAR_BIT 8
34
#endif
35
36
bool literal_prefix_dollar_hex = false;
37
38
static void clean_up_expression (expressionS * expressionP);
39
40
/* We keep a mapping of expression symbols to file positions, so that
41
   we can provide better error messages.  */
42
43
struct expr_symbol_line {
44
  struct expr_symbol_line *next;
45
  symbolS *sym;
46
  const char *file;
47
  unsigned int line;
48
};
49
50
static struct expr_symbol_line *expr_symbol_lines;
51
52
static const expressionS zero = { .X_op = O_constant };
53

54
/* Build a dummy symbol to hold a complex expression.  This is how we
55
   build expressions up out of other expressions.  The symbol is put
56
   into the fake section expr_section.  */
57
58
symbolS *
59
make_expr_symbol (const expressionS *expressionP)
60
59.9k
{
61
59.9k
  symbolS *symbolP;
62
59.9k
  struct expr_symbol_line *n;
63
64
59.9k
  if (expressionP->X_op == O_symbol
65
59.9k
      && expressionP->X_add_number == 0)
66
18.3k
    return expressionP->X_add_symbol;
67
68
41.6k
  if (expressionP->X_op == O_big)
69
24
    {
70
      /* This won't work, because the actual value is stored in
71
   generic_floating_point_number or generic_bignum, and we are
72
   going to lose it if we haven't already.  */
73
24
      if (expressionP->X_add_number > 0)
74
5
  as_bad (_("bignum invalid"));
75
19
      else
76
19
  as_bad (_("floating point number invalid"));
77
24
      expressionP = &zero;
78
24
    }
79
80
  /* Putting constant symbols in absolute_section rather than
81
     expr_section is convenient for the old a.out code, for which
82
     S_GET_SEGMENT does not always retrieve the value put in by
83
     S_SET_SEGMENT.  */
84
41.6k
  symbolP = symbol_create (FAKE_LABEL_NAME,
85
41.6k
         (expressionP->X_op == O_constant
86
41.6k
          ? absolute_section
87
41.6k
          : expressionP->X_op == O_register
88
20.1k
            ? reg_section
89
20.1k
            : expr_section),
90
41.6k
         &zero_address_frag, 0);
91
41.6k
  symbol_set_value_expression (symbolP, expressionP);
92
93
41.6k
  if (expressionP->X_op == O_constant)
94
21.5k
    resolve_symbol_value (symbolP);
95
96
41.6k
  n = notes_alloc (sizeof (*n));
97
41.6k
  n->sym = symbolP;
98
41.6k
  n->file = as_where (&n->line);
99
41.6k
  n->next = expr_symbol_lines;
100
41.6k
  expr_symbol_lines = n;
101
102
41.6k
  return symbolP;
103
59.9k
}
104
105
/* Return the file and line number for an expr symbol.  Return
106
   non-zero if something was found, 0 if no information is known for
107
   the symbol.  */
108
109
int
110
expr_symbol_where (symbolS *sym, const char **pfile, unsigned int *pline)
111
0
{
112
0
  struct expr_symbol_line *l;
113
114
0
  for (l = expr_symbol_lines; l != NULL; l = l->next)
115
0
    {
116
0
      if (l->sym == sym)
117
0
  {
118
0
    *pfile = l->file;
119
0
    *pline = l->line;
120
0
    return 1;
121
0
  }
122
0
    }
123
124
0
  return 0;
125
0
}
126
127
/* Look up a previously used .startof. / .sizeof. symbol, or make a fresh
128
   one.  */
129
static symbolS **seen[2];
130
static unsigned int nr_seen[2];
131
132
static symbolS *
133
symbol_lookup_or_make (const char *name, bool start)
134
57
{
135
57
  char *buf = concat (start ? ".startof." : ".sizeof.", name, NULL);
136
57
  symbolS *symbolP;
137
57
  unsigned int i;
138
139
122
  for (i = 0; i < nr_seen[start]; ++i)
140
105
    {
141
105
    symbolP = seen[start][i];
142
143
105
    if (! symbolP)
144
12
      break;
145
146
93
    name = S_GET_NAME (symbolP);
147
93
    if ((symbols_case_sensitive
148
93
   ? strcmp (buf, name)
149
93
   : strcasecmp (buf, name)) == 0)
150
28
      {
151
28
  free (buf);
152
28
  return symbolP;
153
28
      }
154
93
    }
155
156
29
  symbolP = symbol_make (buf);
157
29
  free (buf);
158
159
29
  if (i >= nr_seen[start])
160
17
    {
161
17
      unsigned int nr = (i + 1) * 2;
162
163
17
      seen[start] = XRESIZEVEC (symbolS *, seen[start], nr);
164
17
      nr_seen[start] = nr;
165
17
      memset (&seen[start][i + 1], 0, (nr - i - 1) * sizeof(seen[0][0]));
166
17
    }
167
168
29
  seen[start][i] = symbolP;
169
170
29
  return symbolP;
171
57
}
172

173
/* Utilities for building expressions.
174
   Since complex expressions are recorded as symbols for use in other
175
   expressions these return a symbolS * and not an expressionS *.
176
   These explicitly do not take an "add_number" argument.  */
177
/* ??? For completeness' sake one might want expr_build_symbol.
178
   It would just return its argument.  */
179
180
/* Build an expression for an unsigned constant.
181
   The corresponding one for signed constants is missing because
182
   there's currently no need for it.  One could add an unsigned_p flag
183
   but that seems more clumsy.  */
184
185
symbolS *
186
expr_build_uconstant (offsetT value)
187
0
{
188
0
  expressionS e;
189
190
0
  e.X_op = O_constant;
191
0
  e.X_add_number = value;
192
0
  e.X_unsigned = 1;
193
0
  e.X_extrabit = 0;
194
0
  return make_expr_symbol (&e);
195
0
}
196

197
/* Build any floating-point literal here.
198
   Also build any bignum literal here.  */
199
200
/* Seems atof_machine can backscan through generic_bignum and hit whatever
201
   happens to be loaded before it in memory.  And its way too complicated
202
   for me to fix right.  Thus a hack.  JF:  Just make generic_bignum bigger,
203
   and never write into the early words, thus they'll always be zero.
204
   I hate Dean's floating-point code.  Bleh.  */
205
LITTLENUM_TYPE generic_bignum[SIZE_OF_LARGE_NUMBER + 6];
206
207
FLONUM_TYPE generic_floating_point_number = {
208
  &generic_bignum[6],   /* low.  (JF: Was 0)  */
209
  &generic_bignum[SIZE_OF_LARGE_NUMBER + 6 - 1], /* high.  JF: (added +6)  */
210
  0,        /* leader.  */
211
  0,        /* exponent.  */
212
  0       /* sign.  */
213
};
214
215

216
static void
217
floating_constant (expressionS *expressionP)
218
5.03k
{
219
  /* input_line_pointer -> floating-point constant.  */
220
5.03k
  int error_code;
221
222
5.03k
  error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
223
5.03k
           &generic_floating_point_number);
224
225
5.03k
  if (error_code)
226
3
    {
227
3
      if (error_code == ERROR_EXPONENT_OVERFLOW)
228
3
  {
229
3
    as_bad (_("bad floating-point constant: exponent overflow"));
230
3
  }
231
0
      else
232
0
  {
233
0
    as_bad (_("bad floating-point constant: unknown error code=%d"),
234
0
      error_code);
235
0
  }
236
3
    }
237
5.03k
  expressionP->X_op = O_big;
238
  /* input_line_pointer -> just after constant, which may point to
239
     whitespace.  */
240
5.03k
  expressionP->X_add_number = -1;
241
5.03k
}
242
243
uint32_t
244
generic_bignum_to_int32 (void)
245
6
{
246
6
  return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
247
6
     << LITTLENUM_NUMBER_OF_BITS)
248
6
    | ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
249
6
}
250
251
uint64_t
252
generic_bignum_to_int64 (void)
253
193
{
254
193
  return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
255
193
         << LITTLENUM_NUMBER_OF_BITS)
256
193
        | ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
257
193
       << LITTLENUM_NUMBER_OF_BITS)
258
193
      | ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
259
193
     << LITTLENUM_NUMBER_OF_BITS)
260
193
    | ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
261
193
}
262
263
static void
264
integer_constant (int radix, expressionS *expressionP)
265
102k
{
266
102k
  char *start;    /* Start of number.  */
267
102k
  char *suffix = NULL;
268
102k
  char c;
269
102k
  valueT number;  /* Offset or (absolute) value.  */
270
102k
  short int digit;  /* Value of next digit in current radix.  */
271
102k
  int too_many_digits = 0;  /* If we see >= this number of.  */
272
102k
  char *name;   /* Points to name of symbol.  */
273
102k
  symbolS *symbolP; /* Points to symbol.  */
274
275
102k
  bool small;   /* True if fits in 32 bits (64 bits with BFD64).  */
276
277
  /* May be bignum, or may fit in 32 bits.  */
278
  /* Most numbers fit into 32 bits, and we want this case to be fast.
279
     so we pretend it will fit into 32 bits.  If, after making up a 32
280
     bit number, we realise that we have scanned more digits than
281
     comfortably fit into 32 bits, we re-scan the digits coding them
282
     into a bignum.  For decimal and octal numbers we are
283
     conservative: Some numbers may be assumed bignums when in fact
284
     they do fit into 32 bits.  Numbers of any radix can have excess
285
     leading zeros: We strive to recognise this and cast them back
286
     into 32 bits.  We must check that the bignum really is more than
287
     32 bits, and change it back to a 32-bit number if it fits.  The
288
     number we are looking for is expected to be positive, but if it
289
     fits into 32 bits as an unsigned number, we let it be a 32-bit
290
     number.  The cavalier approach is for speed in ordinary cases.  */
291
  /* This has been extended for 64 bits.  We blindly assume that if
292
     you're compiling in 64-bit mode, the target is a 64-bit machine.
293
     This should be cleaned up.  */
294
295
102k
#ifdef BFD64
296
102k
#define valuesize 64
297
#else /* includes non-bfd case, mostly */
298
#define valuesize 32
299
#endif
300
301
102k
  if (is_end_of_stmt (*input_line_pointer))
302
10
    {
303
10
      expressionP->X_op = O_absent;
304
10
      return;
305
10
    }
306
307
102k
  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri) && radix == 0)
308
0
    {
309
0
      int flt = 0;
310
311
      /* In MRI mode, the number may have a suffix indicating the
312
   radix.  For that matter, it might actually be a floating
313
   point constant.  */
314
0
      for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
315
0
  {
316
0
    if (*suffix == 'e' || *suffix == 'E')
317
0
      flt = 1;
318
0
  }
319
320
0
      if (suffix == input_line_pointer)
321
0
  {
322
0
    radix = 10;
323
0
    suffix = NULL;
324
0
  }
325
0
      else
326
0
  {
327
0
    c = *--suffix;
328
0
    c = TOUPPER (c);
329
    /* If we have both NUMBERS_WITH_SUFFIX and LOCAL_LABELS_FB,
330
       we distinguish between 'B' and 'b'.  This is the case for
331
       Z80.  */
332
0
    if ((NUMBERS_WITH_SUFFIX && LOCAL_LABELS_FB ? *suffix : c) == 'B')
333
0
      radix = 2;
334
0
    else if (c == 'D')
335
0
      radix = 10;
336
0
    else if (c == 'O' || c == 'Q')
337
0
      radix = 8;
338
0
    else if (c == 'H')
339
0
      radix = 16;
340
0
    else if (suffix[1] == '.' || c == 'E' || flt)
341
0
      {
342
0
        floating_constant (expressionP);
343
0
        return;
344
0
      }
345
0
    else
346
0
      {
347
0
        radix = 10;
348
0
        suffix = NULL;
349
0
      }
350
0
  }
351
0
    }
352
353
102k
  switch (radix)
354
102k
    {
355
0
    case 2:
356
0
      too_many_digits = valuesize + 1;
357
0
      break;
358
408
    case 8:
359
408
      too_many_digits = (valuesize + 2) / 3 + 1;
360
408
      break;
361
116
    case 16:
362
116
      too_many_digits = (valuesize + 3) / 4 + 1;
363
116
      break;
364
101k
    case 10:
365
101k
      too_many_digits = (valuesize + 11) / 4; /* Very rough.  */
366
101k
      break;
367
102k
    }
368
102k
#undef valuesize
369
102k
  start = input_line_pointer;
370
102k
  c = *input_line_pointer++;
371
102k
  for (number = 0;
372
473k
       (digit = hex_value (c)) < radix;
373
371k
       c = *input_line_pointer++)
374
371k
    {
375
371k
      number = number * radix + digit;
376
371k
    }
377
  /* c contains character after number.  */
378
  /* input_line_pointer->char after c.  */
379
102k
  small = (input_line_pointer - start - 1) < too_many_digits;
380
381
102k
  if (radix == 16 && c == '_')
382
62
    {
383
      /* This is literal of the form 0x333_0_12345678_1.
384
   This example is equivalent to 0x00000333000000001234567800000001.  */
385
386
62
      int num_little_digits = 0;
387
62
      int i;
388
62
      input_line_pointer = start; /* -> 1st digit.  */
389
390
62
      know (LITTLENUM_NUMBER_OF_BITS == 16);
391
392
298
      for (c = '_'; c == '_'; num_little_digits += 2)
393
236
  {
394
395
    /* Convert one 64-bit word.  */
396
236
    int ndigit = 0;
397
236
    number = 0;
398
236
    for (c = *input_line_pointer++;
399
1.61k
         (digit = hex_value (c)) < radix;
400
1.38k
         c = *(input_line_pointer++))
401
1.38k
      {
402
1.38k
        number = number * radix + digit;
403
1.38k
        ndigit++;
404
1.38k
      }
405
406
    /* Check for 8 digit per word max.  */
407
236
    if (ndigit > 8)
408
56
      as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
409
410
    /* Add this chunk to the bignum.
411
       Shift things down 2 little digits.  */
412
236
    know (LITTLENUM_NUMBER_OF_BITS == 16);
413
236
    for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
414
920
         i >= 2;
415
684
         i--)
416
684
      generic_bignum[i] = generic_bignum[i - 2];
417
418
    /* Add the new digits as the least significant new ones.  */
419
236
    generic_bignum[0] = number & 0xffffffff;
420
236
    generic_bignum[1] = number >> 16;
421
236
  }
422
423
      /* Again, c is char after number, input_line_pointer->after c.  */
424
425
62
      if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
426
0
  num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
427
428
62
      gas_assert (num_little_digits >= 4);
429
430
62
      if (num_little_digits != 8)
431
6
  as_bad (_("a bignum with underscores must have exactly 4 words"));
432
433
      /* We might have some leading zeros.  These can be trimmed to give
434
   us a change to fit this constant into a small number.  */
435
80
      while (generic_bignum[num_little_digits - 1] == 0
436
80
       && num_little_digits > 1)
437
18
  num_little_digits--;
438
439
62
      if (num_little_digits <= 2)
440
6
  {
441
    /* will fit into 32 bits.  */
442
6
    number = generic_bignum_to_int32 ();
443
6
    small = 1;
444
6
  }
445
56
#ifdef BFD64
446
56
      else if (num_little_digits <= 4)
447
0
  {
448
    /* Will fit into 64 bits.  */
449
0
    number = generic_bignum_to_int64 ();
450
0
    small = 1;
451
0
  }
452
56
#endif
453
56
      else
454
56
  {
455
56
    small = 0;
456
457
    /* Number of littlenums in the bignum.  */
458
56
    number = num_little_digits;
459
56
  }
460
62
    }
461
102k
  else if (!small)
462
1.15k
    {
463
      /* We saw a lot of digits. manufacture a bignum the hard way.  */
464
1.15k
      LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum.  */
465
1.15k
      LITTLENUM_TYPE *pointer;  /* -> littlenum we are frobbing now.  */
466
1.15k
      long carry;
467
468
1.15k
      leader = generic_bignum;
469
1.15k
      generic_bignum[0] = 0;
470
1.15k
      generic_bignum[1] = 0;
471
1.15k
      generic_bignum[2] = 0;
472
1.15k
      generic_bignum[3] = 0;
473
1.15k
      input_line_pointer = start; /* -> 1st digit.  */
474
1.15k
      c = *input_line_pointer++;
475
46.2k
      for (; (carry = hex_value (c)) < radix; c = *input_line_pointer++)
476
45.0k
  {
477
306k
    for (pointer = generic_bignum; pointer <= leader; pointer++)
478
261k
      {
479
261k
        long work;
480
481
261k
        work = carry + radix * *pointer;
482
261k
        *pointer = work & LITTLENUM_MASK;
483
261k
        carry = work >> LITTLENUM_NUMBER_OF_BITS;
484
261k
      }
485
45.0k
    if (carry)
486
9.36k
      {
487
9.36k
        if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
488
8.25k
    {
489
      /* Room to grow a longer bignum.  */
490
8.25k
      *++leader = carry;
491
8.25k
    }
492
9.36k
      }
493
45.0k
  }
494
      /* Again, c is char after number.  */
495
      /* input_line_pointer -> after c.  */
496
1.15k
      know (LITTLENUM_NUMBER_OF_BITS == 16);
497
1.15k
      if (leader < generic_bignum + 2)
498
0
  {
499
    /* Will fit into 32 bits.  */
500
0
    number = generic_bignum_to_int32 ();
501
0
    small = 1;
502
0
  }
503
1.15k
#ifdef BFD64
504
1.15k
      else if (leader < generic_bignum + 4)
505
193
  {
506
    /* Will fit into 64 bits.  */
507
193
    number = generic_bignum_to_int64 ();
508
193
    small = 1;
509
193
  }
510
966
#endif
511
966
      else
512
966
  {
513
    /* Number of littlenums in the bignum.  */
514
966
    number = leader - generic_bignum + 1;
515
966
  }
516
1.15k
    }
517
518
102k
  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
519
102k
      && suffix != NULL
520
102k
      && input_line_pointer - 1 == suffix)
521
0
    c = *input_line_pointer++;
522
523
102k
#ifndef tc_allow_U_suffix
524
304k
#define tc_allow_U_suffix 1
525
102k
#endif
526
102k
  bool u_seen = !tc_allow_U_suffix;
527
  /* PR 19910: Look for, and ignore, a U suffix to the number.  */
528
102k
  if (!u_seen && (c == 'U' || c == 'u'))
529
4
    {
530
4
      c = *input_line_pointer++;
531
4
      u_seen = true;
532
4
    }
533
534
102k
#ifndef tc_allow_L_suffix
535
508k
#define tc_allow_L_suffix 1
536
102k
#endif
537
102k
  bool l_seen = !tc_allow_L_suffix;
538
  /* PR 20732: Look for, and ignore, a L or LL suffix to the number.  */
539
102k
  if (tc_allow_L_suffix && (c == 'L' || c == 'l'))
540
138
    {
541
138
      c = * input_line_pointer++;
542
138
      l_seen = true;
543
138
      if (c == 'L' || c == 'l')
544
23
  c = *input_line_pointer++;
545
138
      if (!u_seen && (c == 'U' || c == 'u'))
546
78
  c = *input_line_pointer++;
547
138
    }
548
549
102k
  if (small)
550
101k
    {
551
      /* Here with number, in correct radix. c is the next char.  */
552
101k
      bool maybe_label = suffix == NULL
553
101k
       && (!tc_allow_U_suffix || !u_seen)
554
101k
       && (!tc_allow_L_suffix || !l_seen)
555
101k
       && (radix == 10 ||
556
100k
           (radix == 8 && input_line_pointer == start + 1));
557
558
101k
      if (LOCAL_LABELS_FB && c == 'b' && maybe_label)
559
81
  {
560
    /* Backward ref to local label.
561
       Because it is backward, expect it to be defined.  */
562
    /* Construct a local label.  */
563
81
    name = fb_label_name (number, 0);
564
565
    /* Seen before, or symbol is defined: OK.  */
566
81
    symbolP = symbol_find (name);
567
81
    if ((symbolP != NULL) && (S_IS_DEFINED (symbolP)))
568
0
      {
569
0
        expressionP->X_op = O_symbol;
570
0
        expressionP->X_add_symbol = symbolP;
571
0
      }
572
81
    else
573
81
      {
574
        /* Either not seen or not defined.  */
575
        /* @@ Should print out the original string instead of
576
     the parsed number.  */
577
81
        as_bad (_("backward ref to unknown label \"%d:\""),
578
81
          (int) number);
579
81
        expressionP->X_op = O_constant;
580
81
      }
581
582
81
    expressionP->X_add_number = 0;
583
81
  }      /* case 'b' */
584
101k
      else if (LOCAL_LABELS_FB && c == 'f' && maybe_label)
585
482
  {
586
    /* Forward reference.  Expect symbol to be undefined or
587
       unknown.  undefined: seen it before.  unknown: never seen
588
       it before.
589
590
       Construct a local label name, then an undefined symbol.
591
       Don't create a xseg frag for it: caller may do that.
592
       Just return it as never seen before.  */
593
482
    name = fb_label_name (number, 1);
594
482
    symbolP = symbol_find_or_make (name);
595
    /* We have no need to check symbol properties.  */
596
482
    expressionP->X_op = O_symbol;
597
482
    expressionP->X_add_symbol = symbolP;
598
482
    expressionP->X_add_number = 0;
599
482
  }      /* case 'f' */
600
100k
      else if (LOCAL_LABELS_DOLLAR && c == '$' && maybe_label)
601
0
  {
602
    /* If the dollar label is *currently* defined, then this is just
603
       another reference to it.  If it is not *currently* defined,
604
       then this is a fresh instantiation of that number, so create
605
       it.  */
606
607
0
    if (dollar_label_defined (number))
608
0
      {
609
0
        name = dollar_label_name (number, 0);
610
0
        symbolP = symbol_find (name);
611
0
        know (symbolP != NULL);
612
0
      }
613
0
    else
614
0
      {
615
0
        name = dollar_label_name (number, 1);
616
0
        symbolP = symbol_find_or_make (name);
617
0
      }
618
619
0
    expressionP->X_op = O_symbol;
620
0
    expressionP->X_add_symbol = symbolP;
621
0
    expressionP->X_add_number = 0;
622
0
  }      /* case '$' */
623
100k
      else
624
100k
  {
625
100k
    expressionP->X_op = O_constant;
626
100k
    expressionP->X_add_number = number;
627
100k
    input_line_pointer--; /* Restore following character.  */
628
100k
  }      /* Really just a number.  */
629
101k
    }
630
1.02k
  else
631
1.02k
    {
632
      /* Not a small number.  */
633
1.02k
      expressionP->X_op = O_big;
634
1.02k
      expressionP->X_add_number = number; /* Number of littlenums.  */
635
1.02k
      expressionP->X_unsigned = 1;
636
1.02k
      input_line_pointer--; /* -> char following number.  */
637
1.02k
    }
638
102k
}
639
640
/* Parse an MRI multi character constant.  */
641
642
static void
643
mri_char_constant (expressionS *expressionP)
644
0
{
645
0
  int i;
646
0
647
0
  if (*input_line_pointer == '\''
648
0
      && input_line_pointer[1] != '\'')
649
0
    {
650
0
      expressionP->X_op = O_constant;
651
0
      expressionP->X_add_number = 0;
652
0
      return;
653
0
    }
654
0
655
0
  /* In order to get the correct byte ordering, we must build the
656
0
     number in reverse.  */
657
0
  for (i = SIZE_OF_LARGE_NUMBER - 1; i >= 0; i--)
658
0
    {
659
0
      int j;
660
0
661
0
      generic_bignum[i] = 0;
662
0
      for (j = 0; j < CHARS_PER_LITTLENUM; j++)
663
0
  {
664
0
    if (*input_line_pointer == '\'')
665
0
      {
666
0
        if (input_line_pointer[1] != '\'')
667
0
    break;
668
0
        ++input_line_pointer;
669
0
      }
670
0
    generic_bignum[i] <<= 8;
671
0
    generic_bignum[i] += *input_line_pointer;
672
0
    ++input_line_pointer;
673
0
  }
674
0
675
0
      if (i < SIZE_OF_LARGE_NUMBER - 1)
676
0
  {
677
0
    /* If there is more than one littlenum, left justify the
678
0
       last one to make it match the earlier ones.  If there is
679
0
       only one, we can just use the value directly.  */
680
0
    for (; j < CHARS_PER_LITTLENUM; j++)
681
0
      generic_bignum[i] <<= 8;
682
0
  }
683
0
684
0
      if (*input_line_pointer == '\''
685
0
    && input_line_pointer[1] != '\'')
686
0
  break;
687
0
    }
688
0
689
0
  if (i < 0)
690
0
    {
691
0
      as_bad (_("character constant too large"));
692
0
      i = 0;
693
0
    }
694
0
695
0
  if (i > 0)
696
0
    {
697
0
      int c;
698
0
      int j;
699
0
700
0
      c = SIZE_OF_LARGE_NUMBER - i;
701
0
      for (j = 0; j < c; j++)
702
0
  generic_bignum[j] = generic_bignum[i + j];
703
0
      i = c;
704
0
    }
705
0
706
0
  know (LITTLENUM_NUMBER_OF_BITS == 16);
707
0
  if (i > 2)
708
0
    {
709
0
      expressionP->X_op = O_big;
710
0
      expressionP->X_add_number = i;
711
0
      expressionP->X_unsigned = 1;
712
0
    }
713
0
  else
714
0
    {
715
0
      expressionP->X_op = O_constant;
716
0
      if (i < 2)
717
0
  expressionP->X_add_number = generic_bignum[0] & LITTLENUM_MASK;
718
0
      else
719
0
  expressionP->X_add_number =
720
0
    (((generic_bignum[1] & LITTLENUM_MASK)
721
0
      << LITTLENUM_NUMBER_OF_BITS)
722
0
     | (generic_bignum[0] & LITTLENUM_MASK));
723
0
    }
724
0
725
0
  /* Skip the final closing quote.  */
726
0
  ++input_line_pointer;
727
0
}
728
729
/* Return an expression representing the current location.  This
730
   handles the magic symbol `.'.  */
731
732
void
733
current_location (expressionS *expressionp, enum expr_mode mode)
734
10.6k
{
735
10.6k
  if (now_seg == absolute_section)
736
8.45k
    {
737
8.45k
      expressionp->X_op = O_constant;
738
8.45k
      expressionp->X_add_number = abs_section_offset;
739
8.45k
    }
740
2.19k
  else
741
2.19k
    {
742
2.19k
      expressionp->X_op = O_symbol;
743
2.19k
      if (mode != expr_defer_incl_dot)
744
2.19k
  {
745
2.19k
    expressionp->X_add_symbol = symbol_temp_new_now ();
746
#ifdef tc_new_dot_label
747
    tc_new_dot_label (expressionp->X_add_symbol);
748
#endif
749
2.19k
  }
750
4
      else
751
4
    expressionp->X_add_symbol = &dot_symbol;
752
2.19k
      expressionp->X_add_number = 0;
753
2.19k
    }
754
10.6k
}
755
756
/* Make a symbol for the current location ('.').  */
757
758
symbolS *
759
expr_build_dot (void)
760
0
{
761
0
  if (now_seg != absolute_section)
762
0
    {
763
0
      symbolS *symbolP = symbol_temp_new_now ();
764
765
#ifdef tc_new_dot_label
766
      tc_new_dot_label (symbolP);
767
#endif
768
0
      return symbolP;
769
0
    }
770
771
0
  return expr_build_uconstant (abs_section_offset);
772
0
}
773
774
/* Copy an expression, preserving X_md.  */
775
776
static void expr_copy (expressionS *dst, const expressionS *src)
777
4
{
778
4
  unsigned short md = dst->X_md;
779
780
4
  *dst = *src;
781
4
  dst->X_md = md;
782
4
}
783
784
#ifndef md_register_arithmetic
785
# define md_register_arithmetic 1
786
#endif
787
788
/* In:  Input_line_pointer points to 1st char of operand, which may
789
  be a space.
790
791
   Out: An expressionS.
792
  The operand may have been empty: in this case X_op == O_absent.
793
  Input_line_pointer->(next non-blank) char after operand.  */
794
795
static segT
796
operand (expressionS *expressionP, enum expr_mode mode)
797
309k
{
798
309k
  char c;
799
309k
  symbolS *symbolP; /* Points to symbol.  */
800
309k
  char *name;   /* Points to name of symbol.  */
801
309k
  segT segment;
802
309k
  operatorT op = O_absent; /* For unary operators.  */
803
804
  /* All integers are regarded as unsigned unless they are negated.
805
     This is because the only thing which cares whether a number is
806
     unsigned is the code in emit_expr which extends constants into
807
     bignums.  It should only sign extend negative numbers, so that
808
     something like ``.quad 0x80000000'' is not sign extended even
809
     though it appears negative if valueT is 32 bits.  */
810
309k
  expressionP->X_unsigned = 1;
811
309k
  expressionP->X_extrabit = 0;
812
813
  /* Digits, assume it is a bignum.  */
814
815
309k
  SKIP_WHITESPACE ();    /* Leading whitespace is part of operand.  */
816
309k
  c = *input_line_pointer++;  /* input_line_pointer -> past char in c.  */
817
818
309k
  if (is_end_of_stmt (c))
819
4.16k
    goto eol;
820
821
305k
  switch (c)
822
305k
    {
823
19.6k
    case '1':
824
66.9k
    case '2':
825
71.5k
    case '3':
826
78.1k
    case '4':
827
80.4k
    case '5':
828
81.6k
    case '6':
829
85.0k
    case '7':
830
86.8k
    case '8':
831
101k
    case '9':
832
101k
      input_line_pointer--;
833
834
101k
      integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
835
101k
      ? 0 : 10,
836
101k
      expressionP);
837
101k
      break;
838
839
#ifdef LITERAL_PREFIXPERCENT_BIN
840
    case '%':
841
      integer_constant (2, expressionP);
842
      break;
843
#endif
844
845
11.8k
    case '0':
846
      /* Non-decimal radix.  */
847
848
11.8k
      if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
849
0
  {
850
0
    char *s;
851
852
    /* Check for a hex or float constant.  */
853
0
    for (s = input_line_pointer; hex_p (*s); s++)
854
0
      ;
855
0
    if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
856
0
      {
857
0
        --input_line_pointer;
858
0
        integer_constant (0, expressionP);
859
0
        break;
860
0
      }
861
0
  }
862
11.8k
      c = *input_line_pointer;
863
11.8k
      switch (c)
864
11.8k
  {
865
6
  case 'o':
866
8
  case 'O':
867
8
  case 'q':
868
8
  case 'Q':
869
8
  case '8':
870
14
  case '9':
871
14
    if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
872
0
      {
873
0
        integer_constant (0, expressionP);
874
0
        break;
875
0
      }
876
    /* Fall through.  */
877
5.81k
  default:
878
5.84k
  default_case:
879
5.84k
    if (c && strchr (FLT_CHARS, c))
880
0
      {
881
0
        input_line_pointer++;
882
0
        floating_constant (expressionP);
883
0
        expressionP->X_add_number = - TOLOWER (c);
884
0
      }
885
5.84k
    else
886
5.84k
      {
887
        /* The string was only zero.  */
888
5.84k
        expressionP->X_op = O_constant;
889
5.84k
        expressionP->X_add_number = 0;
890
5.84k
      }
891
892
5.84k
    break;
893
894
0
  case 'x':
895
126
  case 'X':
896
126
    if (flag_m68k_mri)
897
0
      goto default_case;
898
126
    input_line_pointer++;
899
126
    integer_constant (16, expressionP);
900
126
    break;
901
902
0
  case 'b':
903
0
    if (LOCAL_LABELS_FB && !flag_m68k_mri
904
0
        && input_line_pointer[1] != '0'
905
0
        && input_line_pointer[1] != '1')
906
0
      {
907
        /* Parse this as a back reference to label 0.  */
908
0
        input_line_pointer--;
909
0
        integer_constant (10, expressionP);
910
0
        break;
911
0
      }
912
    /* Otherwise, parse this as a binary number.  */
913
    /* Fall through.  */
914
0
  case 'B':
915
0
    if (input_line_pointer[1] == '0'
916
0
        || input_line_pointer[1] == '1')
917
0
      {
918
0
        input_line_pointer++;
919
0
        integer_constant (2, expressionP);
920
0
        break;
921
0
      }
922
0
    if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
923
0
      input_line_pointer++;
924
0
    goto default_case;
925
926
0
  case 'l':
927
0
  case 'L':
928
    /* Accept an L suffix to the zero.  */
929
0
    if (tc_allow_L_suffix)
930
0
      goto numeric;
931
0
    goto default_case;
932
933
1
  case 'u':
934
3
  case 'U':
935
    /* Accept a U suffix to the zero.  */
936
3
    if (!tc_allow_U_suffix)
937
0
      goto default_case;
938
    /* Fall through.  */
939
154
  case '0':
940
220
  case '1':
941
323
  case '2':
942
335
  case '3':
943
365
  case '4':
944
376
  case '5':
945
405
  case '6':
946
408
  case '7':
947
408
  numeric:
948
408
    integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
949
408
          ? 0 : 8,
950
408
          expressionP);
951
408
    break;
952
953
2.48k
  case 'f':
954
2.48k
    if (LOCAL_LABELS_FB)
955
2.48k
      {
956
2.48k
        int is_label = 1;
957
958
        /* If it says "0f" and it could possibly be a floating point
959
     number, make it one.  Otherwise, make it a local label,
960
     and try to deal with parsing the rest later.  */
961
2.48k
        if (!is_end_of_stmt (input_line_pointer[1])
962
2.48k
      && strchr (FLT_CHARS, 'f') != NULL)
963
2.48k
    {
964
2.48k
      char *cp = input_line_pointer + 1;
965
966
2.48k
      atof_generic (&cp, ".", EXP_CHARS,
967
2.48k
        &generic_floating_point_number);
968
969
      /* Was nothing parsed, or does it look like an
970
         expression?  */
971
2.48k
      is_label = (cp == input_line_pointer + 1
972
2.48k
            || (cp == input_line_pointer + 2
973
2.10k
          && (cp[-1] == '-' || cp[-1] == '+'))
974
2.48k
            || *cp == 'f'
975
2.48k
            || *cp == 'b');
976
2.48k
    }
977
2.48k
        if (is_label)
978
406
    {
979
406
      input_line_pointer--;
980
406
      integer_constant (10, expressionP);
981
406
      break;
982
406
    }
983
2.48k
      }
984
    /* Fall through.  */
985
986
2.08k
  case 'd':
987
2.08k
  case 'D':
988
2.08k
    if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
989
0
      {
990
0
        integer_constant (0, expressionP);
991
0
        break;
992
0
      }
993
    /* Fall through.  */
994
2.08k
  case 'F':
995
5.00k
  case 'r':
996
5.01k
  case 'e':
997
5.02k
  case 'E':
998
5.03k
  case 'g':
999
5.03k
  case 'G':
1000
5.03k
    input_line_pointer++;
1001
5.03k
    floating_constant (expressionP);
1002
5.03k
    expressionP->X_add_number = - TOLOWER (c);
1003
5.03k
    break;
1004
1005
21
  case '$':
1006
21
    if (LOCAL_LABELS_DOLLAR)
1007
0
      {
1008
0
        integer_constant (10, expressionP);
1009
0
        break;
1010
0
      }
1011
21
    else
1012
21
      goto default_case;
1013
11.8k
  }
1014
1015
11.8k
      break;
1016
1017
11.8k
#ifndef NEED_INDEX_OPERATOR
1018
11.8k
    case '[':
1019
105
# ifdef md_need_index_operator
1020
105
      if (md_need_index_operator())
1021
0
  goto de_fault;
1022
105
# endif
1023
105
#endif
1024
      /* Fall through.  */
1025
2.01k
    case '(':
1026
      /* Didn't begin with digit & not a name.  */
1027
2.01k
      segment = expr (0, expressionP, mode);
1028
      /* expression () will pass trailing whitespace.  */
1029
2.01k
      if ((c == '(' && *input_line_pointer != ')')
1030
2.01k
    || (c == '[' && *input_line_pointer != ']'))
1031
1.96k
  {
1032
1.96k
    if (* input_line_pointer)
1033
1.26k
      as_bad (_("found '%c', expected: '%c'"),
1034
1.26k
        * input_line_pointer, c == '(' ? ')' : ']');
1035
699
    else
1036
699
      as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
1037
1.96k
  }      
1038
55
      else
1039
55
  input_line_pointer++;
1040
2.01k
      SKIP_ALL_WHITESPACE ();
1041
      /* Here with input_line_pointer -> char after "(...)".  */
1042
2.01k
      return segment;
1043
1044
#ifdef TC_M68K
1045
    case 'E':
1046
      if (! flag_m68k_mri || *input_line_pointer != '\'')
1047
  goto de_fault;
1048
      as_bad (_("EBCDIC constants are not supported"));
1049
      /* Fall through.  */
1050
    case 'A':
1051
      if (! flag_m68k_mri || *input_line_pointer != '\'')
1052
  goto de_fault;
1053
      ++input_line_pointer;
1054
#endif
1055
      /* Fall through.  */
1056
349
    case '\'':
1057
349
      if (! flag_m68k_mri)
1058
349
  {
1059
    /* Warning: to conform to other people's assemblers NO
1060
       ESCAPEMENT is permitted for a single quote.  The next
1061
       character, parity errors and all, is taken as the value
1062
       of the operand.  VERY KINKY.  */
1063
349
    expressionP->X_op = O_constant;
1064
349
    expressionP->X_add_number = *input_line_pointer++;
1065
349
    break;
1066
349
  }
1067
1068
0
      mri_char_constant (expressionP);
1069
0
      break;
1070
1071
#ifdef TC_M68K
1072
    case '"':
1073
      /* Double quote is the bitwise not operator in MRI mode.  */
1074
      if (! flag_m68k_mri)
1075
  goto de_fault;
1076
#endif
1077
      /* Fall through.  */
1078
608
    case '~':
1079
      /* '~' is permitted to start a label on the Delta.  */
1080
608
      if (is_name_beginner (c))
1081
0
  goto isname;
1082
608
      op = O_bit_not;
1083
608
      goto unary;
1084
1085
1.14k
    case '!':
1086
1.14k
      op = O_logical_not;
1087
1.14k
      goto unary;
1088
1089
53.0k
    case '-':
1090
53.0k
      op = O_uminus;
1091
      /* Fall through.  */
1092
58.6k
    case '+':
1093
58.6k
      {
1094
60.4k
      unary:
1095
60.4k
  operand (expressionP, mode);
1096
1097
60.4k
#ifdef md_optimize_expr
1098
60.4k
  if (md_optimize_expr (NULL, op, expressionP))
1099
0
  {
1100
    /* Skip.  */
1101
0
    ;
1102
0
  }
1103
60.4k
  else
1104
60.4k
#endif
1105
60.4k
  if (expressionP->X_op == O_constant)
1106
43.3k
    {
1107
      /* input_line_pointer -> char after operand.  */
1108
43.3k
      if (op == O_uminus)
1109
40.1k
        {
1110
40.1k
    expressionP->X_add_number
1111
40.1k
      = - (addressT) expressionP->X_add_number;
1112
    /* Notice: '-' may overflow: no warning is given.
1113
       This is compatible with other people's
1114
       assemblers.  Sigh.  */
1115
40.1k
    expressionP->X_unsigned = 0;
1116
40.1k
    if (expressionP->X_add_number)
1117
32.4k
      expressionP->X_extrabit ^= 1;
1118
40.1k
        }
1119
3.20k
      else if (op == O_bit_not)
1120
53
        {
1121
53
    expressionP->X_add_number = ~ expressionP->X_add_number;
1122
53
    expressionP->X_extrabit ^= 1;
1123
53
    expressionP->X_unsigned = 0;
1124
53
        }
1125
3.15k
      else if (op == O_logical_not)
1126
422
        {
1127
422
    expressionP->X_add_number = ! expressionP->X_add_number;
1128
422
    expressionP->X_unsigned = 1;
1129
422
    expressionP->X_extrabit = 0;
1130
422
        }
1131
43.3k
    }
1132
17.0k
  else if (expressionP->X_op == O_big
1133
17.0k
     && expressionP->X_add_number <= 0
1134
17.0k
     && op == O_uminus
1135
17.0k
     && (generic_floating_point_number.sign == '+'
1136
24
         || generic_floating_point_number.sign == 'P'))
1137
12
    {
1138
      /* Negative flonum (eg, -1.000e0).  */
1139
12
      if (generic_floating_point_number.sign == '+')
1140
12
        generic_floating_point_number.sign = '-';
1141
0
      else
1142
0
        generic_floating_point_number.sign = 'N';
1143
12
    }
1144
17.0k
  else if (expressionP->X_op == O_big
1145
17.0k
     && expressionP->X_add_number > 0)
1146
1.38k
    {
1147
1.38k
      int i;
1148
1149
1.38k
      if (op == O_uminus || op == O_bit_not)
1150
1.12k
        {
1151
16.8k
    for (i = 0; i < expressionP->X_add_number; ++i)
1152
15.6k
      generic_bignum[i] = ~generic_bignum[i];
1153
1154
    /* Extend the bignum to at least the size of .octa.  */
1155
1.12k
    if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1156
558
      {
1157
558
        expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1158
7.45k
        for (; i < expressionP->X_add_number; ++i)
1159
6.89k
          generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1160
558
      }
1161
1162
1.12k
    if (op == O_uminus)
1163
991
      for (i = 0; i < expressionP->X_add_number; ++i)
1164
991
        {
1165
991
          generic_bignum[i] += 1;
1166
991
          if (generic_bignum[i])
1167
984
      break;
1168
991
        }
1169
1170
1.12k
    expressionP->X_unsigned = 0;
1171
1.12k
        }
1172
260
      else if (op == O_logical_not)
1173
257
        {
1174
373
    for (i = 0; i < expressionP->X_add_number; ++i)
1175
373
      if (generic_bignum[i] != 0)
1176
257
        break;
1177
257
    expressionP->X_add_number = i >= expressionP->X_add_number;
1178
257
    expressionP->X_op = O_constant;
1179
257
    expressionP->X_unsigned = 1;
1180
257
    expressionP->X_extrabit = 0;
1181
257
        }
1182
1.38k
    }
1183
15.6k
  else if (expressionP->X_op != O_illegal
1184
15.6k
     && expressionP->X_op != O_absent)
1185
13.7k
    {
1186
13.7k
      if (op != O_absent)
1187
10.8k
        {
1188
10.8k
    expressionP->X_add_symbol = make_expr_symbol (expressionP);
1189
10.8k
    expressionP->X_op = op;
1190
10.8k
    expressionP->X_add_number = 0;
1191
10.8k
        }
1192
2.87k
      else if (!md_register_arithmetic && expressionP->X_op == O_register)
1193
38
        {
1194
    /* Convert to binary '+'.  */
1195
38
    expressionP->X_op_symbol = make_expr_symbol (expressionP);
1196
38
    expressionP->X_add_symbol = make_expr_symbol (&zero);
1197
38
    expressionP->X_add_number = 0;
1198
38
    expressionP->X_op = O_add;
1199
38
        }
1200
13.7k
    }
1201
1.94k
  else
1202
1.94k
    as_warn (_("Unary operator %c ignored because bad operand follows"),
1203
1.94k
       c);
1204
60.4k
      }
1205
60.4k
      break;
1206
1207
0
#if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1208
735
    case '$':
1209
735
      if (literal_prefix_dollar_hex)
1210
0
  {
1211
    /* $L is the start of a local label, not a hex constant.  */
1212
0
    if (* input_line_pointer == 'L')
1213
0
    goto isname;
1214
0
    integer_constant (16, expressionP);
1215
0
  }
1216
735
      else
1217
735
  {
1218
735
    goto isname;
1219
735
  }
1220
0
      break;
1221
#else
1222
    case '$':
1223
      /* '$' is the program counter when in MRI mode, or when
1224
   DOLLAR_DOT is defined.  */
1225
#ifndef DOLLAR_DOT
1226
      if (! flag_m68k_mri)
1227
  goto de_fault;
1228
#endif
1229
      if (DOLLAR_AMBIGU && hex_p (*input_line_pointer))
1230
  {
1231
    /* In MRI mode and on Z80, '$' is also used as the prefix
1232
       for a hexadecimal constant.  */
1233
    integer_constant (16, expressionP);
1234
    break;
1235
  }
1236
1237
      if (is_part_of_name (*input_line_pointer))
1238
  goto isname;
1239
1240
      current_location (expressionP, mode);
1241
      break;
1242
#endif
1243
1244
13.1k
    case '.':
1245
13.1k
      if (!is_part_of_name (*input_line_pointer))
1246
10.6k
  {
1247
10.6k
    current_location (expressionP, mode);
1248
10.6k
    break;
1249
10.6k
  }
1250
2.47k
      else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1251
2.47k
    && ! is_part_of_name (input_line_pointer[8]))
1252
2.47k
         || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1253
2.10k
       && ! is_part_of_name (input_line_pointer[7])))
1254
373
  {
1255
373
    int start;
1256
1257
373
    start = (input_line_pointer[1] == 't'
1258
373
       || input_line_pointer[1] == 'T');
1259
373
    input_line_pointer += start ? 8 : 7;
1260
373
    SKIP_WHITESPACE ();
1261
1262
    /* Cover for the as_bad () invocations below.  */
1263
373
    expressionP->X_op = O_absent;
1264
1265
373
    if (*input_line_pointer != '(')
1266
5
      as_bad (_("syntax error in .startof. or .sizeof."));
1267
368
    else
1268
368
      {
1269
368
        ++input_line_pointer;
1270
368
        SKIP_WHITESPACE ();
1271
368
        c = get_symbol_name (& name);
1272
368
        if (! *name)
1273
311
    {
1274
311
      as_bad (_("expected symbol name"));
1275
311
      (void) restore_line_pointer (c);
1276
311
      if (c == ')')
1277
311
        ++input_line_pointer;
1278
311
      break;
1279
311
    }
1280
1281
57
        expressionP->X_op = O_symbol;
1282
57
        expressionP->X_add_symbol = symbol_lookup_or_make (name, start);
1283
57
        expressionP->X_add_number = 0;
1284
1285
57
        restore_line_pointer (c);
1286
57
        SKIP_WHITESPACE ();
1287
57
        if (*input_line_pointer != ')')
1288
57
    as_bad (_("syntax error in .startof. or .sizeof."));
1289
0
        else
1290
0
    ++input_line_pointer;
1291
57
      }
1292
62
    break;
1293
373
  }
1294
2.10k
      else
1295
2.10k
  {
1296
2.10k
    goto isname;
1297
2.10k
  }
1298
1299
4.22k
    case ',':
1300
8.39k
    eol:
1301
      /* Can't imagine any other kind of operand.  */
1302
8.39k
      expressionP->X_op = O_absent;
1303
8.39k
      input_line_pointer--;
1304
8.39k
      break;
1305
1306
#ifdef TC_M68K
1307
    case '%':
1308
      if (! flag_m68k_mri)
1309
  goto de_fault;
1310
      integer_constant (2, expressionP);
1311
      break;
1312
1313
    case '@':
1314
      if (! flag_m68k_mri)
1315
  goto de_fault;
1316
      integer_constant (8, expressionP);
1317
      break;
1318
1319
    case ':':
1320
      if (! flag_m68k_mri)
1321
  goto de_fault;
1322
1323
      /* In MRI mode, this is a floating point constant represented
1324
   using hexadecimal digits.  */
1325
1326
      ++input_line_pointer;
1327
      integer_constant (16, expressionP);
1328
      break;
1329
1330
    case '*':
1331
      if (! flag_m68k_mri || is_part_of_name (*input_line_pointer))
1332
  goto de_fault;
1333
1334
      current_location (expressionP, mode);
1335
      break;
1336
#endif
1337
1338
111k
    default:
1339
111k
#if defined(md_need_index_operator) || defined(TC_M68K)
1340
111k
    de_fault:
1341
111k
#endif
1342
111k
      if (is_name_beginner (c) || c == '"')  /* Here if did not begin with a digit.  */
1343
84.1k
  {
1344
    /* Identifier begins here.
1345
       This is kludged for speed, so code is repeated.  */
1346
86.9k
  isname:
1347
86.9k
    -- input_line_pointer;
1348
86.9k
    c = get_symbol_name (&name);
1349
1350
86.9k
#ifdef md_operator
1351
86.9k
    {
1352
86.9k
      op = md_operator (name, 1, &c);
1353
86.9k
      switch (op)
1354
86.9k
        {
1355
0
        case O_uminus:
1356
0
    restore_line_pointer (c);
1357
0
    c = '-';
1358
0
    goto unary;
1359
0
        case O_bit_not:
1360
0
    restore_line_pointer (c);
1361
0
    c = '~';
1362
0
    goto unary;
1363
0
        case O_logical_not:
1364
0
    restore_line_pointer (c);
1365
0
    c = '!';
1366
0
    goto unary;
1367
0
        case O_illegal:
1368
0
    as_bad (_("invalid use of operator \"%s\""), name);
1369
0
    break;
1370
86.9k
        default:
1371
86.9k
    break;
1372
86.9k
        }
1373
1374
86.9k
      if (op != O_absent && op != O_illegal)
1375
0
        {
1376
0
    restore_line_pointer (c);
1377
0
    expr (9, expressionP, mode);
1378
0
    expressionP->X_add_symbol = make_expr_symbol (expressionP);
1379
0
    expressionP->X_op_symbol = NULL;
1380
0
    expressionP->X_add_number = 0;
1381
0
    expressionP->X_op = op;
1382
0
    break;
1383
0
        }
1384
86.9k
    }
1385
86.9k
#endif
1386
1387
86.9k
#ifdef md_parse_name
1388
    /* This is a hook for the backend to parse certain names
1389
       specially in certain contexts.  If a name always has a
1390
       specific value, it can often be handled by simply
1391
       entering it in the symbol table.  */
1392
86.9k
    if (md_parse_name (name, expressionP, mode, &c))
1393
0
      {
1394
0
        restore_line_pointer (c);
1395
0
        break;
1396
0
      }
1397
86.9k
#endif
1398
1399
86.9k
    symbolP = symbol_find_or_make (name);
1400
1401
    /* If we have an absolute symbol or a reg, then we know its
1402
       value now.  */
1403
86.9k
    segment = S_GET_SEGMENT (symbolP);
1404
86.9k
    if (!expr_defer_p (mode)
1405
86.9k
        && segment == absolute_section
1406
86.9k
        && !S_FORCE_RELOC (symbolP, 0))
1407
5.22k
      {
1408
5.22k
        expressionP->X_op = O_constant;
1409
5.22k
        expressionP->X_add_number = S_GET_VALUE (symbolP);
1410
5.22k
      }
1411
81.7k
    else if (!expr_defer_p (mode) && segment == reg_section)
1412
2
      {
1413
2
        if (md_register_arithmetic)
1414
0
    {
1415
0
      expressionP->X_op = O_register;
1416
0
      expressionP->X_add_number = S_GET_VALUE (symbolP);
1417
0
    }
1418
2
        else
1419
2
    {
1420
2
      expr_copy (expressionP,
1421
2
           symbol_get_value_expression (symbolP));
1422
2
      resolve_register (expressionP);
1423
2
    }
1424
2
      }
1425
81.7k
    else
1426
81.7k
      {
1427
81.7k
        expressionP->X_op = O_symbol;
1428
81.7k
        expressionP->X_add_symbol = symbolP;
1429
81.7k
        expressionP->X_add_number = 0;
1430
81.7k
      }
1431
1432
86.9k
    restore_line_pointer (c);
1433
86.9k
  }
1434
27.6k
      else
1435
27.6k
  {
1436
    /* Let the target try to parse it.  Success is indicated by changing
1437
       the X_op field to something other than O_absent and pointing
1438
       input_line_pointer past the expression.  If it can't parse the
1439
       expression, X_op and input_line_pointer should be unchanged.  */
1440
27.6k
    expressionP->X_op = O_absent;
1441
27.6k
    --input_line_pointer;
1442
27.6k
    md_operand (expressionP);
1443
27.6k
    if (expressionP->X_op == O_absent)
1444
27.1k
      {
1445
27.1k
        ++input_line_pointer;
1446
27.1k
        as_bad (_("bad expression"));
1447
27.1k
        expressionP->X_op = O_constant;
1448
27.1k
        expressionP->X_add_number = 0;
1449
27.1k
      }
1450
27.6k
  }
1451
114k
      break;
1452
305k
    }
1453
1454
  /* It is more 'efficient' to clean up the expressionS when they are
1455
     created.  Doing it here saves lines of code.  */
1456
307k
  clean_up_expression (expressionP);
1457
307k
  SKIP_ALL_WHITESPACE ();    /* -> 1st char after operand.  */
1458
307k
  know (!is_whitespace (*input_line_pointer));
1459
1460
  /* The PA port needs this information.  */
1461
307k
  if (expressionP->X_add_symbol)
1462
98.1k
    symbol_mark_used (expressionP->X_add_symbol);
1463
1464
307k
  if (!expr_defer_p (mode))
1465
307k
    {
1466
307k
      expressionP->X_add_symbol
1467
307k
  = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1468
307k
      expressionP->X_op_symbol
1469
307k
  = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1470
307k
    }
1471
1472
307k
  switch (expressionP->X_op)
1473
307k
    {
1474
220k
    default:
1475
220k
      return absolute_section;
1476
87.2k
    case O_symbol:
1477
87.2k
      return S_GET_SEGMENT (expressionP->X_add_symbol);
1478
513
    case O_register:
1479
513
      return reg_section;
1480
307k
    }
1481
307k
}
1482

1483
/* Internal.  Simplify a struct expression for use by expr ().  */
1484
1485
/* In:  address of an expressionS.
1486
  The X_op field of the expressionS may only take certain values.
1487
  Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
1488
1489
   Out: expressionS may have been modified:
1490
  Unused fields zeroed to help expr ().  */
1491
1492
static void
1493
clean_up_expression (expressionS *expressionP)
1494
307k
{
1495
307k
  switch (expressionP->X_op)
1496
307k
    {
1497
0
    case O_illegal:
1498
10.6k
    case O_absent:
1499
10.6k
      expressionP->X_add_number = 0;
1500
      /* Fall through.  */
1501
17.8k
    case O_big:
1502
209k
    case O_constant:
1503
209k
    case O_register:
1504
209k
      expressionP->X_add_symbol = NULL;
1505
      /* Fall through.  */
1506
296k
    case O_symbol:
1507
307k
    case O_uminus:
1508
307k
    case O_bit_not:
1509
307k
      expressionP->X_op_symbol = NULL;
1510
307k
      break;
1511
366
    default:
1512
366
      break;
1513
307k
    }
1514
307k
}
1515

1516
/* Expression parser.  */
1517
1518
/* We allow an empty expression, and just assume (absolute,0) silently.
1519
   Unary operators and parenthetical expressions are treated as operands.
1520
   As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
1521
1522
   We used to do an aho/ullman shift-reduce parser, but the logic got so
1523
   warped that I flushed it and wrote a recursive-descent parser instead.
1524
   Now things are stable, would anybody like to write a fast parser?
1525
   Most expressions are either register (which does not even reach here)
1526
   or 1 symbol. Then "symbol+constant" and "symbol-symbol" are common.
1527
   So I guess it doesn't really matter how inefficient more complex expressions
1528
   are parsed.
1529
1530
   After expr(RANK,resultP) input_line_pointer->operator of rank <= RANK.
1531
   Also, we have consumed any leading or trailing spaces (operand does that)
1532
   and done all intervening operators.
1533
1534
   This returns the segment of the result, which will be
1535
   absolute_section or the segment of a symbol.  */
1536
1537
#undef __
1538
#define __ O_illegal
1539
#ifndef O_SINGLE_EQ
1540
#define O_SINGLE_EQ O_illegal
1541
#endif
1542
1543
/* Maps ASCII -> operators.  */
1544
static const operatorT op_encoding[256] = {
1545
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1546
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1547
1548
  __, O_bit_or_not, __, __, __, O_modulus, O_bit_and, __,
1549
  __, __, O_multiply, O_add, __, O_subtract, __, O_divide,
1550
  __, __, __, __, __, __, __, __,
1551
  __, __, __, __, O_lt, O_SINGLE_EQ, O_gt, __,
1552
  __, __, __, __, __, __, __, __,
1553
  __, __, __, __, __, __, __, __,
1554
  __, __, __, __, __, __, __, __,
1555
  __, __, __,
1556
#ifdef NEED_INDEX_OPERATOR
1557
  O_index,
1558
#else
1559
  __,
1560
#endif
1561
  __, __, O_bit_exclusive_or, __,
1562
  __, __, __, __, __, __, __, __,
1563
  __, __, __, __, __, __, __, __,
1564
  __, __, __, __, __, __, __, __,
1565
  __, __, __, __, O_bit_inclusive_or, __, __, __,
1566
1567
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1568
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1569
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1570
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1571
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1572
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1573
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __,
1574
  __, __, __, __, __, __, __, __, __, __, __, __, __, __, __, __
1575
};
1576
1577
/* Rank Examples
1578
   0  operand, (expression)
1579
   1  ||
1580
   2  &&
1581
   3  == <> < <= >= >
1582
   4  + -
1583
   5  used for * / % in MRI mode
1584
   6  & ^ ! |
1585
   7  * / % << >>
1586
   8  unary - unary ~
1587
*/
1588
static operator_rankT op_rank[O_max] = {
1589
  0,  /* O_illegal */
1590
  0,  /* O_absent */
1591
  0,  /* O_constant */
1592
  0,  /* O_symbol */
1593
  0,  /* O_symbol_rva */
1594
  0,  /* O_secidx */
1595
  0,  /* O_register */
1596
  0,  /* O_big */
1597
  9,  /* O_uminus */
1598
  9,  /* O_bit_not */
1599
  9,  /* O_logical_not */
1600
  8,  /* O_multiply */
1601
  8,  /* O_divide */
1602
  8,  /* O_modulus */
1603
  8,  /* O_left_shift */
1604
  8,  /* O_right_shift */
1605
  7,  /* O_bit_inclusive_or */
1606
  7,  /* O_bit_or_not */
1607
  7,  /* O_bit_exclusive_or */
1608
  7,  /* O_bit_and */
1609
  5,  /* O_add */
1610
  5,  /* O_subtract */
1611
  4,  /* O_eq */
1612
  4,  /* O_ne */
1613
  4,  /* O_lt */
1614
  4,  /* O_le */
1615
  4,  /* O_ge */
1616
  4,  /* O_gt */
1617
  3,  /* O_logical_and */
1618
  2,  /* O_logical_or */
1619
  1,  /* O_index */
1620
};
1621
1622
/* Unfortunately, in MRI mode for the m68k, multiplication and
1623
   division have lower precedence than the bit wise operators.  This
1624
   function sets the operator precedences correctly for the current
1625
   mode.  Also, MRI uses a different bit_not operator, and this fixes
1626
   that as well.  */
1627
1628
1.01k
#define STANDARD_MUL_PRECEDENCE 8
1629
0
#define MRI_MUL_PRECEDENCE 6
1630
1631
void
1632
expr_set_precedence (void)
1633
339
{
1634
339
  if (flag_m68k_mri)
1635
0
    {
1636
0
      op_rank[O_multiply] = MRI_MUL_PRECEDENCE;
1637
0
      op_rank[O_divide] = MRI_MUL_PRECEDENCE;
1638
0
      op_rank[O_modulus] = MRI_MUL_PRECEDENCE;
1639
0
    }
1640
339
  else
1641
339
    {
1642
339
      op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1643
339
      op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1644
339
      op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1645
339
    }
1646
339
}
1647
1648
void
1649
expr_set_rank (operatorT op, operator_rankT rank)
1650
2
{
1651
2
  gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank));
1652
2
  op_rank[op] = rank;
1653
2
}
1654
1655
/* Initialize the expression parser.  */
1656
1657
void
1658
expr_begin (void)
1659
28
{
1660
28
  expr_set_precedence ();
1661
1662
  /* Verify that X_op field is wide enough.  */
1663
28
  {
1664
28
    expressionS e;
1665
28
    e.X_op = O_max;
1666
28
    gas_assert (e.X_op == O_max);
1667
28
  }
1668
1669
28
  memset (seen, 0, sizeof seen);
1670
28
  memset (nr_seen, 0, sizeof nr_seen);
1671
28
  expr_symbol_lines = NULL;
1672
28
}
1673
1674
void
1675
expr_end (void)
1676
28
{
1677
84
  for (size_t i = 0; i < ARRAY_SIZE (seen); i++)
1678
56
    free (seen[i]);
1679
28
}
1680

1681
/* Return the encoding for the operator at INPUT_LINE_POINTER, and
1682
   sets NUM_CHARS to the number of characters in the operator.
1683
   Does not advance INPUT_LINE_POINTER.  */
1684
1685
static inline operatorT
1686
operatorf (int *num_chars)
1687
331k
{
1688
331k
  int c;
1689
331k
  operatorT ret;
1690
1691
331k
  c = *input_line_pointer & 0xff;
1692
331k
  *num_chars = 1;
1693
1694
331k
  if (is_end_of_stmt (c))
1695
70.4k
    return O_illegal;
1696
1697
261k
#ifdef md_operator
1698
261k
  if (is_name_beginner (c))
1699
107k
    {
1700
107k
      char *name;
1701
107k
      char ec = get_symbol_name (& name);
1702
1703
107k
      ret = md_operator (name, 2, &ec);
1704
107k
      switch (ret)
1705
107k
  {
1706
107k
  case O_absent:
1707
107k
    *input_line_pointer = ec;
1708
107k
    input_line_pointer = name;
1709
107k
    break;
1710
0
  case O_uminus:
1711
0
  case O_bit_not:
1712
0
  case O_logical_not:
1713
0
    as_bad (_("invalid use of operator \"%s\""), name);
1714
0
    ret = O_illegal;
1715
    /* FALLTHROUGH */
1716
0
  default:
1717
0
    *input_line_pointer = ec;
1718
0
    *num_chars = input_line_pointer - name;
1719
0
    input_line_pointer = name;
1720
0
    return ret;
1721
107k
  }
1722
107k
    }
1723
261k
#endif
1724
1725
261k
  switch (c)
1726
261k
    {
1727
171k
    default:
1728
171k
      ret = op_encoding[c];
1729
171k
#ifdef md_operator
1730
171k
      if (ret == O_illegal)
1731
143k
  {
1732
143k
    char *start = input_line_pointer;
1733
1734
143k
    ret = md_operator (NULL, 2, NULL);
1735
143k
    if (ret != O_illegal)
1736
143k
      *num_chars = input_line_pointer - start;
1737
143k
    input_line_pointer = start;
1738
143k
  }
1739
171k
#endif
1740
171k
      return ret;
1741
1742
12.6k
    case '+':
1743
56.7k
    case '-':
1744
56.7k
      return op_encoding[c];
1745
1746
836
    case '<':
1747
836
      switch (input_line_pointer[1])
1748
836
  {
1749
507
  default:
1750
507
    return op_encoding[c];
1751
70
  case '<':
1752
70
    ret = O_left_shift;
1753
70
    break;
1754
70
  case '>':
1755
70
    ret = O_ne;
1756
70
    break;
1757
189
  case '=':
1758
189
    ret = O_le;
1759
189
    break;
1760
836
  }
1761
329
      *num_chars = 2;
1762
329
      return ret;
1763
1764
21.2k
    case '=':
1765
21.2k
      if (input_line_pointer[1] != '=')
1766
2.25k
  return op_encoding[c];
1767
1768
19.0k
      *num_chars = 2;
1769
19.0k
      return O_eq;
1770
1771
1.98k
    case '>':
1772
1.98k
      switch (input_line_pointer[1])
1773
1.98k
  {
1774
548
  default:
1775
548
    return op_encoding[c];
1776
1.30k
  case '>':
1777
1.30k
    ret = O_right_shift;
1778
1.30k
    break;
1779
133
  case '=':
1780
133
    ret = O_ge;
1781
133
    break;
1782
1.98k
  }
1783
1.43k
      *num_chars = 2;
1784
1.43k
      return ret;
1785
1786
1.48k
    case '!':
1787
1.48k
      switch (input_line_pointer[1])
1788
1.48k
  {
1789
34
  case '!':
1790
    /* We accept !! as equivalent to ^ for MRI compatibility. */
1791
34
    *num_chars = 2;
1792
34
    return O_bit_exclusive_or;
1793
405
  case '=':
1794
    /* We accept != as equivalent to <>.  */
1795
405
    *num_chars = 2;
1796
405
    return O_ne;
1797
1.04k
  default:
1798
1.04k
    if (flag_m68k_mri)
1799
0
      return O_bit_inclusive_or;
1800
1.04k
    return op_encoding[c];
1801
1.48k
  }
1802
1803
5.32k
    case '|':
1804
5.32k
      if (input_line_pointer[1] != '|')
1805
842
  return op_encoding[c];
1806
1807
4.48k
      *num_chars = 2;
1808
4.48k
      return O_logical_or;
1809
1810
2.48k
    case '&':
1811
2.48k
      if (input_line_pointer[1] != '&')
1812
682
  return op_encoding[c];
1813
1814
1.80k
      *num_chars = 2;
1815
1.80k
      return O_logical_and;
1816
261k
    }
1817
1818
  /* NOTREACHED  */
1819
261k
}
1820
1821
/* Implement "word-size + 1 bit" addition for
1822
   {resultP->X_extrabit:resultP->X_add_number} + {rhs_highbit:amount}.  This
1823
   is used so that the full range of unsigned word values and the full range of
1824
   signed word values can be represented in an O_constant expression, which is
1825
   useful e.g. for .sleb128 directives.  */
1826
1827
void
1828
add_to_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1829
11.6k
{
1830
11.6k
  valueT ures = resultP->X_add_number;
1831
11.6k
  valueT uamount = amount;
1832
1833
11.6k
  resultP->X_add_number += uamount;
1834
1835
11.6k
  resultP->X_extrabit ^= rhs_highbit;
1836
1837
11.6k
  if (ures + uamount < ures)
1838
41
    resultP->X_extrabit ^= 1;
1839
11.6k
}
1840
1841
/* Similarly, for subtraction.  */
1842
1843
void
1844
subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1845
22.5k
{
1846
22.5k
  valueT ures = resultP->X_add_number;
1847
22.5k
  valueT uamount = amount;
1848
1849
22.5k
  resultP->X_add_number -= uamount;
1850
1851
22.5k
  resultP->X_extrabit ^= rhs_highbit;
1852
1853
22.5k
  if (ures < uamount)
1854
6.31k
    resultP->X_extrabit ^= 1;
1855
22.5k
}
1856
1857
/* Parse an expression.  */
1858
1859
segT
1860
expr (int rankarg,    /* Larger # is higher rank.  */
1861
      expressionS *resultP, /* Deliver result here.  */
1862
      enum expr_mode mode /* Controls behavior.  */)
1863
249k
{
1864
249k
  operator_rankT rank = (operator_rankT) rankarg;
1865
249k
  segT retval;
1866
249k
  expressionS right;
1867
249k
  operatorT op_left;
1868
249k
  operatorT op_right;
1869
249k
  int op_chars;
1870
1871
249k
  know (rankarg >= 0);
1872
1873
  /* Save the value of dot for the fixup code.  */
1874
249k
  if (rank == 0)
1875
167k
    symbol_set_value_now (&dot_symbol);
1876
1877
249k
  retval = operand (resultP, mode);
1878
1879
  /* operand () gobbles spaces.  */
1880
249k
  know (!is_whitespace (*input_line_pointer));
1881
1882
249k
  op_left = operatorf (&op_chars);
1883
331k
  while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1884
82.1k
    {
1885
82.1k
      segT rightseg;
1886
82.1k
      bool is_unsigned;
1887
82.1k
      offsetT frag_off;
1888
1889
82.1k
      input_line_pointer += op_chars; /* -> after operator.  */
1890
1891
82.1k
      right.X_md = 0;
1892
82.1k
      rightseg = expr (op_rank[(int) op_left], &right, mode);
1893
82.1k
      if (right.X_op == O_absent)
1894
1.61k
  {
1895
1.61k
    as_warn (_("missing operand; zero assumed"));
1896
1.61k
    right.X_op = O_constant;
1897
1.61k
    right.X_add_number = 0;
1898
1.61k
    right.X_add_symbol = NULL;
1899
1.61k
    right.X_op_symbol = NULL;
1900
1.61k
  }
1901
1902
82.1k
      know (!is_whitespace (*input_line_pointer));
1903
1904
82.1k
      if (op_left == O_index)
1905
0
  {
1906
0
    if (*input_line_pointer != ']')
1907
0
      as_bad ("missing right bracket");
1908
0
    else
1909
0
      {
1910
0
        ++input_line_pointer;
1911
0
        SKIP_WHITESPACE ();
1912
0
      }
1913
0
  }
1914
1915
82.1k
      op_right = operatorf (&op_chars);
1916
1917
82.1k
      know (op_right == O_illegal || op_left == O_index
1918
82.1k
      || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1919
82.1k
      know ((int) op_left >= (int) O_multiply);
1920
#ifndef md_operator
1921
      know ((int) op_left <= (int) O_index);
1922
#else
1923
82.1k
      know ((int) op_left < (int) O_max);
1924
82.1k
#endif
1925
1926
      /* input_line_pointer->after right-hand quantity.  */
1927
      /* left-hand quantity in resultP.  */
1928
      /* right-hand quantity in right.  */
1929
      /* operator in op_left.  */
1930
1931
82.1k
      if (resultP->X_op == O_big)
1932
352
  {
1933
352
    if (resultP->X_add_number > 0)
1934
97
      as_warn (_("left operand is a bignum; integer 0 assumed"));
1935
255
    else
1936
255
      as_warn (_("left operand is a float; integer 0 assumed"));
1937
352
    resultP->X_op = O_constant;
1938
352
    resultP->X_add_number = 0;
1939
352
    resultP->X_add_symbol = NULL;
1940
352
    resultP->X_op_symbol = NULL;
1941
352
  }
1942
82.1k
      if (right.X_op == O_big)
1943
2.69k
  {
1944
2.69k
    if (right.X_add_number > 0)
1945
20
      as_warn (_("right operand is a bignum; integer 0 assumed"));
1946
2.67k
    else
1947
2.67k
      as_warn (_("right operand is a float; integer 0 assumed"));
1948
2.69k
    right.X_op = O_constant;
1949
2.69k
    right.X_add_number = 0;
1950
2.69k
    right.X_add_symbol = NULL;
1951
2.69k
    right.X_op_symbol = NULL;
1952
2.69k
  }
1953
1954
82.1k
      is_unsigned = resultP->X_unsigned && right.X_unsigned;
1955
1956
82.1k
      if (expr_defer_p (mode)
1957
82.1k
    && ((resultP->X_add_symbol != NULL
1958
319
         && S_IS_FORWARD_REF (resultP->X_add_symbol))
1959
319
        || (right.X_add_symbol != NULL
1960
291
      && S_IS_FORWARD_REF (right.X_add_symbol))))
1961
36
  goto general;
1962
1963
      /* Optimize common cases.  */
1964
82.0k
#ifdef md_optimize_expr
1965
82.0k
      if (md_optimize_expr (resultP, op_left, &right))
1966
0
  {
1967
    /* Skip.  */
1968
0
    is_unsigned = resultP->X_unsigned;
1969
0
  }
1970
82.0k
      else
1971
82.0k
#endif
1972
82.0k
      if (op_left == O_add && right.X_op == O_constant
1973
82.0k
    && (md_register_arithmetic || resultP->X_op != O_register))
1974
9.45k
  {
1975
    /* X + constant.  */
1976
9.45k
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
1977
9.45k
  }
1978
      /* This case comes up in PIC code.  */
1979
72.6k
      else if (op_left == O_subtract
1980
72.6k
         && right.X_op == O_symbol
1981
72.6k
         && resultP->X_op == O_symbol
1982
72.6k
         && retval == rightseg
1983
#ifdef md_allow_local_subtract
1984
         && md_allow_local_subtract (resultP, & right, rightseg)
1985
#endif
1986
72.6k
         && ((SEG_NORMAL (rightseg)
1987
157
        && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
1988
157
        && !S_FORCE_RELOC (right.X_add_symbol, 0))
1989
157
       || right.X_add_symbol == resultP->X_add_symbol)
1990
72.6k
         && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1991
32
               symbol_get_frag (right.X_add_symbol),
1992
32
               &frag_off))
1993
32
  {
1994
32
    offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
1995
32
        - S_GET_VALUE (right.X_add_symbol);
1996
32
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1997
32
    subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
1998
32
    add_to_result (resultP, symval_diff, symval_diff < 0);
1999
32
    resultP->X_op = O_constant;
2000
32
    resultP->X_add_symbol = 0;
2001
32
    is_unsigned = false;
2002
32
  }
2003
72.5k
      else if (op_left == O_subtract && right.X_op == O_constant
2004
72.5k
         && (md_register_arithmetic || resultP->X_op != O_register))
2005
21.4k
  {
2006
    /* X - constant.  */
2007
21.4k
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
2008
21.4k
    is_unsigned = false;
2009
21.4k
  }
2010
51.0k
      else if (op_left == O_add && resultP->X_op == O_constant
2011
51.0k
         && (md_register_arithmetic || right.X_op != O_register))
2012
203
  {
2013
    /* Constant + X.  */
2014
203
    resultP->X_op = right.X_op;
2015
203
    resultP->X_add_symbol = right.X_add_symbol;
2016
203
    resultP->X_op_symbol = right.X_op_symbol;
2017
203
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
2018
203
    retval = rightseg;
2019
203
  }
2020
50.8k
      else if (resultP->X_op == O_constant && right.X_op == O_constant)
2021
23.5k
  {
2022
    /* Constant OP constant.  */
2023
23.5k
    offsetT v = right.X_add_number;
2024
23.5k
    if (v == 0 && (op_left == O_divide || op_left == O_modulus))
2025
2.88k
      {
2026
2.88k
        as_warn (_("division by zero"));
2027
2.88k
        v = 1;
2028
2.88k
      }
2029
23.5k
    switch (op_left)
2030
23.5k
      {
2031
0
      default:      goto general;
2032
8.49k
      case O_multiply:
2033
        /* Do the multiply as unsigned to silence ubsan.  The
2034
     result is of course the same when we throw away high
2035
     bits of the result.  */
2036
8.49k
        resultP->X_add_number *= (valueT) v;
2037
8.49k
        break;
2038
2039
52
      case O_divide:
2040
52
        if (v == 1)
2041
31
    break;
2042
21
        if (v == -1)
2043
0
    {
2044
      /* Dividing the largest negative value representable in offsetT
2045
         by -1 has a non-representable result in common binary
2046
         notation.  Treat it as negation instead, carried out as an
2047
         unsigned operation to avoid UB.  */
2048
0
      resultP->X_add_number = - (valueT) resultP->X_add_number;
2049
0
    }
2050
21
        else
2051
21
    resultP->X_add_number /= v;
2052
21
        break;
2053
2054
3.58k
      case O_modulus:
2055
        /* See above for why in particular -1 needs special casing.
2056
           While the operation is UB in C, mathematically it has a well-
2057
           defined result.  */
2058
3.58k
        if (v == 1 || v == -1)
2059
2.85k
    resultP->X_add_number = 0;
2060
732
        else
2061
732
    resultP->X_add_number %= v;
2062
3.58k
        break;
2063
2064
36
      case O_left_shift:
2065
166
      case O_right_shift:
2066
        /* We always use unsigned shifts.  According to the ISO
2067
     C standard, left shift of a signed type having a
2068
     negative value is undefined behaviour, and right
2069
     shift of a signed type having negative value is
2070
     implementation defined.  Left shift of a signed type
2071
     when the result overflows is also undefined
2072
     behaviour.  So don't trigger ubsan warnings or rely
2073
     on characteristics of the compiler.  */
2074
166
        if ((valueT) v >= sizeof (valueT) * CHAR_BIT)
2075
71
    {
2076
71
      as_warn_value_out_of_range (_("shift count"), v, 0,
2077
71
                sizeof (valueT) * CHAR_BIT - 1,
2078
71
                NULL, 0);
2079
71
      resultP->X_add_number = 0;
2080
71
    }
2081
95
        else if (op_left == O_left_shift)
2082
23
    resultP->X_add_number
2083
23
      = (valueT) resultP->X_add_number << (valueT) v;
2084
72
        else
2085
72
    resultP->X_add_number
2086
72
      = (valueT) resultP->X_add_number >> (valueT) v;
2087
166
        is_unsigned = resultP->X_unsigned;
2088
166
        break;
2089
671
      case O_bit_inclusive_or:  resultP->X_add_number |= v; break;
2090
599
      case O_bit_or_not:    resultP->X_add_number |= ~v; break;
2091
463
      case O_bit_exclusive_or:  resultP->X_add_number ^= v; break;
2092
31
      case O_bit_and:   resultP->X_add_number &= v; break;
2093
        /* Constant + constant (O_add) is handled by the
2094
     previous if statement for constant + X, so is omitted
2095
     here.  */
2096
0
      case O_subtract:
2097
0
        subtract_from_result (resultP, v, 0);
2098
0
        is_unsigned = false;
2099
0
        break;
2100
4.27k
      case O_eq:
2101
4.27k
        resultP->X_add_number =
2102
4.27k
    resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
2103
4.27k
        is_unsigned = false;
2104
4.27k
        break;
2105
229
      case O_ne:
2106
229
        resultP->X_add_number =
2107
229
    resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
2108
229
        is_unsigned = false;
2109
229
        break;
2110
157
      case O_lt:
2111
157
        resultP->X_add_number =
2112
157
    resultP->X_add_number <  v ? ~ (offsetT) 0 : 0;
2113
157
        is_unsigned = false;
2114
157
        break;
2115
6
      case O_le:
2116
6
        resultP->X_add_number =
2117
6
    resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
2118
6
        is_unsigned = false;
2119
6
        break;
2120
9
      case O_ge:
2121
9
        resultP->X_add_number =
2122
9
    resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
2123
9
        is_unsigned = false;
2124
9
        break;
2125
162
      case O_gt:
2126
162
        resultP->X_add_number =
2127
162
    resultP->X_add_number >  v ? ~ (offsetT) 0 : 0;
2128
162
        is_unsigned = false;
2129
162
        break;
2130
909
      case O_logical_and:
2131
909
        resultP->X_add_number = resultP->X_add_number && v;
2132
909
        is_unsigned = true;
2133
909
        break;
2134
3.68k
      case O_logical_or:
2135
3.68k
        resultP->X_add_number = resultP->X_add_number || v;
2136
3.68k
        is_unsigned = true;
2137
3.68k
        break;
2138
23.5k
      }
2139
23.5k
  }
2140
27.3k
      else if (resultP->X_op == O_symbol
2141
27.3k
         && right.X_op == O_symbol
2142
27.3k
         && (op_left == O_add
2143
3.93k
       || op_left == O_subtract
2144
3.93k
       || (resultP->X_add_number == 0
2145
1.04k
           && right.X_add_number == 0)))
2146
3.78k
  {
2147
    /* Symbol OP symbol.  */
2148
3.78k
    resultP->X_op = op_left;
2149
3.78k
    resultP->X_op_symbol = right.X_add_symbol;
2150
3.78k
    if (op_left == O_add)
2151
1.92k
      add_to_result (resultP, right.X_add_number, right.X_extrabit);
2152
1.86k
    else if (op_left == O_subtract)
2153
971
      {
2154
971
        subtract_from_result (resultP, right.X_add_number,
2155
971
            right.X_extrabit);
2156
971
        if (retval == rightseg
2157
971
      && SEG_NORMAL (retval)
2158
971
      && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
2159
971
      && !S_FORCE_RELOC (right.X_add_symbol, 0))
2160
0
    {
2161
0
      retval = absolute_section;
2162
0
      rightseg = absolute_section;
2163
0
    }
2164
971
      }
2165
3.78k
  }
2166
23.5k
      else
2167
23.5k
  {
2168
23.6k
        general:
2169
    /* The general case.  */
2170
23.6k
    resultP->X_add_symbol = make_expr_symbol (resultP);
2171
23.6k
    resultP->X_op_symbol = make_expr_symbol (&right);
2172
23.6k
    resultP->X_op = op_left;
2173
23.6k
    resultP->X_add_number = 0;
2174
23.6k
    resultP->X_extrabit = 0;
2175
23.6k
  }
2176
2177
82.1k
      resultP->X_unsigned = is_unsigned;
2178
2179
82.1k
      if (retval != rightseg)
2180
31.1k
  {
2181
31.1k
    if (retval == undefined_section)
2182
20.4k
      ;
2183
10.7k
    else if (rightseg == undefined_section)
2184
8.76k
      retval = rightseg;
2185
1.94k
    else if (retval == expr_section)
2186
251
      ;
2187
1.69k
    else if (rightseg == expr_section)
2188
270
      retval = rightseg;
2189
1.42k
    else if (retval == reg_section)
2190
477
      ;
2191
948
    else if (rightseg == reg_section)
2192
0
      retval = rightseg;
2193
948
    else if (rightseg == absolute_section)
2194
534
      ;
2195
414
    else if (retval == absolute_section)
2196
96
      retval = rightseg;
2197
318
#ifdef DIFF_EXPR_OK
2198
318
    else if (op_left == O_subtract)
2199
307
      ;
2200
11
#endif
2201
11
    else
2202
11
      as_bad (_("operation combines symbols in different segments"));
2203
31.1k
  }
2204
2205
82.1k
      op_left = op_right;
2206
82.1k
    }        /* While next operator is >= this rank.  */
2207
2208
  /* The PA port needs this information.  */
2209
249k
  if (resultP->X_add_symbol)
2210
97.5k
    symbol_mark_used (resultP->X_add_symbol);
2211
2212
249k
  if (rank == 0 && mode == expr_evaluate)
2213
93.4k
    resolve_expression (resultP);
2214
2215
249k
  return resultP->X_op == O_constant ? absolute_section : retval;
2216
249k
}
2217
2218
/* Resolve an expression without changing any symbols/sub-expressions
2219
   used.  */
2220
2221
int
2222
resolve_expression (expressionS *expressionP)
2223
165k
{
2224
  /* Help out with CSE.  */
2225
165k
  valueT final_val = expressionP->X_add_number;
2226
165k
  symbolS *add_symbol = expressionP->X_add_symbol;
2227
165k
  symbolS *orig_add_symbol = add_symbol;
2228
165k
  symbolS *op_symbol = expressionP->X_op_symbol;
2229
165k
  operatorT op = expressionP->X_op;
2230
165k
  valueT left, right;
2231
165k
  segT seg_left, seg_right;
2232
165k
  fragS *frag_left, *frag_right;
2233
165k
  offsetT frag_off;
2234
2235
165k
  switch (op)
2236
165k
    {
2237
4.58k
    default:
2238
4.58k
      return 0;
2239
2240
102k
    case O_constant:
2241
102k
    case O_register:
2242
102k
      left = 0;
2243
102k
      break;
2244
2245
15.5k
    case O_symbol:
2246
15.5k
    case O_symbol_rva:
2247
15.5k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2248
110
  return 0;
2249
2250
15.4k
      break;
2251
2252
15.4k
    case O_uminus:
2253
12.6k
    case O_bit_not:
2254
12.8k
    case O_logical_not:
2255
12.8k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2256
9.68k
  return 0;
2257
2258
3.14k
      if (seg_left != absolute_section)
2259
3.12k
  return 0;
2260
2261
25
      if (op == O_logical_not)
2262
7
  left = !left;
2263
18
      else if (op == O_uminus)
2264
18
  left = -left;
2265
0
      else
2266
0
  left = ~left;
2267
25
      op = O_constant;
2268
25
      break;
2269
2270
4.83k
    case O_multiply:
2271
7.49k
    case O_divide:
2272
7.78k
    case O_modulus:
2273
7.80k
    case O_left_shift:
2274
8.52k
    case O_right_shift:
2275
8.56k
    case O_bit_inclusive_or:
2276
8.61k
    case O_bit_or_not:
2277
9.44k
    case O_bit_exclusive_or:
2278
9.73k
    case O_bit_and:
2279
9.97k
    case O_add:
2280
16.1k
    case O_subtract:
2281
28.7k
    case O_eq:
2282
28.8k
    case O_ne:
2283
28.9k
    case O_lt:
2284
29.0k
    case O_le:
2285
29.0k
    case O_ge:
2286
29.2k
    case O_gt:
2287
29.3k
    case O_logical_and:
2288
29.5k
    case O_logical_or:
2289
29.5k
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
2290
29.5k
    || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
2291
19.4k
  return 0;
2292
2293
      /* Simplify addition or subtraction of a constant by folding the
2294
   constant into X_add_number.  */
2295
10.1k
      if (op == O_add)
2296
87
  {
2297
87
    if (seg_right == absolute_section)
2298
0
      {
2299
0
        final_val += right;
2300
0
        op = O_symbol;
2301
0
        break;
2302
0
      }
2303
87
    else if (seg_left == absolute_section)
2304
40
      {
2305
40
        final_val += left;
2306
40
        left = right;
2307
40
        seg_left = seg_right;
2308
40
        add_symbol = op_symbol;
2309
40
        orig_add_symbol = expressionP->X_op_symbol;
2310
40
        op = O_symbol;
2311
40
        break;
2312
40
      }
2313
87
  }
2314
10.0k
      else if (op == O_subtract)
2315
5.98k
  {
2316
5.98k
    if (seg_right == absolute_section)
2317
41
      {
2318
41
        final_val -= right;
2319
41
        op = O_symbol;
2320
41
        break;
2321
41
      }
2322
5.98k
  }
2323
2324
      /* Equality and non-equality tests are permitted on anything.
2325
   Subtraction, and other comparison operators are permitted if
2326
   both operands are in the same section.
2327
   Shifts by constant zero are permitted on anything.
2328
   Multiplies, bit-ors, and bit-ands with constant zero are
2329
   permitted on anything.
2330
   Multiplies and divides by constant one are permitted on
2331
   anything.
2332
   Binary operations with both operands being the same register
2333
   or undefined symbol are permitted if the result doesn't depend
2334
   on the input value.
2335
   Otherwise, both operands must be absolute.  We already handled
2336
   the case of addition or subtraction of a constant above.  */
2337
10.0k
      frag_off = 0;
2338
10.0k
      if (!(seg_left == absolute_section
2339
10.0k
         && seg_right == absolute_section)
2340
10.0k
    && !(op == O_eq || op == O_ne)
2341
10.0k
    && !((op == O_subtract
2342
8.82k
    || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2343
8.82k
         && seg_left == seg_right
2344
8.82k
         && (finalize_syms
2345
49
       || frag_offset_fixed_p (frag_left, frag_right, &frag_off)
2346
49
       || (op == O_gt
2347
0
           && frag_gtoffset_p (left, frag_left,
2348
0
             right, frag_right, &frag_off)))
2349
8.82k
         && (seg_left != reg_section || left == right)
2350
8.82k
         && (seg_left != undefined_section || add_symbol == op_symbol)))
2351
8.82k
  {
2352
8.82k
    if ((seg_left == absolute_section && left == 0)
2353
8.82k
        || (seg_right == absolute_section && right == 0))
2354
2.53k
      {
2355
2.53k
        if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2356
703
    {
2357
703
      if (!(seg_right == absolute_section && right == 0))
2358
41
        {
2359
41
          seg_left = seg_right;
2360
41
          left = right;
2361
41
          add_symbol = op_symbol;
2362
41
          orig_add_symbol = expressionP->X_op_symbol;
2363
41
        }
2364
703
      op = O_symbol;
2365
703
      break;
2366
703
    }
2367
1.83k
        else if (op == O_left_shift || op == O_right_shift)
2368
512
    {
2369
512
      if (!(seg_left == absolute_section && left == 0))
2370
6
        {
2371
6
          op = O_symbol;
2372
6
          break;
2373
6
        }
2374
512
    }
2375
1.31k
        else if (op != O_multiply
2376
1.31k
           && op != O_bit_or_not && op != O_bit_and)
2377
731
          return 0;
2378
2.53k
      }
2379
6.28k
    else if (op == O_multiply
2380
6.28k
       && seg_left == absolute_section && left == 1)
2381
0
      {
2382
0
        seg_left = seg_right;
2383
0
        left = right;
2384
0
        add_symbol = op_symbol;
2385
0
        orig_add_symbol = expressionP->X_op_symbol;
2386
0
        op = O_symbol;
2387
0
        break;
2388
0
      }
2389
6.28k
    else if ((op == O_multiply || op == O_divide)
2390
6.28k
       && seg_right == absolute_section && right == 1)
2391
0
      {
2392
0
        op = O_symbol;
2393
0
        break;
2394
0
      }
2395
6.28k
    else if (!(left == right
2396
6.28k
         && ((seg_left == reg_section && seg_right == reg_section)
2397
256
       || (seg_left == undefined_section
2398
256
           && seg_right == undefined_section
2399
256
           && add_symbol == op_symbol))))
2400
6.28k
      return 0;
2401
6
    else if (op == O_bit_and || op == O_bit_inclusive_or)
2402
0
      {
2403
0
        op = O_symbol;
2404
0
        break;
2405
0
      }
2406
6
    else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2407
0
      return 0;
2408
8.82k
  }
2409
2410
2.36k
      right += frag_off / OCTETS_PER_BYTE;
2411
2.36k
      switch (op)
2412
2.36k
  {
2413
0
  case O_add:     left += right; break;
2414
0
  case O_subtract:    left -= right; break;
2415
680
  case O_multiply:    left *= right; break;
2416
9
  case O_divide:
2417
9
    if (right == 0)
2418
9
      return 0;
2419
    /* See expr() for reasons of the special casing.  */
2420
0
    if (right == 1)
2421
0
      break;
2422
0
    if ((offsetT) right == -1)
2423
0
      left = -left;
2424
0
    else
2425
0
      left = (offsetT) left / (offsetT) right;
2426
0
    break;
2427
202
  case O_modulus:
2428
202
    if (right == 0)
2429
18
      return 0;
2430
    /* Again, see expr() for reasons of the special casing.  */
2431
184
    if (right == 1 || (offsetT) right == -1)
2432
0
      left = 0;
2433
184
    else
2434
184
      left = (offsetT) left % (offsetT) right;
2435
184
    break;
2436
6
  case O_left_shift:
2437
6
    if (right >= sizeof (left) * CHAR_BIT)
2438
0
      left = 0;
2439
6
    else
2440
6
      left <<= right;
2441
6
    break;
2442
699
  case O_right_shift:
2443
699
    if (right >= sizeof (left) * CHAR_BIT)
2444
0
      left = 0;
2445
699
    else
2446
699
      left >>= right;
2447
699
    break;
2448
0
  case O_bit_inclusive_or:  left |= right; break;
2449
11
  case O_bit_or_not:    left |= ~right; break;
2450
69
  case O_bit_exclusive_or:  left ^= right; break;
2451
1
  case O_bit_and:     left &= right; break;
2452
532
  case O_eq:
2453
567
  case O_ne:
2454
567
    left = (left == right
2455
567
      && seg_left == seg_right
2456
567
      && (finalize_syms || frag_left == frag_right)
2457
567
      && (seg_left != undefined_section
2458
160
          || add_symbol == op_symbol)
2459
567
      ? ~ (valueT) 0 : 0);
2460
567
    if (op == O_ne)
2461
35
      left = ~left;
2462
567
    break;
2463
6
  case O_lt:
2464
6
    left = (offsetT) left <  (offsetT) right ? ~ (valueT) 0 : 0;
2465
6
    break;
2466
2
  case O_le:
2467
2
    left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2468
2
    break;
2469
43
  case O_ge:
2470
43
    left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2471
43
    break;
2472
73
  case O_gt:
2473
73
    left = (offsetT) left >  (offsetT) right ? ~ (valueT) 0 : 0;
2474
73
    break;
2475
0
  case O_logical_and: left = left && right; break;
2476
0
  case O_logical_or:  left = left || right; break;
2477
0
  default:    abort ();
2478
2.36k
  }
2479
2480
2.34k
      op = O_constant;
2481
2.34k
      break;
2482
165k
    }
2483
2484
121k
  if (op == O_symbol)
2485
16.2k
    {
2486
16.2k
      if (seg_left == absolute_section)
2487
9
  op = O_constant;
2488
16.2k
      else if (seg_left == reg_section && final_val == 0)
2489
43
  op = O_register;
2490
16.1k
      else if (!symbol_same_p (add_symbol, orig_add_symbol))
2491
644
  final_val += left;
2492
16.2k
      expressionP->X_add_symbol = add_symbol;
2493
16.2k
    }
2494
121k
  expressionP->X_op = op;
2495
2496
121k
  if (op == O_constant || op == O_register)
2497
105k
    final_val += left;
2498
121k
  expressionP->X_add_number = final_val;
2499
2500
121k
  return 1;
2501
165k
}
2502
2503
/* "Look through" register equates.  */
2504
void resolve_register (expressionS *expP)
2505
2
{
2506
2
  symbolS *sym;
2507
2
  offsetT acc = 0;
2508
2
  const expressionS *e = expP;
2509
2510
2
  if (expP->X_op != O_symbol)
2511
0
    return;
2512
2513
2
  do
2514
2
    {
2515
2
      if (!md_register_arithmetic && e->X_add_number)
2516
0
  break;
2517
2
      sym = e->X_add_symbol;
2518
2
      acc += e->X_add_number;
2519
2
      e = symbol_get_value_expression (sym);
2520
2
    }
2521
2
  while (symbol_equated_p (sym));
2522
2523
2
  if (e->X_op == O_register)
2524
2
    {
2525
2
      expr_copy (expP, e);
2526
2
      expP->X_add_number += acc;
2527
2
    }
2528
2
}
2529

2530
/* This lives here because it belongs equally in expr.c & read.c.
2531
   expr.c is just a branch office read.c anyway, and putting it
2532
   here lessens the crowd at read.c.
2533
2534
   Assume input_line_pointer is at start of symbol name, or the
2535
   start of a double quote enclosed symbol name.  Advance
2536
   input_line_pointer past symbol name.  Turn that character into a '\0',
2537
   returning its former value, which may be the closing double quote.
2538
2539
   This allows a string compare (RMS wants symbol names to be strings)
2540
   of the symbol name.
2541
2542
   NOTE: The input buffer is further altered when adjacent strings are
2543
   concatenated by the function.  Callers caring about the original buffer
2544
   contents will need to make a copy before calling here.
2545
2546
   There will always be a char following symbol name, because all good
2547
   lines end in end-of-line.  */
2548
2549
char
2550
get_symbol_name (char ** ilp_return)
2551
898k
{
2552
898k
  char c;
2553
2554
898k
  * ilp_return = input_line_pointer;
2555
  /* We accept FAKE_LABEL_CHAR in a name in case this is being called with a
2556
     constructed string.  */
2557
898k
  if (is_name_beginner (c = *input_line_pointer++)
2558
898k
      || (input_from_string && c == FAKE_LABEL_CHAR))
2559
880k
    {
2560
7.75M
      while (is_part_of_name (c = *input_line_pointer++)
2561
7.75M
       || (input_from_string && c == FAKE_LABEL_CHAR))
2562
6.87M
  ;
2563
880k
      if (is_name_ender (c))
2564
0
  c = *input_line_pointer++;
2565
880k
    }
2566
17.7k
  else if (c == '"')
2567
10.1k
    {
2568
10.1k
      char *dst = input_line_pointer;
2569
2570
10.1k
      * ilp_return = input_line_pointer;
2571
10.1k
      for (;;)
2572
558k
  {
2573
558k
    c = *input_line_pointer++;
2574
2575
558k
    if (c == 0)
2576
2.75k
      {
2577
2.75k
        as_warn (_("missing closing '\"'"));
2578
2.75k
        break;
2579
2.75k
      }
2580
2581
555k
    if (c == '"')
2582
13.2k
      {
2583
13.2k
        char *ilp_save = input_line_pointer;
2584
2585
13.2k
        SKIP_WHITESPACE ();
2586
13.2k
        if (*input_line_pointer == '"')
2587
5.93k
    {
2588
5.93k
      ++input_line_pointer;
2589
5.93k
      continue;
2590
5.93k
    }
2591
7.36k
        input_line_pointer = ilp_save;
2592
7.36k
        break;
2593
13.2k
      }
2594
2595
542k
    if (c == '\\')
2596
609
      switch (*input_line_pointer)
2597
609
        {
2598
6
        case '"':
2599
32
        case '\\':
2600
32
    c = *input_line_pointer++;
2601
32
    break;
2602
2603
577
        default:
2604
577
    if (c != 0)
2605
577
      as_warn (_("'\\%c' in quoted symbol name; "
2606
577
           "behavior may change in the future"),
2607
577
         *input_line_pointer);
2608
577
    break;
2609
609
        }
2610
2611
542k
    *dst++ = c;
2612
542k
  }
2613
10.1k
      *dst = 0;
2614
10.1k
    }
2615
898k
  *--input_line_pointer = 0;
2616
898k
  return c;
2617
898k
}
2618
2619
/* Replace the NUL character pointed to by input_line_pointer
2620
   with C.  If C is \" then advance past it.  Return the character
2621
   now pointed to by input_line_pointer.  */
2622
2623
char
2624
restore_line_pointer (char c)
2625
720k
{
2626
720k
  * input_line_pointer = c;
2627
720k
  if (c == '"')
2628
22.6k
    c = * ++ input_line_pointer;
2629
720k
  return c;
2630
720k
}
2631
2632
unsigned int
2633
get_single_number (void)
2634
0
{
2635
0
  expressionS exp;
2636
0
  operand (&exp, expr_normal);
2637
0
  return exp.X_add_number;
2638
0
}