From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2124) id 50DC33858C52; Mon, 4 Jul 2022 10:26:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50DC33858C52 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Nick Clifton To: bfd-cvs@sourceware.org Subject: [binutils-gdb] opcodes/avr: Implement style support in the disassembler X-Act-Checkin: binutils-gdb X-Git-Author: Marcus Nilsson X-Git-Refname: refs/heads/master X-Git-Oldrev: 2c474c46943e5242f356a0c0676e2f7bd223c8a9 X-Git-Newrev: a0f3a4c646cce619b6c5392b4ec8dcceeb5729ba Message-Id: <20220704102609.50DC33858C52@sourceware.org> Date: Mon, 4 Jul 2022 10:26:09 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 10:26:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da0f3a4c646cc= e619b6c5392b4ec8dcceeb5729ba commit a0f3a4c646cce619b6c5392b4ec8dcceeb5729ba Author: Marcus Nilsson Date: Mon Jul 4 11:25:42 2022 +0100 opcodes/avr: Implement style support in the disassembler =20 * 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. Diff: --- opcodes/ChangeLog | 9 +++++++++ opcodes/avr-dis.c | 51 +++++++++++++++++++++++++++++++++++++++++------= ---- opcodes/disassemble.c | 5 +++++ 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 3d9f4a14532..c51b1734e20 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,12 @@ +2022-07-04 Marcus Nilsson + + * 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. + 2022-04-07 Andreas Krebbel =20 * s390-mkopc.c (main): Enable z16 as CPU string in the opcode diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c index aab37962688..7e5d4d520e7 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 =3D (insn & 0x01f0) >> 4; /* Destination register. */ =20 sprintf (buf, "r%d", insn); + *style =3D dis_style_register; break; =20 case 'd': @@ -81,10 +83,12 @@ avr_operand (unsigned int insn, sprintf (buf, "r%d", 16 + (insn & 0xf)); else sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4)); + *style =3D dis_style_register; break; =20 case 'w': sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3)); + *style =3D dis_style_register; break; =20 case 'a': @@ -92,6 +96,7 @@ avr_operand (unsigned int insn, sprintf (buf, "r%d", 16 + (insn & 7)); else sprintf (buf, "r%d", 16 + ((insn >> 4) & 7)); + *style =3D dis_style_register; break; =20 case 'v': @@ -99,6 +104,7 @@ avr_operand (unsigned int insn, sprintf (buf, "r%d", (insn & 0xf) * 2); else sprintf (buf, "r%d", ((insn & 0xf0) >> 3)); + *style =3D dis_style_register; break; =20 case 'e': @@ -123,6 +129,7 @@ avr_operand (unsigned int insn, if (AVR_UNDEF_P (insn)) sprintf (comment, _("undefined")); } + *style =3D dis_style_register; break; =20 case 'z': @@ -143,6 +150,7 @@ avr_operand (unsigned int insn, *buf =3D '\0'; if (AVR_UNDEF_P (insn)) sprintf (comment, _("undefined")); + *style =3D dis_style_register; break; =20 case 'b': @@ -159,6 +167,7 @@ avr_operand (unsigned int insn, *buf++ =3D 'Z'; sprintf (buf, "+%d", x); sprintf (comment, "0x%02x", x); + *style =3D dis_style_register; } break; =20 @@ -173,6 +182,7 @@ avr_operand (unsigned int insn, info->insn_info_valid =3D 1; info->insn_type =3D dis_jsr; info->target =3D *sym_addr; + *style =3D dis_style_address; break; =20 case 'L': @@ -185,6 +195,7 @@ avr_operand (unsigned int insn, info->insn_info_valid =3D 1; info->insn_type =3D dis_branch; info->target =3D *sym_addr; + *style =3D dis_style_address_offset; } break; =20 @@ -199,6 +210,7 @@ avr_operand (unsigned int insn, info->insn_info_valid =3D 1; info->insn_type =3D dis_condbranch; info->target =3D *sym_addr; + *style =3D dis_style_address_offset; } break; =20 @@ -209,6 +221,7 @@ avr_operand (unsigned int insn, *sym_addr =3D val; sprintf (buf, "0x%04X", insn2); strcpy (comment, comment_start); + *style =3D dis_style_immediate; } break; =20 @@ -222,12 +235,14 @@ avr_operand (unsigned int insn, *sym_addr =3D val | 0x800000; sprintf (buf, "0x%02x", val); strcpy (comment, comment_start); + *style =3D dis_style_immediate; } break; =20 case 'M': sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf)); sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf)); + *style =3D dis_style_immediate; break; =20 case 'n': @@ -235,6 +250,7 @@ avr_operand (unsigned int insn, /* xgettext:c-format */ opcodes_error_handler (_("internal disassembler error")); ok =3D 0; + *style =3D dis_style_immediate; break; =20 case 'K': @@ -244,15 +260,18 @@ avr_operand (unsigned int insn, x =3D (insn & 0xf) | ((insn >> 2) & 0x30); sprintf (buf, "0x%02x", x); sprintf (comment, "%d", x); + *style =3D dis_style_immediate; } break; =20 case 's': sprintf (buf, "%d", insn & 7); + *style =3D dis_style_immediate; break; =20 case 'S': sprintf (buf, "%d", (insn >> 4) & 7); + *style =3D dis_style_immediate; break; =20 case 'P': @@ -263,6 +282,7 @@ avr_operand (unsigned int insn, x |=3D (insn >> 5) & 0x30; sprintf (buf, "0x%02x", x); sprintf (comment, "%d", x); + *style =3D dis_style_address; } break; =20 @@ -273,11 +293,13 @@ avr_operand (unsigned int insn, x =3D (insn >> 3) & 0x1f; sprintf (buf, "0x%02x", x); sprintf (comment, "%d", x); + *style =3D dis_style_address; } break; =20 case 'E': sprintf (buf, "%d", (insn >> 4) & 15); + *style =3D dis_style_immediate; break; =20 case '?': @@ -323,12 +345,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info) const struct avr_opcodes_s *opcode; static unsigned int *maskptr; void *stream =3D info->stream; - fprintf_ftype prin =3D info->fprintf_func; + fprintf_styled_ftype prin =3D info->fprintf_styled_func; static unsigned int *avr_bin_masks; static int initialized; int cmd_len =3D 2; int ok =3D 0; char op1[20], op2[20], comment1[40], comment2[40]; + enum disassembler_style style_op1, style_op2; int sym_op1 =3D 0, sym_op2 =3D 0; bfd_vma sym_addr1, sym_addr2; =20 @@ -400,6 +423,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info) op2[0] =3D 0; comment1[0] =3D 0; comment2[0] =3D 0; + style_op1 =3D dis_style_text; + style_op2 =3D dis_style_text; =20 if (opcode->name) { @@ -421,12 +446,14 @@ print_insn_avr (bfd_vma addr, disassemble_info *info) int regs =3D REGISTER_P (*constraints); =20 ok =3D 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); =20 if (ok && *(++constraints) =3D=3D ',') ok =3D 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); } } =20 @@ -439,22 +466,26 @@ print_insn_avr (bfd_vma addr, disassemble_info *info) comment2[0] =3D 0; } =20 - (*prin) (stream, "%s", ok ? opcode->name : ".word"); - + (*prin) (stream, ok ? dis_style_mnemonic : dis_style_assembler_directive, + "%s", ok ? opcode->name : ".word"); + =20 if (*op1) - (*prin) (stream, "\t%s", op1); + (*prin) (stream, style_op1, "\t%s", op1); =20 if (*op2) - (*prin) (stream, ", %s", op2); + { + (*prin) (stream, dis_style_text, ", "); + (*prin) (stream, style_op2, "%s", op2); + } =20 if (*comment1) - (*prin) (stream, "\t; %s", comment1); + (*prin) (stream, dis_style_comment_start, "\t; %s", comment1); =20 if (sym_op1) info->print_address_func (sym_addr1, info); =20 if (*comment2) - (*prin) (stream, " %s", comment2); + (*prin) (stream, dis_style_comment_start, " %s", comment2); =20 if (sym_op2) info->print_address_func (sym_addr2, info); diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index 17cf6378890..9c0dacaf391 100644 --- a/opcodes/disassemble.c +++ b/opcodes/disassemble.c @@ -618,6 +618,11 @@ disassemble_init_for_target (struct disassemble_info *= info) info->disassembler_needs_relocs =3D true; break; #endif +#ifdef ARCH_avr + case bfd_arch_avr: + info->created_styled_output =3D true; + break; +#endif #ifdef ARCH_csky case bfd_arch_csky: info->symbol_is_valid =3D csky_symbol_is_valid;