Coverage Report

Created: 2025-07-08 11:15

/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
0
#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
0
{
61
0
  symbolS *symbolP;
62
0
  struct expr_symbol_line *n;
63
64
0
  if (expressionP->X_op == O_symbol
65
0
      && expressionP->X_add_number == 0)
66
0
    return expressionP->X_add_symbol;
67
68
0
  if (expressionP->X_op == O_big)
69
0
    {
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
0
      if (expressionP->X_add_number > 0)
74
0
  as_bad (_("bignum invalid"));
75
0
      else
76
0
  as_bad (_("floating point number invalid"));
77
0
      expressionP = &zero;
78
0
    }
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
0
  symbolP = symbol_create (FAKE_LABEL_NAME,
85
0
         (expressionP->X_op == O_constant
86
0
          ? absolute_section
87
0
          : expressionP->X_op == O_register
88
0
            ? reg_section
89
0
            : expr_section),
90
0
         &zero_address_frag, 0);
91
0
  symbol_set_value_expression (symbolP, expressionP);
92
93
0
  if (expressionP->X_op == O_constant)
94
0
    resolve_symbol_value (symbolP);
95
96
0
  n = notes_alloc (sizeof (*n));
97
0
  n->sym = symbolP;
98
0
  n->file = as_where (&n->line);
99
0
  n->next = expr_symbol_lines;
100
0
  expr_symbol_lines = n;
101
102
0
  return symbolP;
103
0
}
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
0
{
135
0
  char *buf = concat (start ? ".startof." : ".sizeof.", name, NULL);
136
0
  symbolS *symbolP;
137
0
  unsigned int i;
138
139
0
  for (i = 0; i < nr_seen[start]; ++i)
140
0
    {
141
0
    symbolP = seen[start][i];
142
143
0
    if (! symbolP)
144
0
      break;
145
146
0
    name = S_GET_NAME (symbolP);
147
0
    if ((symbols_case_sensitive
148
0
   ? strcmp (buf, name)
149
0
   : strcasecmp (buf, name)) == 0)
150
0
      {
151
0
  free (buf);
152
0
  return symbolP;
153
0
      }
154
0
    }
155
156
0
  symbolP = symbol_make (buf);
157
0
  free (buf);
158
159
0
  if (i >= nr_seen[start])
160
0
    {
161
0
      unsigned int nr = (i + 1) * 2;
162
163
0
      seen[start] = XRESIZEVEC (symbolS *, seen[start], nr);
164
0
      nr_seen[start] = nr;
165
0
      memset (&seen[start][i + 1], 0, (nr - i - 1) * sizeof(seen[0][0]));
166
0
    }
167
168
0
  seen[start][i] = symbolP;
169
170
0
  return symbolP;
171
0
}
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
0
{
219
  /* input_line_pointer -> floating-point constant.  */
220
0
  int error_code;
221
222
0
  error_code = atof_generic (&input_line_pointer, ".", EXP_CHARS,
223
0
           &generic_floating_point_number);
224
225
0
  if (error_code)
226
0
    {
227
0
      if (error_code == ERROR_EXPONENT_OVERFLOW)
228
0
  {
229
0
    as_bad (_("bad floating-point constant: exponent overflow"));
230
0
  }
231
0
      else
232
0
  {
233
0
    as_bad (_("bad floating-point constant: unknown error code=%d"),
234
0
      error_code);
235
0
  }
236
0
    }
237
0
  expressionP->X_op = O_big;
238
  /* input_line_pointer -> just after constant, which may point to
239
     whitespace.  */
240
0
  expressionP->X_add_number = -1;
241
0
}
242
243
uint32_t
244
generic_bignum_to_int32 (void)
245
0
{
246
0
  return ((((uint32_t) generic_bignum[1] & LITTLENUM_MASK)
247
0
     << LITTLENUM_NUMBER_OF_BITS)
248
0
    | ((uint32_t) generic_bignum[0] & LITTLENUM_MASK));
249
0
}
250
251
uint64_t
252
generic_bignum_to_int64 (void)
253
0
{
254
0
  return ((((((((uint64_t) generic_bignum[3] & LITTLENUM_MASK)
255
0
         << LITTLENUM_NUMBER_OF_BITS)
256
0
        | ((uint64_t) generic_bignum[2] & LITTLENUM_MASK))
257
0
       << LITTLENUM_NUMBER_OF_BITS)
258
0
      | ((uint64_t) generic_bignum[1] & LITTLENUM_MASK))
259
0
     << LITTLENUM_NUMBER_OF_BITS)
260
0
    | ((uint64_t) generic_bignum[0] & LITTLENUM_MASK));
261
0
}
262
263
static void
264
integer_constant (int radix, expressionS *expressionP)
265
0
{
266
0
  char *start;    /* Start of number.  */
267
0
  char *suffix = NULL;
268
0
  char c;
269
0
  valueT number;  /* Offset or (absolute) value.  */
270
0
  short int digit;  /* Value of next digit in current radix.  */
271
0
  int too_many_digits = 0;  /* If we see >= this number of.  */
272
0
  char *name;   /* Points to name of symbol.  */
273
0
  symbolS *symbolP; /* Points to symbol.  */
274
275
0
  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
0
#ifdef BFD64
296
0
#define valuesize 64
297
#else /* includes non-bfd case, mostly */
298
#define valuesize 32
299
#endif
300
301
0
  if (is_end_of_stmt (*input_line_pointer))
302
0
    {
303
0
      expressionP->X_op = O_absent;
304
0
      return;
305
0
    }
306
307
0
  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
0
  switch (radix)
354
0
    {
355
0
    case 2:
356
0
      too_many_digits = valuesize + 1;
357
0
      break;
358
0
    case 8:
359
0
      too_many_digits = (valuesize + 2) / 3 + 1;
360
0
      break;
361
0
    case 16:
362
0
      too_many_digits = (valuesize + 3) / 4 + 1;
363
0
      break;
364
0
    case 10:
365
0
      too_many_digits = (valuesize + 11) / 4; /* Very rough.  */
366
0
      break;
367
0
    }
368
0
#undef valuesize
369
0
  start = input_line_pointer;
370
0
  c = *input_line_pointer++;
371
0
  for (number = 0;
372
0
       (digit = hex_value (c)) < radix;
373
0
       c = *input_line_pointer++)
374
0
    {
375
0
      number = number * radix + digit;
376
0
    }
377
  /* c contains character after number.  */
378
  /* input_line_pointer->char after c.  */
379
0
  small = (input_line_pointer - start - 1) < too_many_digits;
380
381
0
  if (radix == 16 && c == '_')
382
0
    {
383
      /* This is literal of the form 0x333_0_12345678_1.
384
   This example is equivalent to 0x00000333000000001234567800000001.  */
385
386
0
      int num_little_digits = 0;
387
0
      int i;
388
0
      input_line_pointer = start; /* -> 1st digit.  */
389
390
0
      know (LITTLENUM_NUMBER_OF_BITS == 16);
391
392
0
      for (c = '_'; c == '_'; num_little_digits += 2)
393
0
  {
394
395
    /* Convert one 64-bit word.  */
396
0
    int ndigit = 0;
397
0
    number = 0;
398
0
    for (c = *input_line_pointer++;
399
0
         (digit = hex_value (c)) < radix;
400
0
         c = *(input_line_pointer++))
401
0
      {
402
0
        number = number * radix + digit;
403
0
        ndigit++;
404
0
      }
405
406
    /* Check for 8 digit per word max.  */
407
0
    if (ndigit > 8)
408
0
      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
0
    know (LITTLENUM_NUMBER_OF_BITS == 16);
413
0
    for (i = min (num_little_digits + 1, SIZE_OF_LARGE_NUMBER - 1);
414
0
         i >= 2;
415
0
         i--)
416
0
      generic_bignum[i] = generic_bignum[i - 2];
417
418
    /* Add the new digits as the least significant new ones.  */
419
0
    generic_bignum[0] = number & 0xffffffff;
420
0
    generic_bignum[1] = number >> 16;
421
0
  }
422
423
      /* Again, c is char after number, input_line_pointer->after c.  */
424
425
0
      if (num_little_digits > SIZE_OF_LARGE_NUMBER - 1)
426
0
  num_little_digits = SIZE_OF_LARGE_NUMBER - 1;
427
428
0
      gas_assert (num_little_digits >= 4);
429
430
0
      if (num_little_digits != 8)
431
0
  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
0
      while (generic_bignum[num_little_digits - 1] == 0
436
0
       && num_little_digits > 1)
437
0
  num_little_digits--;
438
439
0
      if (num_little_digits <= 2)
440
0
  {
441
    /* will fit into 32 bits.  */
442
0
    number = generic_bignum_to_int32 ();
443
0
    small = 1;
444
0
  }
445
0
#ifdef BFD64
446
0
      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
0
#endif
453
0
      else
454
0
  {
455
0
    small = 0;
456
457
    /* Number of littlenums in the bignum.  */
458
0
    number = num_little_digits;
459
0
  }
460
0
    }
461
0
  else if (!small)
462
0
    {
463
      /* We saw a lot of digits. manufacture a bignum the hard way.  */
464
0
      LITTLENUM_TYPE *leader; /* -> high order littlenum of the bignum.  */
465
0
      LITTLENUM_TYPE *pointer;  /* -> littlenum we are frobbing now.  */
466
0
      long carry;
467
468
0
      leader = generic_bignum;
469
0
      generic_bignum[0] = 0;
470
0
      generic_bignum[1] = 0;
471
0
      generic_bignum[2] = 0;
472
0
      generic_bignum[3] = 0;
473
0
      input_line_pointer = start; /* -> 1st digit.  */
474
0
      c = *input_line_pointer++;
475
0
      for (; (carry = hex_value (c)) < radix; c = *input_line_pointer++)
476
0
  {
477
0
    for (pointer = generic_bignum; pointer <= leader; pointer++)
478
0
      {
479
0
        long work;
480
481
0
        work = carry + radix * *pointer;
482
0
        *pointer = work & LITTLENUM_MASK;
483
0
        carry = work >> LITTLENUM_NUMBER_OF_BITS;
484
0
      }
485
0
    if (carry)
486
0
      {
487
0
        if (leader < generic_bignum + SIZE_OF_LARGE_NUMBER - 1)
488
0
    {
489
      /* Room to grow a longer bignum.  */
490
0
      *++leader = carry;
491
0
    }
492
0
      }
493
0
  }
494
      /* Again, c is char after number.  */
495
      /* input_line_pointer -> after c.  */
496
0
      know (LITTLENUM_NUMBER_OF_BITS == 16);
497
0
      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
0
#ifdef BFD64
504
0
      else if (leader < generic_bignum + 4)
505
0
  {
506
    /* Will fit into 64 bits.  */
507
0
    number = generic_bignum_to_int64 ();
508
0
    small = 1;
509
0
  }
510
0
#endif
511
0
      else
512
0
  {
513
    /* Number of littlenums in the bignum.  */
514
0
    number = leader - generic_bignum + 1;
515
0
  }
516
0
    }
517
518
0
  if ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
519
0
      && suffix != NULL
520
0
      && input_line_pointer - 1 == suffix)
