From patchwork Mon Nov 28 04:43:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 26497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5433036wrr; Sun, 27 Nov 2022 20:46:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+6LgDII1BKmRj9KxUVQ62zoLYbyyn4JAFMtjKJJLgvM5cD38vm/UBL0rBhu99u65sCbDU X-Received: by 2002:a17:907:a709:b0:79f:cd7c:e861 with SMTP id vw9-20020a170907a70900b0079fcd7ce861mr40670512ejc.339.1669610819866; Sun, 27 Nov 2022 20:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669610819; cv=none; d=google.com; s=arc-20160816; b=qqUQeF3ute6jSID/2gG4tYjynmOz5+wP0SxWgUcsNqoqBpUoqYzTqzi5f/z1ywvGT/ LInsV8kcmZBPN9BSU2AqGRuh6mkGinRDUVYknYB4KV8sYR8WlHE6sXiJLrRQBaenpBaa SylNVxBANlRXAVc2fwT79DpAIF8/sBH1mD0siNKy3zoysjJXjMM/PKG8L24FYDkmxNY9 m+tNvQcj0fKDK4/EVSYk2P4qhPOemasdGSZ3D5w+KeNBqk+0OjLxYhlBk1hBBAF26xdE xB+yIGaMyWmKTI27f9fz1/rjfFeJlaOlwXSK31KdUEMfv3tW13u7WzKC8HajVnqeEuBs ir9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=aYMPmris9xEH07eV+RcaAF8Nyhc+DvwAZYRNQFL1Hpo=; b=1BQzIGJNDRZp3bAbhrWXb4yqejMvk/AApqNbfZ1Gxst+c/rvO1V91oV5nbB2l2Th02 T2F6lAIb5J9y6Nom6VSP/CrUyAzAHfAGbftLqFfp+3JvzJmz4qtTRaATbXDyfdoc8HzC hK+1J62dvCNjGYM+VL1mNsJwE3KpZa/81ywmgwqcOnf6KF2NxuKB6ng14aR5UvpGwJ90 Ng02X0G8Tfewjr+OkciwadeMOqYoQjHIr5BhPbJL2+svT50EDM9QyF0XDHY+MGq2xkAP OHUv0+EU+iOLkY1wTmD/dGPQll1/tZ7qgxUJn3DqMr6rxnM/+qBW23yzuEIb8+f8XOg9 kVww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=x78yyj6E; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xe14-20020a170907318e00b007ae85c3b7b3si9568153ejb.362.2022.11.27.20.46.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 20:46:59 -0800 (PST) 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=@sourceware.org header.s=default header.b=x78yyj6E; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67661384EF40 for ; Mon, 28 Nov 2022 04:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67661384EF40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669610737; bh=aYMPmris9xEH07eV+RcaAF8Nyhc+DvwAZYRNQFL1Hpo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x78yyj6EGWyfRY8QBG/9NLF5F0upkdnHAmEwPuaZj6BwtwO4s36qqVYyvoeSVUWx9 rvMa7SJwBXELCNfIko+xLXLCuLHHaTdbxKbZYr/tm3dDhrdd3Inu1Gedm97nxl5y2P icCxBt2QsXxguCjM2TgWkFNmWt4N0JiN9OFo0Urg= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 9BC29385B53D for ; Mon, 28 Nov 2022 04:44:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9BC29385B53D Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id EF94D300089; Mon, 28 Nov 2022 04:44:46 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Cc: binutils@sourceware.org Subject: [PATCH v2 04/11] RISC-V: Split riscv_get_map_state into two steps Date: Mon, 28 Nov 2022 04:43:39 +0000 Message-Id: <395973f56b805a000b0e2929c6b2ba6cd8fd140b.1669610611.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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 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: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI 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?1749536825560433114?= X-GMAIL-MSGID: =?utf-8?q?1750713834970964958?= From: Tsukasa OI Because mapping symbol optimization would remove riscv_get_map_state function, this commit splits symbol name checking step into a separate function riscv_get_map_state_by_name. Let alone the optimization, splitting the code improves readability. opcodes/ChangeLog: * riscv-dis.c (riscv_get_map_state): Split symbol name checking into a separate function. (riscv_get_map_state_by_name): New. --- opcodes/riscv-dis.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index f6fdd5badfe6..38eb91349d9a 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -818,6 +818,24 @@ riscv_disassemble_insn (bfd_vma memaddr, return insnlen; } +/* Return new mapping state if a given symbol name is of mapping symbols', + MAP_NONE otherwise. If arch is not NULL and name denotes a mapping symbol + with ISA string, *arch is updated to the ISA string. */ + +static enum riscv_seg_mstate +riscv_get_map_state_by_name (const char *name, const char** arch) +{ + if (startswith (name, "$x")) + { + if (arch && startswith (name + 2, "rv")) + *arch = name + 2; + return MAP_INSN; + } + else if (startswith (name, "$d")) + return MAP_DATA; + return MAP_NONE; +} + /* Return true if we find the suitable mapping symbol, and also update the STATE. Otherwise, return false. */ @@ -826,28 +844,23 @@ riscv_get_map_state (int n, enum riscv_seg_mstate *state, struct disassemble_info *info) { - const char *name; + const char *name, *arch = NULL; /* If the symbol is in a different section, ignore it. */ if (info->section != NULL && info->section != info->symtab[n]->section) return false; - name = bfd_asymbol_name(info->symtab[n]); - if (startswith (name, "$x")) + name = bfd_asymbol_name (info->symtab[n]); + enum riscv_seg_mstate newstate = riscv_get_map_state_by_name (name, &arch); + if (newstate == MAP_NONE) + return false; + *state = newstate; + if (arch) { - if (startswith (name + 2, "rv")) - { - riscv_release_subset_list (&riscv_subsets); - riscv_parse_subset (&riscv_rps_dis, name + 2); - } - *state = MAP_INSN; + riscv_release_subset_list (&riscv_subsets); + riscv_parse_subset (&riscv_rps_dis, arch); } - else if (startswith (name, "$d")) - *state = MAP_DATA; - else - return false; - return true; }