All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@gmail.com, philmd@linaro.org
Subject: [PATCH 6/6] disas/cris: Improve output of register names
Date: Fri, 12 Apr 2024 22:23:33 -0700	[thread overview]
Message-ID: <20240413052333.688151-7-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240413052333.688151-1-richard.henderson@linaro.org>

Add REGISTER_PREFIX as a string literal that may be concatenated
with other string literals.  Use a table of the 16 register names
instead of using g_string_append_printf.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas/cris.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/disas/cris.c b/disas/cris.c
index 71c292188a..01ea63c428 100644
--- a/disas/cris.c
+++ b/disas/cris.c
@@ -1234,6 +1234,7 @@ cris_cc_strings[] =
 #endif
 
 /* Sometimes we prefix all registers with this character.  */
+#define REGISTER_PREFIX      "$"
 #define REGISTER_PREFIX_CHAR '$'
 
 enum cris_disass_family
@@ -1669,26 +1670,31 @@ format_dec(long number, GString *str, int signedp)
 static void
 format_reg(enum cris_disass_family distype, int regno, GString *str)
 {
-  g_string_append_c(str, REGISTER_PREFIX_CHAR);
+  static const char reg_names[16][5] = {
+    REGISTER_PREFIX "r0",
+    REGISTER_PREFIX "r1",
+    REGISTER_PREFIX "r2",
+    REGISTER_PREFIX "r3",
+    REGISTER_PREFIX "r4",
+    REGISTER_PREFIX "r5",
+    REGISTER_PREFIX "r6",
+    REGISTER_PREFIX "r7",
+    REGISTER_PREFIX "r8",
+    REGISTER_PREFIX "r9",
+    REGISTER_PREFIX "r10",
+    REGISTER_PREFIX "r11",
+    REGISTER_PREFIX "r12",
+    REGISTER_PREFIX "r13",
+    REGISTER_PREFIX "sp",
+    REGISTER_PREFIX "pc",
+  };
+  const char *name = reg_names[regno];
 
-  switch (regno)
-    {
-    case 15:
-      /* For v32, there is no context in which we output PC.  */
-      if (distype == cris_dis_v32)
-        g_string_append(str, "acr");
-      else
-        g_string_append(str, "pc");
-      break;
+  /* For v32, there is no context in which we output PC.  */
+  if (regno == 15 && distype == cris_dis_v32)
+    name = REGISTER_PREFIX "acr";
 
-    case 14:
-      g_string_append(str, "sp");
-      break;
-
-    default:
-      g_string_append_printf(str, "r%d", regno);
-      break;
-    }
+  g_string_append(str, name);
 }
 
 /* Format the name of a support register into outbuffer.  */
@@ -1861,8 +1867,7 @@ print_with_operands(const struct cris_opcode *opcodep,
         break;
 
       case 'A':
-        g_string_append_c(str, REGISTER_PREFIX_CHAR);
-        g_string_append(str, "acr");
+        g_string_append(str, REGISTER_PREFIX "acr");
         break;
 
       case '[':
-- 
2.34.1



  parent reply	other threads:[~2024-04-13  5:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13  5:23 [PATCH 0/6] disas/cris: Use GString instead of sprintf Richard Henderson
2024-04-13  5:23 ` [PATCH 1/6] disas/cris: Untabify Richard Henderson
2024-04-13  5:23 ` [PATCH 2/6] disas/cris: Remove TRACE_CASE and related code Richard Henderson
2024-04-13  5:23 ` [PATCH 3/6] disas/cris: Drop with_reg_prefix Richard Henderson
2024-04-13  5:23 ` [PATCH 4/6] disas/cris: Use GString in print_with_operands and subroutines Richard Henderson
2024-04-13  5:23 ` [PATCH 5/6] disas/cris: Remove struct cris_disasm_data Richard Henderson
2024-04-13  5:23 ` Richard Henderson [this message]
2024-04-13  8:45 ` [PATCH 0/6] disas/cris: Use GString instead of sprintf Peter Maydell
2024-04-16  8:35 ` Edgar E. Iglesias

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=20240413052333.688151-7-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.