public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: WANG Xuerui <i.swmail@xen0n.name>
To: binutils@sourceware.org
Cc: Chenghua Xu <xuchenghua@loongson.cn>,
	Zhensong Liu <liuzhensong@loongson.cn>,
	Qinggang Meng <mengqinggang@loongson.cn>,
	Xi Ruoyao <xry111@xry111.site>, WANG Xuerui <git@xen0n.name>
Subject: [PATCH v3 3/6] opcodes/loongarch: implement style support in the disassembler
Date: Wed, 14 Dec 2022 13:52:01 +0800	[thread overview]
Message-ID: <20221214055204.2890795-4-i.swmail@xen0n.name> (raw)
In-Reply-To: <20221214055204.2890795-1-i.swmail@xen0n.name>

From: WANG Xuerui <git@xen0n.name>

Update the LoongArch disassembler to supply style information to the
disassembler output. The output formatting remains unchanged.
---
 opcodes/disassemble.c   |  5 +++++
 opcodes/loongarch-dis.c | 41 ++++++++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
index b8e0bd14b51..f4adbe555ee 100644
--- a/opcodes/disassemble.c
+++ b/opcodes/disassemble.c
@@ -647,6 +647,11 @@ disassemble_init_for_target (struct disassemble_info * info)
       info->skip_zeroes = 16;
       break;
 #endif
+#ifdef ARCH_loongarch
+    case bfd_arch_loongarch:
+      info->created_styled_output = true;
+      break;
+#endif
 #ifdef ARCH_tic4x
     case bfd_arch_tic4x:
       info->skip_zeroes = 32;
diff --git a/opcodes/loongarch-dis.c b/opcodes/loongarch-dis.c
index d0a66e7a2a4..44f035b2181 100644
--- a/opcodes/loongarch-dis.c
+++ b/opcodes/loongarch-dis.c
@@ -136,7 +136,7 @@ dis_one_arg (char esc1, char esc2, const char *bit_field,
   if (esc1)
     {
       if (need_comma)
-	info->fprintf_func (info->stream, ", ");
+	info->fprintf_styled_func (info->stream, dis_style_text, ", ");
       need_comma = 1;
       imm = loongarch_decode_imm (bit_field, insn, 1);
       u_imm = loongarch_decode_imm (bit_field, insn, 0);
@@ -145,35 +145,38 @@ dis_one_arg (char esc1, char esc2, const char *bit_field,
   switch (esc1)
     {
     case 'r':
-      info->fprintf_func (info->stream, "%s", loongarch_r_disname[u_imm]);
+      info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_r_disname[u_imm]);
       break;
     case 'f':
-      info->fprintf_func (info->stream, "%s", loongarch_f_disname[u_imm]);
+      info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_f_disname[u_imm]);
       break;
     case 'c':
       switch (esc2)
 	{
 	case 'r':
-	  info->fprintf_func (info->stream, "%s", loongarch_cr_disname[u_imm]);
+	  info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_cr_disname[u_imm]);
 	  break;
 	default:
-	  info->fprintf_func (info->stream, "%s", loongarch_c_disname[u_imm]);
+	  info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_c_disname[u_imm]);
 	}
       break;
     case 'v':
-      info->fprintf_func (info->stream, "%s", loongarch_v_disname[u_imm]);
+      info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_v_disname[u_imm]);
       break;
     case 'x':
-      info->fprintf_func (info->stream, "%s", loongarch_x_disname[u_imm]);
+      info->fprintf_styled_func (info->stream, dis_style_register, "%s", loongarch_x_disname[u_imm]);
       break;
     case 'u':
-      info->fprintf_func (info->stream, "0x%x", u_imm);
+      info->fprintf_styled_func (info->stream, dis_style_immediate, "0x%x", u_imm);
       break;
     case 's':
       if (imm == 0)
-	info->fprintf_func (info->stream, "%d", imm);
+	info->fprintf_styled_func (info->stream, dis_style_immediate, "%d", imm);
       else
