diff options
author | Alan Modra <amodra@gmail.com> | 2022-07-07 08:37:10 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-07-09 21:21:36 +0930 |
commit | bdcc1de1ecfabc7d2560aa56cbe5425cb43e9cac (patch) | |
tree | 052d9411ca4a306644e193dfbcd5dfee99049291 /gas/macro.c | |
parent | d1cffdc3644b21187c3709ae3c9c757f9d59558e (diff) | |
download | gdb-bdcc1de1ecfabc7d2560aa56cbe5425cb43e9cac.zip gdb-bdcc1de1ecfabc7d2560aa56cbe5425cb43e9cac.tar.gz gdb-bdcc1de1ecfabc7d2560aa56cbe5425cb43e9cac.tar.bz2 |
macro.c: use string hash from hash.h for macro_hash
Another case of duplicated hash.h code, the only minor difference
being that macro->format_hash was created with 7 entries vs. str_hash
with 16 entries.
* macro.c (macro_init, define_macro): Use str_htab_create.
(do_formals, define_macro, macro_expand_body): Use str_hash_insert
(macro_expand_body): Use str_hash_find and str_hash_delete.
(delete_macro): Likewise.
(sub_actual, macro_expand, check_macro): Use str_hash_find.
(expand_irp): Use str_htab_create and str_hash_insert.
* macro.h (struct macro_struct): Tidy.
(struct macro_hash_entry, macro_hash_entry_t, hash_macro_entry),
(eq_macro_entry, macro_entry_alloc, macro_entry_find),
(struct formal_hash_entry, formal_hash_entry_t),
(hash_formal_entry, eq_formal_entry, formal_entry_alloc),
(formal_entry_find): Delete.
* config/tc-iq2000.c (iq2000_add_macro): Use str_htab_create
and str_hash_insert.
Diffstat (limited to 'gas/macro.c')
-rw-r--r-- | gas/macro.c | 62 |
1 files changed, 21 insertions, 41 deletions
diff --git a/gas/macro.c b/gas/macro.c index 3aba78f..b360b2e 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -44,7 +44,7 @@ /* The macro hash table. */ -struct htab *macro_hash; +htab_t macro_hash; /* Whether any macros have been defined. */ @@ -76,8 +76,7 @@ void macro_init (int alternate, int mri, int strip_at, size_t (*exp) (const char *, size_t, sb *, offsetT *)) { - macro_hash = htab_create_alloc (16, hash_macro_entry, eq_macro_entry, - NULL, xcalloc, free); + macro_hash = str_htab_create (); macro_defined = 0; macro_alternate = alternate; macro_mri = mri; @@ -536,7 +535,6 @@ do_formals (macro_entry *macro, size_t idx, sb *in) { formal_entry *formal = new_formal (); size_t cidx; - formal_hash_entry_t *elt; idx = get_token (idx, in, &formal->name); if (formal->name.len == 0) @@ -599,10 +597,8 @@ do_formals (macro_entry *macro, size_t idx, sb *in) } /* Add to macro's hash table. */ - elt = formal_entry_alloc (name, formal); - if (htab_insert (macro->formal_hash, elt, 0) != NULL) + if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL) { - free (elt); as_bad_where (macro->file, macro->line, _("A parameter named `%s' " "already exists for macro `%s'"), @@ -626,7 +622,6 @@ do_formals (macro_entry *macro, size_t idx, sb *in) if (macro_mri) { formal_entry *formal = new_formal (); - formal_hash_entry_t *elt; /* Add a special NARG formal, which macro_expand will set to the number of arguments. */ @@ -640,10 +635,8 @@ do_formals (macro_entry *macro, size_t idx, sb *in) sb_add_string (&formal->name, name); /* Add to macro's hash table. */ - elt = formal_entry_alloc (name, formal); - if (htab_insert (macro->formal_hash, elt, 0) != NULL) + if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL) { - free (elt); as_bad_where (macro->file, macro->line, _("Reserved word `%s' used as parameter in macro `%s'"), name, macro->name); @@ -698,8 +691,7 @@ define_macro (size_t idx, sb *in, sb *label, macro->formal_count = 0; macro->formals = 0; - macro->formal_hash = htab_create_alloc (7, hash_formal_entry, eq_formal_entry, - NULL, xcalloc, free); + macro->formal_hash = str_htab_create (); idx = sb_skip_white (idx, in); if (! buffer_and_nest ("MACRO", "ENDM", ¯o->sub, get_line)) @@ -746,12 +738,8 @@ define_macro (size_t idx, sb *in, sb *label, name.ptr[idx] = TOLOWER (name.ptr[idx]); if (!error) { - macro_hash_entry_t *elt = macro_entry_alloc (macro->name, macro); - if (htab_insert (macro_hash, elt, 0) != NULL) - { - free (elt); - error = _("Macro `%s' was already defined"); - } + if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL) + error = _("Macro `%s' was already defined"); } if (namep != NULL) @@ -796,7 +784,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash, && (src == start || in->ptr[src - 1] != '@')) ptr = NULL; else - ptr = formal_entry_find (formal_hash, sb_terminate (t)); + ptr = str_hash_find (formal_hash, sb_terminate (t)); if (ptr) { if (ptr->actual.len) @@ -951,14 +939,11 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, { const char *name; formal_entry *f = new_formal (); - formal_hash_entry_t *elt; src = get_token (src, in, &f->name); name = sb_terminate (&f->name); - elt = formal_entry_alloc (name, f); - if (htab_insert (formal_hash, elt, 0) != NULL) + if (str_hash_insert (formal_hash, name, f, 0) != NULL) { - free (elt); as_bad_where (macro->file, macro->line + macro_line, _("`%s' was already used as parameter " "(or another local) name"), name); @@ -1006,7 +991,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, sb_reset (&t); src = get_token (src + 2, in, &t); - ptr = formal_entry_find (formal_hash, sb_terminate (&t)); + ptr = str_hash_find (formal_hash, sb_terminate (&t)); if (ptr == NULL) { /* FIXME: We should really return a warning string here, @@ -1050,8 +1035,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals, f = loclist->next; name = sb_terminate (&loclist->name); - formal_hash_entry_t needle = { name, NULL }; - htab_remove_elt (formal_hash, &needle); + str_hash_delete (formal_hash, name); del_formal (loclist); loclist = f; } @@ -1136,7 +1120,7 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out) } /* Lookup the formal in the macro's list. */ - ptr = formal_entry_find (m->formal_hash, sb_terminate (&t)); + ptr = str_hash_find (m->formal_hash, sb_terminate (&t)); if (!ptr) { as_bad (_("Parameter named `%s' does not exist for macro `%s'"), @@ -1234,7 +1218,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_find (m->formal_hash, sb_terminate (&t)); + ptr = str_hash_find (m->formal_hash, sb_terminate (&t)); sprintf (buffer, "%d", narg); sb_add_string (&ptr->actual, buffer); } @@ -1294,7 +1278,7 @@ check_macro (const char *line, sb *expand, for (cls = copy; *cls != '\0'; cls ++) *cls = TOLOWER (*cls); - macro = macro_entry_find (macro_hash, copy); + macro = str_hash_find (macro_hash, copy); free (copy); if (macro == NULL) @@ -1324,8 +1308,7 @@ delete_macro (const char *name) { char *copy; size_t i, len; - void **slot; - macro_hash_entry_t needle; + macro_entry *macro; len = strlen (name); copy = XNEWVEC (char, len + 1); @@ -1333,13 +1316,11 @@ delete_macro (const char *name) copy[i] = TOLOWER (name[i]); copy[i] = '\0'; - needle.name = copy; - needle.macro = NULL; - slot = htab_find_slot (macro_hash, &needle, NO_INSERT); - if (slot) + macro = str_hash_find (macro_hash, copy); + if (macro != NULL) { - free_macro (((macro_hash_entry_t *) *slot)->macro); - htab_clear_slot (macro_hash, slot); + free_macro (macro); + str_hash_delete (macro_hash, copy); } else as_warn (_("Attempt to purge non-existing macro `%s'"), copy); @@ -1372,10 +1353,9 @@ 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 = htab_create_alloc (16, hash_formal_entry, eq_formal_entry, - NULL, xcalloc, free); + h = str_htab_create (); - htab_insert (h, formal_entry_alloc (sb_terminate (&f.name), &f), 0); + str_hash_insert (h, sb_terminate (&f.name), &f, 0); f.index = 1; f.next = NULL; |