public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] opcodes/avr: Implement style support in the disassembler
@ 2022-06-06 19:11 Marcus Nilsson
  2022-06-17  8:57 ` Marcus Nilsson
  2022-06-29 17:20 ` [PING][PATCH] " Marcus Nilsson
  0 siblings, 2 replies; 4+ messages in thread
From: Marcus Nilsson @ 2022-06-06 19:11 UTC (permalink / raw)
  To: binutils

Update the AVR disassembler to supply style information to the
disassembler output.

By adding an additional parameter to avr_operand() we can fill in
style information for each operand. The output formatting remains
unchanged.

opcodes/ChangeLog:
	* disassemble.c: (disassemble_init_for_target): Set
	created_styled_output for AVR based targets.
	* avr-dis.c: (print_insn_avr): Use fprintf_styled_ftype
	instead of fprintf_ftype throughout.
	(avr_operand): Pass in and fill disassembler_style when
	parsing operands.
---
 opcodes/avr-dis.c     | 51 +++++++++++++++++++++++++++++++++++--------
 opcodes/disassemble.c |  5 +++++
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c
index aab37962688..0614e7dd746 100644
--- a/opcodes/avr-dis.c
+++ b/opcodes/avr-dis.c
@@ -56,6 +56,7 @@ avr_operand (unsigned int        insn,
              char *              opcode_str,
 	     char *              buf,
 	     char *              comment,
+	     enum disassembler_style *  style,
 	     int                 regs,
 	     int *               sym,
 	     bfd_vma *           sym_addr,
@@ -74,6 +75,7 @@ avr_operand (unsigned int        insn,
 	insn = (insn & 0x01f0) >> 4; /* Destination register.  */
 
       sprintf (buf, "r%d", insn);
+      *style = dis_style_register;
       break;
 
     case 'd':
@@ -81,10 +83,13 @@ avr_operand (unsigned int        insn,
 	sprintf (buf, "r%d", 16 + (insn & 0xf));
       else
 	sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4));
+
+      *style = dis_style_register;
       break;
 
     case 'w':
       sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3));
+      *style = dis_style_register;
       break;
 
     case 'a':
