Coverage Report

Created: 2026-04-04 08:16

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
18.9M
#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
354
{
53
354
  string_tuple_t *tuple = ent;
54
354
  free_macro ((macro_entry *) tuple->value);
55
354
}
56
57
/* Initialize macro processing.  */
58
59
void
60
macro_init (void)
61
567
{
62
567
  macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
63
567
          macro_del_f, notes_calloc, NULL);
64
567
  macro_defined = 0;
65
567
}
66
67
void
68
macro_end (void)
69
567
{
70
567
  if (ENABLE_LEAK_CHECK)
71
567
    htab_delete (macro_hash);
72
567
}
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
2.03k
{
85
2.03k
  size_t from_len;
86
2.03k
  size_t to_len = strlen (to);
87
2.03k
  int depth = 1;
88
2.03k
  size_t line_start, more;
89
90
2.03k
  if (to_len == 4 && strcasecmp (to, "ENDR") == 0)
91
1.33k
    {
92
1.33k
      from = NULL;
93
1.33k
      from_len = 0;
94
1.33k
    }
95
705
  else
96
705
    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
2.03k
  {
102
2.03k
    unsigned int line;
103
2.03k
    char *linefile;
104
105
2.03k
    const char *prefix = flag_m68k_mri ? "" : ".";
106
2.03k
    const char *file = as_where_top (&line);
107
108
2.03k
    if (*input_line_pointer == '\n')
109
1.18k
      line++;
110
2.03k
    if (file)
111
2.03k
      linefile = xasprintf ("\t%slinefile %u \"%s\"", prefix, line, file);
112
0
    else
113
0
      linefile = xasprintf ("\t%slinefile %u .", prefix, line);
114
2.03k
    sb_add_string (ptr, linefile);
115
2.03k
    xfree (linefile);
116
2.03k
  }
117
118
2.03k
  line_start = ptr->len;
119
2.03k
  more = get_line (ptr);
120
792k
  while (more)
121
792k
    {
122
      /* Try to find the first pseudo op on the line.  */
123
792k
      size_t i = line_start;
124
792k
      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
792k
      if (! LABELS_WITHOUT_COLONS)
132
792k
  {
133
    /* Skip leading whitespace.  */
134
792k
    i = sb_skip_white (i, ptr);
135
792k
  }
136
137
792k
      for (;;)
138
792k
  {
139
    /* Skip over a label, if any.  */
140
792k
    if (i >= ptr->len || ! is_name_beginner (ptr->ptr[i]))
141
5.31k
      break;
142
787k
    i++;
143
3.93M
    while (i < ptr->len && is_part_of_name (ptr->ptr[i]))
144
3.15M
      i++;
145
787k
    if (i < ptr->len && is_name_ender (ptr->ptr[i]))
146
0
      i++;
147
    /* Skip whitespace.  */
148
787k
    i = sb_skip_white (i, ptr);
149
    /* Check for the colon.  */
150
787k
    if (i >= ptr->len || ptr->ptr[i] != ':')
151
787k
      {
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
787k
        if (LABELS_WITHOUT_COLONS && !had_colon)
157
0
    break;
158
787k
        i = line_start;
159
787k
        break;
160
787k
      }
161
103
    i++;
162
103
    line_start = i;
163
103
    had_colon = true;
164
103
  }
165
166
      /* Skip trailing whitespace.  */
167
792k
      i = sb_skip_white (i, ptr);
168
169
792k
      if (i < ptr->len && (ptr->ptr[i] == '.'
170
423k
         || NO_PSEUDO_DOT
171
423k
         || flag_mri))
172
786k
  {
173
786k
    if (! flag_m68k_mri && ptr->ptr[i] == '.')
174
364k
      i++;
175
786k
    size_t len = ptr->len - i;
176
786k
    if (from == NULL)
177
784k
      {
178
784k
        if (len >= 5 && strncasecmp (ptr->ptr + i, "IREPC", 5) == 0)
179
0
    from_len = 5;
180
784k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IREP", 4) == 0)
181
3
    from_len = 4;
182
784k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IRPC", 4) == 0)
183
1
    from_len = 4;
184
784k
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "REPT", 4) == 0)
185
5
    from_len = 4;
186
784k
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "IRP", 3) == 0)
187
4
    from_len = 3;
188
784k
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "REP", 3) == 0)
189
19
    from_len = 3;
190
783k
        else
191
783k
    from_len = 0;
192
784k
      }
193
786k
    if ((from != NULL
194
786k
         ? (len >= from_len
195
1.12k
      && strncasecmp (ptr->ptr + i, from, from_len) == 0)
196
786k
         : from_len > 0)
197
32
        && (len == from_len
198
31
      || ! (is_part_of_name (ptr->ptr[i + from_len])
199
22
      || is_name_ender (ptr->ptr[i + from_len]))))
