public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-06-15 17:16 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-15 17:16 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8d0988c6369218bd862410a7b0bf518a96576bd1

commit 8d0988c6369218bd862410a7b0bf518a96576bd1
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Mon Jun 7 11:41:37 2021 -0500

    rs6000: Add helper functions for parsing
    
    2021-06-07  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    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.

Diff:
---
 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).  */
+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;
+    }
+}
+
+static inline void
+safe_inc_pos (void)
+{
+  if (pos++ >= LINELEN)
+    {
+      (*diag) ("line length overrun.\n");
+      exit (1);
+    }
+}
+
+/* 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;
+}
+
+/* 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;
+}
+
+/* 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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-06-25 16:15 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-06-25 16:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:643ab7459789d98707031c6081e686608030c864

commit 643ab7459789d98707031c6081e686608030c864
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Mon Jun 7 11:41:37 2021 -0500

    rs6000: Add helper functions for parsing
    
    2021-06-07  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    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.

Diff:
---
 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).  */
+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;
+    }
+}
+
+static inline void
+safe_inc_pos (void)
+{
+  if (pos++ >= LINELEN)
+    {
+      (*diag) ("line length overrun.\n");
+      exit (1);
+    }
+}
+
+/* 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;
+}
+
+/* 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;
+}
+
+/* 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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-04-26 20:48 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-26 20:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:339c02294ee06570958bc71c772f33736a103fa9

commit 339c02294ee06570958bc71c772f33736a103fa9
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 12:46:38 2021 -0600

    rs6000: Add helper functions for parsing
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * 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 0e8b315208b..f3e1d31c225 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -164,6 +164,10 @@ along with GCC; see the file COPYING3.  If not see
 #include <assert.h>
 #include <unistd.h>
 
+/* 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;
@@ -186,6 +190,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;
@@ -210,3 +219,115 @@ 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).  */
+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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-04-02 22:09 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-02 22:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:80cde440aef3021245072e412a0b91b6d7a8e6b4

commit 80cde440aef3021245072e412a0b91b6d7a8e6b4
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 12:46:38 2021 -0600

    rs6000: Add helper functions for parsing
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * 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 0e8b315208b..f3e1d31c225 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -164,6 +164,10 @@ along with GCC; see the file COPYING3.  If not see
 #include <assert.h>
 #include <unistd.h>
 
+/* 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;
@@ -186,6 +190,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;
@@ -210,3 +219,115 @@ 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).  */
+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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-04-01 19:47 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-04-01 19:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:42cb5b7fe07e9ef066a7b27f8fa6b8210e9a648c

commit 42cb5b7fe07e9ef066a7b27f8fa6b8210e9a648c
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 12:46:38 2021 -0600

    rs6000: Add helper functions for parsing
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * 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 32bb231f2e3..136d6911760 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -163,6 +163,10 @@ along with GCC; see the file COPYING3.  If not see
 #include <assert.h>
 #include <unistd.h>
 
+/* 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;
@@ -185,6 +189,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;
@@ -209,3 +218,115 @@ 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).  */
+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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing
@ 2021-03-25 15:44 William Schmidt
  0 siblings, 0 replies; 6+ messages in thread
From: William Schmidt @ 2021-03-25 15:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f6208350ca9325068d3fca9518d385a5459da580

commit f6208350ca9325068d3fca9518d385a5459da580
Author: Bill Schmidt <wschmidt@linux.ibm.com>
Date:   Wed Mar 3 12:46:38 2021 -0600

    rs6000: Add helper functions for parsing
    
    2021-03-03  Bill Schmidt  <wschmidt@linux.ibm.com>
    
    gcc/
            * 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 32bb231f2e3..136d6911760 100644
--- a/gcc/config/rs6000/rs6000-gen-builtins.c
+++ b/gcc/config/rs6000/rs6000-gen-builtins.c
@@ -163,6 +163,10 @@ along with GCC; see the file COPYING3.  If not see
 #include <assert.h>
 #include <unistd.h>
 
+/* 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;
@@ -185,6 +189,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;
@@ -209,3 +218,115 @@ 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).  */
+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;
+}


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-25 16:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 17:16 [gcc(refs/users/wschmidt/heads/builtins10)] rs6000: Add helper functions for parsing William Schmidt
  -- strict thread matches above, loose matches on Subject: below --
2021-06-25 16:15 William Schmidt
2021-04-26 20:48 William Schmidt
2021-04-02 22:09 William Schmidt
2021-04-01 19:47 William Schmidt
2021-03-25 15:44 William Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).