@@ -92,6 +97,8 @@ avr_operand (unsigned int        insn,
 	sprintf (buf, "r%d", 16 + (insn & 7));
       else
 	sprintf (buf, "r%d", 16 + ((insn >> 4) & 7));
+
+      *style = dis_style_register;
       break;
 
     case 'v':
@@ -99,6 +106,8 @@ avr_operand (unsigned int        insn,
 	sprintf (buf, "r%d", (insn & 0xf) * 2);
       else
 	sprintf (buf, "r%d", ((insn & 0xf0) >> 3));
+
+      *style = dis_style_register;
       break;
 
     case 'e':
@@ -119,6 +128,7 @@ avr_operand (unsigned int        insn,
 	    default: xyz = "??"; ok = 0;
 	  }
 	strcpy (buf, xyz);
+	*style = dis_style_register;
 
 	if (AVR_UNDEF_P (insn))
 	  sprintf (comment, _("undefined"));
@@ -143,6 +153,8 @@ avr_operand (unsigned int        insn,
       *buf = '\0';
       if (AVR_UNDEF_P (insn))
 	sprintf (comment, _("undefined"));
+
+      *style = dis_style_register;
       break;
 
     case 'b':
@@ -159,6 +171,7 @@ avr_operand (unsigned int        insn,
 	  *buf++ = 'Z';
 	sprintf (buf, "+%d", x);
 	sprintf (comment, "0x%02x", x);
+	*style = dis_style_register;
       }
       break;
 
@@ -173,6 +186,7 @@ avr_operand (unsigned int        insn,
       info->insn_info_valid = 1;
       info->insn_type = dis_jsr;
       info->target = *sym_addr;
+      *style = dis_style_address;
       break;
 
     case 'L':
@@ -185,6 +199,7 @@ avr_operand (unsigned int        insn,
         info->insn_info_valid = 1;
         info->insn_type = dis_branch;
         info->target = *sym_addr;
+	*style = dis_style_address_offset;
       }
       break;
 
@@ -199,6 +214,7 @@ avr_operand (unsigned int        insn,
         info->insn_info_valid = 1;
         info->insn_type = dis_condbranch;
         info->target = *sym_addr;
+	*style = dis_style_address_offset;
       }
       break;
 
@@ -209,6 +225,7 @@ avr_operand (unsigned int        insn,
         *sym_addr = val;
         sprintf (buf, "0x%04X", insn2);
         strcpy (comment, comment_start);
+	*style = dis_style_immediate;
       }
       break;
 
@@ -222,12 +239,14 @@ avr_operand (unsigned int        insn,
         *sym_addr = val | 0x800000;
         sprintf (buf, "0x%02x", val);
         strcpy (comment, comment_start);
+	*style = dis_style_immediate;
       }
       break;
 
     case 'M':
       sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
       sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf));
+      *style = dis_style_immediate;
       break;
 
     case 'n':
@@ -244,15 +263,18 @@ avr_operand (unsigned int        insn,
 	x = (insn & 0xf) | ((insn >> 2) & 0x30);
 	sprintf (buf, "0x%02x", x);
 	sprintf (comment, "%d", x);
+	*style = dis_style_immediate;
       }
       break;
 
     case 's':
       sprintf (buf, "%d", insn & 7);
+      *style = dis_style_immediate;
       break;
 
     case 'S':
       sprintf (buf, "%d", (insn >> 4) & 7);
+      *style = dis_style_immediate;
       break;
 
     case 'P':
@@ -263,6 +285,7 @@ avr_operand (unsigned int        insn,
 	x |= (insn >> 5) & 0x30;
 	sprintf (buf, "0x%02x", x);
 	sprintf (comment, "%d", x);
+	*style = dis_style_address;
       }
       break;
 
@@ -273,11 +296,13 @@ avr_operand (unsigned int        insn,
 	x = (insn >> 3) & 0x1f;
 	sprintf (buf, "0x%02x", x);
 	sprintf (comment, "%d", x);
+	*style = dis_style_address;
       }
       break;
 
     case 'E':
       sprintf (buf, "%d", (insn >> 4) & 15);
+      *style = dis_style_immediate;
       break;
 
     case '?':
@@ -323,12 +348,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
   const struct avr_opcodes_s *opcode;
   static unsigned int *maskptr;
   void *stream = info->stream;
-  fprintf_ftype prin = info->fprintf_func;
+  fprintf_styled_ftype prin = info->fprintf_styled_func;
   static unsigned int *avr_bin_masks;
   static int initialized;
   int cmd_len = 2;
   int ok = 0;
   char op1[20], op2[20], comment1[40], comment2[40];
+  enum disassembler_style style_op1, style_op2;
   int sym_op1 = 0, sym_op2 = 0;
   bfd_vma sym_addr1, sym_addr2;
 
@@ -400,6 +426,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
   op2[0] = 0;
   comment1[0] = 0;
   comment2[0] = 0;
+  style_op1 = dis_style_text;
+  style_op2 = dis_style_text;
 
   if (opcode->name)
     {
@@ -421,12 +449,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
 	  int regs = REGISTER_P (*constraints);
 
 	  ok = avr_operand (insn, insn2, addr, *constraints, opcode_str, op1,
-			    comment1, 0, &sym_op1, &sym_addr1, info);
+			    comment1, &style_op1, 0, &sym_op1, &sym_addr1,
+			    info);
 
 	  if (ok && *(++constraints) == ',')
 	    ok = avr_operand (insn, insn2, addr, *(++constraints), opcode_str,
-			      op2, *comment1 ? comment2 : comment1, regs,
-			      &sym_op2, &sym_addr2, info);
+			      op2, *comment1 ? comment2 : comment1,
+			      &style_op2, regs, &sym_op2, &sym_addr2, info);
 	}
     }
 
@@ -439,22 +468,26 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
       comment2[0] = 0;
     }
 
-  (*prin) (stream, "%s", ok ? opcode->name : ".word");
+  (*prin) (stream, ok ? dis_style_mnemonic : dis_style_assembler_directive,
+	   "%s", ok ? opcode->name : ".word");
 
   if (*op1)
-      (*prin) (stream, "\t%s", op1);
+    (*prin) (stream, style_op1, "\t%s", op1);
 
   if (*op2)
-    (*prin) (stream, ", %s", op2);
+    {
+      (*prin) (stream, dis_style_text, ", ");
+      (*prin) (stream, style_op2, "%s", op2);
+    }
 
   if (*comment1)
-    (*prin) (stream, "\t; %s", comment1);
+    (*prin) (stream, dis_style_comment_start, "\t; %s", comment1);
 
   if (sym_op1)
     info->print_address_func (sym_addr1, info);
 
   if (*comment2)
