Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/gas/macro.c
Line
Count
Source
1
/* macro.c - macro support for gas
2
   Copyright (C) 1994-2026 Free Software Foundation, Inc.
3
4
   Written by Steve and Judy Chamberlain of Cygnus Support,
5
      sac@cygnus.com
6
7
   This file is part of GAS, the GNU Assembler.
8
9
   GAS is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3, or (at your option)
12
   any later version.
13
14
   GAS is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
19
   You should have received a copy of the GNU General Public License
20
   along with GAS; see the file COPYING.  If not, write to the Free
21
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22
   02110-1301, USA.  */
23
24
#include "as.h"
25
#include "safe-ctype.h"
26
#include "sb.h"
27
#include "macro.h"
28
29
/* The routines in this file handle macro definition and expansion.
30
   They are called by gas.  */
31
32
/* The macro hash table.  */
33
34
htab_t macro_hash;
35
36
/* Whether any macros have been defined.  */
37
38
int macro_defined;
39
40
/* Whether we should strip '@' characters.  */
41
42
9.80M
#define macro_strip_at false
43
44
/* Number of macro expansions that have been done.  */
45
46
static unsigned int macro_number;
47
48
static void free_macro (macro_entry *);
49
50
static void
51
macro_del_f (void *ent)
52
23
{
53
23
  string_tuple_t *tuple = ent;
54
23
  free_macro ((macro_entry *) tuple->value);
55
23
}
56
57
/* Initialize macro processing.  */
58
59
void
60
macro_init (void)
61
368
{
62
368
  macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
63
368
          macro_del_f, notes_calloc, NULL);
64
368
  macro_defined = 0;
65
368
}
66
67
void
68
macro_end (void)
69
368
{
70
368
  if (ENABLE_LEAK_CHECK)
71
368
    htab_delete (macro_hash);
72
368
}
73
74
/* Read input lines till we get to a TO string.
75
   Increase nesting depth if we get a FROM string.
76
   Put the results into sb at PTR.
77
   FROM may be NULL (or will be ignored) if TO is "ENDR".
78
   Add a new input line to an sb using GET_LINE.
79
   Return 1 on success, 0 on unexpected EOF.  */
80
81
int
82
buffer_and_nest (const char *from, const char *to, sb *ptr,
83
     size_t (*get_line) (sb *))
84
1.26k
{
85
1.26k
  size_t from_len;
86
1.26k
  size_t to_len = strlen (to);
87
1.26k
  int depth = 1;
88
1.26k
  size_t line_start, more;
89
90
1.26k
  if (to_len == 4 && strcasecmp (to, "ENDR") == 0)
91
1.03k
    {
92
1.03k
      from = NULL;
93
1.03k
      from_len = 0;
94
1.03k
    }
95
233
  else
96
233
    from_len = strlen (from);
97
98
  /* Record the present source position, such that diagnostics and debug info
99
     can be properly associated with the respective original lines, rather
100
     than with the line of the ending directive (TO).  */
101
1.26k
  {
102
1.26k
    unsigned int line;
103
1.26k
    char *linefile;
104
105
1.26k
    const char *prefix = flag_m68k_mri ? "" : ".";
106
1.26k
    const char *file = as_where_top (&line);
107
108
1.26k
    if (*input_line_pointer == '\n')
109
1.00k
      line++;
110
1.26k
    if (file)
111
1.26k
      linefile = xasprintf ("\t%slinefile %u \"%s\"", prefix, line, file);
112
0
    else
113
0
      linefile = xasprintf ("\t%slinefile %u .", prefix, line);
114
1.26k
    sb_add_string (ptr, linefile);
115
1.26k
    xfree (linefile);
116
1.26k
  }
117
118
1.26k
  line_start = ptr->len;
119
1.26k
  more = get_line (ptr);
120
14.7k
  while (more)
121
14.6k
    {
122
      /* Try to find the first pseudo op on the line.  */
123
14.6k
      size_t i = line_start;
124
14.6k
      bool had_colon = false;
125
126
      /* With normal syntax we can suck what we want till we get
127
   to the dot.  With the alternate, labels have to start in
128
   the first column, since we can't tell what's a label and
129
   what's a pseudoop.  */
130
131
14.6k
      if (! LABELS_WITHOUT_COLONS)
132
14.6k
  {
133
    /* Skip leading whitespace.  */
134
14.6k
    i = sb_skip_white (i, ptr);
135
14.6k
  }
136
137
14.6k
      for (;;)
138
14.6k
  {
139
    /* Skip over a label, if any.  */
140
14.6k
    if (i >= ptr->len || ! is_name_beginner (ptr->ptr[i]))
141
7.44k
      break;
142
7.22k
    i++;
143
38.4k
    while (i < ptr->len && is_part_of_name (ptr->ptr[i]))
144
31.1k
      i++;
145
7.22k
    if (i < ptr->len && is_name_ender (ptr->ptr[i]))
146
0
      i++;
147
    /* Skip whitespace.  */
148
7.22k
    i = sb_skip_white (i, ptr);
149
    /* Check for the colon.  */
150
7.22k
    if (i >= ptr->len || ptr->ptr[i] != ':')
151
7.19k
      {
152
        /* LABELS_WITHOUT_COLONS doesn't mean we cannot have a
153
     colon after a label.  If we do have a colon on the
154
     first label then handle more than one label on the
155
     line, assuming that each label has a colon.  */
156
7.19k
        if (LABELS_WITHOUT_COLONS && !had_colon)
157
0
    break;
158
7.19k
        i = line_start;
159
7.19k
        break;
160
7.19k
      }
161
28
    i++;
162
28
    line_start = i;
163
28
    had_colon = true;
164
28
  }
165
166
      /* Skip trailing whitespace.  */
167
14.6k
      i = sb_skip_white (i, ptr);
168
169
14.6k
      if (i < ptr->len && (ptr->ptr[i] == '.'
170
4.21k
         || NO_PSEUDO_DOT
171
4.21k
         || flag_mri))
172
6.82k
  {
173
6.82k
    if (! flag_m68k_mri && ptr->ptr[i] == '.')
174
4.81k
      i++;
175
6.82k
    size_t len = ptr->len - i;
176
6.82k
    if (from == NULL)
177
5.02k
      {
178
5.02k
        if (len >= 5 && strncasecmp (ptr->ptr + i, "IREPC", 5) == 0)
179
0
    from_len = 5;
180
5.02k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IREP", 4) == 0)
181
0
    from_len = 4;
182
5.02k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IRPC", 4) == 0)
183
14
    from_len = 4;
184
5.00k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "REPT", 4) == 0)
185
0
    from_len = 4;
186
5.00k
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "IRP", 3) == 0)
187
3
    from_len = 3;
