diff options
author | Martin Liska <mliska@suse.cz> | 2020-08-15 19:47:35 +0200 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-08-20 10:56:07 +0930 |
commit | 32e4c1c2d7adfa71121b70c544c721b8c04b39f5 (patch) | |
tree | 8d7de29b0b35eec58d702ccf5b7af64837e889bb | |
parent | 2b272f449e8664977d0aafba82c416b27b5f2d6f (diff) | |
download | gdb-32e4c1c2d7adfa71121b70c544c721b8c04b39f5.zip gdb-32e4c1c2d7adfa71121b70c544c721b8c04b39f5.tar.gz gdb-32e4c1c2d7adfa71121b70c544c721b8c04b39f5.tar.bz2 |
Use libiberty hash in gas/read.c.
* read.c (struct po_entry): New.
(hash_po_entry): Likewise.
(eq_po_entry): Likewise.
(po_entry_alloc): Likewise.
(po_entry_find): Likewise.
(pop_insert): Likewise.
(pobegin): Use htab hash table.
(read_a_source_file): Likewise.
(s_macro): Likewise.
(read_print_statistics): Likewise.
* config/tc-m68k.c (m68k_conditional_pseudoop): Add const qualifier.
* config/tc-m68k.h (m68k_conditional_pseudoop): Likewise.
-rw-r--r-- | gas/ChangeLog | 15 | ||||
-rw-r--r-- | gas/config/tc-m68k.c | 2 | ||||
-rw-r--r-- | gas/config/tc-m68k.h | 2 | ||||
-rw-r--r-- | gas/read.c | 73 |
4 files changed, 77 insertions, 15 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog index e474edd..a2da4f9 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,20 @@ 2020-08-20 Martin Liska <mliska@suse.cz> + * read.c (struct po_entry): New. + (hash_po_entry): Likewise. + (eq_po_entry): Likewise. + (po_entry_alloc): Likewise. + (po_entry_find): Likewise. + (pop_insert): Likewise. + (pobegin): Use htab hash table. + (read_a_source_file): Likewise. + (s_macro): Likewise. + (read_print_statistics): Likewise. + * config/tc-m68k.c (m68k_conditional_pseudoop): Add const qualifier. + * config/tc-m68k.h (m68k_conditional_pseudoop): Likewise. + +2020-08-20 Martin Liska <mliska@suse.cz> + * config/tc-iq2000.c (iq2000_add_macro): Use htab hash table. * macro.c (struct hash_control): Use htab. (macro_init): Likewise. diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c index 6ffc943..6fe3f4a 100644 --- a/gas/config/tc-m68k.c +++ b/gas/config/tc-m68k.c @@ -5560,7 +5560,7 @@ s_proc (int ignore ATTRIBUTE_UNUSED) alignment is needed. */ int -m68k_conditional_pseudoop (pseudo_typeS *pop) +m68k_conditional_pseudoop (const pseudo_typeS *pop) { return (pop->poc_handler == s_mri_if || pop->poc_handler == s_mri_else); diff --git a/gas/config/tc-m68k.h b/gas/config/tc-m68k.h index e586eca..89bf046 100644 --- a/gas/config/tc-m68k.h +++ b/gas/config/tc-m68k.h @@ -47,7 +47,7 @@ extern const char *m68k_comment_chars; extern void m68k_mri_mode_change (int); #define MRI_MODE_CHANGE(i) m68k_mri_mode_change (i) -extern int m68k_conditional_pseudoop (pseudo_typeS *); +extern int m68k_conditional_pseudoop (const pseudo_typeS *); #define tc_conditional_pseudoop(pop) m68k_conditional_pseudoop (pop) extern void m68k_frob_label (symbolS *); @@ -295,7 +295,53 @@ address_bytes (void) /* Set up pseudo-op tables. */ -static struct hash_control *po_hash; +struct po_entry +{ + const char *poc_name; + + const pseudo_typeS *pop; +}; + +typedef struct po_entry po_entry_t; + +/* Hash function for a po_entry. */ + +static hashval_t +hash_po_entry (const void *e) +{ + const po_entry_t *entry = (const po_entry_t *) e; + return htab_hash_string (entry->poc_name); +} + +/* Equality function for a po_entry. */ + +static int +eq_po_entry (const void *a, const void *b) +{ + const po_entry_t *ea = (const po_entry_t *) a; + const po_entry_t *eb = (const po_entry_t *) b; + + return strcmp (ea->poc_name, eb->poc_name) == 0; +} + +static po_entry_t * +po_entry_alloc (const char *poc_name, const pseudo_typeS *pop) +{ + po_entry_t *entry = XNEW (po_entry_t); + entry->poc_name = poc_name; + entry->pop = pop; + return entry; +} + +static const pseudo_typeS * +po_entry_find (htab_t table, const char *poc_name) +{ + po_entry_t needle = { poc_name, NULL }; + po_entry_t *entry = htab_find (table, &needle); + return entry != NULL ? entry->pop : NULL; +} + +static struct htab *po_hash; static const pseudo_typeS potable[] = { {"abort", s_abort, 0}, @@ -514,14 +560,14 @@ static const char *pop_table_name; void pop_insert (const pseudo_typeS *table) { - const char *errtxt; const pseudo_typeS *pop; for (pop = table; pop->poc_name; pop++) { - errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); - if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists"))) - as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name, - errtxt); + int exists = po_entry_find (po_hash, pop->poc_name) != NULL; + if (!pop_override_ok && exists) + as_fatal (_("error constructing %s pseudo-op table"), pop_table_name); + else if (!exists) + htab_insert (po_hash, po_entry_alloc (pop->poc_name, pop)); } } @@ -540,7 +586,8 @@ pop_insert (const pseudo_typeS *table) static void pobegin (void) { - po_hash = hash_new (); + po_hash = htab_create_alloc (16, hash_po_entry, eq_po_entry, NULL, + xcalloc, xfree); /* Do the target-specific pseudo ops. */ pop_table_name = "md"; @@ -819,7 +866,7 @@ read_a_source_file (const char *name) char next_char; char *s; /* String of symbol, '\0' appended. */ long temp; - pseudo_typeS *pop; + const pseudo_typeS *pop; #ifdef WARN_COMMENTS found_comment = 0; @@ -1069,7 +1116,7 @@ read_a_source_file (const char *name) { /* The MRI assembler uses pseudo-ops without a period. */ - pop = (pseudo_typeS *) hash_find (po_hash, s); + pop = po_entry_find (po_hash, s); if (pop != NULL && pop->poc_handler == NULL) pop = NULL; } @@ -1084,7 +1131,7 @@ read_a_source_file (const char *name) already know that the pseudo-op begins with a '.'. */ if (pop == NULL) - pop = (pseudo_typeS *) hash_find (po_hash, s + 1); + pop = po_entry_find (po_hash, s + 1); if (pop && !pop->poc_handler) pop = NULL; @@ -2739,10 +2786,10 @@ s_macro (int ignore ATTRIBUTE_UNUSED) } if (((NO_PSEUDO_DOT || flag_m68k_mri) - && hash_find (po_hash, name) != NULL) + && po_entry_find (po_hash, name) != NULL) || (!flag_m68k_mri && *name == '.' - && hash_find (po_hash, name + 1) != NULL)) + && po_entry_find (po_hash, name + 1) != NULL)) as_warn_where (file, line, _("attempt to redefine pseudo-op `%s' ignored"), @@ -6128,7 +6175,7 @@ s_ignore (int arg ATTRIBUTE_UNUSED) void read_print_statistics (FILE *file) { - hash_print_statistics (file, "pseudo-op table", po_hash); + htab_print_statistics (file, "pseudo-op table", po_hash); } /* Inserts the given line into the input stream. |