From 9f418533f26281f5d9bf776d9d18605f8b2c3b0f Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 10 Jun 2010 20:22:49 +0000 Subject: Makefile.in (READ_MD_H): Add $(HASHTAB_H). gcc/ * Makefile.in (READ_MD_H): Add $(HASHTAB_H). (build/genconstants.o): Depend on $(READ_MD_H) gensupport.h. * genconstants.c: Include read-md.h. * read-rtl.c (md_constants): Move to read-md.c. (md_name): Move to read-md.h. (initialize_iterators): Use leading_string_hash instead of def_hash and leading_string_eq_p instead of def_name_eq_p. (read_name): Move to read-md.c. (def_hash, def_name_eq_p): Delete. (read_constants, traverse_md_constants): Move to read-md.c. * rtl.h (md_constant, traverse_md_constants): Move to read-md.h. * read-md.h: Include hashtab.h. (md_name): Moved from read-rtl.c. (md_constant): Moved from read-md.h. (leading_string_hash, leading_string_eq_p, read_name) (read_constants, traverse_md_constants): Declare. * read-md.c (md_constants): Moved from read-rtl.c. (leading_string_hash, leading_string_eq_p): New functions. (read_name, read_constants, traverse_md_constants): Moved from read-rtl.c. From-SVN: r160575 --- gcc/ChangeLog | 23 +++++++ gcc/Makefile.in | 4 +- gcc/genconstants.c | 1 + gcc/read-md.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/read-md.h | 25 ++++++++ gcc/read-rtl.c | 173 ++--------------------------------------------------- gcc/rtl.h | 4 -- 7 files changed, 207 insertions(+), 173 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d62dc4..c40d0a1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,28 @@ 2010-06-10 Richard Sandiford + * Makefile.in (READ_MD_H): Add $(HASHTAB_H). + (build/genconstants.o): Depend on $(READ_MD_H) gensupport.h. + * genconstants.c: Include read-md.h. + * read-rtl.c (md_constants): Move to read-md.c. + (md_name): Move to read-md.h. + (initialize_iterators): Use leading_string_hash instead of def_hash + and leading_string_eq_p instead of def_name_eq_p. + (read_name): Move to read-md.c. + (def_hash, def_name_eq_p): Delete. + (read_constants, traverse_md_constants): Move to read-md.c. + * rtl.h (md_constant, traverse_md_constants): Move to read-md.h. + * read-md.h: Include hashtab.h. + (md_name): Moved from read-rtl.c. + (md_constant): Moved from read-md.h. + (leading_string_hash, leading_string_eq_p, read_name) + (read_constants, traverse_md_constants): Declare. + * read-md.c (md_constants): Moved from read-rtl.c. + (leading_string_hash, leading_string_eq_p): New functions. + (read_name, read_constants, traverse_md_constants): Moved from + read-rtl.c. + +2010-06-10 Richard Sandiford + * read-rtl.c (md_name): New structure. (read_name): Take an md_name instead of a buffer pointer. Use the "string" field instead of strcpy when expanding constants. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index f3a354c..b8379d0 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -871,7 +871,7 @@ RTL_BASE_H = rtl.h rtl.def $(MACHMODE_H) reg-notes.def insn-notes.def \ $(INPUT_H) $(REAL_H) statistics.h $(VEC_H) $(FIXED_VALUE_H) alias.h FIXED_VALUE_H = fixed-value.h $(MACHMODE_H) double-int.h RTL_H = $(RTL_BASE_H) genrtl.h vecir.h -READ_MD_H = $(OBSTACK_H) read-md.h +READ_MD_H = $(OBSTACK_H) $(HASHTAB_H) read-md.h PARAMS_H = params.h params.def BUILTINS_DEF = builtins.def sync-builtins.def omp-builtins.def TREE_H = tree.h all-tree.def tree.def c-family/c-common.def \ @@ -3814,7 +3814,7 @@ build/genconditions.o : genconditions.c $(RTL_BASE_H) $(BCONFIG_H) \ build/genconfig.o : genconfig.c $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \ coretypes.h $(GTM_H) errors.h gensupport.h build/genconstants.o : genconstants.c $(RTL_BASE_H) $(BCONFIG_H) \ - $(SYSTEM_H) coretypes.h $(GTM_H) errors.h + $(SYSTEM_H) coretypes.h $(GTM_H) errors.h $(READ_MD_H) gensupport.h build/genemit.o : genemit.c $(RTL_BASE_H) $(BCONFIG_H) $(SYSTEM_H) \ coretypes.h $(GTM_H) errors.h $(READ_MD_H) gensupport.h build/genextract.o : genextract.c $(RTL_BASE_H) $(BCONFIG_H) \ diff --git a/gcc/genconstants.c b/gcc/genconstants.c index a68dbf1..1a0182c 100644 --- a/gcc/genconstants.c +++ b/gcc/genconstants.c @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" #include "rtl.h" #include "errors.h" +#include "read-md.h" #include "gensupport.h" /* Called via traverse_md_constants; emit a #define for diff --git a/gcc/read-md.c b/gcc/read-md.c index 654e625..07882aa 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -62,6 +62,29 @@ const char *read_md_filename; /* The current line number in READ_MD_FILE. */ int read_md_lineno; +/* A table of md_constant structures, hashed by name. Null if no + constant expansion should occur. */ +static htab_t md_constants; + +/* Given an object that starts with a char * name field, return a hash + code for its name. */ + +hashval_t +leading_string_hash (const void *def) +{ + return htab_hash_string (*(const char *const *) def); +} + +/* Given two objects that start with char * name fields, return true if + they have the same name. */ + +int +leading_string_eq_p (const void *def1, const void *def2) +{ + return strcmp (*(const char *const *) def1, + *(const char *const *) def2) == 0; +} + /* Return a hash value for the pointer pointed to by DEF. */ static hashval_t @@ -314,6 +337,63 @@ read_skip_spaces (void) } } +/* Read an rtx code name into NAME. It is terminated by any of the + punctuation chars of rtx printed syntax. */ + +void +read_name (struct md_name *name) +{ + int c; + size_t i; + + c = read_skip_spaces (); + + i = 0; + while (1) + { + if (c == ' ' || c == '\n' || c == '\t' || c == '\f' || c == '\r' + || c == EOF) + break; + if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' + || c == '(' || c == '[') + { + unread_char (c); + break; + } + + if (i == sizeof (name->buffer) - 1) + fatal_with_file_and_line ("name too long"); + name->buffer[i++] = c; + + c = read_char (); + } + + if (i == 0) + fatal_with_file_and_line ("missing name or number"); + if (c == '\n') + read_md_lineno++; + + name->buffer[i] = 0; + name->string = name->buffer; + + if (md_constants) + { + /* Do constant expansion. */ + struct md_constant *def; + + do + { + struct md_constant tmp_def; + + tmp_def.name = name->string; + def = (struct md_constant *) htab_find (md_constants, &tmp_def); + if (def) + name->string = def->value; + } + while (def); + } +} + /* Subroutine of the string readers. Handles backslash escapes. Caller has read the backslash, but not placed it into the obstack. */ @@ -522,6 +602,76 @@ scan_comma_elt (const char **pstr) return start; } +/* Process a define_constants directive, starting with the optional space + after the "define_constants". */ + +void +read_constants (void) +{ + int c; + htab_t defs; + + defs = md_constants; + if (! defs) + defs = htab_create (32, leading_string_hash, + leading_string_eq_p, (htab_del) 0); + + c = read_skip_spaces (); + if (c != '[') + fatal_expected_char ('[', c); + + /* Disable constant expansion during definition processing. */ + md_constants = 0; + while ( (c = read_skip_spaces ()) != ']') + { + struct md_name name, value; + struct md_constant *def, tmp_def; + void **entry_ptr; + + if (c != '(') + fatal_expected_char ('(', c); + + read_name (&name); + read_name (&value); + + tmp_def.name = name.string; + entry_ptr = htab_find_slot (defs, &tmp_def, INSERT); + if (*entry_ptr) + { + def = (struct md_constant *) *entry_ptr; + if (strcmp (def->value, value.string) != 0) + fatal_with_file_and_line ("redefinition of %s, was %s, now %s", + def->name, def->value, value.string); + } + else + { + def = XNEW (struct md_constant); + def->name = xstrdup (name.string); + def->value = xstrdup (value.string); + *entry_ptr = def; + } + + c = read_skip_spaces (); + if (c != ')') + fatal_expected_char (')', c); + } + md_constants = defs; + c = read_skip_spaces (); + if (c != ')') + fatal_expected_char (')', c); +} + +/* For every constant definition, call CALLBACK with two arguments: + a pointer a pointer to the constant definition and INFO. + Stop when CALLBACK returns zero. */ + +void +traverse_md_constants (htab_trav callback, void *info) +{ + if (md_constants) + htab_traverse (md_constants, callback, info); +} + /* Initialize this file's static data. */ void diff --git a/gcc/read-md.h b/gcc/read-md.h index 075260b..2edd3ce 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -20,6 +20,26 @@ along with GCC; see the file COPYING3. If not see . */ #include "obstack.h" +#include "hashtab.h" + +/* Holds one symbol or number in the .md file. */ +struct md_name { + /* The name as it appeared in the .md file. Names are syntactically + limited to the length of this buffer. */ + char buffer[256]; + + /* The name that should actually be used by the generator programs. + This is an expansion of NAME, after things like constant substitution. */ + char *string; +}; + +/* This structure represents a constant defined by define_constant. + NAME is the name of the constant and VALUE is the string it + expands to. */ +struct md_constant { + char *name; + char *value; +}; extern FILE *read_md_file; extern int read_md_lineno; @@ -42,6 +62,8 @@ unread_char (int ch) ungetc (ch, read_md_file); } +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 *); extern void print_md_ptr_loc (const void *); extern const char *join_c_conditions (const char *, const char *); @@ -52,8 +74,11 @@ 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 read_name (struct md_name *); extern char *read_quoted_string (void); extern char *read_string (int); extern int n_comma_elts (const char *); extern const char *scan_comma_elt (const char **); +extern void read_constants (void); +extern void traverse_md_constants (htab_trav, void *); extern void init_md_reader (void); diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c index 1b7d77d..a3a9b61 100644 --- a/gcc/read-rtl.c +++ b/gcc/read-rtl.c @@ -33,19 +33,6 @@ along with GCC; see the file COPYING3. If not see #include "read-md.h" #include "gensupport.h" -static htab_t md_constants; - -/* Holds one symbol or number in the .md file. */ -struct md_name { - /* The name as it appeared in the .md file. Names are syntactically - limited to the length of this buffer. */ - char buffer[256]; - - /* The name that should actually be used by the generator programs. - This is an expansion of NAME, after things like constant substitution. */ - char *string; -}; - /* One element in a singly-linked list of (integer, string) pairs. */ struct map_value { struct map_value *next; @@ -125,10 +112,6 @@ static struct mapping *add_mapping (struct iterator_group *, htab_t t, static struct map_value **add_map_value (struct map_value **, int, const char *); static void initialize_iterators (void); -static void read_name (struct md_name *); -static hashval_t def_hash (const void *); -static int def_name_eq_p (const void *, const void *); -static void read_constants (void); static void read_conditions (void); static void validate_const_int (const char *); static int find_iterator (struct iterator_group *, const char *); @@ -579,15 +562,17 @@ initialize_iterators (void) char *copy, *p; int i; - modes.attrs = htab_create (13, def_hash, def_name_eq_p, 0); - modes.iterators = htab_create (13, def_hash, def_name_eq_p, 0); + modes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); + modes.iterators = htab_create (13, leading_string_hash, + leading_string_eq_p, 0); modes.num_builtins = MAX_MACHINE_MODE; modes.find_builtin = find_mode; modes.uses_iterator_p = uses_mode_iterator_p; modes.apply_iterator = apply_mode_iterator; - codes.attrs = htab_create (13, def_hash, def_name_eq_p, 0); - codes.iterators = htab_create (13, def_hash, def_name_eq_p, 0); + codes.attrs = htab_create (13, leading_string_hash, leading_string_eq_p, 0); + codes.iterators = htab_create (13, leading_string_hash, + leading_string_eq_p, 0); codes.num_builtins = NUM_RTX_CODE; codes.find_builtin = find_code; codes.uses_iterator_p = uses_code_iterator_p; @@ -621,63 +606,6 @@ initialize_iterators (void) upper_ptr = add_map_value (upper_ptr, i, copy); } } - -/* Read an rtx code name into NAME. It is terminated by any of the - punctuation chars of rtx printed syntax. */ - -static void -read_name (struct md_name *name) -{ - int c; - size_t i; - - c = read_skip_spaces (); - - i = 0; - while (1) - { - if (c == ' ' || c == '\n' || c == '\t' || c == '\f' || c == '\r' - || c == EOF) - break; - if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/' - || c == '(' || c == '[') - { - unread_char (c); - break; - } - - if (i == sizeof (name->buffer) - 1) - fatal_with_file_and_line ("name too long"); - name->buffer[i++] = c; - - c = read_char (); - } - - if (i == 0) - fatal_with_file_and_line ("missing name or number"); - if (c == '\n') - read_md_lineno++; - - name->buffer[i] = 0; - name->string = name->buffer; - - if (md_constants) - { - /* Do constant expansion. */ - struct md_constant *def; - - do - { - struct md_constant tmp_def; - - tmp_def.name = name->string; - def = (struct md_constant *) htab_find (md_constants, &tmp_def); - if (def) - name->string = def->value; - } - while (def); - } -} /* Provide a version of a function to read a long long if the system does not provide one. */ @@ -716,95 +644,6 @@ atoll (const char *p) return tmp_wide; } #endif - -/* Given an object that starts with a char * name field, return a hash - code for its name. */ -static hashval_t -def_hash (const void *def) -{ - unsigned result, i; - const char *string = *(const char *const *) def; - - for (result = i = 0; *string++ != '\0'; i++) - result += ((unsigned char) *string << (i % CHAR_BIT)); - return result; -} - -/* Given two objects that start with char * name fields, return true if - they have the same name. */ -static int -def_name_eq_p (const void *def1, const void *def2) -{ - return ! strcmp (*(const char *const *) def1, - *(const char *const *) def2); -} - -/* Process a define_constants directive, starting with the optional space - after the "define_constants". */ -static void -read_constants (void) -{ - int c; - htab_t defs; - - c = read_skip_spaces (); - if (c != '[') - fatal_expected_char ('[', c); - - defs = md_constants; - if (! defs) - defs = htab_create (32, def_hash, def_name_eq_p, (htab_del) 0); - - /* Disable constant expansion during definition processing. */ - md_constants = 0; - while ( (c = read_skip_spaces ()) != ']') - { - struct md_name name, value; - struct md_constant *def, tmp_def; - void **entry_ptr; - - if (c != '(') - fatal_expected_char ('(', c); - - read_name (&name); - read_name (&value); - - tmp_def.name = name.string; - entry_ptr = htab_find_slot (defs, &tmp_def, INSERT); - if (*entry_ptr) - { - def = (struct md_constant *) *entry_ptr; - if (strcmp (def->value, value.string) != 0) - fatal_with_file_and_line ("redefinition of %s, was %s, now %s", - def->name, def->value, value.string); - } - else - { - def = XNEW (struct md_constant); - def->name = xstrdup (name.string); - def->value = xstrdup (value.string); - *entry_ptr = def; - } - - c = read_skip_spaces (); - if (c != ')') - fatal_expected_char (')', c); - } - md_constants = defs; - c = read_skip_spaces (); - if (c != ')') - fatal_expected_char (')', c); -} - -/* For every constant definition, call CALLBACK with two arguments: - a pointer a pointer to the constant definition and INFO. - Stops when CALLBACK returns zero. */ -void -traverse_md_constants (htab_trav callback, void *info) -{ - if (md_constants) - htab_traverse (md_constants, callback, info); -} /* Process a define_conditions directive, starting with the optional space after the "define_conditions". The directive looks like this: diff --git a/gcc/rtl.h b/gcc/rtl.h index 1ed8f73..5826496 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -2356,10 +2356,6 @@ extern void init_varasm_once (void); extern rtx make_debug_expr_from_rtl (const_rtx); -/* In rtl.c */ -extern void traverse_md_constants (int (*) (void **, void *), void *); -struct md_constant { char *name, *value; }; - /* In read-rtl.c */ extern bool read_rtx (rtx *, int *); -- cgit v1.1