188
5.00k
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "REP", 3) == 0)
189
1
    from_len = 3;
190
5.00k
        else
191
5.00k
    from_len = 0;
192
5.02k
      }
193
6.82k
    if ((from != NULL
194
6.82k
         ? (len >= from_len
195
892
      && strncasecmp (ptr->ptr + i, from, from_len) == 0)
196
6.82k
         : from_len > 0)
197
18
        && (len == from_len
198
18
      || ! (is_part_of_name (ptr->ptr[i + from_len])
199
18
      || is_name_ender (ptr->ptr[i + from_len]))))
200
18
      depth++;
201
6.82k
    if (len >= to_len
202
5.78k
        && strncasecmp (ptr->ptr + i, to, to_len) == 0
203
1.34k
        && (len == to_len
204
894
      || ! (is_part_of_name (ptr->ptr[i + to_len])
205
759
      || is_name_ender (ptr->ptr[i + to_len]))))
206
1.20k
      {
207
1.20k
        depth--;
208
1.20k
        if (depth == 0)
209
1.19k
    {
210
      /* Reset the string to not include the ending rune.  */
211
1.19k
      ptr->len = line_start;
212
213
      /* With the ending directive consumed here, announce the
214
         line for macro-expanded listings. */
215
1.19k
      if (listing & LISTING_MACEXP)
216
0
        listing_newline (NULL);
217
1.19k
      break;
218
1.19k
    }
219
1.20k
      }
220
221
    /* PR gas/16908
222
       Apply .linefile directives that appear within the macro, alongside
223
       keeping them for later expansion of the macro.  */
224
5.63k
    if (from != NULL && strcasecmp (from, "MACRO") == 0
225
1.58k
        && len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
226
193
      {
227
193
        sb_add_char (ptr, more);
228
193
        temp_ilp (sb_terminate (ptr) + i + 8);
229
193
        s_linefile (0);
230
193
        restore_ilp ();
231
193
        line_start = ptr->len;
232
193
        more = get_line (ptr);
233
193
        continue;
234
193
      }
235
5.63k
  }
236
237
      /* Add the original end-of-line char to the end and keep running.  */
238
13.2k
      sb_add_char (ptr, more);
239
13.2k
      line_start = ptr->len;
240
13.2k
      more = get_line (ptr);
241
13.2k
    }
242
243
  /* Return 1 on success, 0 on unexpected EOF.  */
244
1.26k
  return depth == 0;
245
1.26k
}
246
247
/* Pick up a token.  */
248
249
static size_t
250
get_token (size_t idx, sb *in, sb *name)
251
993k
{
252
993k
  if (idx < in->len
253
993k
      && is_name_beginner (in->ptr[idx]))
254
565k
    {
255
565k
      sb_add_char (name, in->ptr[idx++]);
256
3.60M
      while (idx < in->len
257
3.60M
       && is_part_of_name (in->ptr[idx]))
258
3.04M
  {
259
3.04M
    sb_add_char (name, in->ptr[idx++]);
260
3.04M
  }
261
565k
      if (idx < in->len
262
565k
       && is_name_ender (in->ptr[idx]))
263
0
  {
264
0
    sb_add_char (name, in->ptr[idx++]);
265
0
  }
266
565k
    }
267
  /* Ignore trailing &.  */
268
993k
  if (flag_macro_alternate && idx < in->len && in->ptr[idx] == '&')
269
0
    idx++;
270
993k
  return idx;
271
993k
}
272
273
/* Pick up a string.  */
274
275
static size_t
276
getstring (size_t idx, sb *in, sb *acc)
277
48
{
278
96
  while (idx < in->len
279
61
   && (in->ptr[idx] == '"'
280
17
       || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
281
13
       || (in->ptr[idx] == '\'' && flag_macro_alternate)))
282
48
    {
283
48
      if (in->ptr[idx] == '<')
284
4
  {
285
4
    int nest = 0;
286
4
    idx++;
287
4
    while (idx < in->len)
288
0
      {
289
0
        if (in->ptr[idx] == '!' && idx + 1 < in->len)
290
0
    idx++;
291
0
        else if (in->ptr[idx] == '>')
292
0
    {
293
0
      if (nest == 0)
294
0
        {
295
0
          idx++;
296
0
          break;
297
0
        }
298
0
      nest--;
299
0
    }
300
0
        else if (in->ptr[idx] == '<')
301
0
    nest++;
302
303
0
        sb_add_char (acc, in->ptr[idx]);
304
0
        idx++;
305
0
      }
306
4
  }
307
44
      else if (in->ptr[idx] == '"' || in->ptr[idx] == '\'')
308
44
  {
309
44
    char tchar = in->ptr[idx];
310
44
    int escaped = 0;
311
312
44
    idx++;
313
323
    while (idx < in->len)
314
295
      {
315
295
        if (in->ptr[idx - 1] == '\\')
316
0
    escaped ^= 1;
317
295
        else
318
295
    escaped = 0;
319
320
295
        if (flag_macro_alternate
321
0
      && in->ptr[idx] == '!' && idx + 1 < in->len)
322
0
    {
323
0
      idx++;
324
0
    }
325
295
        else if (!escaped && in->ptr[idx] == tchar)
326
39
    {
327
39
      idx++;
328
39
      if (idx >= in->len || in->ptr[idx] != tchar)
329
16
        break;
330
39
    }
331
279
        sb_add_char (acc, in->ptr[idx]);
332
279
        idx++;
333
279
      }
334
44
  }
335
48
    }
336
337
48
  return idx;
338
48
}
339
340
/* Fetch string from the input stream,
341
   rules:
342
    %<expr>   -> return string of decimal value of <expr>
343
    "string"    -> return string
344
    (string)    -> return (string-including-whitespaces)
345
    xyx<whitespace>     -> return xyz.  */