521
0
    c = *input_line_pointer++;
522
523
0
#ifndef tc_allow_U_suffix
524
0
#define tc_allow_U_suffix 1
525
0
#endif
526
0
  bool u_seen = !tc_allow_U_suffix;
527
  /* PR 19910: Look for, and ignore, a U suffix to the number.  */
528
0
  if (!u_seen && (c == 'U' || c == 'u'))
529
0
    {
530
0
      c = *input_line_pointer++;
531
0
      u_seen = true;
532
0
    }
533
534
0
#ifndef tc_allow_L_suffix
535
0
#define tc_allow_L_suffix 1
536
0
#endif
537
0
  bool l_seen = !tc_allow_L_suffix;
538
  /* PR 20732: Look for, and ignore, a L or LL suffix to the number.  */
539
0
  if (tc_allow_L_suffix && (c == 'L' || c == 'l'))
540
0
    {
541
0
      c = * input_line_pointer++;
542
0
      l_seen = true;
543
0
      if (c == 'L' || c == 'l')
544
0
  c = *input_line_pointer++;
545
0
      if (!u_seen && (c == 'U' || c == 'u'))
546
0
  c = *input_line_pointer++;
547
0
    }
548
549
0
  if (small)
550
0
    {
551
      /* Here with number, in correct radix. c is the next char.  */
552
0
      bool maybe_label = suffix == NULL
553
0
       && (!tc_allow_U_suffix || !u_seen)
554
0
       && (!tc_allow_L_suffix || !l_seen)
555
0
       && (radix == 10 ||
556
0
           (radix == 8 && input_line_pointer == start + 1));
557
558
0
      if (LOCAL_LABELS_FB && c == 'b' && maybe_label)
559
0
  {
560
    /* Backward ref to local label.
561
       Because it is backward, expect it to be defined.  */
562
    /* Construct a local label.  */
563
0
    name = fb_label_name (number, 0);
564
565
    /* Seen before, or symbol is defined: OK.  */
566
0
    symbolP = symbol_find (name);
567
0
    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
0
    else
573
0
      {
574
        /* Either not seen or not defined.  */
575
        /* @@ Should print out the original string instead of
576
     the parsed number.  */
577
0
        as_bad (_("backward ref to unknown label \"%d:\""),
578
0
          (int) number);
579
0
        expressionP->X_op = O_constant;
580
0
      }
581
582
0
    expressionP->X_add_number = 0;
583
0
  }     /* case 'b' */
584
0
      else if (LOCAL_LABELS_FB && c == 'f' && maybe_label)
585
0
  {
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
0
    name = fb_label_name (number, 1);
594
0
    symbolP = symbol_find_or_make (name);
595
    /* We have no need to check symbol properties.  */
596
0
    expressionP->X_op = O_symbol;
597
0
    expressionP->X_add_symbol = symbolP;
598
0
    expressionP->X_add_number = 0;
599
0
  }     /* case 'f' */
600
0
      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
0
      else
624
0
  {
625
0
    expressionP->X_op = O_constant;
626
0
    expressionP->X_add_number = number;
627
0
    input_line_pointer--; /* Restore following character.  */
628
0
  }      /* Really just a number.  */
629
0
    }
630
0
  else
631
0
    {
632
      /* Not a small number.  */
633
0
      expressionP->X_op = O_big;
634
0
      expressionP->X_add_number = number; /* Number of littlenums.  */
635
0
      expressionP->X_unsigned = 1;
636
0
      input_line_pointer--; /* -> char following number.  */
637
0
    }