200
23
      depth++;
201
786k
    if (len >= to_len
202
784k
        && strncasecmp (ptr->ptr + i, to, to_len) == 0
203
1.91k
        && (len == to_len
204
474
      || ! (is_part_of_name (ptr->ptr[i + to_len])
205
452
      || is_name_ender (ptr->ptr[i + to_len]))))
206
1.89k
      {
207
1.89k
        depth--;
208
1.89k
        if (depth == 0)
209
1.87k
    {
210
      /* Reset the string to not include the ending rune.  */
211
1.87k
      ptr->len = line_start;
212
213
      /* With the ending directive consumed here, announce the
214
         line for macro-expanded listings. */
215
1.87k
      if (listing & LISTING_MACEXP)
216
0
        listing_newline (NULL);
217
1.87k
      break;
218
1.87k
    }
219
1.89k
      }
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
784k
    if (from != NULL && strcasecmp (from, "MACRO") == 0
225
2.11k
        && len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
226
323
      {
227
323
        sb_add_char (ptr, more);
228
323
        temp_ilp (sb_terminate (ptr) + i + 8);
229
323
        s_linefile (0);
230
323
        restore_ilp ();
231
323
        line_start = ptr->len;
232
323
        more = get_line (ptr);
233
323
        continue;
234
323
      }
235
784k
  }
236
237
      /* Add the original end-of-line char to the end and keep running.  */
238
790k
      sb_add_char (ptr, more);
239
790k
      line_start = ptr->len;
240
790k
      more = get_line (ptr);
241
790k
    }
242
243
  /* Return 1 on success, 0 on unexpected EOF.  */
244
2.03k
  return depth == 0;