346
347
static size_t
348
get_any_string (size_t idx, sb *in, sb *out)
349
181
{
350
181
  sb_reset (out);
351
181
  idx = sb_skip_white (idx, in);
352
353
181
  if (idx < in->len)
354
181
    {
355
181
      if (in->ptr[idx] == '%' && flag_macro_alternate)
356
0
  {
357
    /* Turn the following expression into a string.  */
358
0
    expressionS ex;
359
0
    char buf[64];
360
361
0
    sb_terminate (in);
362
363
0
    temp_ilp (in->ptr + idx + 1);
364
0
    expression_and_evaluate (&ex);
365
0
    idx = input_line_pointer - in->ptr;
366
0
    restore_ilp ();
367
368
0
    if (ex.X_op != O_constant)
369
0
      as_bad (_("%% operator needs absolute expression"));
370
371
0
    sprintf (buf, "%" PRId64, (int64_t) ex.X_add_number);
372
0
    sb_add_string (out, buf);
373
0
  }
374
181
      else if (in->ptr[idx] == '"'
375
137
         || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
376
133
         || (flag_macro_alternate && in->ptr[idx] == '\''))
377
48
  {
378
48
    if (flag_macro_alternate && ! macro_strip_at && in->ptr[idx] != '<')
379
0
      {
380
        /* Keep the quotes.  */
381
0
        sb_add_char (out, '"');
382
0
        idx = getstring (idx, in, out);
383
0
        sb_add_char (out, '"');
384
0
      }
385
48
    else
386
48
      {
387
48
        idx = getstring (idx, in, out);
388
48
      }
389
48
  }
390
133
      else
391
133
  {
392
133
    char *br_buf = XNEWVEC (char, 1);
393
133
    char *in_br = br_buf;
394
395
133
    *in_br = '\0';
396
2.00k
    while (idx < in->len
397
1.96k
     && (*in_br || !is_whitespace (in->ptr[idx]))
398
1.94k
     && in->ptr[idx] != ','
399
1.87k
     && (in->ptr[idx] != '<'
400
5
         || (! flag_macro_alternate && ! flag_mri)))
401
1.87k
      {
402
1.87k
        char tchar = in->ptr[idx];
403
404
1.87k
        switch (tchar)
405
1.87k
    {
406
8
    case '"':
407
8
    case '\'':
408
8
      sb_add_char (out, in->ptr[idx++]);
409
12
      while (idx < in->len
410
9
       && in->ptr[idx] != tchar)
411
4
        sb_add_char (out, in->ptr[idx++]);
412
8
      if (idx == in->len)
413
3
        {
414
3
          free (br_buf);
415
3
          return idx;
416
3
        }
417
5
      break;
418
20
    case '(':
419
20
    case '[':
420
20
      if (in_br > br_buf)
421
0
        --in_br;
422
20
      else
423
20
        {
424
20
          br_buf = XNEWVEC (char, strlen (in_br) + 2);
425
20
          strcpy (br_buf + 1, in_br);
426
20
          free (in_br);
427
20
          in_br = br_buf;
428
20
        }
429
20
      *in_br = tchar;
430
20
      break;
431
13
    case ')':
432
13
      if (*in_br == '(')
433
13
        ++in_br;
434
13
      break;
435
3
    case ']':
436
3
      if (*in_br == '[')
437
0
        ++in_br;
438
3
      break;
439
1.87k
    }
440
1.86k
        sb_add_char (out, tchar);
441
1.86k
        ++idx;
442
1.86k
      }
443
130
    free (br_buf);
444
130
  }
445
181
    }
446
447
178
  return idx;
448
181
}
449
450
/* Allocate a new formal.  */
451
452
static formal_entry *
453
new_formal (void)
454
296
{
455
296
  formal_entry *formal;
456
457
296
  formal = XNEW (formal_entry);
458
459
296
  sb_new (&formal->name);
460
296
  sb_new (&formal->def);
461
296
  sb_new (&formal->actual);
462
296
  formal->next = NULL;
463
296
  formal->type = FORMAL_OPTIONAL;
464
296
  return formal;
465
296
}
466
467
/* Free a formal.  */
468
469
static void
470
del_formal (formal_entry *formal)
471
296
{
472
296
  sb_kill (&formal->actual);
473
296
  sb_kill (&formal->def);
474
296
  sb_kill (&formal->name);
475
296
  free (formal);
476
296
}
477
478
/* Pick up the formal parameters of a macro definition.  */
479
480
static size_t
481
do_formals (macro_entry *macro, size_t idx, sb *in)
482
233
{
483
233
  formal_entry **p = &macro->formals;
484
233
  const char *name;
485
486
233
  idx = sb_skip_white (idx, in);
487
266
  while (idx < in->len)
488
43
    {
489
43
      formal_entry *formal = new_formal ();
490
43
      size_t cidx;
491
492
43
      idx = get_token (idx, in, &formal->name);
493
43
      if (formal->name.len == 0)
494
10
  {
495
10
    if (macro->formal_count)
496
0
      --idx;
497
10
    del_formal (formal);  /* 'formal' goes out of scope.  */
498
10
    break;
499
10
  }
500
33
      idx = sb_skip_white (idx, in);
501
      /* This is a formal.  */
502
33
      name = sb_terminate (&formal->name);
503
33
      if (! flag_mri
504
8
    && idx < in->len
505
0
    && in->ptr[idx] == ':'
506
0
    && (! is_name_beginner (':')
507
0
        || idx + 1 >= in->len
508
0
        || ! is_part_of_name (in->ptr[idx + 1])))
509
0
  {
510
    /* Got a qualifier.  */
511
0
    sb qual;
512
513
0
    sb_new (&qual);
514
0
    idx = get_token (sb_skip_white (idx + 1, in), in, &qual);
515
0
    sb_terminate (&qual);
516
0
    if (qual.len == 0)
517
0
      as_bad_where (macro->file,
518
0
        macro->line,
519
0
        _("Missing parameter qualifier for `%s' in macro `%s'"),
520
0
        name,
521
0
        macro->name);
522
0
    else if (strcmp (qual.ptr, "req") == 0)
523
0
      formal->type = FORMAL_REQUIRED;
524
0
    else if (strcmp (qual.ptr, "vararg") == 0)
525
0
      formal->type = FORMAL_VARARG;
526
0
    else
527
0
      as_bad_where (macro->file,
528
0
        macro->line,
529
0
        _("`%s' is not a valid parameter qualifier for `%s' in macro `%s'"),
530
0
        qual.ptr,
531
0
        name,
532
0
        macro->name);
533
0
    sb_kill (&qual);
534
0
    idx = sb_skip_white (idx, in);
535
0
  }
536
33
      if (idx < in->len && in->ptr[idx] == '=')
537
1
  {
538
    /* Got a default.  */
539
1
    idx = get_any_string (idx + 1, in, &formal->def);
540
1
    idx = sb_skip_white (idx, in);
541
1
    if (formal->type == FORMAL_REQUIRED)
542
0
      {
543
0
        sb_reset (&formal->def);
544
0
        as_warn_where (macro->file,
545
0
          macro->line,
546
0
          _("Pointless default value for required parameter `%s' in macro `%s'"),
547
0
          name,
548
0
          macro->name);
549
0
      }
550
1
  }
551
552
      /* Add to macro's hash table.  */
553
33
      if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL)
554
0
  {
555
0
    as_bad_where (macro->file, macro->line,
556
0
      _("A parameter named `%s' "
557
0
        "already exists for macro `%s'"),
558
0
      name, macro->name);
559
0
  }
560
561
33
      formal->index = macro->formal_count++;
562
33
      *p = formal;
563
33
      p = &formal->next;
564
33
      if (formal->type == FORMAL_VARARG)
565
0
  break;
566
33
      cidx = idx;
567
33
      idx = sb_skip_comma (idx, in);
568
33
      if (idx != cidx && idx >= in->len)
569
0
  {
570
0
    idx = cidx;
571
0
    break;
572
0
  }
573
33
    }