638
0
}
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
0
{
735
0
  if (now_seg == absolute_section)
736
0
    {
737
0
      expressionp->X_op = O_constant;
738
0
      expressionp->X_add_number = abs_section_offset;
739
0
    }
740
0
  else
741
0
    {
742
0
      expressionp->X_op = O_symbol;
743
0
      if (mode != expr_defer_incl_dot)
744
0
  {
745
0
    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
0
  }
750
0
      else
751
0
    expressionp->X_add_symbol = &dot_symbol;
752
0
      expressionp->X_add_number = 0;
753
0
    }
754
0
}
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
0
{
778
0
  unsigned short md = dst->X_md;
779
780
0
  *dst = *src;
781
0
  dst->X_md = md;
782
0
}
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
0
{
798
0
  char c;
799
0
  symbolS *symbolP; /* Points to symbol.  */
800
0
  char *name;   /* Points to name of symbol.  */
801
0
  segT segment;
802
0
  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
0
  expressionP->X_unsigned = 1;
811
0
  expressionP->X_extrabit = 0;
812
813
  /* Digits, assume it is a bignum.  */
814
815
0
  SKIP_WHITESPACE ();    /* Leading whitespace is part of operand.  */
816
0
  c = *input_line_pointer++;  /* input_line_pointer -> past char in c.  */
817
818
0
  if (is_end_of_stmt (c))
819
0
    goto eol;
820
821
0
  switch (c)
822
0
    {
823
0
    case '1':
824
0
    case '2':
825
0
    case '3':
826
0
    case '4':
827
0
    case '5':
828
0
    case '6':
829
0
    case '7':
830
0
    case '8':
831
0
    case '9':
832
0
      input_line_pointer--;
833
834
0
      integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
835
0
      ? 0 : 10,
836
0
      expressionP);
837
0
      break;
838
839
#ifdef LITERAL_PREFIXPERCENT_BIN
840
    case '%':
841
      integer_constant (2, expressionP);
842
      break;
843
#endif
844
845
0
    case '0':
846
      /* Non-decimal radix.  */
847
848
0
      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
0
      c = *input_line_pointer;
863
0
      switch (c)
864
0
  {
865
0
  case 'o':
866
0
  case 'O':
867
0
  case 'q':
868
0
  case 'Q':
869
0
  case '8':
870
0
  case '9':
871
0
    if (NUMBERS_WITH_SUFFIX || flag_m68k_mri)
872
0
      {
873
0
        integer_constant (0, expressionP);
874
0
        break;
875
0
      }
876
    /* Fall through.  */
877
0
  default:
878
0
  default_case:
879
0
    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
0
    else
886
0
      {
887
        /* The string was only zero.  */
888
0
        expressionP->X_op = O_constant;
889
0
        expressionP->X_add_number = 0;
890
0
      }
891
892
0
    break;
893
894
0
  case 'x':
895
0
  case 'X':
896
0
    if (flag_m68k_mri)
897
0
      goto default_case;
898
0
    input_line_pointer++;
899
0
    integer_constant (16, expressionP);
900
0
    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
0
  case 'u':
934
0
  case 'U':
935
    /* Accept a U suffix to the zero.  */
936
0
    if (!tc_allow_U_suffix)
937
0
      goto default_case;
938
    /* Fall through.  */
939
0
  case '0':
940
0
  case '1':
941
0
  case '2':
942
0
  case '3':
943
0
  case '4':
944
0
  case '5':
945
0
  case '6':
946
0
  case '7':
947
0
  numeric:
948
0
    integer_constant ((flag_m68k_mri || NUMBERS_WITH_SUFFIX)
949
0
          ? 0 : 8,
950
0
          expressionP);
951
0
    break;
952
953
0
  case 'f':
954
0
    if (LOCAL_LABELS_FB)
955
0
      {
956
0
        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
0
        if (!is_end_of_stmt (input_line_pointer[1])
962
0
      && strchr (FLT_CHARS, 'f') != NULL)
963
0
    {
964
0
      char *cp = input_line_pointer + 1;
965
966
0
      atof_generic (&cp, ".", EXP_CHARS,
967
0
        &generic_floating_point_number);
968
969
      /* Was nothing parsed, or does it look like an
970
         expression?  */
971
0
      is_label = (cp == input_line_pointer + 1
972
0
            || (cp == input_line_pointer + 2
973
0
          && (cp[-1] == '-' || cp[-1] == '+'))
974
0
            || *cp == 'f'
975
0
            || *cp == 'b');
976
0
    }
977
0
        if (is_label)
978
0
    {
979
0
      input_line_pointer--;
980
0
      integer_constant (10, expressionP);
981
0
      break;
982
0
    }
983
0
      }
984
    /* Fall through.  */
985
986
0
  case 'd':
987
0
  case 'D':
988
0
    if (flag_m68k_mri || NUMBERS_WITH_SUFFIX)
989
0
      {
990
0
        integer_constant (0, expressionP);
991
0
        break;
992
0
      }
993
    /* Fall through.  */
994
0
  case 'F':
995
0
  case 'r':
996
0
  case 'e':
997
0
  case 'E':
998
0
  case 'g':
999
0
  case 'G':
1000
0
    input_line_pointer++;
1001
0
    floating_constant (expressionP);
1002
0
    expressionP->X_add_number = - TOLOWER (c);
1003
0
    break;
1004
1005
0
  case '$':
1006
0
    if (LOCAL_LABELS_DOLLAR)
1007
0
      {
1008
0
        integer_constant (10, expressionP);
1009
0
        break;
1010
0
      }
1011
0
    else
1012
0
      goto default_case;
1013
0
  }
1014
1015
0
      break;
1016
1017
0
#ifndef NEED_INDEX_OPERATOR
1018
0
    case '[':
1019
0
# ifdef md_need_index_operator
1020
0
      if (md_need_index_operator())
1021
0
  goto de_fault;
1022
0
# endif
1023
0
#endif
1024
      /* Fall through.  */
1025
0
    case '(':
1026
      /* Didn't begin with digit & not a name.  */
1027
0
      segment = expr (0, expressionP, mode);
1028
      /* expression () will pass trailing whitespace.  */
1029
0
      if ((c == '(' && *input_line_pointer != ')')
1030
0
    || (c == '[' && *input_line_pointer != ']'))
1031
0
  {
1032
0
    if (* input_line_pointer)
1033
0
      as_bad (_("found '%c', expected: '%c'"),
1034
0
        * input_line_pointer, c == '(' ? ')' : ']');
1035
0
    else
1036
0
      as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
1037
0
  }     
1038
0
      else
1039
0
  input_line_pointer++;
1040
0
      SKIP_ALL_WHITESPACE ();
1041
      /* Here with input_line_pointer -> char after "(...)".  */
1042
0
      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
0
    case '\'':
1057
0
      if (! flag_m68k_mri)
1058
0
  {
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
0
    expressionP->X_op = O_constant;
1064
0
    expressionP->X_add_number = *input_line_pointer++;
1065
0
    break;
1066
0
  }
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
0
    case '~':
1079
      /* '~' is permitted to start a label on the Delta.  */
1080
0
      if (is_name_beginner (c))
1081
0
  goto isname;
1082
0
      op = O_bit_not;
1083
0
      goto unary;
1084
1085
0
    case '!':
1086
0
      op = O_logical_not;
1087
0
      goto unary;
1088
1089
0
    case '-':
1090
0
      op = O_uminus;
1091
      /* Fall through.  */
1092
0
    case '+':
1093
0
      {
1094
0
      unary:
1095
0
  operand (expressionP, mode);
1096
1097
0
#ifdef md_optimize_expr
1098
0
  if (md_optimize_expr (NULL, op, expressionP))
1099
0
  {
1100
    /* Skip.  */
1101
0
    ;
1102
0
  }
1103
0
  else
1104
0
#endif
1105
0
  if (expressionP->X_op == O_constant)
1106
0
    {
1107
      /* input_line_pointer -> char after operand.  */
1108
0
      if (op == O_uminus)
1109
0
        {
1110
0
    expressionP->X_add_number
1111
0
      = - (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
0
    expressionP->X_unsigned = 0;
1116
0
    if (expressionP->X_add_number)
1117
0
      expressionP->X_extrabit ^= 1;
1118
0
        }
1119
0
      else if (op == O_bit_not)
1120
0
        {
1121
0
    expressionP->X_add_number = ~ expressionP->X_add_number;
1122
0
    expressionP->X_extrabit ^= 1;
1123
0
    expressionP->X_unsigned = 0;
1124
0
        }
1125
0
      else if (op == O_logical_not)
1126
0
        {
1127
0
    expressionP->X_add_number = ! expressionP->X_add_number;
1128
0
    expressionP->X_unsigned = 1;
1129
0
    expressionP->X_extrabit = 0;
1130
0
        }
1131
0
    }
1132
0
  else if (expressionP->X_op == O_big
1133
0
     && expressionP->X_add_number <= 0
1134
0
     && op == O_uminus
1135
0
     && (generic_floating_point_number.sign == '+'
1136
0
         || generic_floating_point_number.sign == 'P'))
1137
0
    {
1138
      /* Negative flonum (eg, -1.000e0).  */
1139
0
      if (generic_floating_point_number.sign == '+')
1140
0
        generic_floating_point_number.sign = '-';
1141
0
      else
1142
0
        generic_floating_point_number.sign = 'N';
1143
0
    }
1144
0
  else if (expressionP->X_op == O_big
1145
0
     && expressionP->X_add_number > 0)
1146
0
    {
1147
0
      int i;
1148
1149
0
      if (op == O_uminus || op == O_bit_not)
1150
0
        {
1151
0
    for (i = 0; i < expressionP->X_add_number; ++i)
1152
0
      generic_bignum[i] = ~generic_bignum[i];
1153
1154
    /* Extend the bignum to at least the size of .octa.  */
1155
0
    if (expressionP->X_add_number < SIZE_OF_LARGE_NUMBER)
1156
0
      {
1157
0
        expressionP->X_add_number = SIZE_OF_LARGE_NUMBER;
1158
0
        for (; i < expressionP->X_add_number; ++i)
1159
0
          generic_bignum[i] = ~(LITTLENUM_TYPE) 0;
1160
0
      }
1161
1162
0
    if (op == O_uminus)
1163
0
      for (i = 0; i < expressionP->X_add_number; ++i)
1164
0
        {
1165
0
          generic_bignum[i] += 1;
1166
0
          if (generic_bignum[i])
1167
0
      break;
1168
0
        }
1169
1170
0
    expressionP->X_unsigned = 0;
1171
0
        }
1172
0
      else if (op == O_logical_not)
1173
0
        {
1174
0
    for (i = 0; i < expressionP->X_add_number; ++i)
1175
0
      if (generic_bignum[i] != 0)
1176
0
        break;
1177
0
    expressionP->X_add_number = i >= expressionP->X_add_number;
1178
0
    expressionP->X_op = O_constant;
1179
0
    expressionP->X_unsigned = 1;
1180
0
    expressionP->X_extrabit = 0;
1181
0
        }
1182
0
    }
1183
0
  else if (expressionP->X_op != O_illegal
1184
0
     && expressionP->X_op != O_absent)
1185
0
    {
1186
0
      if (op != O_absent)
1187
0
        {
1188
0
    expressionP->X_add_symbol = make_expr_symbol (expressionP);
1189
0
    expressionP->X_op = op;
1190
0
    expressionP->X_add_number = 0;
1191
0
        }
1192
0
      else if (!md_register_arithmetic && expressionP->X_op == O_register)
1193
0
        {
1194
    /* Convert to binary '+'.  */
1195
0
    expressionP->X_op_symbol = make_expr_symbol (expressionP);
1196
0
    expressionP->X_add_symbol = make_expr_symbol (&zero);
1197
0
    expressionP->X_add_number = 0;
1198
0
    expressionP->X_op = O_add;
1199
0
        }
1200
0
    }
1201
0
  else
1202
0
    as_warn (_("Unary operator %c ignored because bad operand follows"),
1203
0
       c);
1204
0
      }
1205
0
      break;
1206
1207
0
#if !defined (DOLLAR_DOT) && !defined (TC_M68K)
1208
0
    case '$':
1209
0
      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
0
      else
1217
0
  {
1218
0
    goto isname;
1219
0
  }
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
0
    case '.':
1245
0
      if (!is_part_of_name (*input_line_pointer))
1246
0
  {
1247
0
    current_location (expressionP, mode);
1248
0
    break;
1249
0
  }
1250
0
      else if ((strncasecmp (input_line_pointer, "startof.", 8) == 0
1251
0
    && ! is_part_of_name (input_line_pointer[8]))
1252
0
         || (strncasecmp (input_line_pointer, "sizeof.", 7) == 0
1253
0
       && ! is_part_of_name (input_line_pointer[7])))
1254
0
  {
1255
0
    int start;
1256
1257
0
    start = (input_line_pointer[1] == 't'
1258
0
       || input_line_pointer[1] == 'T');
1259
0
    input_line_pointer += start ? 8 : 7;
1260
0
    SKIP_WHITESPACE ();
1261
1262
    /* Cover for the as_bad () invocations below.  */
1263
0
    expressionP->X_op = O_absent;
1264
1265
0
    if (*input_line_pointer != '(')
1266
0
      as_bad (_("syntax error in .startof. or .sizeof."));
1267
0
    else
1268
0
      {
1269
0
        ++input_line_pointer;
1270
0
        SKIP_WHITESPACE ();
1271
0
        c = get_symbol_name (& name);
1272
0
        if (! *name)
1273
0
    {
1274
0
      as_bad (_("expected symbol name"));
1275
0
      (void) restore_line_pointer (c);
1276
0
      if (c == ')')
1277
0
        ++input_line_pointer;
1278
0
      break;
1279
0
    }
1280
1281
0
        expressionP->X_op = O_symbol;
1282
0
        expressionP->X_add_symbol = symbol_lookup_or_make (name, start);
1283
0
        expressionP->X_add_number = 0;
1284
1285
0
        restore_line_pointer (c);
1286
0
        SKIP_WHITESPACE ();
1287
0
        if (*input_line_pointer != ')')
1288
0
    as_bad (_("syntax error in .startof. or .sizeof."));
1289
0
        else
1290
0
    ++input_line_pointer;
1291
0
      }
1292
0
    break;
1293
0
  }
1294
0
      else
1295
0
  {
1296
0
    goto isname;
1297
0
  }
1298
1299
0
    case ',':
1300
0
    eol:
1301
      /* Can't imagine any other kind of operand.  */
1302
0
      expressionP->X_op = O_absent;
1303
0
      input_line_pointer--;
1304
0
      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
0
    default:
1339
0
#if defined(md_need_index_operator) || defined(TC_M68K)
1340
0
    de_fault:
1341
0
#endif
1342
0
      if (is_name_beginner (c) || c == '"') /* Here if did not begin with a digit.  */
1343
0
  {
1344
    /* Identifier begins here.
1345
       This is kludged for speed, so code is repeated.  */
1346
0
  isname:
1347
0
    -- input_line_pointer;
1348
0
    c = get_symbol_name (&name);
1349
1350
0
#ifdef md_operator
1351
0
    {
1352
0
      op = md_operator (name, 1, &c);
1353
0
      switch (op)
1354
0
        {
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
0
        default:
1371
0
    break;
1372
0
        }
1373
1374
0
      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
0
    }
1385
0
#endif
1386
1387
0
#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
0
    if (md_parse_name (name, expressionP, mode, &c))
1393
0
      {
1394
0
        restore_line_pointer (c);
1395
0
        break;
1396
0
      }
1397
0
#endif
1398
1399
0
    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
0
    segment = S_GET_SEGMENT (symbolP);
1404
0
    if (!expr_defer_p (mode)
1405
0
        && segment == absolute_section
1406
0
        && !S_FORCE_RELOC (symbolP, 0))
1407
0
      {
1408
0
        expressionP->X_op = O_constant;
1409
0
        expressionP->X_add_number = S_GET_VALUE (symbolP);
1410
0
      }
1411
0
    else if (!expr_defer_p (mode) && segment == reg_section)
1412
0
      {
1413
0
        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
0
        else
1419
0
    {
1420
0
      expr_copy (expressionP,
1421
0
           symbol_get_value_expression (symbolP));
1422
0
      resolve_register (expressionP);
1423
0
    }
1424
0
      }
1425
0
    else
1426
0
      {
1427
0
        expressionP->X_op = O_symbol;
1428
0
        expressionP->X_add_symbol = symbolP;
1429
0
        expressionP->X_add_number = 0;
1430
0
      }
1431
1432
0
    restore_line_pointer (c);
1433
0
  }
1434
0
      else
1435
0
  {
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
0
    expressionP->X_op = O_absent;
1441
0
    --input_line_pointer;
1442
0
    md_operand (expressionP);
1443
0
    if (expressionP->X_op == O_absent)
1444
0
      {
1445
0
        ++input_line_pointer;
1446
0
        as_bad (_("bad expression"));
1447
0
        expressionP->X_op = O_constant;
1448
0
        expressionP->X_add_number = 0;
1449
0
      }
1450
0
  }
1451
0
      break;
1452
0
    }
1453
1454
  /* It is more 'efficient' to clean up the expressionS when they are
1455
     created.  Doing it here saves lines of code.  */
1456
0
  clean_up_expression (expressionP);
1457
0
  SKIP_ALL_WHITESPACE ();    /* -> 1st char after operand.  */
1458
0
  know (!is_whitespace (*input_line_pointer));
1459
1460
  /* The PA port needs this information.  */
1461
0
  if (expressionP->X_add_symbol)
1462
0
    symbol_mark_used (expressionP->X_add_symbol);
1463
1464
0
  if (!expr_defer_p (mode))
1465
0
    {
1466
0
      expressionP->X_add_symbol
1467
0
  = symbol_clone_if_forward_ref (expressionP->X_add_symbol);
1468
0
      expressionP->X_op_symbol
1469
0
  = symbol_clone_if_forward_ref (expressionP->X_op_symbol);
1470
0
    }
1471
1472
0
  switch (expressionP->X_op)
1473
0
    {
1474
0
    default:
1475
0
      return absolute_section;
1476
0
    case O_symbol:
1477
0
      return S_GET_SEGMENT (expressionP->X_add_symbol);
1478
0
    case O_register:
1479
0
      return reg_section;
1480
0
    }
1481
0
}
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
0
{
1495
0
  switch (expressionP->X_op)
1496
0
    {
1497
0
    case O_illegal:
1498
0
    case O_absent:
1499
0
      expressionP->X_add_number = 0;
1500
      /* Fall through.  */
1501
0
    case O_big:
1502
0
    case O_constant:
1503
0
    case O_register:
1504
0
      expressionP->X_add_symbol = NULL;
1505
      /* Fall through.  */
1506
0
    case O_symbol:
1507
0
    case O_uminus:
1508
0
    case O_bit_not:
1509
0
      expressionP->X_op_symbol = NULL;
1510
0
      break;
1511
0
    default:
1512
0
      break;
1513
0
    }
1514
0
}
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
0
#define STANDARD_MUL_PRECEDENCE 8
1629
0
#define MRI_MUL_PRECEDENCE 6
1630
1631
void
1632
expr_set_precedence (void)
1633
0
{
1634
0
  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
0
  else
1641
0
    {
1642
0
      op_rank[O_multiply] = STANDARD_MUL_PRECEDENCE;
1643
0
      op_rank[O_divide] = STANDARD_MUL_PRECEDENCE;
1644
0
      op_rank[O_modulus] = STANDARD_MUL_PRECEDENCE;
1645
0
    }
1646
0
}
1647
1648
void
1649
expr_set_rank (operatorT op, operator_rankT rank)
1650
0
{
1651
0
  gas_assert (op >= O_md1 && op < ARRAY_SIZE (op_rank));
1652
0
  op_rank[op] = rank;
1653
0
}
1654
1655
/* Initialize the expression parser.  */
1656
1657
void
1658
expr_begin (void)
1659
0
{
1660
0
  expr_set_precedence ();
1661
1662
  /* Verify that X_op field is wide enough.  */
1663
0
  {
1664
0
    expressionS e;
1665
0
    e.X_op = O_max;
1666
0
    gas_assert (e.X_op == O_max);
1667
0
  }
1668
1669
0
  memset (seen, 0, sizeof seen);
1670
0
  memset (nr_seen, 0, sizeof nr_seen);
1671
0
  expr_symbol_lines = NULL;
1672
0
}
1673
1674
void
1675
expr_end (void)
1676
0
{
1677
0
  for (size_t i = 0; i < ARRAY_SIZE (seen); i++)
1678
0
    free (seen[i]);
1679
0
}
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
0
{
1688
0
  int c;
1689
0
  operatorT ret;
1690
1691
0
  c = *input_line_pointer & 0xff;
1692
0
  *num_chars = 1;
1693
1694
0
  if (is_end_of_stmt (c))
1695
0
    return O_illegal;
1696
1697
0
#ifdef md_operator
1698
0
  if (is_name_beginner (c))
1699
0
    {
1700
0
      char *name;
1701
0
      char ec = get_symbol_name (& name);
1702
1703
0
      ret = md_operator (name, 2, &ec);
1704
0
      switch (ret)
1705
0
  {
1706
0
  case O_absent:
1707
0
    *input_line_pointer = ec;
1708
0
    input_line_pointer = name;
1709
0
    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
0
  }
1722
0
    }
1723
0
#endif
1724
1725
0
  switch (c)
1726
0
    {
1727
0
    default:
1728
0
      ret = op_encoding[c];
1729
0
#ifdef md_operator
1730
0
      if (ret == O_illegal)
1731
0
  {
1732
0
    char *start = input_line_pointer;
1733
1734
0
    ret = md_operator (NULL, 2, NULL);
1735
0
    if (ret != O_illegal)
1736
0
      *num_chars = input_line_pointer - start;
1737
0
    input_line_pointer = start;
1738
0
  }
1739
0
#endif
1740
0
      return ret;
1741
1742
0
    case '+':
1743
0
    case '-':
1744
0
      return op_encoding[c];
1745
1746
0
    case '<':
1747
0
      switch (input_line_pointer[1])
1748
0
  {
1749
0
  default:
1750
0
    return op_encoding[c];
1751
0
  case '<':
1752
0
    ret = O_left_shift;
1753
0
    break;
1754
0
  case '>':
1755
0
    ret = O_ne;
1756
0
    break;
1757
0
  case '=':
1758
0
    ret = O_le;
1759
0
    break;
1760
0
  }
1761
0
      *num_chars = 2;
1762
0
      return ret;
1763
1764
0
    case '=':
1765
0
      if (input_line_pointer[1] != '=')
1766
0
  return op_encoding[c];
1767
1768
0
      *num_chars = 2;
1769
0
      return O_eq;
1770
1771
0
    case '>':
1772
0
      switch (input_line_pointer[1])
1773
0
  {
1774
0
  default:
1775
0
    return op_encoding[c];
1776
0
  case '>':
1777
0
    ret = O_right_shift;
1778
0
    break;
1779
0
  case '=':
1780
0
    ret = O_ge;
1781
0
    break;
1782
0
  }
1783
0
      *num_chars = 2;
1784
0
      return ret;
1785
1786
0
    case '!':
1787
0
      switch (input_line_pointer[1])
1788
0
  {
1789
0
  case '!':
1790
    /* We accept !! as equivalent to ^ for MRI compatibility. */
1791
0
    *num_chars = 2;
1792
0
    return O_bit_exclusive_or;
1793
0
  case '=':
1794
    /* We accept != as equivalent to <>.  */
1795
0
    *num_chars = 2;
1796
0
    return O_ne;
1797
0
  default:
1798
0
    if (flag_m68k_mri)
1799
0
      return O_bit_inclusive_or;
1800
0
    return op_encoding[c];
1801
0
  }
1802
1803
0
    case '|':
1804
0
      if (input_line_pointer[1] != '|')
1805
0
  return op_encoding[c];
1806
1807
0
      *num_chars = 2;
1808
0
      return O_logical_or;
1809
1810
0
    case '&':
1811
0
      if (input_line_pointer[1] != '&')
1812
0
  return op_encoding[c];
1813
1814
0
      *num_chars = 2;
1815
0
      return O_logical_and;
1816
0
    }
1817
1818
  /* NOTREACHED  */
1819
0
}
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
0
{
1830
0
  valueT ures = resultP->X_add_number;
1831
0
  valueT uamount = amount;
1832
1833
0
  resultP->X_add_number += uamount;
1834
1835
0
  resultP->X_extrabit ^= rhs_highbit;
1836
1837
0
  if (ures + uamount < ures)
1838
0
    resultP->X_extrabit ^= 1;
1839
0
}
1840
1841
/* Similarly, for subtraction.  */
1842
1843
void
1844
subtract_from_result (expressionS *resultP, offsetT amount, int rhs_highbit)
1845
0
{
1846
0
  valueT ures = resultP->X_add_number;
1847
0
  valueT uamount = amount;
1848
1849
0
  resultP->X_add_number -= uamount;
1850
1851
0
  resultP->X_extrabit ^= rhs_highbit;
1852
1853
0
  if (ures < uamount)
1854
0
    resultP->X_extrabit ^= 1;
1855
0
}
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
0
{
1864
0
  operator_rankT rank = (operator_rankT) rankarg;
1865
0
  segT retval;
1866
0
  expressionS right;
1867
0
  operatorT op_left;
1868
0
  operatorT op_right;
1869
0
  int op_chars;
1870
1871
0
  know (rankarg >= 0);
1872
1873
  /* Save the value of dot for the fixup code.  */
1874
0
  if (rank == 0)
1875
0
    symbol_set_value_now (&dot_symbol);
1876
1877
0
  retval = operand (resultP, mode);
1878
1879
  /* operand () gobbles spaces.  */
1880
0
  know (!is_whitespace (*input_line_pointer));
1881
1882
0
  op_left = operatorf (&op_chars);
1883
0
  while (op_left != O_illegal && op_rank[(int) op_left] > rank)
1884
0
    {
1885
0
      segT rightseg;
1886
0
      bool is_unsigned;
1887
0
      offsetT frag_off;
1888
1889
0
      input_line_pointer += op_chars; /* -> after operator.  */
1890
1891
0
      right.X_md = 0;
1892
0
      rightseg = expr (op_rank[(int) op_left], &right, mode);
1893
0
      if (right.X_op == O_absent)
1894
0
  {
1895
0
    as_warn (_("missing operand; zero assumed"));
1896
0
    right.X_op = O_constant;
1897
0
    right.X_add_number = 0;
1898
0
    right.X_add_symbol = NULL;
1899
0
    right.X_op_symbol = NULL;
1900
0
  }
1901
1902
0
      know (!is_whitespace (*input_line_pointer));
1903
1904
0
      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
0
      op_right = operatorf (&op_chars);
1916
1917
0
      know (op_right == O_illegal || op_left == O_index
1918
0
      || op_rank[(int) op_right] <= op_rank[(int) op_left]);
1919
0
      know ((int) op_left >= (int) O_multiply);
1920
#ifndef md_operator
1921
      know ((int) op_left <= (int) O_index);
1922
#else
1923
0
      know ((int) op_left < (int) O_max);
1924
0
#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
0
      if (resultP->X_op == O_big)
1932
0
  {
1933
0
    if (resultP->X_add_number > 0)
1934
0
      as_warn (_("left operand is a bignum; integer 0 assumed"));
1935
0
    else
1936
0
      as_warn (_("left operand is a float; integer 0 assumed"));
1937
0
    resultP->X_op = O_constant;
1938
0
    resultP->X_add_number = 0;
1939
0
    resultP->X_add_symbol = NULL;
1940
0
    resultP->X_op_symbol = NULL;
1941
0
  }
1942
0
      if (right.X_op == O_big)
1943
0
  {
1944
0
    if (right.X_add_number > 0)
1945
0
      as_warn (_("right operand is a bignum; integer 0 assumed"));
1946
0
    else
1947
0
      as_warn (_("right operand is a float; integer 0 assumed"));
1948
0
    right.X_op = O_constant;
1949
0
    right.X_add_number = 0;
1950
0
    right.X_add_symbol = NULL;
1951
0
    right.X_op_symbol = NULL;
1952
0
  }
1953
1954
0
      is_unsigned = resultP->X_unsigned && right.X_unsigned;
1955
1956
0
      if (expr_defer_p (mode)
1957
0
    && ((resultP->X_add_symbol != NULL
1958
0
         && S_IS_FORWARD_REF (resultP->X_add_symbol))
1959
0
        || (right.X_add_symbol != NULL
1960
0
      && S_IS_FORWARD_REF (right.X_add_symbol))))
1961
0
  goto general;
1962
1963
      /* Optimize common cases.  */
1964
0
#ifdef md_optimize_expr
1965
0
      if (md_optimize_expr (resultP, op_left, &right))
1966
0
  {
1967
    /* Skip.  */
1968
0
    is_unsigned = resultP->X_unsigned;
1969
0
  }
1970
0
      else
1971
0
#endif
1972
0
      if (op_left == O_add && right.X_op == O_constant
1973
0
    && (md_register_arithmetic || resultP->X_op != O_register))
1974
0
  {
1975
    /* X + constant.  */
1976
0
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
1977
0
  }
1978
      /* This case comes up in PIC code.  */
1979
0
      else if (op_left == O_subtract
1980
0
         && right.X_op == O_symbol
1981
0
         && resultP->X_op == O_symbol
1982
0
         && retval == rightseg
1983
#ifdef md_allow_local_subtract
1984
         && md_allow_local_subtract (resultP, & right, rightseg)
1985
#endif
1986
0
         && ((SEG_NORMAL (rightseg)
1987
0
        && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
1988
0
        && !S_FORCE_RELOC (right.X_add_symbol, 0))
1989
0
       || right.X_add_symbol == resultP->X_add_symbol)
1990
0
         && frag_offset_fixed_p (symbol_get_frag (resultP->X_add_symbol),
1991
0
               symbol_get_frag (right.X_add_symbol),
1992
0
               &frag_off))
1993
0
  {
1994
0
    offsetT symval_diff = S_GET_VALUE (resultP->X_add_symbol)
1995
0
        - S_GET_VALUE (right.X_add_symbol);
1996
0
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
1997
0
    subtract_from_result (resultP, frag_off / OCTETS_PER_BYTE, 0);
1998
0
    add_to_result (resultP, symval_diff, symval_diff < 0);
1999
0
    resultP->X_op = O_constant;
2000
0
    resultP->X_add_symbol = 0;
2001
0
    is_unsigned = false;
2002
0
  }
2003
0
      else if (op_left == O_subtract && right.X_op == O_constant
2004
0
         && (md_register_arithmetic || resultP->X_op != O_register))
2005
0
  {
2006
    /* X - constant.  */
2007
0
    subtract_from_result (resultP, right.X_add_number, right.X_extrabit);
2008
0
    is_unsigned = false;
2009
0
  }
2010
0
      else if (op_left == O_add && resultP->X_op == O_constant
2011
0
         && (md_register_arithmetic || right.X_op != O_register))
2012
0
  {
2013
    /* Constant + X.  */
2014
0
    resultP->X_op = right.X_op;
2015
0
    resultP->X_add_symbol = right.X_add_symbol;
2016
0
    resultP->X_op_symbol = right.X_op_symbol;
2017
0
    add_to_result (resultP, right.X_add_number, right.X_extrabit);
2018
0
    retval = rightseg;
2019
0
  }
2020
0
      else if (resultP->X_op == O_constant && right.X_op == O_constant)
2021
0
  {
2022
    /* Constant OP constant.  */
2023
0
    offsetT v = right.X_add_number;
2024
0
    if (v == 0 && (op_left == O_divide || op_left == O_modulus))
2025
0
      {
2026
0
        as_warn (_("division by zero"));
2027
0
        v = 1;
2028
0
      }
2029
0
    switch (op_left)
2030
0
      {
2031
0
      default:      goto general;
2032
0
      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
0
        resultP->X_add_number *= (valueT) v;
2037
0
        break;
2038
2039
0
      case O_divide:
2040
0
        if (v == 1)
2041
0
    break;
2042
0
        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
0
        else
2051
0
    resultP->X_add_number /= v;
2052
0
        break;
2053
2054
0
      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
0
        if (v == 1 || v == -1)
2059
0
    resultP->X_add_number = 0;
2060
0
        else
2061
0
    resultP->X_add_number %= v;
2062
0
        break;
2063
2064
0
      case O_left_shift:
2065
0
      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
0
        if ((valueT) v >= sizeof (valueT) * CHAR_BIT)
2075
0
    {
2076
0
      as_warn_value_out_of_range (_("shift count"), v, 0,
2077
0
                sizeof (valueT) * CHAR_BIT - 1,
2078
0
                NULL, 0);
2079
0
      resultP->X_add_number = 0;
2080
0
    }
2081
0
        else if (op_left == O_left_shift)
2082
0
    resultP->X_add_number
2083
0
      = (valueT) resultP->X_add_number << (valueT) v;
2084
0
        else
2085
0
    resultP->X_add_number
2086
0
      = (valueT) resultP->X_add_number >> (valueT) v;
2087
0
        is_unsigned = resultP->X_unsigned;
2088
0
        break;
2089
0
      case O_bit_inclusive_or:  resultP->X_add_number |= v; break;
2090
0
      case O_bit_or_not:    resultP->X_add_number |= ~v; break;
2091
0
      case O_bit_exclusive_or:  resultP->X_add_number ^= v; break;
2092
0
      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
0
      case O_eq:
2101
0
        resultP->X_add_number =
2102
0
    resultP->X_add_number == v ? ~ (offsetT) 0 : 0;
2103
0
        is_unsigned = false;
2104
0
        break;
2105
0
      case O_ne:
2106
0
        resultP->X_add_number =
2107
0
    resultP->X_add_number != v ? ~ (offsetT) 0 : 0;
2108
0
        is_unsigned = false;
2109
0
        break;
2110
0
      case O_lt:
2111
0
        resultP->X_add_number =
2112
0
    resultP->X_add_number <  v ? ~ (offsetT) 0 : 0;
2113
0
        is_unsigned = false;
2114
0
        break;
2115
0
      case O_le:
2116
0
        resultP->X_add_number =
2117
0
    resultP->X_add_number <= v ? ~ (offsetT) 0 : 0;
2118
0
        is_unsigned = false;
2119
0
        break;
2120
0
      case O_ge:
2121
0
        resultP->X_add_number =
2122
0
    resultP->X_add_number >= v ? ~ (offsetT) 0 : 0;
2123
0
        is_unsigned = false;
2124
0
        break;
2125
0
      case O_gt:
2126
0
        resultP->X_add_number =
2127
0
    resultP->X_add_number >  v ? ~ (offsetT) 0 : 0;
2128
0
        is_unsigned = false;
2129
0
        break;
2130
0
      case O_logical_and:
2131
0
        resultP->X_add_number = resultP->X_add_number && v;
2132
0
        is_unsigned = true;
2133
0
        break;
2134
0
      case O_logical_or:
2135
0
        resultP->X_add_number = resultP->X_add_number || v;
2136
0
        is_unsigned = true;
2137
0
        break;
2138
0
      }
2139
0
  }
2140
0
      else if (resultP->X_op == O_symbol
2141
0
         && right.X_op == O_symbol
2142
0
         && (op_left == O_add
2143
0
       || op_left == O_subtract
2144
0
       || (resultP->X_add_number == 0
2145
0
           && right.X_add_number == 0)))
2146
0
  {
2147
    /* Symbol OP symbol.  */
2148
0
    resultP->X_op = op_left;
2149
0
    resultP->X_op_symbol = right.X_add_symbol;
2150
0
    if (op_left == O_add)
2151
0
      add_to_result (resultP, right.X_add_number, right.X_extrabit);
2152
0
    else if (op_left == O_subtract)
2153
0
      {
2154
0
        subtract_from_result (resultP, right.X_add_number,
2155
0
            right.X_extrabit);
2156
0
        if (retval == rightseg
2157
0
      && SEG_NORMAL (retval)
2158
0
      && !S_FORCE_RELOC (resultP->X_add_symbol, 0)
2159
0
      && !S_FORCE_RELOC (right.X_add_symbol, 0))
2160
0
    {
2161
0
      retval = absolute_section;
2162
0
      rightseg = absolute_section;
2163
0
    }
2164
0
      }
2165
0
  }
2166
0
      else
2167
0
  {
2168
0
        general:
2169
    /* The general case.  */
2170
0
    resultP->X_add_symbol = make_expr_symbol (resultP);
2171
0
    resultP->X_op_symbol = make_expr_symbol (&right);
2172
0
    resultP->X_op = op_left;
2173
0
    resultP->X_add_number = 0;
2174
0
    resultP->X_extrabit = 0;
2175
0
  }
2176
2177
0
      resultP->X_unsigned = is_unsigned;
2178
2179
0
      if (retval != rightseg)
2180
0
  {
2181
0
    if (retval == undefined_section)
2182
0
      ;
2183
0
    else if (rightseg == undefined_section)
2184
0
      retval = rightseg;
2185
0
    else if (retval == expr_section)
2186
0
      ;
2187
0
    else if (rightseg == expr_section)
2188
0
      retval = rightseg;
2189
0
    else if (retval == reg_section)
2190
0
      ;
2191
0
    else if (rightseg == reg_section)
2192
0
      retval = rightseg;
2193
0
    else if (rightseg == absolute_section)
2194
0
      ;
2195
0
    else if (retval == absolute_section)
2196
0
      retval = rightseg;
2197
0
#ifdef DIFF_EXPR_OK
2198
0
    else if (op_left == O_subtract)
2199
0
      ;
2200
0
#endif
2201
0
    else
2202
0
      as_bad (_("operation combines symbols in different segments"));
2203
0
  }
2204
2205
0
      op_left = op_right;
2206
0
    }       /* While next operator is >= this rank.  */
2207
2208
  /* The PA port needs this information.  */
2209
0
  if (resultP->X_add_symbol)
2210
0
    symbol_mark_used (resultP->X_add_symbol);
2211
2212
0
  if (rank == 0 && mode == expr_evaluate)
2213
0
    resolve_expression (resultP);
2214
2215
0
  return resultP->X_op == O_constant ? absolute_section : retval;
2216
0
}
2217
2218
/* Resolve an expression without changing any symbols/sub-expressions
2219
   used.  */
