From patchwork Wed Jun 28 11:51:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WANG Xuerui X-Patchwork-Id: 113817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8861049vqr; Wed, 28 Jun 2023 04:52:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Qnb0UYBrXx8wfY6SqFlfe+RH6vt05yp543mQFj3myW4wDL7XdjhrY4sJDkGeuPwHvzmgx X-Received: by 2002:a05:6402:5210:b0:51a:41fd:9732 with SMTP id s16-20020a056402521000b0051a41fd9732mr1629884edd.11.1687953159332; Wed, 28 Jun 2023 04:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687953159; cv=none; d=google.com; s=arc-20160816; b=KBdsIoiJ1kv2JfNmmlJN44HVDFTP90Kti/UD314dyxkK/HiKIjvHEVD3qKTXOPZq1l lkSKrULgVLIAZ1PvFmp7KEDXRfUGZbBY2nExaeuAUgU1G2ubmh7d3g0mJ+Alb8UcKJJF YgRwzYhx3GGQMV6tUBx6BuDsWngF5PKZqg7P0R+x4rENDNtpyB5XWJrbkn9VcLTeus9z T8lmxzCWx5TBAYP7QmpiEXQaUOx+m1XTKRWp/JQq3yUh/un01Ka2NcoULnxnItjI0Ugy zSfTcXVMtRlLUUTl+iODDSdZC4B2Dp/kZ9lWkbFSLr9j6lTcceY3djQ8/OMQObBhk8yA 08zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=KRhrNB4HJQoj+Bk6/mbwoaQl/WGr6G5hT+sUKrqWn2g=; fh=F52lMKP/ag7PTpjpGsg79bnedhkoffS1BBUct4g/1x0=; b=Xx86+Rh8pB79GOmYfCUsK9KWZPSBg7o3ektVJAHuF1V1q5wngE5EDPMdA/zO2VFHb8 An/Qh6Ds8T3FHLC/savx23jW4+SFF/OgSXN1oo9JXcch6ylxaofpiyXFl3EaPPwnKxGS q28yUMQMA6bB2Q/z6JfjPchszaKpdAgrQ4i+sUn95LTMKtiU/dcwbk6p6BNpv9uDxPPT Kfs6S+CC/I+aPjLCcc1AmK2JdlBbC0a9V130gKHnWqOqLSC1FODUN6sZRAaRmHEXn9kh hEdV1vxdDZ8E5Ejoxhr7IUQtODBeGO6CqvawauLE/Rzf8nlOrVX9x0z8jeWcCgVHHL6Q s8HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=lg67GCJ8; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z24-20020aa7cf98000000b0051be56c8f79si4842972edx.10.2023.06.28.04.52.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 04:52:39 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=lg67GCJ8; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 257973856619 for ; Wed, 28 Jun 2023 11:51:51 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by sourceware.org (Postfix) with ESMTPS id 8C0083858298 for ; Wed, 28 Jun 2023 11:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C0083858298 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1687953085; bh=YBjfCk/xepuYPuO1bDPPWOkIq9Uqc2PZNrEDPHYEzLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lg67GCJ8xDGyi+0dvvKrP/7419L+2cCqErvvSLYciZC1O/sXYiMbRGooEJeFDy8nE lX8nj8jg8GCBfMwIUxdFuJt6g7O0orEOhtcse0tBEe1MHOqA+MGZFcgMLbxHsyHAt0 UroRgLyRb1L1NS/+J/sJSoeTa2nhKbedsQ602a7I= Received: from ld50.lan (unknown [101.88.25.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 36EF5605CA; Wed, 28 Jun 2023 19:51:25 +0800 (CST) From: WANG Xuerui To: binutils@sourceware.org Cc: Chenghua Xu , Zhensong Liu , Qinggang Meng , Lulu Cheng , Fangrui Song , Xi Ruoyao , WANG Xuerui Subject: [PATCH v5 3/6] opcodes/loongarch: implement style support in the disassembler Date: Wed, 28 Jun 2023 19:51:00 +0800 Message-Id: <20230628115103.3440262-4-i.swmail@xen0n.name> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230628115103.3440262-1-i.swmail@xen0n.name> References: <20230628115103.3440262-1-i.swmail@xen0n.name> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769947172151476309?= X-GMAIL-MSGID: =?utf-8?q?1769947172151476309?= 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 | 43 ++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index 03cfccc562e..7a4a641c2b9 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 085d0ab2d75..3238495a845 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,44 +230,40 @@ 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); } - 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#"); - if (info->insn_type == dis_branch || info->insn_type == dis_condbranch) { - info->fprintf_func (info->stream, " "); + info->fprintf_styled_func (info->stream, dis_style_comment_start, "\t# "); info->print_address_func (info->target, info); } }