public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libopcodes/s390: add support for disassembler styling
@ 2022-07-07 10:25 Andrew Burgess
  2022-07-07 10:53 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-07-07 10:25 UTC (permalink / raw)
  To: binutils; +Cc: Andrew Burgess

This commit adds disassembler style to the libopcodes s390
disassembler.  This conversion was pretty straight forward, I just
converted the fprintf_func calls to fprintf_styled_func calls and
added an appropriate style.

For testing the new styling I just assembled then disassembled the
source files in gas/testsuite/gas/s390 and manually checked that the
styling looked reasonable.

If the user does not request styled output from objdump, then there
should be no change in the disassembler output after this commit.
---
 opcodes/s390-dis.c | 87 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 71 insertions(+), 16 deletions(-)

diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 03715ed5f0b..df44efb95ab 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -186,7 +186,8 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
   char separator;
 
   /* Mnemonic.  */
-  info->fprintf_func (info->stream, "%s", opcode->name);
+  info->fprintf_styled_func (info->stream, dis_style_mnemonic,
+			     "%s", opcode->name);
 
   /* Operands.  */
   separator = '\t';
@@ -222,24 +223,60 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
 	}
 
       if (flags & S390_OPERAND_GPR)
-	info->fprintf_func (info->stream, "%c%%r%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%r%u", val.u);
+	}
       else if (flags & S390_OPERAND_FPR)
-	info->fprintf_func (info->stream, "%c%%f%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%f%u", val.u);
+	}
       else if (flags & S390_OPERAND_VR)
-	info->fprintf_func (info->stream, "%c%%v%i", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%v%i", val.u);
+	}
       else if (flags & S390_OPERAND_AR)
-	info->fprintf_func (info->stream, "%c%%a%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%a%u", val.u);
+	}
       else if (flags & S390_OPERAND_CR)
-	info->fprintf_func (info->stream, "%c%%c%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%c%u", val.u);
+	}
       else if (flags & S390_OPERAND_PCREL)
 	{
-	  info->fprintf_func (info->stream, "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
 	  info->print_address_func (memaddr + val.i + val.i, info);
 	}
       else if (flags & S390_OPERAND_SIGNED)
-	info->fprintf_func (info->stream, "%c%i", separator, val.i);
+	{
+	  enum disassembler_style style;
+
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  style = ((flags & S390_OPERAND_DISP)
+		   ? dis_style_address_offset : dis_style_immediate);
+	  info->fprintf_styled_func (info->stream, style, "%i", val.i);
+	}
       else
 	{
+	  enum disassembler_style style;
+
 	  if (flags & S390_OPERAND_OR1)
 	    val.u &= ~1;
 	  if (flags & S390_OPERAND_OR2)
@@ -251,14 +288,18 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
 	      && val.u == 0
 	      && opindex[1] == 0)
 	    break;
-	  info->fprintf_func (info->stream, "%c%u", separator, val.u);
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  style = ((flags & S390_OPERAND_DISP)
+		   ? dis_style_address_offset : dis_style_immediate);
+	  info->fprintf_styled_func (info->stream, style, "%u", val.u);
 	}
 
       if (flags & S390_OPERAND_DISP)
 	separator = '(';
       else if (flags & S390_OPERAND_BASE)
 	{
-	  info->fprintf_func (info->stream, ")");
+	  info->fprintf_styled_func (info->stream, dis_style_text, ")");
 	  separator = ',';
 	}
       else
@@ -361,19 +402,33 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
       value = (value << 8) + (unsigned int) buffer[1];
       value = (value << 8) + (unsigned int) buffer[2];
       value = (value << 8) + (unsigned int) buffer[3];
-      info->fprintf_func (info->stream, ".long\t0x%08x", value);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".long");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%08x", value);
       return 4;
     case 2:
       value = (unsigned int) buffer[0];
       value = (value << 8) + (unsigned int) buffer[1];
-      info->fprintf_func (info->stream, ".short\t0x%04x", value);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".short");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%04x", value);
       return 2;
     default:
-      info->fprintf_func (info->stream, ".byte\t0x%02x",
-			  (unsigned int) buffer[0]);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".byte");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%02x", (unsigned int) buffer[0]);
       for (i = 1; i < bytes_to_dump; i++)