2220
2221
int
2222
resolve_expression (expressionS *expressionP)
2223
0
{
2224
  /* Help out with CSE.  */
2225
0
  valueT final_val = expressionP->X_add_number;
2226
0
  symbolS *add_symbol = expressionP->X_add_symbol;
2227
0
  symbolS *orig_add_symbol = add_symbol;
2228
0
  symbolS *op_symbol = expressionP->X_op_symbol;
2229
0
  operatorT op = expressionP->X_op;
2230
0
  valueT left, right;
2231
0
  segT seg_left, seg_right;
2232
0
  fragS *frag_left, *frag_right;
2233
0
  offsetT frag_off;
2234
2235
0
  switch (op)
2236
0
    {
2237
0
    default:
2238
0
      return 0;
2239
2240
0
    case O_constant:
2241
0
    case O_register:
2242
0
      left = 0;
2243
0
      break;
2244
2245
0
    case O_symbol:
2246
0
    case O_symbol_rva:
2247
0
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2248
0
  return 0;
2249
2250
0
      break;
2251
2252
0
    case O_uminus:
2253
0
    case O_bit_not:
2254
0
    case O_logical_not:
2255
0
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left))
2256
0
  return 0;
2257
2258
0
      if (seg_left != absolute_section)
2259
0
  return 0;
