From patchwork Tue Nov 15 04:52:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 20187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2521264wru; Mon, 14 Nov 2022 20:58:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf69nhq+lZ+Tjs93eIXVryBSdqSKYOUpewlrWsRC+43gqZYzE+N3vv/Nlg7tzWsCEHW7VNXg X-Received: by 2002:aa7:d4d3:0:b0:45f:b80f:1fe8 with SMTP id t19-20020aa7d4d3000000b0045fb80f1fe8mr13032517edr.118.1668488335932; Mon, 14 Nov 2022 20:58:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668488335; cv=none; d=google.com; s=arc-20160816; b=nrauDY6J6/z1Gytvhx9osw47ygRwdqJMIgoTUqtdagQtfNyE/b2qXn0HVZJGCTpKi0 /+6pkEEAOLjF4mZEc7z9f8Nt8UQGKsJomJ/BvViUXxUpPWxyogjcmjsFThkRPz2g0/G6 tV1gFuH4WGrUZTZw4YysR8IWbt4D+n1izEJETmKDaYngxftLS6iaXwTBi67ucorL+Mg+ GIZa20qlpOjSLEI2ZQpa/3LsyIj7FOiz6CApUm0b6nEliqqSGsgarnk6cnnHOYD2atp3 8ee4FVquo8oTZ2mnPDUF76k5nVZDHuNmtbd356WsviPZAaYpp4pJm4vwY2pkgnm/XFSg DhNg== 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=GQRh4n8J1DQh3RBftXPuwECF7e5ZkecXkOX4DGjnfbA=; b=Hiphccb0F7axArlIV86znWtMVnoYPKBTo8Gx3OBCiXBUBNoxUQrGsVQA+Os3xAYZhm aBwDqGDX6lRzQ87vyJa71KZCeZt450bL9n8pFrrB+R1HF6dDG9VZagNRoQPcmSNhDbNT CbeWVUlHFHSF4d1aWWW4Hf3xItN29M4ixQn1sRcu3CNxjIo99RonbJ/maMVIFLU8IeAw YLiF8XST8r8oqGB0HjvfO6icqqWA9ZKOBPeJLUrqmWI8mrDtwobdxmKoiQzhdqNKBEvl Cgh2iyeeWwso4deFZl6TViNvG/BVfvZ6KG+IZ5a6MluDiJgzsTkaIe5eo4nLhQI7JTjY ZlVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=adFaZ0VW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id wu10-20020a170906eeca00b0078d27c1b499si10910634ejb.500.2022.11.14.20.58.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 20:58:55 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=adFaZ0VW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 CD81C382D3A5 for ; Tue, 15 Nov 2022 04:58:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD81C382D3A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668488305; bh=GQRh4n8J1DQh3RBftXPuwECF7e5ZkecXkOX4DGjnfbA=; 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=adFaZ0VWGWYO78Gy3C5kivKM/wfXFLJ78VNapiDPg0hmgifcr9seO9kCp5Pjr1D9L hnqjl80VvOcCcyPGe46Vo91iYsXlH2Gd4jmm/musKuHIg4HwxT5lyptBFeGUckakzS SDodZ20G0efFh7zpoOa7E18V+sLbAyuQao2kA3as= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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) 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 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?1749536825560433114?= 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; }