From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id AF6C53858D28 for ; Tue, 17 Jan 2023 10:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF6C53858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673951868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e3S1acadrzSEiHCcNyP1ZNuNe1J9tPfOOr3/3Jx3axw=; b=BpsuyBdFCF9mo0Axw8JlJvELE7LI2TSE5uR63YqDPpenXppqsmc4i40Pfsghon2hgVwzs6 tZiCFwuUHbShysZHibcPw3LUbWnmAwjqrJGZL8FoozdpP7x60+9M0qXo/6Viu6Q6BqKbnS 76dgraC9MuKAOpznC2dmA5GhOqLSG10= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-142-y6p7hriuNoCzfaZ0GtcpJg-1; Tue, 17 Jan 2023 05:37:47 -0500 X-MC-Unique: y6p7hriuNoCzfaZ0GtcpJg-1 Received: by mail-qv1-f69.google.com with SMTP id lv8-20020a056214578800b0053477624294so5922650qvb.22 for ; Tue, 17 Jan 2023 02:37:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e3S1acadrzSEiHCcNyP1ZNuNe1J9tPfOOr3/3Jx3axw=; b=GAICteuwZGVW66XT1da3/zgWtMFfurHvYA1PmhDgU5V4OCFDLz9640XhH1hWQmDFY9 bMz79vJLX9GmVssKh8IJtc2Xkjg82II5mLW1K3IgfDVK8x5y3GV7+UeqhiWXIgj9jJGb eS6dbnFeOtDkkNLR01W88/DB4DnMmRPjrVYQV7Dh3pxlFKtOuCnTlQ28trJSLIJagjnV CMl+/qAlIe7EL0UNe+jmGn/gNHY1GeiDAW+Fz3LxUQGoTJPLiaqULBB1nDyklTVBmdiG kCYomDIS2mENWO8kWMfigQcFg1skUsXgTTOMjdwzqO0n0jqu4Aj/Y90QqatEc+lVZqsO kp+Q== X-Gm-Message-State: AFqh2kqlTXfaA1A0PyUYjl/uy5tWGg8UjhhVPhdyPkbwBWJXGuLeyCWx r0halSD2ONG6WK8qWaPUyYbpCgUJ2Y9cCyQxe/IbDXkSfV5593baBNU9+tVOuY1EgGfK1BQcvvJ 48P0gVglRPHGfeRLbIA== X-Received: by 2002:a05:622a:114e:b0:3a6:58fd:4e5e with SMTP id f14-20020a05622a114e00b003a658fd4e5emr44896372qty.24.1673951866696; Tue, 17 Jan 2023 02:37:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXv7PSzjdlJgnLnjWhRg28HayZRbbPUEtBbCKDv8SiEQ8Bo62cBV46DQQRsbVT3H4mZvA6ST8g== X-Received: by 2002:a05:622a:114e:b0:3a6:58fd:4e5e with SMTP id f14-20020a05622a114e00b003a658fd4e5emr44896357qty.24.1673951866464; Tue, 17 Jan 2023 02:37:46 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id 9-20020ac85709000000b003b63a734434sm1388886qtw.52.2023.01.17.02.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 02:37:46 -0800 (PST) From: Andrew Burgess To: WANG Xuerui , binutils@sourceware.org Cc: Chenghua Xu , Zhensong Liu , Qinggang Meng , Xi Ruoyao , WANG Xuerui Subject: Re: [PATCH v3 3/6] opcodes/loongarch: implement style support in the disassembler In-Reply-To: <20221214055204.2890795-4-i.swmail@xen0n.name> References: <20221214055204.2890795-1-i.swmail@xen0n.name> <20221214055204.2890795-4-i.swmail@xen0n.name> Date: Tue, 17 Jan 2023 10:37:44 +0000 Message-ID: <877cxlfnuv.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: WANG Xuerui writes: > From: WANG Xuerui > > 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#"); Based just on the preceding comment, I'm guessing the '#' here is the start of a comment. There is a dis_style_comment_start which styles everything from the first dis_style_comment_start until the end of the line, as a comment, thus: info->fprintf_styled_func (info->stream, dis_style_comment_start, "#"); info->fprintf_styled_func (info->stream, dis_style_text, " This is text!"); Will style both of these using the comment style, despite the second item being given the dis_style_text. Additionally, I notice that the `if` condition that guards the printing of '\t#' is identical to the immediately following `if`, so you could fold the `\t#` into the second if block. Thanks, Andrew > > 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