2260
2261
0
      if (op == O_logical_not)
2262
0
  left = !left;
2263
0
      else if (op == O_uminus)
2264
0
  left = -left;
2265
0
      else
2266
0
  left = ~left;
2267
0
      op = O_constant;
2268
0
      break;
2269
2270
0
    case O_multiply:
2271
0
    case O_divide:
2272
0
    case O_modulus:
2273
0
    case O_left_shift:
2274
0
    case O_right_shift:
2275
0
    case O_bit_inclusive_or:
2276
0
    case O_bit_or_not:
2277
0
    case O_bit_exclusive_or:
2278
0
    case O_bit_and:
2279
0
    case O_add:
2280
0
    case O_subtract:
2281
0
    case O_eq:
2282
0
    case O_ne:
2283
0
    case O_lt:
2284
0
    case O_le:
2285
0
    case O_ge:
2286
0
    case O_gt:
2287
0
    case O_logical_and:
2288
0
    case O_logical_or:
2289
0
      if (!snapshot_symbol (&add_symbol, &left, &seg_left, &frag_left)
2290
0
    || !snapshot_symbol (&op_symbol, &right, &seg_right, &frag_right))
2291
0
  return 0;
2292
2293
      /* Simplify addition or subtraction of a constant by folding the
2294
   constant into X_add_number.  */