574
575
233
  if (flag_mri)
576
223
    {
577
223
      formal_entry *formal = new_formal ();
578
579
      /* Add a special NARG formal, which macro_expand will set to the
580
   number of arguments.  */
581
      /* The same MRI assemblers which treat '@' characters also use
582
   the name $NARG.  At least until we find an exception.  */
583
223
      if (macro_strip_at)
584
0
  name = "$NARG";
585
223
      else
586
223
  name = "NARG";
587
588
223
      sb_add_string (&formal->name, name);
589
590
      /* Add to macro's hash table.  */
591
223
      if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL)
592
0
  {
593
0
    as_bad_where (macro->file, macro->line,
594
0
      _("Reserved word `%s' used as parameter in macro `%s'"),
595
0
      name, macro->name);
596
0
  }
597
598
223
      formal->index = NARG_INDEX;
599
223
      *p = formal;
600
223
    }
601
602
233
  return idx;
603
233
}
604
605
/* Free the memory allocated to a macro.  */
606
607
static void
608
free_macro (macro_entry *macro)
609
233
{
610
233
  formal_entry *formal;
611
612
489
  for (formal = macro->formals; formal; )
613
256
    {
614
256
      formal_entry *f;
615
616
256
      f = formal;
617
256
      formal = formal->next;
618
256
      del_formal (f);
619
256
    }
620
233
  htab_delete (macro->formal_hash);
621
233
  sb_kill (&macro->sub);
622
233
  free ((char *) macro->name);
623
233
  free (macro);
624
233
}
625
626
/* Define a new macro.  */
627
628
macro_entry *
629
define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
630
233
{
631
233
  macro_entry *macro;
632
233
  sb name;
633
233
  size_t idx;
634
233
  const char *error = NULL;
635
636
233
  macro = XNEW (macro_entry);
637
233
  sb_new (&macro->sub);
638
233
  sb_new (&name);
639
233
  macro->file = as_where (&macro->line);
640
641
233
  macro->formal_count = 0;
642
233
  macro->formals = 0;
643
233
  macro->formal_hash = str_htab_create ();
644
233
  macro->count = 0;
645
646
233
  idx = sb_skip_white (0, in);
647
233
  if (! buffer_and_nest ("MACRO", "ENDM", &macro->sub, get_line))
648
18
    error = _("unexpected end of file in macro `%s' definition");
649
233
  if (label != NULL && label->len != 0)
650
194
    {
651
194
      sb_add_sb (&name, label);
652
194
      macro->name = sb_terminate (&name);
653
194
      if (idx < in->len && in->ptr[idx] == '(')
654
0
  {
655
    /* It's the label: MACRO (formals,...)  sort  */
656
0
    idx = do_formals (macro, idx + 1, in);
657
0
    if (idx < in->len && in->ptr[idx] == ')')
658
0
      idx = sb_skip_white (idx + 1, in);
659
0
    else if (!error)
660
0
      error = _("missing `)' after formals in macro definition `%s'");
661
0
  }
662
194
      else
663
194
  {
664
    /* It's the label: MACRO formals,...  sort  */
665
194
    idx = do_formals (macro, idx, in);
666
194
  }
667
194
    }
668
39
  else
669
39
    {
670
39
      size_t cidx;
671
672
39
      idx = get_token (idx, in, &name);
673
39
      macro->name = sb_terminate (&name);
674
39
      if (name.len == 0)
675
11
  error = _("Missing macro name");
676
39
      cidx = sb_skip_white (idx, in);
677
39
      idx = sb_skip_comma (cidx, in);
678
39
      if (idx == cidx || idx < in->len)
679
39
  idx = do_formals (macro, idx, in);
680
0
      else
681
0
  idx = cidx;
682
39
    }
683
233
  if (!error && idx < in->len)
684
0
    error = _("Bad parameter list for macro `%s'");
685
686
  /* And stick it in the macro hash table.  */
687
1.12k
  for (idx = 0; idx < name.len; idx++)
688
890
    name.ptr[idx] = TOLOWER (name.ptr[idx]);
689
233
  if (!error)
690
215
    {
691
215
      if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL)
692
192
  error = _("Macro `%s' was already defined");
693
215
    }
694
695
233
  if (!error)
696
23
    macro_defined = 1;
697
210
  else
698
210
    {
699
210
      as_bad_where (macro->file, macro->line, error, macro->name);
700
210
      free_macro (macro);
701
210
      macro = NULL;
702
210
    }
703
704
233
  return macro;
