From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: Nick Clifton <nickc@redhat.com>, Timothy Wall <twall@alum.mit.edu>
Subject: [PATCH 4/6] gas: fold do_repeat{,_with_expander}()
Date: Fri, 6 May 2022 08:07:37 +0200 [thread overview]
Message-ID: <a7a17bfd-8a99-fa80-4335-40184cac015f@suse.com> (raw)
In-Reply-To: <e96f677b-acf7-e5a9-e99e-48ae61a20da8@suse.com>
do_repeat_with_expander() already deals with the "no expander" case
quite fine, so there's really little point having two functions. What it
lacks compared with do_repeat() is a call to sb_build(), which can
simply be moved (and the then redundant sb_new() be avoided). Along with
this moving also flip if the main if()'s condition such that the "no
expander" case is handled first.
---
The "with-expander" case has a number of issues, though:
- use of literal 8 instead of using the actual size of "expander",
- assertion on user controlled value,
- subsequent code nevertheless depends on that assertion,
- only a single instance of the pattern is being replaced (despite a
comment saying otherwise),
- no separators are required (checked for) around the found "expander"
instance,
- "count" is silently truncated from size_t to unsigned long.
Furthermore .mrepeat doesn't properly nest with itself or inside e.g.
.irp, as the inner .endr will be taken as terminating the other
construct.
--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -566,7 +566,7 @@ rx_rept (int ignore ATTRIBUTE_UNUSED)
{
size_t count = get_absolute_expression ();
- do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP");
+ do_repeat (count, "MREPEAT", "ENDR", "..MACREP");
}
/* Like cons() accept that strings are allowed. */
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -2034,7 +2034,7 @@ tic54x_loop (int count)
if (!is_end_of_line[(unsigned char) *input_line_pointer])
count = get_absolute_expression ();
- do_repeat ((size_t) count, "LOOP", "ENDLOOP");
+ do_repeat ((size_t) count, "LOOP", "ENDLOOP", NULL);
}
/* Normally, endloop gets eaten by the preceding loop. */
--- a/gas/read.c
+++ b/gas/read.c
@@ -3094,14 +3094,17 @@ s_rept (int ignore ATTRIBUTE_UNUSED)
count = (size_t) get_absolute_expression ();
- do_repeat (count, "REPT", "ENDR");
+ do_repeat (count, "REPT", "ENDR", NULL);
}
/* This function provides a generic repeat block implementation. It allows
- different directives to be used as the start/end keys. */
+ different directives to be used as the start/end keys. Any text matching
+ the optional EXPANDER in the block is replaced by the remaining iteration
+ count. */
void
-do_repeat (size_t count, const char *start, const char *end)
+do_repeat (size_t count, const char *start, const char *end,
+ const char *expander)
{
sb one;
sb many;
@@ -3119,46 +3122,16 @@ do_repeat (size_t count, const char *sta
return;
}
- sb_build (&many, count * one.len);
- while (count-- > 0)
- sb_add_sb (&many, &one);
-
- sb_kill (&one);
-
- input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
- sb_kill (&many);
- buffer_limit = input_scrub_next_buffer (&input_line_pointer);
-}
-
-/* Like do_repeat except that any text matching EXPANDER in the
- block is replaced by the iteration count. */
-
-void
-do_repeat_with_expander (size_t count,
- const char * start,
- const char * end,
- const char * expander)
-{
- sb one;
- sb many;
-
- if (((ssize_t) count) < 0)
+ if (expander == NULL || strstr (one.ptr, expander) == NULL)
{
- as_bad (_("negative count for %s - ignored"), start);
- count = 0;
+ sb_build (&many, count * one.len);
+ while (count-- > 0)
+ sb_add_sb (&many, &one);
}
-
- sb_new (&one);
- if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
+ else
{
- as_bad (_("%s without %s"), start, end);
- return;
- }
-
- sb_new (&many);
+ sb_new (&many);
- if (expander != NULL && strstr (one.ptr, expander) != NULL)
- {
while (count -- > 0)
{
int len;
@@ -3177,9 +3150,6 @@ do_repeat_with_expander (size_t count,
sb_kill (& processed);
}
}
- else
- while (count-- > 0)
- sb_add_sb (&many, &one);
sb_kill (&one);
--- a/gas/read.h
+++ b/gas/read.h
@@ -148,8 +148,7 @@ extern void stabs_generate_asm_file (voi
extern void stabs_generate_asm_lineno (void);
extern void stabs_generate_asm_func (const char *, const char *);
extern void stabs_generate_asm_endfunc (const char *, const char *);
-extern void do_repeat (size_t, const char *, const char *);
-extern void do_repeat_with_expander (size_t, const char *, const char *, const char *);
+extern void do_repeat (size_t, const char *, const char *, const char *);
extern void end_repeat (int);
extern void do_parse_cons_expression (expressionS *, int);
next prev parent reply other threads:[~2022-05-06 6:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 6:04 [PATCH 0/6] gas: (mostly) further file/line handling adjustments Jan Beulich
2022-05-06 6:05 ` [PATCH 1/6] gas: tweak .irp and alike file/line handling for M68K/MRI Jan Beulich
2022-05-06 6:06 ` [PATCH 2/6] gas: simplify ignore_input() Jan Beulich
2022-05-06 6:06 ` [PATCH 3/6] gas: don't ignore .linefile inside false conditionals Jan Beulich
2022-05-06 6:07 ` Jan Beulich [this message]
2022-05-06 6:08 ` [PATCH 5/6] gas: avoid bignum related errors when processing .linefile Jan Beulich
2022-05-06 6:08 ` [PATCH 6/6] gas: avoid octal numbers being accepted " Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a7a17bfd-8a99-fa80-4335-40184cac015f@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@sourceware.org \
--cc=nickc@redhat.com \
--cc=twall@alum.mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).