-    (*prin) (stream, " %s", comment2);
+    (*prin) (stream, dis_style_comment_start, " %s", comment2);
 
   if (sym_op2)
     info->print_address_func (sym_addr2, info);
diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
index 5a472ce5349..375ab133439 100644
--- a/opcodes/disassemble.c
+++ b/opcodes/disassemble.c
@@ -624,6 +624,11 @@ disassemble_init_for_target (struct disassemble_info * info)
       info->disassembler_needs_relocs = true;
       break;
 #endif
+#ifdef ARCH_avr
+    case bfd_arch_avr:
+      info->created_styled_output = true;
+      break;
+#endif
 #ifdef ARCH_csky
     case bfd_arch_csky:
       info->symbol_is_valid = csky_symbol_is_valid;
-- 
2.34.1


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

* Re: [PATCH] opcodes/avr: Implement style support in the disassembler
  2022-06-06 19:11 [PATCH] opcodes/avr: Implement style support in the disassembler Marcus Nilsson
@ 2022-06-17  8:57 ` Marcus Nilsson
  2022-06-29 17:20 ` [PING][PATCH] " Marcus Nilsson
  1 sibling, 0 replies; 4+ messages in thread
From: Marcus Nilsson @ 2022-06-17  8:57 UTC (permalink / raw)
  To: binutils

Light ping on this one, any comments?

Thanks,
Marcus Nilsson

On Mon, Jun 6, 2022 at 9:11 PM Marcus Nilsson <brainbomb@gmail.com> wrote:

