From 9c4e96eb1e305a9f35e4dbafb0a1fe29ef226265 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 7 Dec 2016 18:16:32 +0000 Subject: [PATCH] Add some functions for use by the RTL frontend. gcc/ChangeLog: * read-md.c (rtx_reader::require_char): New method. (require_char_ws): Convert from function to... (rtx_reader::require_char_ws): ...method. (rtx_reader::require_word_ws): New method. * read-md.h (rtx_reader::require_char): New method decl. (require_char_ws): Remove global decl in favor of... (rtx_reader::require_char_ws): ...new method decl. (rtx_reader::require_word_ws): New method decl. (rtx_reader::peek_char): New method decl. From-SVN: r243376 --- gcc/ChangeLog | 12 ++++++++++++ gcc/read-md.c | 35 ++++++++++++++++++++++++++++++++++- gcc/read-md.h | 5 ++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 489ec77e81d..c4055dc1501 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2016-12-07 David Malcolm + + * read-md.c (rtx_reader::require_char): New method. + (require_char_ws): Convert from function to... + (rtx_reader::require_char_ws): ...method. + (rtx_reader::require_word_ws): New method. + * read-md.h (rtx_reader::require_char): New method decl. + (require_char_ws): Remove global decl in favor of... + (rtx_reader::require_char_ws): ...new method decl. + (rtx_reader::require_word_ws): New method decl. + (rtx_reader::peek_char): New method decl. + 2016-12-07 Thomas Preud'homme PR rtl-optimization/78617 diff --git a/gcc/read-md.c b/gcc/read-md.c index 6fe26000eb5..095075f37d4 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -340,17 +340,40 @@ read_skip_spaces (void) } } +/* Consume the next character, issuing a fatal error if it is not + EXPECTED. */ + +void +rtx_reader::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. */ void -require_char_ws (char expected) +rtx_reader::require_char_ws (char expected) { int ch = read_skip_spaces (); if (ch != 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 +rtx_reader::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 @@ -386,6 +409,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 +rtx_reader::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 996b514976f..06b89b4c04f 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -116,6 +116,10 @@ class rtx_reader char *read_braced_string (); char *read_string (int star_if_braced); void read_skip_construct (int depth, file_location loc); + void require_char (char expected); + void require_char_ws (char expected); + void require_word_ws (const char *expected); + int peek_char (void); void set_md_ptr_loc (const void *ptr, const char *filename, int lineno); const struct ptr_loc *get_md_ptr_loc (const void *ptr); @@ -269,7 +273,6 @@ 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_ws (char expected); extern int n_comma_elts (const char *); extern const char *scan_comma_elt (const char **); extern void upcase_string (char *); -- 2.30.2