[PATCH] Even more minimal reimplementation of errors.c within read-md.c
David Malcolm
dmalcolm@redhat.com
Fri Dec 2 22:34:00 GMT 2016
On Thu, 2016-12-01 at 13:40 +0100, Bernd Schmidt wrote:
> On 11/30/2016 09:24 PM, David Malcolm wrote:
>
> > gcc/ChangeLog:
> > * read-md.c (have_error): New global, copied from errors.c.
> > (fatal): New function, copied from errors.c.
>
> I would have expected the function to go into diagnostic.c, but
> actually
> there are already various functions of this sort in read-md.
In a way, there are three diagnostic systems in the codebase:
- the functions in errors.h/errors.c (warning, error, fatal, etc)
- the functions in read-md.c (error_at, fatal_at) which share the
"have_error" global with errors.c.
- the "real" diagnostics subsystem (diagnostics.c etc)
It turns out that the only thing using "fatal" within read-md.c is
md_reader::read_md_files. The interface this provides is overly
complicated for the RTL FE's purposes, so the following patch avoids
using it in favor of a simpler, new method: md_reader::read_file.
With that, the only thing needed in read-md.c from errors.c on the host
is just the "have_error" global; the patch verifies that by
conditionalizing the include of errors.h on #ifdef GENERATOR_FILE
(and similarly conditionalizing md_reader::read_md_files, since
"fatal" isn't implemented on the host).
> I'd request
> you place it near fatal_at, and maybe add this to errors.h:
>
> inline bool seen_error ()
> {
> return have_error;
> }
>
> and replace explicit uses of have_error with that to unify things a
> bit.
>
>
> Bernd
seen_error is already implemented in the "real" diagnostic subsystem,
and would be a clash: we want a way to determine if read-md.c's
implementation of error_at was called. Hence it seems simplest to
conditionally add a copy of the "have_error" global to read-md.c.
Thoughts?
gcc/ChangeLog:
* read-md.c: Wrap include of errors.h with #ifdef GENERATOR_FILE.
(have_error): New global, copied from errors.c.
(md_reader::read_md_files): Wrap with #ifdef GENERATOR_FILE.
(md_reader::read_file): New method.
* read-md.h (md_reader::read_file): New method.
* read-rtl-function.c (read_rtl_function_body): Reimplement in
terms of md_reader::read_file.
---
gcc/read-md.c | 31 +++++++++++++++++++++++++++++++
gcc/read-md.h | 1 +
gcc/read-rtl-function.c | 6 +-----
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/gcc/read-md.c b/gcc/read-md.c
index 25bc3c4..e581326 100644
--- a/gcc/read-md.c
+++ b/gcc/read-md.c
@@ -26,11 +26,23 @@ along with GCC; see the file COPYING3. If not see
#endif
#include "system.h"
#include "coretypes.h"
+#ifdef GENERATOR_FILE
#include "errors.h"
+#endif /* #ifdef GENERATOR_FILE */
#include "statistics.h"
#include "vec.h"
#include "read-md.h"
+#ifndef GENERATOR_FILE
+
+/* Minimal reimplementation of errors.c for use by RTL frontend
+ within cc1. */
+
+int have_error = 0;
+
+#endif /* #ifndef GENERATOR_FILE */
+
+
/* Associates PTR (which can be a string, etc.) with the file location
specified by FILENAME and LINENO. */
struct ptr_loc {
@@ -1190,6 +1202,8 @@ md_reader::add_include_path (const char *arg)
m_last_dir_md_include_ptr = &dirtmp->next;
}
+#ifdef GENERATOR_FILE
+
/* The main routine for reading .md files. Try to process all the .md
files specified on the command line and return true if no error occurred.
@@ -1296,6 +1310,23 @@ md_reader::read_md_files (int argc, const char **argv,
return !have_error;
}
+#endif /* #ifdef GENERATOR_FILE */
+
+/* Read FILENAME. */
+
+bool
+md_reader::read_file (const char *filename)
+{
+ m_read_md_filename = filename;
+ m_read_md_file = fopen (m_read_md_filename, "r");
+ if (m_read_md_file == 0)
+ {
+ perror (m_read_md_filename);
+ return false;
+ }
+ handle_toplevel_file ();
+ return !have_error;
+}
/* Read FILENAME, filtering to just the given lines. */
diff --git a/gcc/read-md.h b/gcc/read-md.h
index 6a73b00..5fc7605 100644
--- a/gcc/read-md.h
+++ b/gcc/read-md.h
@@ -110,6 +110,7 @@ class md_reader
virtual ~md_reader ();
bool read_md_files (int, const char **, bool (*) (const char *));
+ bool read_file (const char *filename);
bool read_file_fragment (const char *filename,
int first_line,
int last_line);
diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index ddea836..5188b86 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -1590,12 +1590,8 @@ read_rtl_function_body (const char *path)
init_emit ();
init_varasm_status ();
- auto_vec<const char *> argv (2);
- argv.safe_push (progname);
- argv.safe_push (path);
-
function_reader reader;
- if (!reader.read_md_files (argv.length (), argv.address (), NULL))
+ if (!reader.read_file (path))
return false;
return true;
--
1.8.5.3
More information about the Gcc-patches
mailing list