705
233
}
706
707
/* Scan a token, and then skip KIND.  */
708
709
static size_t
710
get_apost_token (size_t idx, sb *in, sb *name, int kind)
711
814k
{
712
814k
  idx = get_token (idx, in, name);
713
814k
  if (idx < in->len
714
814k
      && in->ptr[idx] == kind
715
25.8k
      && (! flag_mri || macro_strip_at)
716
0
      && (! macro_strip_at || kind == '@'))
717
1.79k
    idx++;
718
814k
  return idx;
719
814k
}
720
721
/* Substitute the actual value for a formal parameter.  */
722
723
static size_t
724
sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
725
      int kind, sb *out, int copyifnotthere)
726
814k
{
727
814k
  size_t src;
728
814k
  formal_entry *ptr;
729
730
814k
  src = get_apost_token (start, in, t, kind);
731
  /* See if it's in the macro's hash table, unless this is
732
     macro_strip_at and kind is '@' and the token did not end in '@'.  */
733
814k
  if (macro_strip_at
734
0
      && kind == '@'
735
0
      && (src == start || in->ptr[src - 1] != '@'))
736
0
    ptr = NULL;
737
814k
  else
738
814k
    ptr = str_hash_find (formal_hash, sb_terminate (t));
739
814k
  if (ptr)
740
279
    {
741
279
      if (ptr->actual.len)
742
278
  {
743
278
    sb_add_sb (out, &ptr->actual);
744
278
  }
745
1
      else
746
1
  {
747
1
    sb_add_sb (out, &ptr->def);
748
1
  }
749
279
    }
750
814k
  else if (kind == '&')
751
3.77k
    {
752
      /* Doing this permits people to use & in macro bodies.  */
753
3.77k
      sb_add_char (out, '&');
754
3.77k
      sb_add_sb (out, t);
755
3.77k
      if (src != start && in->ptr[src - 1] == '&')
756
1.79k
  sb_add_char (out, '&');
757
3.77k
    }
758
810k
  else if (copyifnotthere)
759
550k
    {
760
550k
      sb_add_sb (out, t);
761
550k
    }
762
259k
  else
763
259k
    {
764
259k
      sb_add_char (out, '\\');
765
259k
      sb_add_sb (out, t);
766
259k
    }
767
814k
  return src;
768
814k
}
769
770
/* Expand the body of a macro.  */
771
772
static const char *
773
macro_expand_body (sb *in, sb *out, formal_entry *formals,
774
       struct htab *formal_hash, const macro_entry *macro,
775
       unsigned int instance)
