diff options
author | Martin Liska <mliska@suse.cz> | 2020-08-15 19:47:01 +0200 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-08-20 10:53:40 +0930 |
commit | 2b272f449e8664977d0aafba82c416b27b5f2d6f (patch) | |
tree | 7ea3e404d7c0b07aeac6fb4f3ae2e142d23fd534 /gas/macro.c | |
parent | abebb03c3af215d7542f5e6b71d78823b15220d5 (diff) | |
download | gdb-2b272f449e8664977d0aafba82c416b27b5f2d6f.zip gdb-2b272f449e8664977d0aafba82c416b27b5f2d6f.tar.gz gdb-2b272f449e8664977d0aafba82c416b27b5f2d6f.tar.bz2 |
Use libiberty hash in gas/macro.c.
* config/tc-iq2000.c (iq2000_add_macro): Use htab hash table.
* macro.c (struct hash_control): Use htab.
(macro_init): Likewise.
(do_formals): Likewise.
(free_macro): Likewise.
(define_macro): Likewise.
(sub_actual): Likewise.
(macro_expand_body): Likewise.
(macro_expand): Likewise.
(check_macro): Likewise.
(delete_macro): Likewise.
(expand_irp): Likewise.
* macro.h (struct macro_hash_entry): New struct.
(hash_macro_entry): New.
(eq_macro_entry): Likewise.
(macro_entry_alloc): Likewise.
(macro_entry_find): Likewise.
(struct formal_hash_entry): Likewise.
(hash_formal_entry): Likewise.
(eq_formal_entry): Likewise.
(formal_entry_alloc): Likewise.
(formal_entry_find): Likewise.
Diffstat (limited to 'gas/macro.c')
-rw-r--r-- | gas/macro.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/gas/macro.c b/gas/macro.c index de6b417..d99430e 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -44,7 +44,7 @@ /* The macro hash table. */ -struct hash_control *macro_hash; +struct htab *macro_hash; /* Whether any macros have been defined. */ @@ -76,7 +76,8 @@ void macro_init (int alternate, int mri, int strip_at, size_t (*exp) (const char *, size_t, sb *, offsetT *)) { - macro_hash = hash_new (); + macro_hash = htab_create_alloc (16, hash_macro_entry, eq_macro_entry, + NULL, xcalloc, free); macro_defined = 0; macro_alternate = alternate; macro_mri = mri; @@ -566,8 +567,8 @@ do_formals (macro_entry *macro, size_t idx, sb *in) } /* Add to macro's hash table. */ - if (! hash_find (macro->formal_hash, name)) - hash_jam (macro->formal_hash, name, formal); + if (formal_entry_find (macro->formal_hash, name) == NULL) + htab_insert (macro->formal_hash, formal_entry_alloc (name, formal)); else as_bad_where (macro->file, macro->line, @@ -605,13 +606,13 @@ do_formals (macro_entry *macro, size_t idx, sb *in) sb_add_string (&formal->name, name); /* Add to macro's hash table. */ - if (hash_find (macro->formal_hash, name)) + if (formal_entry_find (macro->formal_hash, name)) as_bad_where (macro->file, macro->line, _("Reserved word `%s' used as parameter in macro `%s'"), name, macro->name); - hash_jam (macro->formal_hash, name, formal); + htab_insert (macro->formal_hash, formal_entry_alloc (name, formal)); formal->index = NARG_INDEX; *p = formal; @@ -635,7 +636,7 @@ free_macro (macro_entry *macro) formal = formal->next; del_formal (f); } - hash_die (macro->formal_hash); + htab_delete (macro->formal_hash); sb_kill (¯o->sub); free (macro); } @@ -662,7 +663,8 @@ define_macro (size_t idx, sb *in, sb *label, macro->formal_count = 0; macro->formals = 0; - macro->formal_hash = hash_new_sized (7); + macro->formal_hash = htab_create_alloc (7, hash_formal_entry, eq_formal_entry, + NULL, xcalloc, free); idx = sb_skip_white (idx, in); if (! buffer_and_nest ("MACRO", "ENDM", ¯o->sub, get_line)) @@ -707,10 +709,10 @@ define_macro (size_t idx, sb *in, sb *label, /* And stick it in the macro hash table. */ for (idx = 0; idx < name.len; idx++) name.ptr[idx] = TOLOWER (name.ptr[idx]); - if (hash_find (macro_hash, macro->name)) + if (macro_entry_find (macro_hash, macro->name)) error = _("Macro `%s' was already defined"); if (!error) - error = hash_jam (macro_hash, macro->name, (void *) macro); + htab_insert (macro_hash, macro_entry_alloc (macro->name, macro)); if (namep != NULL) *namep = macro->name; @@ -740,7 +742,7 @@ get_apost_token (size_t idx, sb *in, sb *name, int kind) /* Substitute the actual value for a formal parameter. */ static size_t -sub_actual (size_t start, sb *in, sb *t, struct hash_control *formal_hash, +sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash, int kind, sb *out, int copyifnotthere) { size_t src; @@ -754,7 +756,7 @@ sub_actual (size_t start, sb *in, sb *t, struct hash_control *formal_hash, && (src == start || in->ptr[src - 1] != '@')) ptr = NULL; else - ptr = (formal_entry *) hash_find (formal_hash, sb_terminate (t)); + ptr = formal_entry_find (formal_hash, sb_terminate (t)); if (ptr) { if (ptr->actual.len) @@ -790,7 +792,7 @@ sub_actual (size_t start, sb *in, sb *t, struct hash_control *formal_hash, static const char * macro_expand_body (sb *in, sb *out, formal_entry *formals, - struct hash_control *formal_hash, const macro_entry *macro) + struct htab *formal_hash, const macro_entry *macro) { sb t; size_t src = 0; @@ -912,7 +914,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, src = get_token (src, in, &f->name); name = sb_terminate (&f->name); - if (! hash_find (formal_hash, name)) + if (formal_entry_find (formal_hash, name) == NULL) { static int loccnt; char buf[20]; @@ -924,9 +926,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, sprintf (buf, IS_ELF ? ".LL%04x" : "LL%04x", ++loccnt); sb_add_string (&f->actual, buf); - err = hash_jam (formal_hash, name, f); - if (err != NULL) - break; + htab_insert (formal_hash, formal_entry_alloc (name, f)); } else { @@ -966,7 +966,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, sb_reset (&t); src = get_token (src + 2, in, &t); - ptr = (formal_entry *) hash_find (formal_hash, sb_terminate (&t)); + ptr = formal_entry_find (formal_hash, sb_terminate (&t)); if (ptr == NULL) { /* FIXME: We should really return a warning string here, @@ -1010,7 +1010,8 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, f = loclist->next; name = sb_terminate (&loclist->name); - hash_delete (formal_hash, name, f == NULL); + formal_hash_entry_t needle = { name, NULL }; + htab_remove_elt (formal_hash, &needle); del_formal (loclist); loclist = f; } @@ -1095,7 +1096,7 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out) } /* Lookup the formal in the macro's list. */ - ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate (&t)); + ptr = formal_entry_find (m->formal_hash, sb_terminate (&t)); if (!ptr) { as_bad (_("Parameter named `%s' does not exist for macro `%s'"), @@ -1193,7 +1194,7 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out) sb_reset (&t); sb_add_string (&t, macro_strip_at ? "$NARG" : "NARG"); - ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate (&t)); + ptr = formal_entry_find (m->formal_hash, sb_terminate (&t)); sprintf (buffer, "%d", narg); sb_add_string (&ptr->actual, buffer); } @@ -1253,7 +1254,7 @@ check_macro (const char *line, sb *expand, for (cls = copy; *cls != '\0'; cls ++) *cls = TOLOWER (*cls); - macro = (macro_entry *) hash_find (macro_hash, copy); + macro = macro_entry_find (macro_hash, copy); free (copy); if (macro == NULL) @@ -1294,14 +1295,14 @@ delete_macro (const char *name) /* We can only ask hash_delete to free memory if we are deleting macros in reverse order to their definition. So just clear out the entry. */ - if ((macro = (macro_entry *) hash_find (macro_hash, copy)) != NULL) + macro = macro_entry_find (macro_hash, copy); + if (macro) { - hash_jam (macro_hash, copy, NULL); + htab_insert (macro_hash, macro_entry_alloc (copy, NULL)); free_macro (macro); } else as_warn (_("Attempt to purge non-existing macro `%s'"), copy); - free (copy); } /* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a @@ -1313,8 +1314,8 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *)) { sb sub; formal_entry f; - struct hash_control *h; - const char *err; + struct htab *h; + const char *err = NULL; idx = sb_skip_white (idx, in); @@ -1330,10 +1331,10 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *)) if (f.name.len == 0) return _("missing model parameter"); - h = hash_new (); - err = hash_jam (h, sb_terminate (&f.name), &f); - if (err != NULL) - return err; + h = htab_create_alloc (16, hash_formal_entry, eq_formal_entry, + NULL, xcalloc, free); + + htab_insert (h, formal_entry_alloc (sb_terminate (&f.name), &f)); f.index = 1; f.next = NULL; @@ -1392,7 +1393,7 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *)) } } - hash_die (h); + htab_delete (h); sb_kill (&f.actual); sb_kill (&f.def); sb_kill (&f.name); |