-	info->fprintf_func (info->stream, ",0x%02x",
-			  (unsigned int) buffer[i]);
+	info->fprintf_styled_func (info->stream, dis_style_immediate,
+				   "0x%02x", (unsigned int) buffer[i]);
       return bytes_to_dump;
     }
   return 0;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libopcodes/s390: add support for disassembler styling
  2022-07-07 10:25 [PATCH] libopcodes/s390: add support for disassembler styling Andrew Burgess
@ 2022-07-07 10:53 ` Nick Clifton
  2022-07-08 10:20   ` Andrew Burgess
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2022-07-07 10:53 UTC (permalink / raw)
  To: Andrew Burgess, binutils

Hi Andrew,

> This commit adds disassembler style to the libopcodes s390
> disassembler.

Don't you also need to set "info->created_styled_output = true;"
in opcodes/disassemble.c:disassemble_init_for_target() ?

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libopcodes/s390: add support for disassembler styling
  2022-07-07 10:53 ` Nick Clifton
@ 2022-07-08 10:20   ` Andrew Burgess
  2022-07-08 10:43     ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2022-07-08 10:20 UTC (permalink / raw)
  To: Nick Clifton, binutils

Nick Clifton via Binutils <binutils@sourceware.org> writes:

> Hi Andrew,
>
>> This commit adds disassembler style to the libopcodes s390
>> disassembler.
>
> Don't you also need to set "info->created_styled_output = true;"
> in opcodes/disassemble.c:disassemble_init_for_target() ?

Ahh, yes.  Thank you.  That flag isn't actually used by anyone yet, but
it will be once the GDB patches land - at which point I would have
spotted this oversight.

Here's the updated patch.

Thanks,
Andrew

---

commit 3496742a2558bf585edcd2c46bfb97989595dd35
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Tue Jul 5 14:17:14 2022 +0100

    libopcodes/s390: add support for disassembler styling
    
    This commit adds disassembler style to the libopcodes s390
    disassembler.  This conversion was pretty straight forward, I just
    converted the fprintf_func calls to fprintf_styled_func calls and
    added an appropriate style.
    
    For testing the new styling I just assembled then disassembled the
    source files in gas/testsuite/gas/s390 and manually checked that the
    styling looked reasonable.
    
    If the user does not request styled output from objdump, then there
    should be no change in the disassembler output after this commit.

diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
index 9c0dacaf391..bd37f042b31 100644
--- a/opcodes/disassemble.c
+++ b/opcodes/disassemble.c
@@ -721,6 +721,7 @@ disassemble_init_for_target (struct disassemble_info * info)
 #ifdef ARCH_s390
     case bfd_arch_s390:
       disassemble_init_s390 (info);
+      info->created_styled_output = true;
       break;
 #endif
 #ifdef ARCH_nds32
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 03715ed5f0b..df44efb95ab 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -186,7 +186,8 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
   char separator;
 
   /* Mnemonic.  */
-  info->fprintf_func (info->stream, "%s", opcode->name);
+  info->fprintf_styled_func (info->stream, dis_style_mnemonic,
+			     "%s", opcode->name);
 
   /* Operands.  */
   separator = '\t';
@@ -222,24 +223,60 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
 	}
 
       if (flags & S390_OPERAND_GPR)
-	info->fprintf_func (info->stream, "%c%%r%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%r%u", val.u);
+	}
       else if (flags & S390_OPERAND_FPR)
-	info->fprintf_func (info->stream, "%c%%f%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%f%u", val.u);
+	}
       else if (flags & S390_OPERAND_VR)
-	info->fprintf_func (info->stream, "%c%%v%i", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%v%i", val.u);
+	}
       else if (flags & S390_OPERAND_AR)
-	info->fprintf_func (info->stream, "%c%%a%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%a%u", val.u);
+	}
       else if (flags & S390_OPERAND_CR)
-	info->fprintf_func (info->stream, "%c%%c%u", separator, val.u);
+	{
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_register,
+				     "%%c%u", val.u);
+	}
       else if (flags & S390_OPERAND_PCREL)
 	{
-	  info->fprintf_func (info->stream, "%c", separator);
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
 	  info->print_address_func (memaddr + val.i + val.i, info);
 	}
       else if (flags & S390_OPERAND_SIGNED)