245
2.03k
}
246
247
/* Pick up a token.  */
248
249
static size_t
250
get_token (size_t idx, sb *in, sb *name)
251
2.88M
{
252
2.88M
  if (idx < in->len
253
2.88M
      && is_name_beginner (in->ptr[idx]))
254
2.48M
    {
255
2.48M
      sb_add_char (name, in->ptr[idx++]);
256
11.8M
      while (idx < in->len
257
11.8M
       && is_part_of_name (in->ptr[idx]))
258
9.38M
  {
259
9.38M
    sb_add_char (name, in->ptr[idx++]);
260
9.38M
  }
261
2.48M
      if (idx < in->len
262
2.48M
       && is_name_ender (in->ptr[idx]))
263
0
  {
264
0
    sb_add_char (name, in->ptr[idx++]);
265
0
  }
266
2.48M
    }
267
  /* Ignore trailing &.  */
268
2.88M
  if (flag_macro_alternate && idx < in->len && in->ptr[idx] == '&')
269
0
    idx++;
270
2.88M
  return idx;
271
2.88M
}
272
273
/* Pick up a string.  */
274
275
static size_t
276
getstring (size_t idx, sb *in, sb *acc)
277
49
{
278
100
  while (idx < in->len
279
85
   && (in->ptr[idx] == '"'
280
75
       || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
281
34
       || (in->ptr[idx] == '\'' && flag_macro_alternate)))
282
51
    {
283
51
      if (in->ptr[idx] == '<')
284
41
  {
285
41
    int nest = 0;
286
41
    idx++;
287
734
    while (idx < in->len)
288
725
      {
289
725
        if (in->ptr[idx] == '!' && idx + 1 < in->len)
290
9
    idx++;
291
716
        else if (in->ptr[idx] == '>')
292
44
    {
293
44
      if (nest == 0)
294
32
        {
295
32
          idx++;
296
32
          break;
297
32
        }
298
12
      nest--;
299
12
    }
300
672
        else if (in->ptr[idx] == '<')
301
19
    nest++;
302
303
693
        sb_add_char (acc, in->ptr[idx]);
304
693
        idx++;
305
693
      }
306
41
  }
307
10
      else if (in->ptr[idx] == '"' || in->ptr[idx] == '\'')
308
10
  {
309
10
    char tchar = in->ptr[idx];
310
10
    int escaped = 0;
311
312
10
    idx++;
313
33
    while (idx < in->len)
314
32
      {
315
32
        if (in->ptr[idx - 1] == '\\')
316
0
    escaped ^= 1;
317
32
        else
318
32
    escaped = 0;
319
320
32
        if (flag_macro_alternate
321
0
      && in->ptr[idx] == '!' && idx + 1 < in->len)
322
0
    {
323
0
      idx++;
324
0
    }
325
32
        else if (!escaped && in->ptr[idx] == tchar)
326
13
    {
327
13
      idx++;
328
13
      if (idx >= in->len || in->ptr[idx] != tchar)
329
9
        break;
330
13
    }
331
23
        sb_add_char (acc, in->ptr[idx]);
332
23
        idx++;
333
23
      }
334
10
  }
335
51
    }
336
337
49
  return idx;
338
49
}
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
999
{
350
999
  sb_reset (out);
351
999
  idx = sb_skip_white (idx, in);
352
353
999
  if (idx < in->len)
354
999
    {
355
999
      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
999
      else if (in->ptr[idx] == '"'
375
989
         || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
376
950
         || (flag_macro_alternate && in->ptr[idx] == '\''))
377
49
  {
378
49
    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
49
    else
386
49
      {
387
49
        idx = getstring (idx, in, out);
388
49
      }
389
49
  }
390
950
      else
391
950
  {
392
950
    char *br_buf = XNEWVEC (char, 1);
393
950
    char *in_br = br_buf;
394
395
950
    *in_br = '\0';
396
9.49k
    while (idx < in->len
397
9.28k
     && (*in_br || !is_whitespace (in->ptr[idx]))
398
9.23k
     && in->ptr[idx] != ','
399
8.63k
     && (in->ptr[idx] != '<'
400
47
         || (! flag_macro_alternate && ! flag_mri)))
401
8.60k
      {
402
8.60k
        char tchar = in->ptr[idx];
403
404
8.60k
        switch (tchar)
405
8.60k
    {
406
62
    case '"':
407
62
    case '\'':
408
62
      sb_add_char (out, in->ptr[idx++]);
409
268
      while (idx < in->len
410
209
       && in->ptr[idx] != tchar)
411
206
        sb_add_char (out, in->ptr[idx++]);
412
62
      if (idx == in->len)
413
59
        {
414
59
          free (br_buf);
415
59
          return idx;
416
59
        }
417
3
      break;
418
41
    case '(':
419
41
    case '[':
420
41
      if (in_br > br_buf)
421
0
        --in_br;
422
41
      else
423
41
        {
424
41
          br_buf = XNEWVEC (char, strlen (in_br) + 2);
425
41
          strcpy (br_buf + 1, in_br);
426
41
          free (in_br);
427
41
          in_br = br_buf;
428
41
        }
429
41
      *in_br = tchar;
430
41
      break;
431
94
    case ')':
432
94
      if (*in_br == '(')
433
28
        ++in_br;
434
94
      break;
435
2
    case ']':
436
2
      if (*in_br == '[')
437
0
        ++in_br;
438
2
      break;
439
8.60k
    }
440
8.54k
        sb_add_char (out, tchar);
441
8.54k
        ++idx;
442
8.54k
      }
443
891
    free (br_buf);
444
891
  }
445
999
    }
446
447
940
  return idx;
448
999
}
449
450
/* Allocate a new formal.  */
451
452
static formal_entry *
453
new_formal (void)
454
2.52k
{
455
2.52k
  formal_entry *formal;
456
457
2.52k
  formal = XNEW (formal_entry);
458
459
2.52k
  sb_new (&formal->name);
460
2.52k
  sb_new (&formal->def);
461
2.52k
  sb_new (&formal->actual);
462
2.52k
  formal->next = NULL;
463
2.52k
  formal->type = FORMAL_OPTIONAL;
464
2.52k
  return formal;
465
2.52k
}
466
467
/* Free a formal.  */
468
469
static void
470
del_formal (formal_entry *formal)
471
2.52k
{
472
2.52k
  sb_kill (&formal->actual);
473
2.52k
  sb_kill (&formal->def);
474
2.52k
  sb_kill (&formal->name);
475
2.52k
  free (formal);
476
2.52k
}
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
705
{
483
705
  formal_entry **p = &macro->formals;
484
705
  const char *name;
485
486
705
  idx = sb_skip_white (idx, in);
487
2.48k
  while (idx < in->len)
488
1.78k
    {
489
1.78k
      formal_entry *formal = new_formal ();
490
1.78k
      size_t cidx;
491
492
1.78k
      idx = get_token (idx, in, &formal->name);
493
1.78k
      if (formal->name.len == 0)
494
5
  {
495
5
    if (macro->formal_count)
496
3
      --idx;
497
5
    del_formal (formal);  /* 'formal' goes out of scope.  */
498
5
    break;
499
5
  }
500
1.78k
      idx = sb_skip_white (idx, in);
501
      /* This is a formal.  */
502
1.78k
      name = sb_terminate (&formal->name);
503
1.78k
      if (! flag_mri
504
7
    && idx < in->len
505
4
    && in->ptr[idx] == ':'
506
1
    && (! is_name_beginner (':')
507
0
        || idx + 1 >= in->len
508
0
        || ! is_part_of_name (in->ptr[idx + 1])))
509
1
  {
510
    /* Got a qualifier.  */
511
1
    sb qual;
512
513
1
    sb_new (&qual);
514
1
    idx = get_token (sb_skip_white (idx + 1, in), in, &qual);
515
1
    sb_terminate (&qual);
516
1
    if (qual.len == 0)
517
1
      as_bad_where (macro->file,
518
1
        macro->line,
519
1
        _("Missing parameter qualifier for `%s' in macro `%s'"),
520
1
        name,
521
1
        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
1
    sb_kill (&qual);
534
1
    idx = sb_skip_white (idx, in);
535
1
  }
536
1.78k
      if (idx < in->len && in->ptr[idx] == '=')
537
12
  {
538
    /* Got a default.  */
539
12
    idx = get_any_string (idx + 1, in, &formal->def);
540
12
    idx = sb_skip_white (idx, in);
541
12
    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
12
  }
551
552
      /* Add to macro's hash table.  */
553
1.78k
      if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL)
554
55
  {
555
55
    as_bad_where (macro->file, macro->line,
556
55
      _("A parameter named `%s' "
557
55
        "already exists for macro `%s'"),
558
55
      name, macro->name);
559
55
  }
560
561
1.78k
      formal->index = macro->formal_count++;
562
1.78k
      *p = formal;
563
1.78k
      p = &formal->next;
564
1.78k
      if (formal->type == FORMAL_VARARG)
565
0
  break;
566
1.78k
      cidx = idx;
567
1.78k
      idx = sb_skip_comma (idx, in);
568
1.78k
      if (idx != cidx && idx >= in->len)
569
0
  {
570
0
    idx = cidx;
571
0
    break;
572
0
  }
573
1.78k
    }
574
575
705
  if (flag_mri)
576
694
    {
577
694
      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
694
      if (macro_strip_at)
584
0
  name = "$NARG";
585
694
      else
586
694
  name = "NARG";
587
588
694
      sb_add_string (&formal->name, name);
589
590
      /* Add to macro's hash table.  */
591
694
      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
694
      formal->index = NARG_INDEX;
599
694
      *p = formal;
600
694
    }
601
602
705
  return idx;
603
705
}
604
605
/* Free the memory allocated to a macro.  */
606
607
static void
608
free_macro (macro_entry *macro)
609
705
{
610
705
  formal_entry *formal;
611
612
3.18k
  for (formal = macro->formals; formal; )
613
2.47k
    {
614
2.47k
      formal_entry *f;
615
616
2.47k
      f = formal;
617
2.47k
      formal = formal->next;
618
2.47k
      del_formal (f);
619
2.47k
    }
620
705
  htab_delete (macro->formal_hash);
621
705
  sb_kill (&macro->sub);
622
705
  free ((char *) macro->name);
623
705
  free (macro);
624
705
}
625
626
/* Define a new macro.  */
627
628
macro_entry *
629
define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
630
705
{
631
705
  macro_entry *macro;
632
705
  sb name;
633
705
  size_t idx;
634
705
  const char *error = NULL;
635
636
705
  macro = XNEW (macro_entry);
637
705
  sb_new (&macro->sub);
638
705
  sb_new (&name);
639
705
  macro->file = as_where (&macro->line);
640
641
705
  macro->formal_count = 0;
642
705
  macro->formals = 0;
643
705
  macro->formal_hash = str_htab_create ();
644
705
  macro->count = 0;
645
646
705
  idx = sb_skip_white (0, in);
647
705
  if (! buffer_and_nest ("MACRO", "ENDM", &macro->sub, get_line))
648
11
    error = _("unexpected end of file in macro `%s' definition");
649
705
  if (label != NULL && label->len != 0)
650
683
    {
651
683
      sb_add_sb (&name, label);
652
683
      macro->name = sb_terminate (&name);
653
683
      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
683
      else
663
683
  {
664
    /* It's the label: MACRO formals,...  sort  */
665
683
    idx = do_formals (macro, idx, in);
666
683
  }
667
683
    }
668
22
  else
669
22
    {
670
22
      size_t cidx;
671
672
22
      idx = get_token (idx, in, &name);
673
22
      macro->name = sb_terminate (&name);
674
22
      if (name.len == 0)
675
2
  error = _("Missing macro name");
676
22
      cidx = sb_skip_white (idx, in);
677
22
      idx = sb_skip_comma (cidx, in);
678
22
      if (idx == cidx || idx < in->len)
679
22
  idx = do_formals (macro, idx, in);
680
0
      else
681
0
  idx = cidx;
682
22
    }
683
705
  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
9.63k
  for (idx = 0; idx < name.len; idx++)
688
8.92k
    name.ptr[idx] = TOLOWER (name.ptr[idx]);
689
705
  if (!error)
690
694
    {
691
694
      if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL)
692
340
  error = _("Macro `%s' was already defined");
693
694
    }
