Add some functions for use by the RTL frontend.

gcc/ChangeLog:
        * read-md.c (require_char): New function.
        (require_word_ws): New function.
        (peek_char): New function.
        * read-md.h (peek_char): New decl.
        (require_char): New decl.
        (require_word_ws): New decl.
---
 gcc/read-md.c | 31 +++++++++++++++++++++++++++++++
 gcc/read-md.h |  4 ++++
 2 files changed, 35 insertions(+)

diff --git a/gcc/read-md.c b/gcc/read-md.c
index 1a13916..1bbf408 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -364,6 +364,16 @@ read_skip_spaces (void)
     }
 }
 
+/* Consume the next character, issuing a fatal error if it is not
+   EXPECTED.  */
+
+void require_char (char expected)
+{
+  int ch = read_char ();
+  if (ch != expected)
+    fatal_expected_char (expected, ch);
+}
+
 /* Consume any whitespace, then consume the next non-whitespace
    character, issuing a fatal error if it is not EXPECTED.  */
 
@@ -375,6 +385,17 @@ require_char_ws (char expected)
     fatal_expected_char (expected, ch);
 }
 
+/* Consume any whitespace, then consume the next word (as per read_name),
+   issuing a fatal error if it is not EXPECTED.  */
+
+void require_word_ws (const char *expected)
+{
+  struct md_name name;
+  read_name (&name);
+  if (strcmp (name.string, expected))
+    fatal_with_file_and_line ("missing '%s'", expected);
+}
+
 /* Read the next character from the file.  */
 
 int
@@ -410,6 +431,16 @@ rtx_reader::unread_char (int ch)
   ungetc (ch, m_read_md_file);
 }
 
+/* Peek at the next character from the file without consuming it.  */
+
+int
+peek_char (void)
+{
+  int ch = read_char ();
+  unread_char (ch);
+  return ch;
+}
+
 /* Read an rtx code name into NAME.  It is terminated by any of the
    punctuation chars of rtx printed syntax.  */
 
diff --git a/gcc/read-md.h b/gcc/read-md.h
index a74cc72..88d2d4f 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -194,6 +194,8 @@ unread_char (int ch)
   rtx_reader_ptr->unread_char (ch);
 }
 
+extern int peek_char (void);
+
 extern hashval_t leading_string_hash (const void *);
 extern int leading_string_eq_p (const void *, const void *);
 extern void copy_md_ptr_loc (const void *, const void *);
@@ -209,7 +211,9 @@ extern void fatal_with_file_and_line (const char *, ...)
   ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
 extern int read_skip_spaces (void);
+extern void require_char (char expected);
 extern void require_char_ws (char expected);
+extern void require_word_ws (const char *expected);
 extern void read_name (struct md_name *);
 extern char *read_quoted_string (void);
 extern char *read_string (int);
-- 
1.8.5.3

Reply via email to