-	info->fprintf_func (info->stream, "%d(0x%x)", imm, u_imm);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_immediate, "%d", imm);
+	  info->fprintf_styled_func (info->stream, dis_style_text, "(0x%x)", u_imm);
+	}
       switch (esc2)
 	{
 	case 'b':
@@ -227,32 +230,32 @@ disassemble_one (insn_t insn, struct disassemble_info *info)
   for (i = 31; 0 <= i; i--)
     {
       if (t & insn)
-	info->fprintf_func (info->stream, "1");
+	info->fprintf_styled_func (info->stream, dis_style_text, "1");
       else
-	info->fprintf_func (info->stream, "0");
+	info->fprintf_styled_func (info->stream, dis_style_text, "0");
       if (have_space[i])
-	info->fprintf_func (info->stream, " ");
+	info->fprintf_styled_func (info->stream, dis_style_text, " ");
       t = t >> 1;
     }
-  info->fprintf_func (info->stream, "\t");
+  info->fprintf_styled_func (info->stream, dis_style_text, "\t");
 #endif
 
   if (!opc)
     {
       info->insn_type = dis_noninsn;
-      info->fprintf_func (info->stream, "0x%08x", insn);
+      info->fprintf_styled_func (info->stream, dis_style_immediate, "0x%08x", insn);
       return;
     }
 
   info->insn_type = dis_nonbranch;
-  info->fprintf_func (info->stream, "%-12s", opc->name);
+  info->fprintf_styled_func (info->stream, dis_style_mnemonic, "%-12s", opc->name);
 
   {
     char *fake_args = xmalloc (strlen (opc->format) + 1);
     const char *fake_arg_strs[MAX_ARG_NUM_PLUS_2];
     strcpy (fake_args, opc->format);
     if (0 < loongarch_split_args_by_comma (fake_args, fake_arg_strs))
-      info->fprintf_func (info->stream, "\t");
+      info->fprintf_styled_func (info->stream, dis_style_text, "\t");
     info->private_data = &insn;
     loongarch_foreach_args (opc->format, fake_arg_strs, dis_one_arg, info);
     free (fake_args);
@@ -260,11 +263,11 @@ disassemble_one (insn_t insn, struct disassemble_info *info)
 
   if (info->insn_type == dis_branch || info->insn_type == dis_condbranch
       /* Someother if we have extra info to print.  */)
-    info->fprintf_func (info->stream, "\t#");
+    info->fprintf_styled_func (info->stream, dis_style_text, "\t#");
 
   if (info->insn_type == dis_branch || info->insn_type == dis_condbranch)
     {
-      info->fprintf_func (info->stream, " ");
+      info->fprintf_styled_func (info->stream, dis_style_text, " ");
       info->print_address_func (info->target, info);
     }
 }
-- 
2.38.1


  parent reply	other threads:[~2022-12-14  5:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  5:51 [PATCH v3 RESEND 0/6] LoongArch: colored disassembly and readability tweaks WANG Xuerui
2022-12-14  5:51 ` [PATCH v3 1/6] LoongArch: support disassembling certain pseudo-instructions WANG Xuerui
2022-12-14  5:52 ` [PATCH v3 2/6] opcodes/loongarch: remove unused code WANG Xuerui
2022-12-14  5:52 ` WANG Xuerui [this message]
2023-01-17 10:37   ` [PATCH v3 3/6] opcodes/loongarch: implement style support in the disassembler Andrew Burgess
2022-12-14  5:52 ` [PATCH v3 4/6] opcodes/loongarch: style disassembled address offsets as such WANG Xuerui
2022-12-14  5:52 ` [PATCH v3 5/6] opcodes/loongarch: do not print hex notation for signed immediates WANG Xuerui
2022-12-14  5:52 ` [PATCH v3 6/6] opcodes/loongarch: print unrecognized insn words with the .word directive WANG Xuerui
2023-01-03  4:05 ` [PATCH v3 RESEND 0/6] LoongArch: colored disassembly and readability tweaks WANG Xuerui
2023-01-03 11:10   ` mengqinggang
2023-01-03 11:16     ` WANG Xuerui
  -- strict thread matches above, loose matches on Subject: below --
2022-12-14  5:46 [PATCH v3 " WANG Xuerui
2022-12-14  5:46 ` [PATCH v3 3/6] opcodes/loongarch: implement style support in the disassembler WANG Xuerui

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=20221214055204.2890795-4-i.swmail@xen0n.name \
    --to=i.swmail@xen0n.name \
    --cc=binutils@sourceware.org \
    --cc=git@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=mengqinggang@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /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).