From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id C5D0A3858292 for ; Mon, 8 Jan 2024 13:47:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5D0A3858292 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5D0A3858292 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721676; cv=none; b=tbpN9lRwRSqsGb3woQWwYxSUKp++Eoircuu/4IdtFTp7BdktnKUqrCjiiKD86/Z6pjyKhuGKk5cagO58jH4xTw40ibjJMHbe9wwJ2M6WKErm2pOnOVzEPUqqDs0cQcHL22Aa4gFIArMYbVwFQyxZRAoHujCN+Pea4FbPSFTgUys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704721676; c=relaxed/simple; bh=Y1+N7pfH2152+A/3ZwJxYJaO3fj+hxQisOpS9XXHfBA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GYfmZXclRT/yRXUZtn1cQz6+I5jof0o7Zo+rcaPbqngjCd8biuwy+wgiL6LYzYsTsNQFZgvEcvPx9PyTz31Y32jTylm8ug5JtYq9Qgv/L6M1+9xAY04BcMP9HC5GC4on3xjF9vSs92c6Bn7Y4kUUoBRuUgK8zHPQ5AP/iNGOmI0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d542701796so3008185ad.1 for ; Mon, 08 Jan 2024 05:47:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704721672; x=1705326472; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D/0+e0XHYwUoo+ZUcUk5RYifTfQWY2+4ucstYkojjVk=; b=frq9OczwMvxBrQ9JogbBIFprAYaSAjHhJwHXuTNab3t0pWTOELbQfBelz4fUEw1Onf rl5DYLXHs8Cn7T1ap3Z6vJVdlL7bgf6ReFR95T06e0q+0d4jamRSnFM6jrrtFEx+rCXQ 9WgIYO02RvqJsDMa/e+I04SfPGX+15FoZUp0P5WwhDZeRol+cYLlxkjXFw0rMfRla8MR Th5j0jVSZmdA7As3Vz65gVj4Jqt5TB5PcpwiCoiwbaLbHsRgVPV5bresgc/xP8ED2af8 sbaAjtJUrcJIa+Z64BS36P9nBvcYzmjE3U1ck6twOung9dvCFNQdWgQ7dvQprP0TKEPk huhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704721672; x=1705326472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D/0+e0XHYwUoo+ZUcUk5RYifTfQWY2+4ucstYkojjVk=; b=HKhaobBmqO+LSzSUvJQ9TY5n8/Ho7rcNtgL3p2DY7opLHMZiylJCb4gbUL1Ea20MTE 2xf7bfkamk7u1ZxSYp6HRYLOPyFi3BVpYqv+d564RHabNCOqZcFrxxz/cEP9lEixuRN2 nYbMmJbwBwvYIX58KawAFh6FtXPOG7Q0LCbjG942YkIRoN0SCei+x5O6+JfehJwgnDi/ ZIGQBkVHzWoVFRbvundZVS3X2xTrvPSHDSeZkJ297wOwIeEaY7Qe66DZNh1J2pUGkv3d G6yOFRouOG2PPd2PapLPTEVe3grNXlNCrTz4mVahtX+VnTpteNqpkrZbwSRqo/dHEcvM BSqQ== X-Gm-Message-State: AOJu0YxESehRPUA6vKGBQ1UKahklnVd4ExdUSQ7f4IwBeAHhXYZOIxHS DCn6bryU7arkB+RkP2CvA+KV08DfXS9q8/1sezRt9mwNDe8KvRyaurVytCdK27iiUYbV5JCEXvK CKfnBraLsLZl64Gej2EANPpaHl2txVeBFtdtwxNaI+DuR8k6XOlWZoY4Q/5jEKy5TR2mSb5nnOL VnLw05EQLSsMA= X-Google-Smtp-Source: AGHT+IG5N+gV/0ddkLgvH/Wd2DYjNcXDHBHKpx/7WFiSu1VTjAihWfDX2JJ5yd5a4qSLbSAgWFeAcQ== X-Received: by 2002:a17:902:e74f:b0:1d0:8a8c:56b6 with SMTP id p15-20020a170902e74f00b001d08a8c56b6mr1526165plf.103.1704721672240; Mon, 08 Jan 2024 05:47:52 -0800 (PST) Received: from hsinchu18.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id jc20-20020a17090325d400b001d403969b65sm4588056plb.187.2024.01.08.05.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:47:51 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com, jeffreyalaw@gmail.com, christoph.muellner@vrull.eu Cc: Kito Cheng Subject: [PATCH 1/5] RISC-V: Extract part parsing base ISA logic into a standalone function [NFC] Date: Mon, 8 Jan 2024 21:47:34 +0800 Message-Id: <20240108134738.998804-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108134738.998804-1-kito.cheng@sifive.com> References: <20240108134738.998804-1-kito.cheng@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: Minor refactor, preparation for further change. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_subset_list::parse_base_ext): New. (riscv_subset_list::parse): Extract part of logic into riscv_subset_list::parse_base_ext. * config/riscv/riscv-subset.h (riscv_subset_list::parse_base_ext): New. --- gcc/common/config/riscv/riscv-common.cc | 68 ++++++++++++++++--------- gcc/config/riscv/riscv-subset.h | 2 + 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 0301d170a41..f0359380451 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -970,25 +970,38 @@ riscv_subset_list::parsing_subset_version (const char *ext, return p; } -/* Parsing function for standard extensions. +/* Parsing function for base extensions, rv[32|64][i|e|g] Return Value: - Points to the end of extensions. + Points to the end of extensions, return NULL if any error. Arguments: `p`: Current parsing position. */ - const char * -riscv_subset_list::parse_std_ext (const char *p) +riscv_subset_list::parse_base_ext (const char *p) { - const char *all_std_exts = riscv_supported_std_ext (); - const char *std_exts = all_std_exts; - unsigned major_version = 0; unsigned minor_version = 0; char std_ext = '\0'; bool explicit_version_p = false; + if (startswith (p, "rv32")) + { + m_xlen = 32; + p += 4; + } + else if (startswith (p, "rv64")) + { + m_xlen = 64; + p += 4; + } + else + { + error_at (m_loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64", + m_arch); + return NULL; + } + /* First letter must start with i, e or g. */ switch (*p) { @@ -1043,6 +1056,28 @@ riscv_subset_list::parse_std_ext (const char *p) "% or %", m_arch); return NULL; } + return p; +} + + +/* Parsing function for standard extensions. + + Return Value: + Points to the end of extensions. + + Arguments: + `p`: Current parsing position. */ + +const char * +riscv_subset_list::parse_std_ext (const char *p) +{ + const char *all_std_exts = riscv_supported_std_ext (); + const char *std_exts = all_std_exts; + + unsigned major_version = 0; + unsigned minor_version = 0; + char std_ext = '\0'; + bool explicit_version_p = false; while (p != NULL && *p) { @@ -1499,22 +1534,9 @@ riscv_subset_list::parse (const char *arch, location_t loc) riscv_subset_list *subset_list = new riscv_subset_list (arch, loc); riscv_subset_t *itr; const char *p = arch; - if (startswith (p, "rv32")) - { - subset_list->m_xlen = 32; - p += 4; - } - else if (startswith (p, "rv64")) - { - subset_list->m_xlen = 64; - p += 4; - } - else - { - error_at (loc, "%<-march=%s%>: ISA string must begin with rv32 or rv64", - arch); - goto fail; - } + p = subset_list->parse_base_ext (p); + if (p == NULL) + goto fail; /* Parsing standard extension. */ p = subset_list->parse_std_ext (p); diff --git a/gcc/config/riscv/riscv-subset.h b/gcc/config/riscv/riscv-subset.h index 14461838db5..c8117d8daf2 100644 --- a/gcc/config/riscv/riscv-subset.h +++ b/gcc/config/riscv/riscv-subset.h @@ -67,6 +67,8 @@ private: const char *parsing_subset_version (const char *, const char *, unsigned *, unsigned *, bool, bool *); + const char *parse_base_ext (const char *); + const char *parse_std_ext (const char *); const char *parse_single_std_ext (const char *); -- 2.34.1