From ff379777e61a01cbf023f664398d0170711a99a2 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 20 Sep 2016 12:40:38 -0400 Subject: [PATCH 10/44] read-md: add some helper functions 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 21de758..495a8a6 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 @@ -399,6 +420,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 82a628b..0410875 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -184,6 +184,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 *); @@ -199,7 +201,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