From 7d0dcbc19c1842714de7580be802530f0467bd9c Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 5 Apr 2016 14:45:23 -0400 Subject: [PATCH 16/91] FIXME: start introducing rtx_reader class --- gcc/gensupport.c | 15 +++++++++++---- gcc/read-md.c | 26 +++++++++++++------------- gcc/read-md.h | 16 ++++++++++------ gcc/rtl/rtl-frontend.c | 13 ++++++++++--- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/gcc/gensupport.c b/gcc/gensupport.c index 0eb4591..20603fd 100644 --- a/gcc/gensupport.c +++ b/gcc/gensupport.c @@ -2226,10 +2226,16 @@ process_define_subst (void) } } -/* A read_md_files callback for reading an rtx. */ +/* FIXME. */ -static void -rtx_handle_directive (file_location loc, const char *rtx_name) +class gen_reader : public rtx_reader +{ + public: + void handle_directive (file_location, const char *); +}; + +void +gen_reader::handle_directive (file_location loc, const char *rtx_name) { auto_vec subrtxs; if (!read_rtx (rtx_name, &subrtxs)) @@ -2516,7 +2522,8 @@ init_rtx_reader_args_cb (int argc, const char **argv, split_sequence_num = 1; peephole2_sequence_num = 1; - read_md_files (argc, argv, parse_opt, rtx_handle_directive); + gen_reader reader; + read_md_files (argc, argv, parse_opt, &reader); if (define_attr_queue != NULL) check_define_attr_duplicates (); diff --git a/gcc/read-md.c b/gcc/read-md.c index aab5f12..a303752 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -92,7 +92,7 @@ static htab_t md_constants; /* A table of enum_type structures, hashed by name. */ static htab_t enum_types; -static void handle_file (directive_handler_t); +static void handle_file (rtx_reader *); /* Given an object that starts with a char * name field, return a hash code for its name. */ @@ -906,7 +906,7 @@ traverse_enum_types (htab_trav callback, void *info) which the "include" occurred. */ static void -handle_include (file_location loc, directive_handler_t handle_directive) +handle_include (file_location loc, rtx_reader *reader) { const char *filename; const char *old_filename; @@ -965,7 +965,7 @@ handle_include (file_location loc, directive_handler_t handle_directive) read_md_file = input_file; read_md_filename = pathname; - handle_file (handle_directive); + handle_file (reader); /* Restore the old cursor. */ read_md_file = old_file; @@ -981,7 +981,7 @@ handle_include (file_location loc, directive_handler_t handle_directive) unknown directives. */ static void -handle_file (directive_handler_t handle_directive) +handle_file (rtx_reader *reader) { struct md_name directive; int c; @@ -1001,9 +1001,9 @@ handle_file (directive_handler_t handle_directive) else if (strcmp (directive.string, "define_c_enum") == 0) handle_enum (loc, false); else if (strcmp (directive.string, "include") == 0) - handle_include (loc, handle_directive); - else if (handle_directive) - handle_directive (loc, directive.string); + handle_include (loc, reader); + else if (reader) + reader->handle_directive (loc, directive.string); else read_skip_construct (1, loc); @@ -1018,7 +1018,7 @@ handle_file (directive_handler_t handle_directive) base_dir accordingly. */ static void -handle_toplevel_file (directive_handler_t handle_directive) +handle_toplevel_file (rtx_reader *reader) { const char *base; @@ -1029,7 +1029,7 @@ handle_toplevel_file (directive_handler_t handle_directive) else base_dir = xstrndup (in_fname, base - in_fname); - handle_file (handle_directive); + handle_file (reader); } /* Parse a -I option with argument ARG. */ @@ -1064,7 +1064,7 @@ parse_include (const char *arg) bool read_md_files (int argc, const char **argv, bool (*parse_opt) (const char *), - directive_handler_t handle_directive) + rtx_reader *reader) { int i; bool no_more_options; @@ -1134,7 +1134,7 @@ read_md_files (int argc, const char **argv, bool (*parse_opt) (const char *), read_md_file = stdin; read_md_filename = ""; - handle_toplevel_file (handle_directive); + handle_toplevel_file (reader); already_read_stdin = true; continue; } @@ -1157,7 +1157,7 @@ read_md_files (int argc, const char **argv, bool (*parse_opt) (const char *), perror (read_md_filename); return false; } - handle_toplevel_file (handle_directive); + handle_toplevel_file (reader); num_files++; } @@ -1167,7 +1167,7 @@ read_md_files (int argc, const char **argv, bool (*parse_opt) (const char *), { read_md_file = stdin; read_md_filename = ""; - handle_toplevel_file (handle_directive); + handle_toplevel_file (reader); } return !have_error; diff --git a/gcc/read-md.h b/gcc/read-md.h index fc3b077..cb5c7ff 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -90,11 +90,15 @@ struct enum_type { unsigned int num_values; }; -/* A callback that handles a single .md-file directive, up to but not - including the closing ')'. It takes two arguments: the file position - at which the directive started, and the name of the directive. The next - unread character is the optional space after the directive name. */ -typedef void (*directive_handler_t) (file_location, const char *); +class rtx_reader +{ + public: + /* A hook that handles a single .md-file directive, up to but not + including the closing ')'. It takes two arguments: the file position + at which the directive started, and the name of the directive. The next + unread character is the optional space after the directive name. */ + virtual void handle_directive (file_location, const char *) = 0; +}; extern const char *in_fname; extern FILE *read_md_file; @@ -151,6 +155,6 @@ extern void traverse_md_constants (htab_trav, void *); extern void traverse_enum_types (htab_trav, void *); extern struct enum_type *lookup_enum_type (const char *); extern bool read_md_files (int, const char **, bool (*) (const char *), - directive_handler_t); + rtx_reader *reader); #endif /* GCC_READ_MD_H */ diff --git a/gcc/rtl/rtl-frontend.c b/gcc/rtl/rtl-frontend.c index 2a17b73..ee2e5d6 100644 --- a/gcc/rtl/rtl-frontend.c +++ b/gcc/rtl/rtl-frontend.c @@ -159,8 +159,14 @@ rtl_langhook_handle_option ( struct uid_hash : int_hash {}; static hash_map insns_by_uid; -static void -directive_handler (file_location loc, const char *name) +class function_reader : public rtx_reader +{ + public: + void handle_directive (file_location, const char *); +}; + +void +function_reader::handle_directive (file_location loc, const char *name) { rtx x = read_rtx_code (name); if (!x) @@ -186,8 +192,9 @@ rtl_langhook_parse_file (void) argv.safe_push (progname); for (unsigned i = 0; i < num_in_fnames; i++) argv.safe_push (in_fnames[i]); + function_reader reader; if (read_md_files (argv.length (), argv.address (), NULL, - directive_handler)) + &reader)) { } else -- 1.8.5.3