From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 625EB3858003 for ; Fri, 9 Jul 2021 19:33:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 625EB3858003 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 169J4PmE072756; Fri, 9 Jul 2021 15:33:03 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 39pu5ra7x0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 15:33:02 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 169JNFst019378; Fri, 9 Jul 2021 19:33:02 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma01wdc.us.ibm.com with ESMTP id 39jfhdry9g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 19:33:02 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 169JX13c20250886 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 19:33:01 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CE4228059; Fri, 9 Jul 2021 19:33:01 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83D482805A; Fri, 9 Jul 2021 19:33:00 +0000 (GMT) Received: from lexx (unknown [9.171.59.93]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 19:33:00 +0000 (GMT) Message-ID: <2f1d4550001868d94ef6a1dfd7c6eba3d86c4c87.camel@vnet.ibm.com> Subject: Re: [PATCH 05/55] rs6000: Add helper functions for parsing From: will schmidt To: Bill Schmidt , gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org Date: Fri, 09 Jul 2021 14:32:59 -0500 In-Reply-To: <643ab7459789d98707031c6081e686608030c864.1623941441.git.wschmidt@linux.ibm.com> References: <643ab7459789d98707031c6081e686608030c864.1623941441.git.wschmidt@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-10.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: -v_JSxqo7FCddaPV-1k5zz2dQl49f2cJ X-Proofpoint-ORIG-GUID: -v_JSxqo7FCddaPV-1k5zz2dQl49f2cJ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_12:2021-07-09, 2021-07-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 spamscore=0 clxscore=1015 adultscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090092 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 09 Jul 2021 19:33:09 -0000 On Thu, 2021-06-17 at 10:18 -0500, Bill Schmidt via Gcc-patches wrote: > 2021-06-07 Bill Schmidt > > gcc/ > * config/rs6000/rs6000-gen-builtins.c (consume_whitespace): New > function. > (advance_line): Likewise. > (safe_inc_pos): Likewise. > (match_identifier): Likewise. > (match_integer): Likewise. > (match_to_right_bracket): Likewise. > --- > gcc/config/rs6000/rs6000-gen-builtins.c | 111 ++++++++++++++++++++++++ > 1 file changed, 111 insertions(+) > > diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c > index 3c53c3401b2..c5d5590e865 100644 > --- a/gcc/config/rs6000/rs6000-gen-builtins.c > +++ b/gcc/config/rs6000/rs6000-gen-builtins.c > @@ -210,3 +210,114 @@ ovld_diag (const char * fmt, ...) > vfprintf (stderr, fmt, args); > va_end (args); > } > + > +/* Pass over unprintable characters and whitespace (other than a newline, > + which terminates the scan). */ AFAIK isspace() and thusly this helper only skips whitespace, so nothing unprintable is actually handled or skipped here. Beyond that comment nit the function seems OK. > +static void > +consume_whitespace (void) > +{ > + while (pos < LINELEN && isspace(linebuf[pos]) && linebuf[pos] != '\n') > + pos++; > + return; > +} > + > +/* Get the next nonblank, noncomment line, returning 0 on EOF, 1 otherwise. */ > +static int > +advance_line (FILE *file) > +{ > + while (1) > + { > + /* Read ahead one line and check for EOF. */ > + if (!fgets (linebuf, sizeof linebuf, file)) > + return 0; > + line++; > + size_t len = strlen (linebuf); > + if (linebuf[len - 1] != '\n') > + (*diag) ("line doesn't terminate with newline\n"); > + pos = 0; > + consume_whitespace (); > + if (linebuf[pos] != '\n' && linebuf[pos] != ';') > + return 1; > + } > +} ok > + > +static inline void > +safe_inc_pos (void) > +{ > + if (pos++ >= LINELEN) > + { > + (*diag) ("line length overrun.\n"); > + exit (1); > + } > +} ok > + > +/* Match an identifier, returning NULL on failure, else a pointer to a > + buffer containing the identifier. */ > +static char * > +match_identifier (void) > +{ > + int lastpos = pos - 1; > + while (isalnum (linebuf[lastpos + 1]) || linebuf[lastpos + 1] == '_') > + ++lastpos; > + > + if (lastpos < pos) > + return 0; > + > + char *buf = (char *) malloc (lastpos - pos + 2); > + memcpy (buf, &linebuf[pos], lastpos - pos + 1); > + buf[lastpos - pos + 1] = '\0'; > + > + pos = lastpos + 1; > + return buf; > +} ok > + > +/* Match an integer and return the string representing its value, > + or a null string on failure. */ > +static char * > +match_integer (void) > +{ > + int startpos = pos; > + if (linebuf[pos] == '-') > + safe_inc_pos (); > + > + int lastpos = pos - 1; > + while (isdigit (linebuf[lastpos + 1])) > + ++lastpos; > + > + if (lastpos < pos) > + return NULL; > + > + pos = lastpos + 1; > + char *buf = (char *) malloc (lastpos - startpos + 2); > + memcpy (buf, &linebuf[startpos], lastpos - startpos + 1); > + buf[lastpos - startpos + 1] = '\0'; > + return buf; > +} Ok > + > +/* Match a string up to but not including a ']', and return its value, > + or zero if there is nothing before the ']'. Error if we don't find > + such a character. */ > +static const char * > +match_to_right_bracket (void) > +{ > + int lastpos = pos - 1; > + while (linebuf[lastpos + 1] != ']') > + { > + if (linebuf[lastpos + 1] == '\n') > + { > + (*diag) ("no ']' found before end of line.\n"); > + exit (1); > + } > + ++lastpos; > + } > + > + if (lastpos < pos) > + return 0; > + > + char *buf = (char *) malloc (lastpos - pos + 2); > + memcpy (buf, &linebuf[pos], lastpos - pos + 1); > + buf[lastpos - pos + 1] = '\0'; > + > + pos = lastpos + 1; > + return buf; > +} Ok. presumably all tested OK.. :-) lgtm, thanks -Will