776
50.5k
{
777
50.5k
  sb t;
778
50.5k
  size_t src = 0;
779
50.5k
  int inquote = 0, macro_line = 0;
780
50.5k
  formal_entry *loclist = NULL;
781
50.5k
  const char *err = NULL;
782
783
50.5k
  sb_new (&t);
784
785
8.73M
  while (src < in->len && !err)
786
8.68M
    {
787
8.68M
      if (in->ptr[src] == '&')
788
5.98k
  {
789
5.98k
    sb_reset (&t);
790
5.98k
    if (flag_mri)
791
2.20k
      {
792
2.20k
        if (src + 1 < in->len && in->ptr[src + 1] == '&')
793
482
    src = sub_actual (src + 2, in, &t, formal_hash, '\'', out, 1);
794
1.72k
        else
795
1.72k
    sb_add_char (out, in->ptr[src++]);
796
2.20k
      }
797
3.77k
    else
798
3.77k
      {
799
        /* Permit macro parameter substitution delineated with
800
     an '&' prefix and optional '&' suffix.  */
801
3.77k
        src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
802
3.77k
      }
803
5.98k
  }
804
8.68M
      else if (in->ptr[src] == '\\')
805
276k
  {
806
276k
    src++;
807
276k
    if (src < in->len && in->ptr[src] == '(')
808
129
      {
809
        /* Sub in till the next ')' literally.  */
810
129
        src++;
811
26.4k
        while (src < in->len && in->ptr[src] != ')')
812
26.3k
    {
813
26.3k
      sb_add_char (out, in->ptr[src++]);
814
26.3k
    }
815
129
        if (src < in->len)
816
0
    src++;
817
129
        else if (!macro)
818
129
    err = _("missing `)'");
819
0
        else
820
0
    as_bad_where (macro->file, macro->line + macro_line, _("missing `)'"));
821
129
      }
822
276k
    else if (src < in->len && in->ptr[src] == '@')
823
4
      {
824
        /* Sub in the total macro invocation number.  */
825
826
4
        char buffer[12];
827
4
        src++;
828
4
        sprintf (buffer, "%u", macro_number);
829
4
        sb_add_string (out, buffer);
830
4
      }
831
276k
    else if (src < in->len && in->ptr[src] == '+')
832
2.04k
      {
833
        /* Sub in the current macro invocation number.  */
834
835
2.04k
        char buffer[12];
836
2.04k
        src++;
837
2.04k
        sprintf (buffer, "%d", instance);
838
2.04k
        sb_add_string (out, buffer);
839
2.04k
      }
840
274k
    else if (src < in->len && in->ptr[src] == '&')
841
13.0k
      {
842
        /* This is a preprocessor variable name, we don't do them
843
     here.  */
844
13.0k
        sb_add_char (out, '\\');
845
13.0k
        sb_add_char (out, '&');
846
13.0k
        src++;
847
13.0k
      }
848
261k
    else if (flag_mri && src < in->len && ISALNUM (in->ptr[src]))
849
1.76k
      {
850
1.76k
        int ind;
851
1.76k
        formal_entry *f;
852
853
1.76k
        if (ISDIGIT (in->ptr[src]))
854
1.08k
    ind = in->ptr[src] - '0';
855
679
        else if (ISUPPER (in->ptr[src]))
856
4
    ind = in->ptr[src] - 'A' + 10;
857
675
        else
858
675
    ind = in->ptr[src] - 'a' + 10;
859
1.76k
        ++src;
860
3.54k
        for (f = formals; f != NULL; f = f->next)
861
1.77k
    {
862
1.77k
      if (f->index == ind - 1)
863
0
        {
864
0
          if (f->actual.len != 0)
865
0
      sb_add_sb (out, &f->actual);
866
0
          else
867
0
      sb_add_sb (out, &f->def);
868
0
          break;
869
0
        }
870
1.77k
    }
871
1.76k
      }
872
259k
    else
873
259k
      {
874
259k
        sb_reset (&t);
875
259k
        src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
876
259k
      }
877
276k
  }
878
8.40M
      else if ((flag_macro_alternate || flag_mri)
879
2.84M
         && is_name_beginner (in->ptr[src])
880
550k
         && (! inquote
881
289k
       || ! macro_strip_at
882
0
       || (src > 0 && in->ptr[src - 1] == '@')))
883
550k
  {
884
550k
    if (! macro
885
2.90k
        || src + 5 >= in->len
886
2.82k
        || strncasecmp (in->ptr + src, "LOCAL", 5) != 0
887
0
        || ! is_whitespace (in->ptr[src + 5])
888
        /* PR 11507: Skip keyword LOCAL if it is found inside a quoted string.  */
889
0
        || inquote)
890
550k
      {
891
550k
        sb_reset (&t);
892
550k
        src = sub_actual (src, in, &t, formal_hash,
893
550k
        (macro_strip_at && inquote) ? '@' : '\'',
894
550k
        out, 1);
895
550k
      }
896
0
    else
897
0
      {
898
0
        src = sb_skip_white (src + 5, in);
899
0
        while (in->ptr[src] != '\n')
900
0
    {
901
0
      const char *name;
902
0
      formal_entry *f = new_formal ();
903
904
0
      src = get_token (src, in, &f->name);
905
0
      name = sb_terminate (&f->name);
906
0
      if (str_hash_insert (formal_hash, name, f, 0) != NULL)
907
0
        {
908
0
          as_bad_where (macro->file, macro->line + macro_line,
909
0
            _("`%s' was already used as parameter "
910
0
              "(or another local) name"), name);
911
0
          del_formal (f);
912
0
        }
913
0
      else
914
0
        {
915
0
          static int loccnt;
916
0
          char buf[20];
917
918
0
          f->index = LOCAL_INDEX;
919
0
          f->next = loclist;
920
0
          loclist = f;
921
922
0
          sprintf (buf, IS_ELF ? ".LL%04x" : "LL%04x", ++loccnt);
923
0
          sb_add_string (&f->actual, buf);
924
0
        }
925
926
0
      src = sb_skip_comma (src, in);
927
0
    }
928
0
      }
929
550k
  }
930
7.85M
      else if (in->ptr[src] == '"'
931
7.59M
         || (flag_mri && in->ptr[src] == '\''))
932
284k
  {
933
284k
    inquote = !inquote;
934
284k
    sb_add_char (out, in->ptr[src++]);
935
284k
  }
936
7.57M
      else if (in->ptr[src] == '@' && macro_strip_at)
937
0
  {
938
0
    ++src;
939
0
    if (src < in->len
940
0
        && in->ptr[src] == '@')
941
0
      {
942
0
        sb_add_char (out, '@');
943
0
        ++src;
944
0
      }
945
0
  }
946
7.57M
      else if (flag_mri
947
2.11M
         && in->ptr[src] == '='
948
189k
         && src + 1 < in->len
949
189k
         && in->ptr[src + 1] == '=')
950
177k
  {
951
177k
    formal_entry *ptr;
952
953
177k
    sb_reset (&t);
954
177k
    src = get_token (src + 2, in, &t);
955
177k
    ptr = str_hash_find (formal_hash, sb_terminate (&t));
956
177k
    if (ptr == NULL)
957
177k
      {
958
        /* FIXME: We should really return a warning string here,
959
     but we can't, because the == might be in the MRI
960
     comment field, and, since the nature of the MRI
961
     comment field depends upon the exact instruction
962
     being used, we don't have enough information here to
963
     figure out whether it is or not.  Instead, we leave
964
     the == in place, which should cause a syntax error if
965
     it is not in a comment.  */
966
177k
        sb_add_char (out, '=');
967
177k
        sb_add_char (out, '=');
968
177k
        sb_add_sb (out, &t);
969
177k
      }
970
0
    else
971
0
      {
972
0
        if (ptr->actual.len)
973
0
    {
974
0
      sb_add_string (out, "-1");
975
0
    }
976
0
        else
977
0
    {
978
0
      sb_add_char (out, '0');
979
0
    }
980
0
      }
981
177k
  }
982
7.39M
      else
983
7.39M
  {
984
7.39M
    if (in->ptr[src] == '\n')
985
214k
      ++macro_line;
986
7.39M
    sb_add_char (out, in->ptr[src++]);
987
7.39M
  }
988
8.68M
    }
989
990
50.5k
  sb_kill (&t);
991
992
50.5k
  while (loclist != NULL)
993
0
    {
994
0
      formal_entry *f;
995
0
      const char *name;
996
997
0
      f = loclist->next;
998
0
      name = sb_terminate (&loclist->name);
999
0
      str_hash_delete (formal_hash, name);
1000
0
      del_formal (loclist);
1001
0
      loclist = f;
1002
0
    }
1003
1004
50.5k
  if (!err && (out->len == 0 || out->ptr[out->len - 1] != '\n'))
1005
1.87k
    sb_add_char (out, '\n');
1006
50.5k
  return err;
1007
50.5k
}
1008
1009
/* Assign values to the formal parameters of a macro, and expand the
1010
   body.  */
