public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH v7 1/7] x86: constify parse_insn()'s input
Date: Fri, 2 Dec 2022 11:18:00 +0100	[thread overview]
Message-ID: <8bfb1c56-8207-fe92-87ae-1b7ef26b3544@suse.com> (raw)
In-Reply-To: <dc39887b-fc6e-2827-e0b1-e99949e08796@suse.com>

The function doesn't alter its input buffer: Reflect this in its
prototype. To avoid using any kind of cast, simply calculate the update
of "line" from the function's input and output.
---
Avoiding a cast the way it's done here is going to be useful in
subsequent patches (there'll be code added between the call and the
update of "line"), so switching to a cast is not really an option.
---
v3: New.

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -158,7 +158,7 @@ static int i386_intel_operand (char *, i
 static int i386_intel_simplify (expressionS *);
 static int i386_intel_parse_name (const char *, expressionS *);
 static const reg_entry *parse_register (char *, char **);
-static char *parse_insn (char *, char *);
+static const char *parse_insn (const char *, char *);
 static char *parse_operands (char *, const char *);
 static void swap_operands (void);
 static void swap_2_operands (unsigned int, unsigned int);
@@ -4845,6 +4845,7 @@ md_assemble (char *line)
 {
   unsigned int j;
   char mnemonic[MAX_MNEM_SIZE], mnem_suffix;
+  const char *end;
   const insn_template *t;
 
   /* Initialize globals.  */
@@ -4860,9 +4861,10 @@ md_assemble (char *line)
      We assume that the scrubber has arranged it so that line[0] is the valid
      start of a (possibly prefixed) mnemonic.  */
 
-  line = parse_insn (line, mnemonic);
-  if (line == NULL)
+  end = parse_insn (line, mnemonic);
+  if (end == NULL)
     return;
+  line += end - line;
   mnem_suffix = i.suffix;
 
   line = parse_operands (line, mnemonic);
@@ -5260,11 +5262,10 @@ md_assemble (char *line)
     last_insn.kind = last_insn_other;
 }
 
-static char *
-parse_insn (char *line, char *mnemonic)
+static const char *
+parse_insn (const char *line, char *mnemonic)
 {
-  char *l = line;
-  char *token_start = l;
+  const char *l = line, *token_start = l;
   char *mnem_p;
   int supported;
   const insn_template *t;


  reply	other threads:[~2022-12-02 10:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 10:13 [PATCH v7 0/7] x86: suffix handling changes Jan Beulich
2022-12-02 10:18 ` Jan Beulich [this message]
2022-12-02 10:18 ` [PATCH v7 2/7] x86: re-work insn/suffix recognition Jan Beulich
2022-12-02 10:19 ` [PATCH v7 3/7] ix86: don't recognize/derive Q suffix in the common case Jan Beulich
2022-12-02 10:20 ` [PATCH v7 4/7] x86-64: allow HLE store of accumulator to absolute 32-bit address Jan Beulich
2022-12-02 10:20 ` [PATCH v7 5/7] x86: move bad-use-of-TLS-reloc check Jan Beulich
2022-12-02 10:21 ` [PATCH v7 6/7] x86: drop (now) stray IsString Jan Beulich
2022-12-02 10:21 ` [PATCH v7 7/7] x86: further re-work insn/suffix recognition to also cover MOVSX Jan Beulich
2022-12-09 10:56 ` [PATCH v7 0/7] x86: suffix handling changes 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=8bfb1c56-8207-fe92-87ae-1b7ef26b3544@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /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).