From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1725) id E8358388A834; Thu, 20 Aug 2020 16:37:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8358388A834 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597941470; bh=9SSU4iiiVQ2kpOzy15UXPhgRxdNI/UPA2MT/sr/i+QA=; h=From:To:Subject:Date:From; b=vHNjowy7B+cS0YxS7Esqw9dzO6tFTzMwJe7psIMLjwl0lrhxzZCfj4MwgGzRSn5gw IFQonTujedjBh47hKsmkl7yzVwImOjKoafsBgfXWNcK5kXhM6cFkYe0AxbVt8Rp+00 NBuj+RiU7ePR795KzNKz0xLUveifsQfbtKjxK+Mw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: William Schmidt To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/wschmidt/heads/builtins3)] rs6000: Add helper functions for parsing X-Act-Checkin: gcc X-Git-Author: Bill Schmidt X-Git-Refname: refs/users/wschmidt/heads/builtins3 X-Git-Oldrev: 876c7a9bbbc3c5e318a80f2ada67e132251b591d X-Git-Newrev: cb16c9f67e7b25c88a0f30355b463fe1e6ced999 Message-Id: <20200820163750.E8358388A834@sourceware.org> Date: Thu, 20 Aug 2020 16:37:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2020 16:37:51 -0000 https://gcc.gnu.org/g:cb16c9f67e7b25c88a0f30355b463fe1e6ced999 commit cb16c9f67e7b25c88a0f30355b463fe1e6ced999 Author: Bill Schmidt Date: Wed Jun 17 09:59:19 2020 -0500 rs6000: Add helper functions for parsing 2020-07-26 Bill Schmidt * config/rs6000/rs6000-gen-builtins.c (MININT): New defined constant. (exit_codes): New enum. (consume_whitespace): New function. (advance_line): Likewise. (safe_inc_pos): Likewise. (match_identifier): Likewise. (match_integer): Likewise. (match_to_right_bracket): Likewise. Diff: --- gcc/config/rs6000/rs6000-gen-builtins.c | 121 ++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index 8c8fad66edf..e2a9b28eb16 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -140,6 +140,10 @@ along with GCC; see the file COPYING3. If not see #include #include +/* Used as a sentinel for range constraints on integer fields. No field can + be 32 bits wide, so this is a safe sentinel value. */ +#define MININT INT32_MIN + /* Input and output file descriptors and pathnames. */ static FILE *bif_file; static FILE *ovld_file; @@ -162,6 +166,11 @@ static char linebuf[LINELEN]; static int line; static int pos; +/* Exit codes for the shell. */ +enum exit_codes { + EC_INTERR +}; + /* Pointer to a diagnostic function. */ void (*diag) (const char *, ...) __attribute__ ((format (printf, 1, 2))) = NULL; @@ -187,3 +196,115 @@ ovld_diag (const char * fmt, ...) va_end (args); } +/* Pass over unprintable characters and whitespace (other than a newline, + which terminates the scan). */ +static void +consume_whitespace () +{ + 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++; + pos = 0; + consume_whitespace (); + if (linebuf[pos] != '\n' && linebuf[pos] != ';') + return 1; + } +} + +static inline void +safe_inc_pos () +{ + if (pos++ >= LINELEN) + { + (*diag) ("line length overrun.\n"); + exit (EC_INTERR); + } +} + +/* Match an identifier, returning NULL on failure, else a pointer to a + buffer containing the identifier. */ +static char * +match_identifier () +{ + int lastpos = pos - 1; + while (isalnum (linebuf[lastpos + 1]) || linebuf[lastpos + 1] == '_') + if (++lastpos >= LINELEN - 1) + { + (*diag) ("line length overrun.\n"); + exit (EC_INTERR); + } + + 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; +} + +/* Match an integer and return its value, or MININT on failure. */ +static int +match_integer () +{ + int startpos = pos; + if (linebuf[pos] == '-') + safe_inc_pos (); + + int lastpos = pos - 1; + while (isdigit (linebuf[lastpos + 1])) + if (++lastpos >= LINELEN - 1) + { + (*diag) ("line length overrun in match_integer.\n"); + exit (EC_INTERR); + } + + if (lastpos < pos) + return MININT; + + pos = lastpos + 1; + char *buf = (char *) malloc (lastpos - startpos + 2); + memcpy (buf, &linebuf[startpos], lastpos - startpos + 1); + buf[lastpos - startpos + 1] = '\0'; + + int x; + sscanf (buf, "%d", &x); + return x; +} + +static const char * +match_to_right_bracket () +{ + int lastpos = pos - 1; + while (linebuf[lastpos + 1] != ']') + if (++lastpos >= LINELEN - 1) + { + (*diag) ("line length overrun.\n"); + exit (EC_INTERR); + } + + 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; +} +