> Update the AVR disassembler to supply style information to the
> disassembler output.
>
> By adding an additional parameter to avr_operand() we can fill in
> style information for each operand. The output formatting remains
> unchanged.
>
> opcodes/ChangeLog:
>         * disassemble.c: (disassemble_init_for_target): Set
>         created_styled_output for AVR based targets.
>         * avr-dis.c: (print_insn_avr): Use fprintf_styled_ftype
>         instead of fprintf_ftype throughout.
>         (avr_operand): Pass in and fill disassembler_style when
>         parsing operands.
> ---
>  opcodes/avr-dis.c     | 51 +++++++++++++++++++++++++++++++++++--------
>  opcodes/disassemble.c |  5 +++++
>  2 files changed, 47 insertions(+), 9 deletions(-)
>
> diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c
> index aab37962688..0614e7dd746 100644
> --- a/opcodes/avr-dis.c
> +++ b/opcodes/avr-dis.c
> @@ -56,6 +56,7 @@ avr_operand (unsigned int        insn,
>               char *              opcode_str,
>              char *              buf,
>              char *              comment,
> +            enum disassembler_style *  style,
>              int                 regs,
>              int *               sym,
>              bfd_vma *           sym_addr,
> @@ -74,6 +75,7 @@ avr_operand (unsigned int        insn,
>         insn = (insn & 0x01f0) >> 4; /* Destination register.  */
>
>        sprintf (buf, "r%d", insn);
> +      *style = dis_style_register;
>        break;
>
>      case 'd':
> @@ -81,10 +83,13 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", 16 + (insn & 0xf));
>        else
>         sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'w':
>        sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3));
> +      *style = dis_style_register;
>        break;
>
>      case 'a':
> @@ -92,6 +97,8 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", 16 + (insn & 7));
>        else
>         sprintf (buf, "r%d", 16 + ((insn >> 4) & 7));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'v':
> @@ -99,6 +106,8 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", (insn & 0xf) * 2);
>        else
>         sprintf (buf, "r%d", ((insn & 0xf0) >> 3));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'e':
> @@ -119,6 +128,7 @@ avr_operand (unsigned int        insn,
>             default: xyz = "??"; ok = 0;
>           }
>         strcpy (buf, xyz);
> +       *style = dis_style_register;
>
>         if (AVR_UNDEF_P (insn))
>           sprintf (comment, _("undefined"));
> @@ -143,6 +153,8 @@ avr_operand (unsigned int        insn,
>        *buf = '\0';
>        if (AVR_UNDEF_P (insn))
>         sprintf (comment, _("undefined"));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'b':
> @@ -159,6 +171,7 @@ avr_operand (unsigned int        insn,
>           *buf++ = 'Z';
>         sprintf (buf, "+%d", x);
>         sprintf (comment, "0x%02x", x);
> +       *style = dis_style_register;
>        }
>        break;
>
> @@ -173,6 +186,7 @@ avr_operand (unsigned int        insn,
>        info->insn_info_valid = 1;
>        info->insn_type = dis_jsr;
>        info->target = *sym_addr;
> +      *style = dis_style_address;
>        break;
>
>      case 'L':
> @@ -185,6 +199,7 @@ avr_operand (unsigned int        insn,
>          info->insn_info_valid = 1;
>          info->insn_type = dis_branch;
>          info->target = *sym_addr;
> +       *style = dis_style_address_offset;
>        }
>        break;
>
> @@ -199,6 +214,7 @@ avr_operand (unsigned int        insn,
>          info->insn_info_valid = 1;
>          info->insn_type = dis_condbranch;
>          info->target = *sym_addr;
> +       *style = dis_style_address_offset;
>        }
>        break;
>
> @@ -209,6 +225,7 @@ avr_operand (unsigned int        insn,
>          *sym_addr = val;
>          sprintf (buf, "0x%04X", insn2);
>          strcpy (comment, comment_start);
> +       *style = dis_style_immediate;
>        }
>        break;
>
> @@ -222,12 +239,14 @@ avr_operand (unsigned int        insn,
>          *sym_addr = val | 0x800000;
>          sprintf (buf, "0x%02x", val);
>          strcpy (comment, comment_start);
> +       *style = dis_style_immediate;
>        }
>        break;
>
>      case 'M':
>        sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
>        sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf));
> +      *style = dis_style_immediate;
>        break;
>
>      case 'n':
> @@ -244,15 +263,18 @@ avr_operand (unsigned int        insn,
>         x = (insn & 0xf) | ((insn >> 2) & 0x30);
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_immediate;
>        }
>        break;
>
>      case 's':
>        sprintf (buf, "%d", insn & 7);
> +      *style = dis_style_immediate;
>        break;
>
>      case 'S':
>        sprintf (buf, "%d", (insn >> 4) & 7);
> +      *style = dis_style_immediate;
>        break;
>
>      case 'P':
> @@ -263,6 +285,7 @@ avr_operand (unsigned int        insn,
>         x |= (insn >> 5) & 0x30;
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_address;
>        }
>        break;
>
> @@ -273,11 +296,13 @@ avr_operand (unsigned int        insn,
>         x = (insn >> 3) & 0x1f;
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_address;
>        }
>        break;
>
>      case 'E':
>        sprintf (buf, "%d", (insn >> 4) & 15);
> +      *style = dis_style_immediate;
>        break;
>
>      case '?':
> @@ -323,12 +348,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>    const struct avr_opcodes_s *opcode;
>    static unsigned int *maskptr;
>    void *stream = info->stream;
> -  fprintf_ftype prin = info->fprintf_func;
> +  fprintf_styled_ftype prin = info->fprintf_styled_func;
>    static unsigned int *avr_bin_masks;
>    static int initialized;
>    int cmd_len = 2;
>    int ok = 0;
>    char op1[20], op2[20], comment1[40], comment2[40];
> +  enum disassembler_style style_op1, style_op2;
>    int sym_op1 = 0, sym_op2 = 0;
>    bfd_vma sym_addr1, sym_addr2;
>
> @@ -400,6 +426,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>    op2[0] = 0;
>    comment1[0] = 0;
>    comment2[0] = 0;
> +  style_op1 = dis_style_text;
> +  style_op2 = dis_style_text;
>
>    if (opcode->name)
>      {
> @@ -421,12 +449,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>           int regs = REGISTER_P (*constraints);
>
>           ok = avr_operand (insn, insn2, addr, *constraints, opcode_str,
> op1,
> -                           comment1, 0, &sym_op1, &sym_addr1, info);
> +                           comment1, &style_op1, 0, &sym_op1, &sym_addr1,
> +                           info);
>
>           if (ok && *(++constraints) == ',')
>             ok = avr_operand (insn, insn2, addr, *(++constraints),
> opcode_str,
> -                             op2, *comment1 ? comment2 : comment1, regs,
> -                             &sym_op2, &sym_addr2, info);
> +                             op2, *comment1 ? comment2 : comment1,
> +                             &style_op2, regs, &sym_op2, &sym_addr2,
> info);
>         }
>      }
>
> @@ -439,22 +468,26 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>        comment2[0] = 0;
>      }
>
> -  (*prin) (stream, "%s", ok ? opcode->name : ".word");
> +  (*prin) (stream, ok ? dis_style_mnemonic :
> dis_style_assembler_directive,
> +          "%s", ok ? opcode->name : ".word");
>
>    if (*op1)
> -      (*prin) (stream, "\t%s", op1);
> +    (*prin) (stream, style_op1, "\t%s", op1);
>
>    if (*op2)
> -    (*prin) (stream, ", %s", op2);
> +    {
> +      (*prin) (stream, dis_style_text, ", ");
> +      (*prin) (stream, style_op2, "%s", op2);
> +    }
>
>    if (*comment1)
> -    (*prin) (stream, "\t; %s", comment1);
> +    (*prin) (stream, dis_style_comment_start, "\t; %s", comment1);
>
>    if (sym_op1)
>      info->print_address_func (sym_addr1, info);
>
>    if (*comment2)
> -    (*prin) (stream, " %s", comment2);
> +    (*prin) (stream, dis_style_comment_start, " %s", comment2);
>
>    if (sym_op2)
>      info->print_address_func (sym_addr2, info);
> diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
> index 5a472ce5349..375ab133439 100644
> --- a/opcodes/disassemble.c
> +++ b/opcodes/disassemble.c
> @@ -624,6 +624,11 @@ disassemble_init_for_target (struct disassemble_info
> * info)
>        info->disassembler_needs_relocs = true;
>        break;
>  #endif
> +#ifdef ARCH_avr
> +    case bfd_arch_avr:
> +      info->created_styled_output = true;
> +      break;
> +#endif
>  #ifdef ARCH_csky
>      case bfd_arch_csky:
>        info->symbol_is_valid = csky_symbol_is_valid;
> --
> 2.34.1
>
>