1011
1012
static const char *
1013
macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
1014
2.14k
{
1015
2.14k
  sb t;
1016
2.14k
  formal_entry *ptr;
1017
2.14k
  formal_entry *f;
1018
2.14k
  int is_keyword = 0;
1019
2.14k
  int narg = 0;
1020
2.14k
  const char *err = NULL;
1021
1022
2.14k
  sb_new (&t);
1023
1024
  /* Reset any old value the actuals may have.  */
1025
4.30k
  for (f = m->formals; f; f = f->next)
1026
2.16k
    sb_reset (&f->actual);
1027
2.14k
  f = m->formals;
1028
4.23k
  while (f != NULL && f->index < 0)
1029
2.09k
    f = f->next;
1030
1031
2.14k
  if (flag_mri)
1032
105
    {
1033
      /* The macro may be called with an optional qualifier, which may
1034
   be referred to in the macro body as \0.  */
1035
105
      if (idx < in->len && in->ptr[idx] == '.')
1036
0
  {
1037
    /* The Microtec assembler ignores this if followed by a white space.
1038
       (Macro invocation with empty extension) */
1039
0
    idx++;
1040
0
    if (idx < in->len && !is_whitespace (in->ptr[idx]))
1041
0
      {
1042
0
        formal_entry *n = new_formal ();
1043
1044
0
        n->index = QUAL_INDEX;
1045
1046
0
        n->next = m->formals;
1047
0
        m->formals = n;
1048
1049
0
        idx = get_any_string (idx, in, &n->actual);
1050
0
      }
1051
0
  }
1052
105
    }
1053
1054
  /* Peel off the actuals and store them away in the hash tables' actuals.  */
1055
2.14k
  idx = sb_skip_white (idx, in);
1056
2.20k
  while (idx < in->len)
1057
577
    {
1058
      /* Look and see if it's a positional or keyword arg.  */
1059
577
      size_t scan;
1060
1061
577
      sb_reset (&t);
1062
577
      scan = !flag_macro_alternate ? get_token (idx, in, &t) : idx;
1063
1064
577
      if (scan > idx && scan < in->len && in->ptr[scan] == '=')
1065
0
  {
1066
0
    is_keyword = 1;
1067
1068
    /* It's OK to go from positional to keyword.  */
1069
1070
    /* Lookup the formal in the macro's list.  */
1071
0
    ptr = str_hash_find (m->formal_hash, sb_terminate (&t));
1072
0
    if (!ptr)
1073
0
      {
1074
0
        as_bad (_("Parameter named `%s' does not exist for macro `%s'"),
1075
0
          t.ptr,
1076
0
          m->name);
1077
0
        sb_reset (&t);
1078
        /* Skip what would be the actual stuff.  */
1079
0
        idx = get_any_string (scan + 1, in, &t);
1080
0
      }
1081
0
    else
1082
0
      {
1083
        /* Insert this value into the right place.  */
1084
0
        if (ptr->actual.len)
1085
0
    {
1086
0
      as_warn (_("Value for parameter `%s' of macro `%s' was already specified"),
1087
0
         ptr->name.ptr,
1088
0
         m->name);
1089
0
      sb_reset (&ptr->actual);
1090
0
    }
1091
        /* Fetch the actual stuff.  */
1092
0
        idx = get_any_string (scan + 1, in, &ptr->actual);
1093
0
        if (ptr->actual.len > 0)
1094
0
    ++narg;
1095
0
      }
1096
0
  }
1097
577
      else
1098
577
  {
1099
577
    if (is_keyword)
1100
0
      {
1101
0
        err = _("can't mix positional and keyword arguments");
1102
0
        break;
1103
0
      }
1104
1105
577
    if (!f)
1106
537
      {
1107
537
        formal_entry **pf;
1108
537
        int c;
1109
1110
537
        if (!flag_mri)
1111
507
    {
1112
507
      err = _("too many positional arguments");
1113
507
      break;
1114
507
    }
1115
1116
30
        f = new_formal ();
1117
1118
30
        c = -1;
1119
72
        for (pf = &m->formals; *pf != NULL; pf = &(*pf)->next)
1120
42
    if ((*pf)->index >= c)
1121
13
      c = (*pf)->index + 1;
1122
30
        if (c == -1)
1123
17
    c = 0;
1124
30
        *pf = f;
1125
30
        f->index = c;
1126
30
      }
1127
1128
70
    if (f->type != FORMAL_VARARG)
1129
70
      idx = get_any_string (idx, in, &f->actual);
1130
0
    else if (idx < in->len)
1131
0
      {
1132
0
        sb_add_buffer (&f->actual, in->ptr + idx, in->len - idx);
1133
0
        idx = in->len;
1134
0
      }
1135
70
    if (f->actual.len > 0)
1136
66
      ++narg;
1137
70
    do
1138
96
      {
1139
96
        f = f->next;
1140
96
      }
1141
96
    while (f != NULL && f->index < 0);
1142
70
  }
1143
1144
70
      if (! flag_mri)
1145
11
  idx = sb_skip_comma (idx, in);
1146
59
      else
1147
59
  {
1148
59
    if (idx < in->len && in->ptr[idx] == ',')
1149
1
      ++idx;
1150
59
    if (idx < in->len && is_whitespace (in->ptr[idx]))
1151
7
      break;
1152
59
  }
1153
70
    }
1154
1155
2.14k
  if (! err)
1156
1.63k
    {
1157
3.32k
      for (ptr = m->formals; ptr; ptr = ptr->next)
1158
1.69k
  {
1159
1.69k
    if (ptr->type == FORMAL_REQUIRED && ptr->actual.len == 0)
1160
0
      as_bad (_("Missing value for required parameter `%s' of macro `%s'"),
1161
0
        ptr->name.ptr,
1162
0
        m->name);
1163
1.69k
  }
1164
1165
1.63k
      if (flag_mri)
1166
105
  {
1167
105
    ptr = str_hash_find (m->formal_hash,
1168
105
             macro_strip_at ? "$NARG" : "NARG");
1169
105
    if (ptr)
1170
102
      {
1171
102
        char buffer[20];
1172
102
        sprintf (buffer, "%d", narg);
1173
102
        sb_add_string (&ptr->actual, buffer);
1174
102
      }
1175
105
  }
1176
1177
1.63k
      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
1178
1.63k
             m->count);
1179
1.63k
    }
1180
1181
  /* Discard any unnamed formal arguments.  */
1182
2.14k
  if (flag_mri)
1183
105
    {
1184
105
      formal_entry **pf;
1185
1186
105
      pf = &m->formals;
1187
267
      while (*pf != NULL)
1188
162
  {
1189
162
    if ((*pf)->name.len != 0)
1190
132
      pf = &(*pf)->next;
1191
30
    else
1192
30
      {
1193
30
        f = (*pf)->next;
1194
30
        del_formal (*pf);
1195
30
        *pf = f;
1196
30
      }
1197
162
  }
1198
105
    }
1199
1200
2.14k
  sb_kill (&t);
1201
2.14k
  if (!err)
1202
1.63k
    {
1203
1.63k
      macro_number++;
1204
1.63k
      m->count++;
1205
1.63k
    }
