From patchwork Wed Jun 17 19:46:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1311470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RpR4drWz; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49nFyf533lz9sRW for ; Thu, 18 Jun 2020 05:49:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D03183A13019; Wed, 17 Jun 2020 19:49:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D03183A13019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592423373; bh=syIlc3TCSaIDsr9pjpuhUIt8VIt56w5zhOjZh7UUN/w=; h=To:Subject:Date:In-Reply-To:References:In-Reply-To:References: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=RpR4drWzaUdQOu2l9zTTbiBKc/R+owSTvMSClxVZmACA5T1R0pw2xiPp1SyAPsjuG uGHeJ9P/GXQ9sp5tISYWUU5C0nqsnQD0ft1jtJfwVVy463H9KxBARiQ3e83pTtk2UL w2UmTr13UMnehtLJzqrxFYsylCy23sbWxqLgvTvQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 1D3B93A13012 for ; Wed, 17 Jun 2020 19:49:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D3B93A13012 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05HJXMXe118747; Wed, 17 Jun 2020 15:49:29 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31q6j5hh6s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2020 15:49:29 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05HJbNFW133595; Wed, 17 Jun 2020 15:49:29 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 31q6j5hgka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2020 15:49:28 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05HJjA53016993; Wed, 17 Jun 2020 19:47:42 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma02dal.us.ibm.com with ESMTP id 31q6c87e2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Jun 2020 19:47:42 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05HJlfr315008636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Jun 2020 19:47:41 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2BEB828059; Wed, 17 Jun 2020 19:47:41 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09B952805A; Wed, 17 Jun 2020 19:47:41 +0000 (GMT) Received: from localhost (unknown [9.40.194.84]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 17 Jun 2020 19:47:40 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 13/28] rs6000: Parsing of overload input file Date: Wed, 17 Jun 2020 14:46:36 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-17_10:2020-06-17, 2020-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 adultscore=0 mlxscore=0 suspectscore=1 clxscore=1015 priorityscore=1501 cotscore=-2147483648 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006170149 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bill Schmidt via Gcc-patches From: Bill Schmidt Reply-To: Bill Schmidt Cc: dje.gcc@gmail.com, segher@kernel.crashing.org, willschm@linux.ibm.com Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 2020-06-17 Bill Schmidt * config/rs6000/rs6000-gen-builtins.c (ovld_stanza): New struct. (MAXOVLDSTANZAS): New defined constant. (ovld_stanzas): New filescope variable. (curr_ovld_stanza): Likewise. (MAXOVLDS): New defined constant. (ovlddata): New struct. (ovlds): New filescope variable. (curr_ovld): Likewise. (parse_ovld_entry): New function. (parse_ovld_stanza): Likewise. (parse_ovld): Implement. --- gcc/config/rs6000/rs6000-gen-builtins.c | 206 +++++++++++++++++++++++- 1 file changed, 205 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index 31661f0f39a..c872c9e0a10 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -292,8 +292,31 @@ struct bifdata { static bifdata bifs[MAXBIFS]; static int num_bifs; static int curr_bif; + +/* Stanzas are groupings of built-in functions and overloads by some + common feature/attribute. These definitions are for overload stanzas. */ +struct ovld_stanza { + char *stanza_id; + char *extern_name; + char *intern_name; +}; + +#define MAXOVLDSTANZAS 256 +static ovld_stanza ovld_stanzas[MAXOVLDSTANZAS]; static int num_ovld_stanzas; +static int curr_ovld_stanza; + +#define MAXOVLDS 16384 +struct ovlddata { + int stanza; + prototype proto; + char *idname; + char *fndecl; +}; + +static ovlddata ovlds[MAXOVLDS]; static int num_ovlds; +static int curr_ovld; /* Exit codes for the shell. */ enum exit_codes { @@ -1390,11 +1413,192 @@ parse_bif () return result; } +/* Parse one two-line entry in the overload file. Return 0 for EOF, 1 for + success, 2 for end-of-stanza, and 6 for a parsing failure. */ +static int +parse_ovld_entry () +{ + /* Check for end of stanza. */ + pos = 0; + consume_whitespace (); + if (linebuf[pos] == '[') + return 2; + + /* Allocate an entry in the overload table. */ + if (num_ovlds >= MAXOVLDS - 1) + { + (*diag) ("too many overloads.\n"); + return 6; + } + + curr_ovld = num_ovlds++; + ovlds[curr_ovld].stanza = curr_ovld_stanza; + + if (!parse_prototype (&ovlds[curr_ovld].proto)) + return 6; + + /* Now process line 2, which just contains the builtin id. */ + if (!advance_line (ovld_file)) + { + (*diag) ("unexpected EOF.\n"); + return 0; + } + + pos = 0; + consume_whitespace (); + int oldpos = pos; + char *id = match_identifier (); + ovlds[curr_ovld].idname = id; + if (!id) + { + (*diag) ("missing overload id at column %d.\n", pos + 1); + return 6; + } + +#ifdef DEBUG + (*diag) ("ID name is '%s'.\n", id); +#endif + + /* The builtin id has to match one from the bif file. */ + if (!rbt_find (&bif_rbt, id)) + { + (*diag) ("builtin ID '%s' not found in bif file.\n", id); + return 6; + } + + /* Save the ID in a lookup structure. */ + if (!rbt_insert (&ovld_rbt, id)) + { + (*diag) ("duplicate function ID '%s' at column %d.\n", id, oldpos + 1); + return 6; + } + + consume_whitespace (); + if (linebuf[pos] != '\n') + { + (*diag) ("garbage at end of line at column %d.\n", pos + 1); + return 6; + } + return 1; +} + +/* Parse one stanza of the input overload file. linebuf already contains the + first line to parse. Return 1 for success, 0 for EOF, 6 for failure. */ +static int +parse_ovld_stanza () +{ + /* Parse the stanza header. */ + pos = 0; + consume_whitespace (); + + if (linebuf[pos] != '[') + { + (*diag) ("ill-formed stanza header at column %d.\n", pos + 1); + return 6; + } + safe_inc_pos (); + + char *stanza_name = match_identifier (); + if (!stanza_name) + { + (*diag) ("no identifier found in stanza header.\n"); + return 6; + } + + /* Add the identifier to a table and set the number to be recorded + with subsequent overload entries. */ + if (num_ovld_stanzas >= MAXOVLDSTANZAS) + { + (*diag) ("too many stanza headers.\n"); + return 6; + } + + curr_ovld_stanza = num_ovld_stanzas++; + ovld_stanza *stanza = &ovld_stanzas[curr_ovld_stanza]; + stanza->stanza_id = stanza_name; + + consume_whitespace (); + if (linebuf[pos] != ',') + { + (*diag) ("missing comma at column %d.\n", pos + 1); + return 6; + } + safe_inc_pos (); + + consume_whitespace (); + stanza->extern_name = match_identifier (); + if (!stanza->extern_name) + { + (*diag) ("missing external name at column %d.\n", pos + 1); + return 6; + } + + consume_whitespace (); + if (linebuf[pos] != ',') + { + (*diag) ("missing comma at column %d.\n", pos + 1); + return 6; + } + safe_inc_pos (); + + consume_whitespace (); + stanza->intern_name = match_identifier (); + if (!stanza->intern_name) + { + (*diag) ("missing internal name at column %d.\n", pos + 1); + return 6; + } + + if (linebuf[pos] != ']') + { + (*diag) ("ill-formed stanza header at column %d.\n", pos + 1); + return 6; + } + safe_inc_pos (); + + consume_whitespace (); + if (linebuf[pos] != '\n' && pos != LINELEN - 1) + { + (*diag) ("garbage after stanza header.\n"); + return 6; + } + + int result = 1; + + while (result != 2) /* end of stanza */ + { + int result; + if (!advance_line (ovld_file)) + return 0; + + result = parse_ovld_entry (); + if (!result) /* EOF */ + return 0; + else if (result > 2) + return 6; + } + + return 1; +} + /* Parse the overload file. Return 1 for success, 6 for a parsing error. */ static int parse_ovld () { - return 1; + int result = 1; + diag = &ovld_diag; + while (result == 1) + { + /* Read ahead one line and check for EOF. */ + if (!advance_line (ovld_file)) + return 1; + + /* Parse a stanza beginning at this line. */ + result = parse_ovld_stanza (); + } + if (result == 0) + return 1; + return result; } /* Write everything to the header file (rs6000-builtins.h). */