2295
0
      if (op == O_add)
2296
0
  {
2297
0
    if (seg_right == absolute_section)
2298
0
      {
2299
0
        final_val += right;
2300
0
        op = O_symbol;
2301
0
        break;
2302
0
      }
2303
0
    else if (seg_left == absolute_section)
2304
0
      {
2305
0
        final_val += left;
2306
0
        left = right;
2307
0
        seg_left = seg_right;
2308
0
        add_symbol = op_symbol;
2309
0
        orig_add_symbol = expressionP->X_op_symbol;
2310
0
        op = O_symbol;
2311
0
        break;
2312
0
      }
2313
0
  }
2314
0
      else if (op == O_subtract)
2315
0
  {
2316
0
    if (seg_right == absolute_section)
2317
0
      {
2318
0
        final_val -= right;
2319
0
        op = O_symbol;
2320
0
        break;
2321
0
      }
2322
0
  }
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
0
      frag_off = 0;
2338
0
      if (!(seg_left == absolute_section
2339
0
         && seg_right == absolute_section)
2340
0
    && !(op == O_eq || op == O_ne)
2341
0
    && !((op == O_subtract
2342
0
    || op == O_lt || op == O_le || op == O_ge || op == O_gt)
2343
0
         && seg_left == seg_right
2344
0
         && (finalize_syms
2345
0
       || frag_offset_fixed_p (frag_left, frag_right, &frag_off)
2346
0
       || (op == O_gt
2347
0
           && frag_gtoffset_p (left, frag_left,
2348
0
             right, frag_right, &frag_off)))
2349
0
         && (seg_left != reg_section || left == right)
2350
0
         && (seg_left != undefined_section || add_symbol == op_symbol)))
