Coverage Report

Created: 2026-11-21 09:00

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