1206
1207
2.14k
  return err;
1208
2.14k
}
1209
1210
/* Check for a macro.  If one is found, put the expansion into
1211
   *EXPAND.  Return 1 if a macro is found, 0 otherwise.  */
1212
1213
int
1214
check_macro (const char *line, sb *expand,
1215
       const char **error, macro_entry **info)
1216
10.4k
{
1217
10.4k
  const char *s;
1218
10.4k
  char *copy, *cls;
1219
10.4k
  macro_entry *macro;
1220
10.4k
  sb line_sb;
1221
1222
10.4k
  if (! is_name_beginner (*line)
1223
19
      && (! flag_mri || *line != '.'))
1224
19
    return 0;
1225
1226
10.3k
  s = line + 1;
1227
44.5k
  while (is_part_of_name (*s))
1228
34.2k
    ++s;
1229
10.3k
  if (is_name_ender (*s))
1230
0
    ++s;
1231
1232
10.3k
  copy = xmemdup0 (line, s - line);
1233
54.9k
  for (cls = copy; *cls != '\0'; cls ++)
1234
44.5k
    *cls = TOLOWER (*cls);
1235
1236
10.3k
  macro = str_hash_find (macro_hash, copy);
1237
10.3k
  free (copy);
1238
1239
10.3k
  if (macro == NULL)
1240
8.24k
    return 0;
1241
1242
  /* Wrap the line up in an sb.  */
1243
2.14k
  sb_new (&line_sb);
1244
19.7k
  while (*s != '\0' && *s != '\n' && *s != '\r')
1245
17.6k
    sb_add_char (&line_sb, *s++);
1246
1247
2.14k
  sb_new (expand);
1248
2.14k
  *error = macro_expand (0, &line_sb, macro, expand);
1249
1250
2.14k
  sb_kill (&line_sb);
1251
1252
  /* Export the macro information if requested.  */
1253
2.14k
  if (info)
1254
2.14k
    *info = macro;
1255
1256
2.14k
  return 1;
1257
10.3k
}
1258
1259
/* Delete a macro.  */
1260
1261
void
1262
delete_macro (const char *name)
1263
0
{
1264
0
  char *copy;
1265
0
  size_t i, len;
1266
0
  macro_entry *macro;
1267
1268
0
  len = strlen (name);
1269
0
  copy = XNEWVEC (char, len + 1);
1270
0
  for (i = 0; i < len; ++i)
1271
0
    copy[i] = TOLOWER (name[i]);
1272
0
  copy[i] = '\0';
1273
1274
0
  macro = str_hash_find (macro_hash, copy);
1275
0
  if (macro != NULL)
1276
0
    str_hash_delete (macro_hash, copy);
1277
0
  else
1278
0
    as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
1279
0
  free (copy);
1280
0
}
1281
1282
/* Handle the MRI IRP and IRPC pseudo-ops.  These are handled as a
1283
   combined macro definition and execution.  This returns NULL on
1284
   success, or an error message otherwise.  */
1285
1286
const char *
1287
expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
1288
970
{
1289
970
  sb sub;
1290
970
  formal_entry f;
1291
970
  struct htab *h;
1292
970
  const char *err = NULL;
1293
1294
970
  idx = sb_skip_white (idx, in);
1295
1296
970
  sb_new (&sub);
1297
970
  if (! buffer_and_nest (NULL, "ENDR", &sub, get_line))
1298
43
    {
1299
43
      err = _("unexpected end of file in irp or irpc");
1300
43
      goto out2;
1301
43
    }
1302
1303
927
  sb_new (&f.name);
1304
927
  sb_new (&f.def);
1305
927
  sb_new (&f.actual);
1306
1307
927
  idx = get_token (idx, in, &f.name);
1308
927
  if (f.name.len == 0)
1309
22
    {
1310
22
      err = _("missing model parameter");
1311
22
      goto out1;
1312
22
    }
1313
1314
905
  h = str_htab_create ();
1315
1316
905
  str_hash_insert (h, sb_terminate (&f.name), &f, 0);
1317
1318
905
  f.index = 1;
1319
905
  f.next = NULL;
1320
905
  f.type = FORMAL_OPTIONAL;
1321
1322
905
  sb_reset (out);
1323
1324
905
  idx = sb_skip_comma (idx, in);
1325
905
  if (idx >= in->len)
1326
0
    {
1327
      /* Expand once with a null string.  */
1328
0
      err = macro_expand_body (&sub, out, &f, h, NULL, 0);
1329
0
    }
1330
905
  else
1331
905
    {
1332
905
      bool in_quotes = false;
1333
905
      unsigned int instance = 0;
1334
1335
49.8k
      while (idx < in->len)
1336
49.1k
  {
1337
49.1k
    if (!irpc)
1338
110
      idx = get_any_string (idx, in, &f.actual);
1339
48.9k
    else
1340
48.9k
      {
1341
48.9k
        if (in->ptr[idx] == '"')
1342
190
    {
1343
190
      in_quotes = ! in_quotes;
1344
190
      ++idx;
1345
1346
190
      if (! in_quotes)
1347
6
        {
1348
6
          idx = sb_skip_white (idx, in);
1349
6
          if (idx >= in->len)
1350
0
      break;
1351
6
        }
1352
190
      continue;
1353
190
    }
1354
48.8k
        sb_reset (&f.actual);
1355
48.8k
        sb_add_char (&f.actual, in->ptr[idx]);
1356
48.8k
        ++idx;
1357
48.8k
      }
1358
1359
48.9k
    err = macro_expand_body (&sub, out, &f, h, NULL, instance);
1360
48.9k
    ++instance;
1361
48.9k
    if (err != NULL)
1362
129
      break;
1363
48.7k
    if (!irpc)
1364
110
      idx = sb_skip_comma (idx, in);
1365
48.6k
    else if (! in_quotes)
1366
48.1k
      idx = sb_skip_white (idx, in);
1367
48.7k
  }
1368
905
    }
1369
1370
905
  htab_delete (h);
1371
927
 out1:
1372
927
  sb_kill (&f.actual);
1373
927
  sb_kill (&f.def);
1374
927
  sb_kill (&f.name);
1375
970
 out2:
1376
970
  sb_kill (&sub);
1377
1378
970
  return err;
1379
927
}