2351
0
  {
2352
0
    if ((seg_left == absolute_section && left == 0)
2353
0
        || (seg_right == absolute_section && right == 0))
2354
0
      {
2355
0
        if (op == O_bit_exclusive_or || op == O_bit_inclusive_or)
2356
0
    {
2357
0
      if (!(seg_right == absolute_section && right == 0))
2358
0
        {
2359
0
          seg_left = seg_right;
2360
0
          left = right;
2361
0
          add_symbol = op_symbol;
2362
0
          orig_add_symbol = expressionP->X_op_symbol;
2363
0
        }
2364
0
      op = O_symbol;
2365
0
      break;
2366
0
    }
2367
0
        else if (op == O_left_shift || op == O_right_shift)
2368
0
    {
2369
0
      if (!(seg_left == absolute_section && left == 0))
2370
0
        {
2371
0
          op = O_symbol;
2372
0
          break;
2373
0
        }
2374
0
    }
2375
0
        else if (op != O_multiply
2376
0
           && op != O_bit_or_not && op != O_bit_and)
2377
0
          return 0;
2378
0
      }
2379
0
    else if (op == O_multiply
2380
0
       && 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
0
    else if ((op == O_multiply || op == O_divide)
2390
0
       && seg_right == absolute_section && right == 1)
2391
0
      {
2392
0
        op = O_symbol;
2393
0
        break;
2394
0
      }
2395
0
    else if (!(left == right
2396
0
         && ((seg_left == reg_section && seg_right == reg_section)
2397
0
       || (seg_left == undefined_section
2398
0
           && seg_right == undefined_section
2399
0
           && add_symbol == op_symbol))))
2400
0
      return 0;
2401
0
    else if (op == O_bit_and || op == O_bit_inclusive_or)
2402
0
      {
2403
0
        op = O_symbol;
2404
0
        break;
2405
0
      }
2406
0
    else if (op != O_bit_exclusive_or && op != O_bit_or_not)
2407
0
      return 0;
2408
0
  }
2409
2410
0
      right += frag_off / OCTETS_PER_BYTE;
2411
0
      switch (op)
2412
0
  {
2413
0
  case O_add:     left += right; break;
2414
0
  case O_subtract:    left -= right; break;
2415
0
  case O_multiply:    left *= right; break;
2416
0
  case O_divide:
2417
0
    if (right == 0)
2418
0
      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
0
  case O_modulus:
2428
0
    if (right == 0)
2429
0
      return 0;
2430
    /* Again, see expr() for reasons of the special casing.  */
2431
0
    if (right == 1 || (offsetT) right == -1)
2432
0
      left = 0;
2433
0
    else
2434
0
      left = (offsetT) left % (offsetT) right;
2435
0
    break;
2436
0
  case O_left_shift:
2437
0
    if (right >= sizeof (left) * CHAR_BIT)
2438
0
      left = 0;
2439
0
    else
2440
0
      left <<= right;
2441
0
    break;
2442
0
  case O_right_shift:
2443
0
    if (right >= sizeof (left) * CHAR_BIT)
2444
0
      left = 0;
2445
0
    else
2446
0
      left >>= right;
2447
0
    break;
2448
0
  case O_bit_inclusive_or:  left |= right; break;
2449
0
  case O_bit_or_not:    left |= ~right; break;
2450
0
  case O_bit_exclusive_or:  left ^= right; break;
2451
0
  case O_bit_and:     left &= right; break;
2452
0
  case O_eq:
2453
0
  case O_ne:
2454
0
    left = (left == right
2455
0
      && seg_left == seg_right
2456
0
      && (finalize_syms || frag_left == frag_right)
2457
0
      && (seg_left != undefined_section
2458
0
          || add_symbol == op_symbol)
2459
0
      ? ~ (valueT) 0 : 0);
2460
0
    if (op == O_ne)
2461
0
      left = ~left;
2462
0
    break;
2463
0
  case O_lt:
2464
0
    left = (offsetT) left <  (offsetT) right ? ~ (valueT) 0 : 0;
2465
0
    break;
2466
0
  case O_le:
2467
0
    left = (offsetT) left <= (offsetT) right ? ~ (valueT) 0 : 0;
2468
0
    break;
2469
0
  case O_ge:
2470
0
    left = (offsetT) left >= (offsetT) right ? ~ (valueT) 0 : 0;
2471
0
    break;
2472
0
  case O_gt:
2473
0
    left = (offsetT) left >  (offsetT) right ? ~ (valueT) 0 : 0;
2474
0
    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
0
  }
2479
2480
0
      op = O_constant;
2481
0
      break;
2482
0
    }