694
695
705
  if (!error)
696
354
    macro_defined = 1;
697
351
  else
698
351
    {
699
351
      as_bad_where (macro->file, macro->line, error, macro->name);
700
351
      free_macro (macro);
701
351
      macro = NULL;
702
351
    }
703
704
705
  return macro;
705
705
}
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
2.86M
{
712
2.86M
  idx = get_token (idx, in, name);
713
2.86M
  if (idx < in->len
714
2.86M
      && in->ptr[idx] == kind
715
16.3k
      && (! flag_mri || macro_strip_at)
716
0
      && (! macro_strip_at || kind == '@'))
717
16.1k
    idx++;
718
2.86M
  return idx;
719
2.86M
}
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
2.86M
{
727
2.86M
  size_t src;
728
2.86M
  formal_entry *ptr;
729
730
2.86M
  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
2.86M
  if (macro_strip_at
734
0
      && kind == '@'
735
0
      && (src == start || in->ptr[src - 1] != '@'))
736
0
    ptr = NULL;
737
2.86M
  else
738
2.86M
    ptr = str_hash_find (formal_hash, sb_terminate (t));
739
2.86M
  if (ptr)
740
17.7k
    {
741
17.7k
      if (ptr->actual.len)
742
12.6k
  {
743
12.6k
    sb_add_sb (out, &ptr->actual);
744
12.6k
  }
745
5.06k
      else
746
5.06k
  {
747
5.06k
    sb_add_sb (out, &ptr->def);
748
5.06k
  }
749
17.7k
    }
750
2.85M
  else if (kind == '&')
751
21.0k
    {
752
      /* Doing this permits people to use & in macro bodies.  */
753
21.0k
      sb_add_char (out, '&');
754
21.0k
      sb_add_sb (out, t);
755
21.0k
      if (src != start && in->ptr[src - 1] == '&')
756
16.1k
  sb_add_char (out, '&');
757
21.0k
    }
758
2.82M
  else if (copyifnotthere)
759
2.34M
    {
760
2.34M
      sb_add_sb (out, t);
761
2.34M
    }
762
488k
  else
763
488k
    {
764
488k
      sb_add_char (out, '\\');
765
488k
      sb_add_sb (out, t);
766
488k
    }
767
2.86M
  return src;
768
2.86M
}
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
6.17k
{
777
6.17k
  sb t;
778
6.17k
  size_t src = 0;
779
6.17k
  int inquote = 0, macro_line = 0;
780
6.17k
  formal_entry *loclist = NULL;
781
6.17k
  const char *err = NULL;
782
783
6.17k
  sb_new (&t);
784
785
14.0M
  while (src < in->len && !err)
786
14.0M
    {
787
14.0M
      if (in->ptr[src] == '&')
788
265k
  {
789
265k
    sb_reset (&t);
790
265k
    if (flag_mri)
791
244k
      {
792
244k
        if (src + 1 < in->len && in->ptr[src + 1] == '&')
793
2.74k
    src = sub_actual (src + 2, in, &t, formal_hash, '\'', out, 1);
794
241k
        else
795
241k
    sb_add_char (out, in->ptr[src++]);
796
244k
      }
797
21.0k
    else
798
21.0k
      {
799
        /* Permit macro parameter substitution delineated with
800
     an '&' prefix and optional '&' suffix.  */
801
21.0k
        src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
802
21.0k
      }
803
265k
  }
804
13.7M
      else if (in->ptr[src] == '\\')
805
492k
  {
806
492k
    src++;
807
492k
    if (src < in->len && in->ptr[src] == '(')
808
131
      {
809
        /* Sub in till the next ')' literally.  */
810
131
        src++;
811
4.50k
        while (src < in->len && in->ptr[src] != ')')
812
4.37k
    {
813
4.37k
      sb_add_char (out, in->ptr[src++]);
814
4.37k
    }
815
131
        if (src < in->len)
816
1
    src++;
817
130
        else if (!macro)
818
130
    err = _("missing `)'");
819
0
        else
820
0
    as_bad_where (macro->file, macro->line + macro_line, _("missing `)'"));
821
131
      }
822
491k
    else if (src < in->len && in->ptr[src] == '@')
823
0
      {
824
        /* Sub in the total macro invocation number.  */
825
826
0
        char buffer[12];
827
0
        src++;
828
0
        sprintf (buffer, "%u", macro_number);
829
0
        sb_add_string (out, buffer);
830
0
      }
831
491k
    else if (src < in->len && in->ptr[src] == '+')
832
0
      {
833
        /* Sub in the current macro invocation number.  */
834
835
0
        char buffer[12];
836
0
        src++;
837
0
        sprintf (buffer, "%d", instance);
838
0
        sb_add_string (out, buffer);
839
0
      }
840
491k
    else if (src < in->len && in->ptr[src] == '&')
841
840
      {
842
        /* This is a preprocessor variable name, we don't do them
843
     here.  */
844
840
        sb_add_char (out, '\\');
845
840
        sb_add_char (out, '&');
846
840
        src++;
847
840
      }
848
491k
    else if (flag_mri && src < in->len && ISALNUM (in->ptr[src]))
849
2.74k
      {
850
2.74k
        int ind;
851
2.74k
        formal_entry *f;
852
853
2.74k
        if (ISDIGIT (in->ptr[src]))
854
1.36k
    ind = in->ptr[src] - '0';
855
1.37k
        else if (ISUPPER (in->ptr[src]))
856
99
    ind = in->ptr[src] - 'A' + 10;
857
1.28k
        else
858
1.28k
    ind = in->ptr[src] - 'a' + 10;
859
2.74k
        ++src;
860
5.48k
        for (f = formals; f != NULL; f = f->next)
861
2.74k
    {
862
2.74k
      if (f->index == ind - 1)
863
2
        {
864
2
          if (f->actual.len != 0)
865
2
      sb_add_sb (out, &f->actual);
866
0
          else
867
0
      sb_add_sb (out, &f->def);
868
2
          break;
869
2
        }
870
2.74k
    }
871
2.74k
      }
872
488k
    else
873
488k
      {
874
488k
        sb_reset (&t);
875
488k
        src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
876
488k
      }
877
492k
  }
878
13.2M
      else if ((flag_macro_alternate || flag_mri)
879
11.5M
         && is_name_beginner (in->ptr[src])
880
2.35M
         && (! inquote
881
1.15M
       || ! macro_strip_at
882
0
       || (src > 0 && in->ptr[src - 1] == '@')))
883
2.35M
  {
884
2.35M
    if (! macro
885
1.06k
        || src + 5 >= in->len
886
918
        || 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
2.35M
      {
891
2.35M
        sb_reset (&t);
892
2.35M
        src = sub_actual (src, in, &t, formal_hash,
893
2.35M
        (macro_strip_at && inquote) ? '@' : '\'',
894
2.35M
        out, 1);
895
2.35M
      }
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
2.35M
  }
930
10.9M
      else if (in->ptr[src] == '"'
931
10.2M
         || (flag_mri && in->ptr[src] == '\''))
932
686k
  {
933
686k
    inquote = !inquote;
934
686k
    sb_add_char (out, in->ptr[src++]);
935
686k
  }
936
10.2M
      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
10.2M
      else if (flag_mri
947
8.53M
         && in->ptr[src] == '='
948
19.6k
         && src + 1 < in->len
949
19.6k
         && in->ptr[src + 1] == '=')
950
18.1k
  {
951
18.1k
    formal_entry *ptr;
952
953
18.1k
    sb_reset (&t);
954
18.1k
    src = get_token (src + 2, in, &t);
955
18.1k
    ptr = str_hash_find (formal_hash, sb_terminate (&t));
956
18.1k
    if (ptr == NULL)
957
18.1k
      {
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
18.1k
        sb_add_char (out, '=');
967
18.1k
        sb_add_char (out, '=');
968
18.1k
        sb_add_sb (out, &t);
969
18.1k
      }
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
18.1k
  }
982
10.2M
      else
983
10.2M
  {
984
10.2M
    if (in->ptr[src] == '\n')
985
885k
      ++macro_line;
986
10.2M
    sb_add_char (out, in->ptr[src++]);
987
10.2M
  }
988
14.0M
    }
989
990
6.17k
  sb_kill (&t);
991
992
6.17k
  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
6.17k
  if (!err && (out->len == 0 || out->ptr[out->len - 1] != '\n'))
1005
198
    sb_add_char (out, '\n');
1006
6.17k
  return err;
1007
6.17k
}
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
211
{
1015
211
  sb t;
1016
211
  formal_entry *ptr;
1017
211
  formal_entry *f;
1018
211
  int is_keyword = 0;
1019
211
  int narg = 0;
1020
211
  const char *err = NULL;
1021
1022
211
  sb_new (&t);
1023
1024
  /* Reset any old value the actuals may have.  */
1025
365
  for (f = m->formals; f; f = f->next)
1026
154
    sb_reset (&f->actual);
1027
211
  f = m->formals;
1028
290
  while (f != NULL && f->index < 0)
1029
79
    f = f->next;
1030
1031
211
  if (flag_mri)
1032
148
    {
1033
      /* The macro may be called with an optional qualifier, which may
1034
   be referred to in the macro body as \0.  */
1035
148
      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
148
    }
1053
1054
  /* Peel off the actuals and store them away in the hash tables' actuals.  */
1055
211
  idx = sb_skip_white (idx, in);
1056
300
  while (idx < in->len)
1057
112
    {
1058
      /* Look and see if it's a positional or keyword arg.  */
1059
112
      size_t scan;
1060
1061
112
      sb_reset (&t);
1062
112
      scan = !flag_macro_alternate ? get_token (idx, in, &t) : idx;
1063
1064
112
      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
112
      else
1098
112
  {
1099
112
    if (is_keyword)
1100
0
      {
1101
0
        err = _("can't mix positional and keyword arguments");
1102
0
        break;
1103
0
      }
1104
1105
112
    if (!f)
1106
62
      {
1107
62
        formal_entry **pf;
1108
62
        int c;
1109
1110
62
        if (!flag_mri)
1111
20
    {
1112
20
      err = _("too many positional arguments");
1113
20
      break;
1114
20
    }
1115
1116
42
        f = new_formal ();
1117
1118
42
        c = -1;
1119
95
        for (pf = &m->formals; *pf != NULL; pf = &(*pf)->next)
1120
53
    if ((*pf)->index >= c)
1121
26
      c = (*pf)->index + 1;
1122
42
        if (c == -1)
1123
26
    c = 0;
1124
42
        *pf = f;
1125
42
        f->index = c;
1126
42
      }
1127
1128
92
    if (f->type != FORMAL_VARARG)
1129
92
      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
92
    if (f->actual.len > 0)
1136
88
      ++narg;
1137
92
    do
1138
95
      {
1139
95
        f = f->next;
1140
95
      }
1141
95
    while (f != NULL && f->index < 0);
1142
92
  }
1143
1144
92
      if (! flag_mri)
1145
42
  idx = sb_skip_comma (idx, in);
1146
50
      else
1147
50
  {
1148
50
    if (idx < in->len && in->ptr[idx] == ',')
1149
2
      ++idx;
1150
50
    if (idx < in->len && is_whitespace (in->ptr[idx]))
1151
3
      break;
1152
50
  }
1153
92
    }
1154
1155
211
  if (! err)
1156
191
    {
1157
387
      for (ptr = m->formals; ptr; ptr = ptr->next)
1158
196
  {
1159
196
    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
196
  }
1164
1165
191
      if (flag_mri)
1166
148
  {
1167
148
    ptr = str_hash_find (m->formal_hash,
1168
148
             macro_strip_at ? "$NARG" : "NARG");
1169
148
    if (ptr)
1170
89
      {
1171
89
        char buffer[20];
1172
89
        sprintf (buffer, "%d", narg);
1173
89
        sb_add_string (&ptr->actual, buffer);
1174
89
      }
1175
148
  }
1176
1177
191
      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
1178
191
             m->count);
1179
191
    }
1180
1181
  /* Discard any unnamed formal arguments.  */
1182
211
  if (flag_mri)
1183
148
    {
1184
148
      formal_entry **pf;
1185
1186
148
      pf = &m->formals;
1187
301
      while (*pf != NULL)
1188
153
  {
1189
153
    if ((*pf)->name.len != 0)
1190
111
      pf = &(*pf)->next;
1191
42
    else
1192
42
      {
1193
42
        f = (*pf)->next;
1194
42
        del_formal (*pf);
1195
42
        *pf = f;
1196
42
      }
1197
153
  }
1198
148
    }
1199
1200
211
  sb_kill (&t);
1201
211
  if (!err)
1202
191
    {
1203
191
      macro_number++;
1204
191
      m->count++;
1205
191
    }
1206
1207
211
  return err;
1208
211
}
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
2.69k
{
1217
2.69k
  const char *s;
1218
2.69k
  char *copy, *cls;
1219
2.69k
  macro_entry *macro;
1220
2.69k
  sb line_sb;
1221
1222
2.69k
  if (! is_name_beginner (*line)
1223
29
      && (! flag_mri || *line != '.'))
1224
29
    return 0;
1225
1226
2.66k
  s = line + 1;
1227
12.4k
  while (is_part_of_name (*s))
1228
9.82k
    ++s;
1229
2.66k
  if (is_name_ender (*s))
1230
0
    ++s;
1231
1232
2.66k
  copy = xmemdup0 (line, s - line);
1233
15.1k
  for (cls = copy; *cls != '\0'; cls ++)
1234
12.4k
    *cls = TOLOWER (*cls);
1235
1236
2.66k
  macro = str_hash_find (macro_hash, copy);
1237
2.66k
  free (copy);
1238
1239
2.66k
  if (macro == NULL)
1240
2.45k
    return 0;
1241
1242
  /* Wrap the line up in an sb.  */
1243
211
  sb_new (&line_sb);
1244
2.51k
  while (*s != '\0' && *s != '\n' && *s != '\r')
1245
2.30k
    sb_add_char (&line_sb, *s++);
1246
1247
211
  sb_new (expand);
1248
211
  *error = macro_expand (0, &line_sb, macro, expand);
1249
1250
211
  sb_kill (&line_sb);
1251
1252
  /* Export the macro information if requested.  */
1253
211
  if (info)
1254
211
    *info = macro;
1255
1256
211
  return 1;
1257
2.66k
}
1258
1259
/* Delete a macro.  */
1260
1261
void
1262
delete_macro (const char *name)
1263
4
{
1264
4
  char *copy;
1265
4
  size_t i, len;
1266
4
  macro_entry *macro;
1267
1268
4
  len = strlen (name);
1269
4
  copy = XNEWVEC (char, len + 1);
1270
39
  for (i = 0; i < len; ++i)
1271
35
    copy[i] = TOLOWER (name[i]);
1272
4
  copy[i] = '\0';
1273
1274
4
  macro = str_hash_find (macro_hash, copy);
1275
4
  if (macro != NULL)
1276
0
    str_hash_delete (macro_hash, copy);
1277
4
  else
1278
4
    as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
1279
4
  free (copy);
1280
4
}
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
321
{
1289
321
  sb sub;
1290
321
  formal_entry f;
1291
321
  struct htab *h;
1292
321
  const char *err = NULL;
1293
1294
321
  idx = sb_skip_white (idx, in);
1295
1296
321
  sb_new (&sub);
1297
321
  if (! buffer_and_nest (NULL, "ENDR", &sub, get_line))
1298
66
    {
1299
66
      err = _("unexpected end of file in irp or irpc");
1300
66
      goto out2;
1301
66
    }
1302
1303
255
  sb_new (&f.name);
1304
255
  sb_new (&f.def);
1305
255
  sb_new (&f.actual);
1306
1307
255
  idx = get_token (idx, in, &f.name);
1308
255
  if (f.name.len == 0)
1309
5
    {
1310
5
      err = _("missing model parameter");
1311
5
      goto out1;
1312
5
    }
1313
1314
250
  h = str_htab_create ();
1315
1316
250
  str_hash_insert (h, sb_terminate (&f.name), &f, 0);
1317
1318
250
  f.index = 1;
1319
250
  f.next = NULL;
1320
250
  f.type = FORMAL_OPTIONAL;
1321
1322
250
  sb_reset (out);
1323
1324
250
  idx = sb_skip_comma (idx, in);
1325
250
  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
250
  else
1331
250
    {
1332
250
      bool in_quotes = false;
1333
250
      unsigned int instance = 0;
1334
1335
6.16k
      while (idx < in->len)
1336
6.04k
  {
1337
6.04k
    if (!irpc)
1338
895
      idx = get_any_string (idx, in, &f.actual);
1339
5.14k
    else
1340
5.14k
      {
1341
5.14k
        if (in->ptr[idx] == '"')
1342
57
    {
1343
57
      in_quotes = ! in_quotes;
1344
57
      ++idx;
1345
1346
57
      if (! in_quotes)
1347
27
        {
1348
27
          idx = sb_skip_white (idx, in);
1349
27
          if (idx >= in->len)
1350
0
      break;
1351
27
        }
1352
57
      continue;
1353
57
    }
1354
5.09k
        sb_reset (&f.actual);
1355
5.09k
        sb_add_char (&f.actual, in->ptr[idx]);
1356
5.09k
        ++idx;
1357
5.09k
      }
1358
1359
5.98k
    err = macro_expand_body (&sub, out, &f, h, NULL, instance);
1360
5.98k
    ++instance;
1361
5.98k
    if (err != NULL)
1362
130
      break;
1363
5.85k
    if (!irpc)
1364
766
      idx = sb_skip_comma (idx, in);
1365
5.09k
    else if (! in_quotes)
1366
4.79k
      idx = sb_skip_white (idx, in);
1367
5.85k
  }
1368
250
    }
1369
1370
250
  htab_delete (h);
1371
255
 out1:
1372
255
  sb_kill (&f.actual);
1373
255
  sb_kill (&f.def);
1374
255
  sb_kill (&f.name);
1375
321
 out2:
1376
321
  sb_kill (&sub);
1377
1378
321
  return err;
1379
255
}