From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127235 invoked by alias); 5 Oct 2016 15:44:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127181 invoked by uid 89); 5 Oct 2016 15:44:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=BAYES_00,MEDICAL_SUBJECT,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=readmdc, read-md.c, EXPECTED X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Oct 2016 15:44:39 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E2D11CCC33 for ; Wed, 5 Oct 2016 15:44:38 +0000 (UTC) Received: from c64.redhat.com (vpn-236-9.phx2.redhat.com [10.3.236.9]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u95FiV5P027350; Wed, 5 Oct 2016 11:44:37 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 07/16] read-md: add some helper functions Date: Wed, 05 Oct 2016 15:44:00 -0000 Message-Id: <1475684110-2521-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1475684110-2521-1-git-send-email-dmalcolm@redhat.com> References: <1475684110-2521-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00259.txt.bz2 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