2483
2484
0
  if (op == O_symbol)
2485
0
    {
2486
0
      if (seg_left == absolute_section)
2487
0
  op = O_constant;
2488
0
      else if (seg_left == reg_section && final_val == 0)
2489
0
  op = O_register;
2490
0
      else if (!symbol_same_p (add_symbol, orig_add_symbol))
2491
0
  final_val += left;
2492
0
      expressionP->X_add_symbol = add_symbol;
2493
0
    }
2494
0
  expressionP->X_op = op;
2495
2496
0
  if (op == O_constant || op == O_register)
2497
0
    final_val += left;
2498
0
  expressionP->X_add_number = final_val;
2499
2500
0
  return 1;
2501
0
}
2502
2503
/* "Look through" register equates.  */
2504
void resolve_register (expressionS *expP)
2505
0
{
2506
0
  symbolS *sym;
2507
0
  offsetT acc = 0;
2508
0
  const expressionS *e = expP;
2509
2510
0
  if (expP->X_op != O_symbol)
2511
0
    return;
2512
2513
0
  do
2514
0
    {
2515
0
      if (!md_register_arithmetic && e->X_add_number)
2516
0
  break;
2517
0
      sym = e->X_add_symbol;
2518
0
      acc += e->X_add_number;
2519
0
      e = symbol_get_value_expression (sym);
2520
0
    }
2521
0
  while (symbol_equated_p (sym));
2522
2523
0
  if (e->X_op == O_register)
2524
0
    {
2525
0
      expr_copy (expP, e);
2526
0
      expP->X_add_number += acc;
2527
0
    }
2528
0
}
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
0
{
2552
0
  char c;
2553
2554
0
  * 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
0
  if (is_name_beginner (c = *input_line_pointer++)
2558
0
      || (input_from_string && c == FAKE_LABEL_CHAR))
2559
0
    {
2560
0
      while (is_part_of_name (c = *input_line_pointer++)
2561
0
       || (input_from_string && c == FAKE_LABEL_CHAR))
2562
0
  ;
2563
0
      if (is_name_ender (c))
2564
0
  c = *input_line_pointer++;
2565
0
    }
2566
0
  else if (c == '"')
2567
0
    {
2568
0
      char *dst = input_line_pointer;
2569
2570
0
      * ilp_return = input_line_pointer;
2571
0
      for (;;)
2572
0
  {
2573
0
    c = *input_line_pointer++;
2574
2575
0
    if (c == 0)
2576
0
      {
2577
0
        as_warn (_("missing closing '\"'"));
2578
0
        break;
2579
0
      }
2580
2581
0
    if (c == '"')
2582
0
      {
2583
0
        char *ilp_save = input_line_pointer;
2584
2585
0
        SKIP_WHITESPACE ();
2586
0
        if (*input_line_pointer == '"')
2587
0
    {
2588
0
      ++input_line_pointer;
2589
0
      continue;
2590
0
    }
2591
0
        input_line_pointer = ilp_save;
2592
0
        break;
2593
0
      }
2594
2595
0
    if (c == '\\')
2596
0
      switch (*input_line_pointer)
2597
0
        {
2598
0
        case '"':
2599
0
        case '\\':
2600
0
    c = *input_line_pointer++;
2601
0
    break;
2602
2603
0
        default:
2604
0
    if (c != 0)
2605
0
      as_warn (_("'\\%c' in quoted symbol name; "
2606
0
           "behavior may change in the future"),
2607
0
         *input_line_pointer);
2608
0
    break;
2609
0
        }
2610
2611
0
    *dst++ = c;
2612
0
  }
2613
0
      *dst = 0;
2614
0
    }
2615
0
  *--input_line_pointer = 0;
2616
0
  return c;
2617
0
}
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
0
{
2626
0
  * input_line_pointer = c;
2627
0
  if (c == '"')
2628
0
    c = * ++ input_line_pointer;
2629
0
  return c;
2630
0
}
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
}