-	info->fprintf_func (info->stream, "%c%i", separator, val.i);
+	{
+	  enum disassembler_style style;
+
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  style = ((flags & S390_OPERAND_DISP)
+		   ? dis_style_address_offset : dis_style_immediate);
+	  info->fprintf_styled_func (info->stream, style, "%i", val.i);
+	}
       else
 	{
+	  enum disassembler_style style;
+
 	  if (flags & S390_OPERAND_OR1)
 	    val.u &= ~1;
 	  if (flags & S390_OPERAND_OR2)
@@ -251,14 +288,18 @@ s390_print_insn_with_opcode (bfd_vma memaddr,
 	      && val.u == 0
 	      && opindex[1] == 0)
 	    break;
-	  info->fprintf_func (info->stream, "%c%u", separator, val.u);
+	  info->fprintf_styled_func (info->stream, dis_style_text,
+				     "%c", separator);
+	  style = ((flags & S390_OPERAND_DISP)
+		   ? dis_style_address_offset : dis_style_immediate);
+	  info->fprintf_styled_func (info->stream, style, "%u", val.u);
 	}
 
       if (flags & S390_OPERAND_DISP)
 	separator = '(';
       else if (flags & S390_OPERAND_BASE)
 	{
-	  info->fprintf_func (info->stream, ")");
+	  info->fprintf_styled_func (info->stream, dis_style_text, ")");
 	  separator = ',';
 	}
       else
@@ -361,19 +402,33 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
       value = (value << 8) + (unsigned int) buffer[1];
       value = (value << 8) + (unsigned int) buffer[2];
       value = (value << 8) + (unsigned int) buffer[3];
-      info->fprintf_func (info->stream, ".long\t0x%08x", value);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".long");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%08x", value);
       return 4;
     case 2:
       value = (unsigned int) buffer[0];
       value = (value << 8) + (unsigned int) buffer[1];
-      info->fprintf_func (info->stream, ".short\t0x%04x", value);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".short");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%04x", value);
       return 2;
     default:
-      info->fprintf_func (info->stream, ".byte\t0x%02x",
-			  (unsigned int) buffer[0]);
+      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
+				 ".byte");
+      info->fprintf_styled_func (info->stream, dis_style_text,
+				 "\t");
+      info->fprintf_styled_func (info->stream, dis_style_immediate,
+				 "0x%02x", (unsigned int) buffer[0]);
       for (i = 1; i < bytes_to_dump; i++)
-	info->fprintf_func (info->stream, ",0x%02x",
-			  (unsigned int) buffer[i]);
+	info->fprintf_styled_func (info->stream, dis_style_immediate,
+				   "0x%02x", (unsigned int) buffer[i]);
       return bytes_to_dump;
     }
   return 0;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libopcodes/s390: add support for disassembler styling
  2022-07-08 10:20   ` Andrew Burgess
@ 2022-07-08 10:43     ` Nick Clifton
  2022-07-08 12:18       ` Andrew Burgess
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2022-07-08 10:43 UTC (permalink / raw)
  To: Andrew Burgess, binutils

Hi Andrew,

> Here's the updated patch.

Go ahead - make my day.

Ahem, I mean, patch approved, please apply (mainline and the new 2.39 branch).

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libopcodes/s390: add support for disassembler styling
  2022-07-08 10:43     ` Nick Clifton
@ 2022-07-08 12:18       ` Andrew Burgess
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2022-07-08 12:18 UTC (permalink / raw)
  To: Nick Clifton, binutils

Nick Clifton via Binutils <binutils@sourceware.org> writes:

> Hi Andrew,
>
>> Here's the updated patch.
>
> Go ahead - make my day.
>
> Ahem, I mean, patch approved, please apply (mainline and the new 2.39 branch).

Thanks, done.

Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-08 12:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-07 10:25 [PATCH] libopcodes/s390: add support for disassembler styling Andrew Burgess
2022-07-07 10:53 ` Nick Clifton
2022-07-08 10:20   ` Andrew Burgess
2022-07-08 10:43     ` Nick Clifton
2022-07-08 12:18       ` Andrew Burgess

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).