diff options
Diffstat (limited to 'gcc/read-md.c')
-rw-r--r-- | gcc/read-md.c | 195 |
1 files changed, 94 insertions, 101 deletions
diff --git a/gcc/read-md.c b/gcc/read-md.c index e158be5..6fe2600 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -21,6 +21,8 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "errors.h" +#include "statistics.h" +#include "vec.h" #include "read-md.h" /* Associates PTR (which can be a string, etc.) with the file location @@ -31,25 +33,6 @@ struct ptr_loc { int lineno; }; -/* Obstack used for allocating MD strings. */ -struct obstack string_obstack; - -/* A table of ptr_locs, hashed on the PTR field. */ -static htab_t ptr_locs; - -/* An obstack for the above. Plain xmalloc is a bit heavyweight for a - small structure like ptr_loc. */ -static struct obstack ptr_loc_obstack; - -/* A hash table of triples (A, B, C), where each of A, B and C is a condition - and A is equivalent to "B && C". This is used to keep track of the source - of conditions that are made up of separate MD strings (such as the split - condition of a define_insn_and_split). */ -static htab_t joined_conditions; - -/* An obstack for allocating joined_conditions entries. */ -static struct obstack joined_conditions_obstack; - /* This callback will be invoked whenever an md include directive is processed. To be used for creation of the dependency file. */ void (*include_callback) (const char *); @@ -58,13 +41,6 @@ void (*include_callback) (const char *); rtx_reader *rtx_reader_ptr; -/* A table of md_constant structures, hashed by name. Null if no - constant expansion should occur. */ -static htab_t md_constants; - -/* A table of enum_type structures, hashed by name. */ -static htab_t enum_types; - /* Given an object that starts with a char * name field, return a hash code for its name. */ @@ -102,32 +78,32 @@ leading_ptr_eq_p (const void *def1, const void *def2) /* Associate PTR with the file position given by FILENAME and LINENO. */ -static void -set_md_ptr_loc (const void *ptr, const char *filename, int lineno) +void +rtx_reader::set_md_ptr_loc (const void *ptr, const char *filename, int lineno) { struct ptr_loc *loc; - loc = (struct ptr_loc *) obstack_alloc (&ptr_loc_obstack, + loc = (struct ptr_loc *) obstack_alloc (&m_ptr_loc_obstack, sizeof (struct ptr_loc)); loc->ptr = ptr; loc->filename = filename; loc->lineno = lineno; - *htab_find_slot (ptr_locs, loc, INSERT) = loc; + *htab_find_slot (m_ptr_locs, loc, INSERT) = loc; } /* Return the position associated with pointer PTR. Return null if no position was set. */ -static const struct ptr_loc * -get_md_ptr_loc (const void *ptr) +const struct ptr_loc * +rtx_reader::get_md_ptr_loc (const void *ptr) { - return (const struct ptr_loc *) htab_find (ptr_locs, &ptr); + return (const struct ptr_loc *) htab_find (m_ptr_locs, &ptr); } /* Associate NEW_PTR with the same file position as OLD_PTR. */ void -copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) +rtx_reader::copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) { const struct ptr_loc *loc = get_md_ptr_loc (old_ptr); if (loc != 0) @@ -138,7 +114,7 @@ copy_md_ptr_loc (const void *new_ptr, const void *old_ptr) directive for it to OUTF. */ void -fprint_md_ptr_loc (FILE *outf, const void *ptr) +rtx_reader::fprint_md_ptr_loc (FILE *outf, const void *ptr) { const struct ptr_loc *loc = get_md_ptr_loc (ptr); if (loc != 0) @@ -147,7 +123,7 @@ fprint_md_ptr_loc (FILE *outf, const void *ptr) /* Special fprint_md_ptr_loc for writing to STDOUT. */ void -print_md_ptr_loc (const void *ptr) +rtx_reader::print_md_ptr_loc (const void *ptr) { fprint_md_ptr_loc (stdout, ptr); } @@ -156,7 +132,7 @@ print_md_ptr_loc (const void *ptr) may be null or empty. */ const char * -join_c_conditions (const char *cond1, const char *cond2) +rtx_reader::join_c_conditions (const char *cond1, const char *cond2) { char *result; const void **entry; @@ -171,11 +147,11 @@ join_c_conditions (const char *cond1, const char *cond2) return cond1; result = concat ("(", cond1, ") && (", cond2, ")", NULL); - obstack_ptr_grow (&joined_conditions_obstack, result); - obstack_ptr_grow (&joined_conditions_obstack, cond1); - obstack_ptr_grow (&joined_conditions_obstack, cond2); - entry = XOBFINISH (&joined_conditions_obstack, const void **); - *htab_find_slot (joined_conditions, entry, INSERT) = entry; + obstack_ptr_grow (&m_joined_conditions_obstack, result); + obstack_ptr_grow (&m_joined_conditions_obstack, cond1); + obstack_ptr_grow (&m_joined_conditions_obstack, cond2); + entry = XOBFINISH (&m_joined_conditions_obstack, const void **); + *htab_find_slot (m_joined_conditions, entry, INSERT) = entry; return result; } @@ -185,9 +161,9 @@ join_c_conditions (const char *cond1, const char *cond2) directive for COND if its original file position is known. */ void -fprint_c_condition (FILE *outf, const char *cond) +rtx_reader::fprint_c_condition (FILE *outf, const char *cond) { - const char **halves = (const char **) htab_find (joined_conditions, &cond); + const char **halves = (const char **) htab_find (m_joined_conditions, &cond); if (halves != 0) { fprintf (outf, "("); @@ -207,7 +183,7 @@ fprint_c_condition (FILE *outf, const char *cond) /* Special fprint_c_condition for writing to STDOUT. */ void -print_c_condition (const char *cond) +rtx_reader::print_c_condition (const char *cond) { fprint_c_condition (stdout, cond); } @@ -414,7 +390,7 @@ rtx_reader::unread_char (int ch) punctuation chars of rtx printed syntax. */ void -read_name (struct md_name *name) +rtx_reader::read_name (struct md_name *name) { int c; size_t i; @@ -458,7 +434,7 @@ read_name (struct md_name *name) name->buffer[i] = 0; name->string = name->buffer; - if (md_constants) + if (m_md_constants) { /* Do constant expansion. */ struct md_constant *def; @@ -468,7 +444,7 @@ read_name (struct md_name *name) struct md_constant tmp_def; tmp_def.name = name->string; - def = (struct md_constant *) htab_find (md_constants, &tmp_def); + def = (struct md_constant *) htab_find (m_md_constants, &tmp_def); if (def) name->string = def->value; } @@ -479,8 +455,8 @@ read_name (struct md_name *name) /* Subroutine of the string readers. Handles backslash escapes. Caller has read the backslash, but not placed it into the obstack. */ -static void -read_escape (void) +void +rtx_reader::read_escape () { int c = read_char (); @@ -508,32 +484,32 @@ read_escape (void) case 'a': case 'b': case 'f': case 'n': case 'r': case 't': case 'v': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case 'x': - obstack_1grow (&string_obstack, '\\'); + obstack_1grow (&m_string_obstack, '\\'); break; /* \; makes stuff for a C string constant containing newline and tab. */ case ';': - obstack_grow (&string_obstack, "\\n\\t", 4); + obstack_grow (&m_string_obstack, "\\n\\t", 4); return; /* pass anything else through, but issue a warning. */ default: fprintf (stderr, "%s:%d: warning: unrecognized escape \\%c\n", - rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (), + get_filename (), get_lineno (), c); - obstack_1grow (&string_obstack, '\\'); + obstack_1grow (&m_string_obstack, '\\'); break; } - obstack_1grow (&string_obstack, c); + obstack_1grow (&m_string_obstack, c); } /* Read a double-quoted string onto the obstack. Caller has scanned the leading quote. */ char * -read_quoted_string (void) +rtx_reader::read_quoted_string () { int c; @@ -548,25 +524,25 @@ read_quoted_string (void) else if (c == '"' || c == EOF) break; - obstack_1grow (&string_obstack, c); + obstack_1grow (&m_string_obstack, c); } - obstack_1grow (&string_obstack, 0); - return XOBFINISH (&string_obstack, char *); + obstack_1grow (&m_string_obstack, 0); + return XOBFINISH (&m_string_obstack, char *); } /* Read a braced string (a la Tcl) onto the string obstack. Caller has scanned the leading brace. Note that unlike quoted strings, the outermost braces _are_ included in the string constant. */ -static char * -read_braced_string (void) +char * +rtx_reader::read_braced_string () { int c; int brace_depth = 1; /* caller-processed */ - unsigned long starting_read_md_lineno = rtx_reader_ptr->get_lineno (); + unsigned long starting_read_md_lineno = get_lineno (); - obstack_1grow (&string_obstack, '{'); + obstack_1grow (&m_string_obstack, '{'); while (brace_depth) { c = read_char (); /* Read the string */ @@ -585,11 +561,11 @@ read_braced_string (void) ("missing closing } for opening brace on line %lu", starting_read_md_lineno); - obstack_1grow (&string_obstack, c); + obstack_1grow (&m_string_obstack, c); } - obstack_1grow (&string_obstack, 0); - return XOBFINISH (&string_obstack, char *); + obstack_1grow (&m_string_obstack, 0); + return XOBFINISH (&m_string_obstack, char *); } /* Read some kind of string constant. This is the high-level routine @@ -597,7 +573,7 @@ read_braced_string (void) and dispatch to the appropriate string constant reader. */ char * -read_string (int star_if_braced) +rtx_reader::read_string (int star_if_braced) { char *stringbuf; int saw_paren = 0; @@ -610,13 +586,13 @@ read_string (int star_if_braced) c = read_skip_spaces (); } - old_lineno = rtx_reader_ptr->get_lineno (); + old_lineno = get_lineno (); if (c == '"') stringbuf = read_quoted_string (); else if (c == '{') { if (star_if_braced) - obstack_1grow (&string_obstack, '*'); + obstack_1grow (&m_string_obstack, '*'); stringbuf = read_braced_string (); } else @@ -625,15 +601,15 @@ read_string (int star_if_braced) if (saw_paren) require_char_ws (')'); - set_md_ptr_loc (stringbuf, rtx_reader_ptr->get_filename (), old_lineno); + set_md_ptr_loc (stringbuf, get_filename (), old_lineno); return stringbuf; } /* Skip the rest of a construct that started at line LINENO and that is currently nested by DEPTH levels of parentheses. */ -static void -read_skip_construct (int depth, file_location loc) +void +rtx_reader::read_skip_construct (int depth, file_location loc) { struct md_name name; int c; @@ -774,8 +750,8 @@ add_constant (htab_t defs, char *name, char *value, /* Process a define_constants directive, starting with the optional space after the "define_constants". */ -static void -handle_constants (void) +void +rtx_reader::handle_constants () { int c; htab_t defs; @@ -783,8 +759,8 @@ handle_constants (void) require_char_ws ('['); /* Disable constant expansion during definition processing. */ - defs = md_constants; - md_constants = 0; + defs = m_md_constants; + m_md_constants = 0; while ( (c = read_skip_spaces ()) != ']') { struct md_name name, value; @@ -798,7 +774,7 @@ handle_constants (void) require_char_ws (')'); } - md_constants = defs; + m_md_constants = defs; } /* For every constant definition, call CALLBACK with two arguments: @@ -806,9 +782,9 @@ handle_constants (void) Stop when CALLBACK returns zero. */ void -traverse_md_constants (htab_trav callback, void *info) +rtx_reader::traverse_md_constants (htab_trav callback, void *info) { - htab_traverse (md_constants, callback, info); + htab_traverse (get_md_constants (), callback, info); } /* Return a malloc()ed decimal string that represents number NUMBER. */ @@ -828,8 +804,8 @@ md_decimal_string (int number) number on which the directive started and MD_P is true if the directive is a define_enum rather than a define_c_enum. */ -static void -handle_enum (file_location loc, bool md_p) +void +rtx_reader::handle_enum (file_location loc, bool md_p) { char *enum_name, *value_name; struct md_name name; @@ -839,7 +815,7 @@ handle_enum (file_location loc, bool md_p) int c; enum_name = read_string (false); - slot = htab_find_slot (enum_types, &enum_name, INSERT); + slot = htab_find_slot (m_enum_types, &enum_name, INSERT); if (*slot) { def = (struct enum_type *) *slot; @@ -883,7 +859,7 @@ handle_enum (file_location loc, bool md_p) value_name = xstrdup (name.string); ev->name = value_name; } - ev->def = add_constant (md_constants, value_name, + ev->def = add_constant (get_md_constants (), value_name, md_decimal_string (def->num_values), def); *def->tail_ptr = ev; @@ -895,9 +871,9 @@ handle_enum (file_location loc, bool md_p) /* Try to find the definition of the given enum. Return null on failure. */ struct enum_type * -lookup_enum_type (const char *name) +rtx_reader::lookup_enum_type (const char *name) { - return (struct enum_type *) htab_find (enum_types, &name); + return (struct enum_type *) htab_find (m_enum_types, &name); } /* For every enum definition, call CALLBACK with two arguments: @@ -905,9 +881,9 @@ lookup_enum_type (const char *name) returns zero. */ void -traverse_enum_types (htab_trav callback, void *info) +rtx_reader::traverse_enum_types (htab_trav callback, void *info) { - htab_traverse (enum_types, callback, info); + htab_traverse (m_enum_types, callback, info); } @@ -925,12 +901,43 @@ rtx_reader::rtx_reader () { /* Set the global singleton pointer. */ rtx_reader_ptr = this; + + obstack_init (&m_string_obstack); + + m_ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); + obstack_init (&m_ptr_loc_obstack); + + m_joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); + obstack_init (&m_joined_conditions_obstack); + + m_md_constants = htab_create (31, leading_string_hash, + leading_string_eq_p, (htab_del) 0); + + m_enum_types = htab_create (31, leading_string_hash, + leading_string_eq_p, (htab_del) 0); + + /* Unlock the stdio streams. */ + unlock_std_streams (); } /* rtx_reader's destructor. */ rtx_reader::~rtx_reader () { + free (m_base_dir); + + htab_delete (m_enum_types); + + htab_delete (m_md_constants); + + obstack_free (&m_joined_conditions_obstack, NULL); + htab_delete (m_joined_conditions); + + obstack_free (&m_ptr_loc_obstack, NULL); + htab_delete (m_ptr_locs); + + obstack_free (&m_string_obstack, NULL); + /* Clear the global singleton pointer. */ rtx_reader_ptr = NULL; } @@ -1105,20 +1112,6 @@ rtx_reader::read_md_files (int argc, const char **argv, bool already_read_stdin; int num_files; - /* Initialize global data. */ - obstack_init (&string_obstack); - ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); - obstack_init (&ptr_loc_obstack); - joined_conditions = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0); - obstack_init (&joined_conditions_obstack); - md_constants = htab_create (31, leading_string_hash, - leading_string_eq_p, (htab_del) 0); - enum_types = htab_create (31, leading_string_hash, - leading_string_eq_p, (htab_del) 0); - - /* Unlock the stdio streams. */ - unlock_std_streams (); - /* First we loop over all the options. */ for (i = 1; i < argc; i++) if (argv[i][0] == '-') |