-- 
Marcus Nilsson
-
tel: +46(0)704911844
mail: marcus@landmarknilsson.se
github: github.com/metmo
linkedin: linkedin.com/in/landmarknilsson

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

* [PING][PATCH] opcodes/avr: Implement style support in the disassembler
  2022-06-06 19:11 [PATCH] opcodes/avr: Implement style support in the disassembler Marcus Nilsson
  2022-06-17  8:57 ` Marcus Nilsson
@ 2022-06-29 17:20 ` Marcus Nilsson
  2022-06-30 11:10   ` Nick Clifton
  1 sibling, 1 reply; 4+ messages in thread
From: Marcus Nilsson @ 2022-06-29 17:20 UTC (permalink / raw)
  To: binutils

One more ping for this one

Thanks,
Marcus Nilsson

On Mon, Jun 6, 2022 at 9:11 PM Marcus Nilsson <brainbomb@gmail.com> wrote:

> Update the AVR disassembler to supply style information to the
> disassembler output.
>
> By adding an additional parameter to avr_operand() we can fill in
> style information for each operand. The output formatting remains
> unchanged.
>
> opcodes/ChangeLog:
>         * disassemble.c: (disassemble_init_for_target): Set
>         created_styled_output for AVR based targets.
>         * avr-dis.c: (print_insn_avr): Use fprintf_styled_ftype
>         instead of fprintf_ftype throughout.
>         (avr_operand): Pass in and fill disassembler_style when
>         parsing operands.
> ---
>  opcodes/avr-dis.c     | 51 +++++++++++++++++++++++++++++++++++--------
>  opcodes/disassemble.c |  5 +++++
>  2 files changed, 47 insertions(+), 9 deletions(-)
>
> diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c
> index aab37962688..0614e7dd746 100644
> --- a/opcodes/avr-dis.c
> +++ b/opcodes/avr-dis.c
> @@ -56,6 +56,7 @@ avr_operand (unsigned int        insn,
>               char *              opcode_str,
>              char *              buf,
>              char *              comment,
> +            enum disassembler_style *  style,
>              int                 regs,
>              int *               sym,
>              bfd_vma *           sym_addr,
> @@ -74,6 +75,7 @@ avr_operand (unsigned int        insn,
>         insn = (insn & 0x01f0) >> 4; /* Destination register.  */
>
>        sprintf (buf, "r%d", insn);
> +      *style = dis_style_register;
>        break;
>
>      case 'd':
> @@ -81,10 +83,13 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", 16 + (insn & 0xf));
>        else
>         sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'w':
>        sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3));
> +      *style = dis_style_register;
>        break;
>
>      case 'a':
> @@ -92,6 +97,8 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", 16 + (insn & 7));
>        else
>         sprintf (buf, "r%d", 16 + ((insn >> 4) & 7));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'v':
> @@ -99,6 +106,8 @@ avr_operand (unsigned int        insn,
>         sprintf (buf, "r%d", (insn & 0xf) * 2);
>        else
>         sprintf (buf, "r%d", ((insn & 0xf0) >> 3));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'e':
> @@ -119,6 +128,7 @@ avr_operand (unsigned int        insn,
>             default: xyz = "??"; ok = 0;
>           }
>         strcpy (buf, xyz);
> +       *style = dis_style_register;
>
>         if (AVR_UNDEF_P (insn))
>           sprintf (comment, _("undefined"));
> @@ -143,6 +153,8 @@ avr_operand (unsigned int        insn,
>        *buf = '\0';
>        if (AVR_UNDEF_P (insn))
>         sprintf (comment, _("undefined"));
> +
> +      *style = dis_style_register;
>        break;
>
>      case 'b':
> @@ -159,6 +171,7 @@ avr_operand (unsigned int        insn,
>           *buf++ = 'Z';
>         sprintf (buf, "+%d", x);
>         sprintf (comment, "0x%02x", x);
> +       *style = dis_style_register;
>        }
>        break;
>
> @@ -173,6 +186,7 @@ avr_operand (unsigned int        insn,
>        info->insn_info_valid = 1;
>        info->insn_type = dis_jsr;
>        info->target = *sym_addr;
> +      *style = dis_style_address;
>        break;
>
>      case 'L':
> @@ -185,6 +199,7 @@ avr_operand (unsigned int        insn,
>          info->insn_info_valid = 1;
>          info->insn_type = dis_branch;
>          info->target = *sym_addr;
> +       *style = dis_style_address_offset;
>        }
>        break;
>
> @@ -199,6 +214,7 @@ avr_operand (unsigned int        insn,
>          info->insn_info_valid = 1;
>          info->insn_type = dis_condbranch;
>          info->target = *sym_addr;
> +       *style = dis_style_address_offset;
>        }
>        break;
>
> @@ -209,6 +225,7 @@ avr_operand (unsigned int        insn,
>          *sym_addr = val;
>          sprintf (buf, "0x%04X", insn2);
>          strcpy (comment, comment_start);
> +       *style = dis_style_immediate;
>        }
>        break;
>
> @@ -222,12 +239,14 @@ avr_operand (unsigned int        insn,
>          *sym_addr = val | 0x800000;
>          sprintf (buf, "0x%02x", val);
>          strcpy (comment, comment_start);
> +       *style = dis_style_immediate;
>        }
>        break;
>
>      case 'M':
>        sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
>        sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf));
> +      *style = dis_style_immediate;
>        break;
>
>      case 'n':
> @@ -244,15 +263,18 @@ avr_operand (unsigned int        insn,
>         x = (insn & 0xf) | ((insn >> 2) & 0x30);
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_immediate;
>        }
>        break;
>
>      case 's':
>        sprintf (buf, "%d", insn & 7);
> +      *style = dis_style_immediate;
>        break;
>
>      case 'S':
>        sprintf (buf, "%d", (insn >> 4) & 7);
> +      *style = dis_style_immediate;
>        break;
>
>      case 'P':
> @@ -263,6 +285,7 @@ avr_operand (unsigned int        insn,
>         x |= (insn >> 5) & 0x30;
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_address;
>        }
>        break;
>
> @@ -273,11 +296,13 @@ avr_operand (unsigned int        insn,
>         x = (insn >> 3) & 0x1f;
>         sprintf (buf, "0x%02x", x);
>         sprintf (comment, "%d", x);
> +       *style = dis_style_address;
>        }
>        break;
>
>      case 'E':
>        sprintf (buf, "%d", (insn >> 4) & 15);
> +      *style = dis_style_immediate;
>        break;
>
>      case '?':
> @@ -323,12 +348,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>    const struct avr_opcodes_s *opcode;
>    static unsigned int *maskptr;
>    void *stream = info->stream;
> -  fprintf_ftype prin = info->fprintf_func;
> +  fprintf_styled_ftype prin = info->fprintf_styled_func;
>    static unsigned int *avr_bin_masks;
>    static int initialized;
>    int cmd_len = 2;
>    int ok = 0;
>    char op1[20], op2[20], comment1[40], comment2[40];
> +  enum disassembler_style style_op1, style_op2;
>    int sym_op1 = 0, sym_op2 = 0;
>    bfd_vma sym_addr1, sym_addr2;
>
> @@ -400,6 +426,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>    op2[0] = 0;
>    comment1[0] = 0;
>    comment2[0] = 0;
> +  style_op1 = dis_style_text;
> +  style_op2 = dis_style_text;
>
>    if (opcode->name)
>      {
> @@ -421,12 +449,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>           int regs = REGISTER_P (*constraints);
>
>           ok = avr_operand (insn, insn2, addr, *constraints, opcode_str,
> op1,
> -                           comment1, 0, &sym_op1, &sym_addr1, info);
> +                           comment1, &style_op1, 0, &sym_op1, &sym_addr1,
> +                           info);
>
>           if (ok && *(++constraints) == ',')
>             ok = avr_operand (insn, insn2, addr, *(++constraints),
> opcode_str,
> -                             op2, *comment1 ? comment2 : comment1, regs,
> -                             &sym_op2, &sym_addr2, info);
> +                             op2, *comment1 ? comment2 : comment1,
> +                             &style_op2, regs, &sym_op2, &sym_addr2,
> info);
>         }
>      }
>
> @@ -439,22 +468,26 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
>        comment2[0] = 0;
>      }
>
> -  (*prin) (stream, "%s", ok ? opcode->name : ".word");
> +  (*prin) (stream, ok ? dis_style_mnemonic :
> dis_style_assembler_directive,
> +          "%s", ok ? opcode->name : ".word");
>
>    if (*op1)
> -      (*prin) (stream, "\t%s", op1);
> +    (*prin) (stream, style_op1, "\t%s", op1);
>
>    if (*op2)
> -    (*prin) (stream, ", %s", op2);
> +    {
> +      (*prin) (stream, dis_style_text, ", ");
> +      (*prin) (stream, style_op2, "%s", op2);
> +    }
>
>    if (*comment1)
> -    (*prin) (stream, "\t; %s", comment1);
> +    (*prin) (stream, dis_style_comment_start, "\t; %s", comment1);
>
>    if (sym_op1)
>      info->print_address_func (sym_addr1, info);
>
>    if (*comment2)
> -    (*prin) (stream, " %s", comment2);
> +    (*prin) (stream, dis_style_comment_start, " %s", comment2);
>
>    if (sym_op2)
>      info->print_address_func (sym_addr2, info);
> diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
> index 5a472ce5349..375ab133439 100644
> --- a/opcodes/disassemble.c
> +++ b/opcodes/disassemble.c
> @@ -624,6 +624,11 @@ disassemble_init_for_target (struct disassemble_info
> * info)
>        info->disassembler_needs_relocs = true;
>        break;
>  #endif
> +#ifdef ARCH_avr
> +    case bfd_arch_avr:
> +      info->created_styled_output = true;
> +      break;
> +#endif
>  #ifdef ARCH_csky
>      case bfd_arch_csky:
>        info->symbol_is_valid = csky_symbol_is_valid;
> --
> 2.34.1
>
>

-- 
Marcus Nilsson
-
tel: +46(0)704911844
mail: marcus@landmarknilsson.se
github: github.com/metmo
linkedin: linkedin.com/in/landmarknilsson

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

* Re: [PING][PATCH] opcodes/avr: Implement style support in the disassembler
  2022-06-29 17:20 ` [PING][PATCH] " Marcus Nilsson
@ 2022-06-30 11:10   ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2022-06-30 11:10 UTC (permalink / raw)
  To: Marcus Nilsson, binutils

Hi Marcus,

> One more ping for this one

Sorry for the silence. :-(

>> opcodes/ChangeLog:
>>          * disassemble.c: (disassemble_init_for_target): Set
>>          created_styled_output for AVR based targets.
>>          * avr-dis.c: (print_insn_avr): Use fprintf_styled_ftype
>>          instead of fprintf_ftype throughout.
>>          (avr_operand): Pass in and fill disassembler_style when
>>          parsing operands.

Patch approved = please apply.

Cheers
   Nick


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

end of thread, other threads:[~2022-06-30 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 19:11 [PATCH] opcodes/avr: Implement style support in the disassembler Marcus Nilsson
2022-06-17  8:57 ` Marcus Nilsson
2022-06-29 17:20 ` [PING][PATCH] " Marcus Nilsson
2022-06-30 11:10   ` Nick Clifton

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