From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 01E58382EF38 for ; Tue, 15 Nov 2022 04:58:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01E58382EF38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 56401300089; Tue, 15 Nov 2022 04:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1668488295; bh=GQRh4n8J1DQh3RBftXPuwECF7e5ZkecXkOX4DGjnfbA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Mime-Version:Content-Transfer-Encoding; b=PQJGbcrmhP6WCkLWR5zLrEeV+LqA82C3W7TmGhpE+OFbbHFu40hs36+FvXVi3wyNT xHG2i4oHwSNVnBnBvibekoV7Eb8sN42ZgfN+cEJQPzv981lYUpEEb/rxgOLtyV1OM1 oziREfxyZZ9Fzny4h2yb5p7EBg+CRffhpnoCAJJo= From: Tsukasa OI To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Cc: binutils@sourceware.org Subject: [PATCH 04/11] RISC-V: Split riscv_get_map_state into two steps Date: Tue, 15 Nov 2022 04:52:47 +0000 Message-Id: In-Reply-To: References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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 d3bd4ceec1e..3135db30ccd 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -816,6 +816,24 @@ riscv_disassemble_insn (bfd_vma memaddr, insn_t word, disassemble_info *info) 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. */ @@ -824,28 +842,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; } -- 2.37.2