/* The macro hash table. */
-struct htab *macro_hash;
+htab_t macro_hash;
/* Whether any macros have been defined. */
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;
{
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)
}
/* 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'"),
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. */
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);
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))
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)
&& (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)
{
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);
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,
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;
}
}
/* 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'"),
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);
}
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)
{
char *copy;
size_t i, len;
- void **slot;
- macro_hash_entry_t needle;
+ macro_entry *macro;
len = strlen (name);
copy = XNEWVEC (char, len + 1);
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);
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;
{
sb sub; /* Substitution text. */
int formal_count; /* Number of formal args. */
- formal_entry *formals; /* Pointer to list of formal_structs. */
- struct htab *formal_hash; /* Hash table of formals. */
+ formal_entry *formals; /* List of formal_structs. */
+ htab_t formal_hash; /* Hash table of formals. */
const char *name; /* Macro name. */
- const char *file; /* File the macro was defined in. */
+ const char *file; /* File the macro was defined in. */
unsigned int line; /* Line number of definition. */
} macro_entry;
/* The macro hash table. */
-extern struct htab *macro_hash;
-
-struct macro_hash_entry
-{
- const char *name;
- macro_entry *macro;
-};
-
-typedef struct macro_hash_entry macro_hash_entry_t;
-
-/* Hash function for a macro_hash_entry. */
-
-static inline hashval_t
-hash_macro_entry (const void *e)
-{
- const macro_hash_entry_t *entry = (const macro_hash_entry_t *) e;
- return htab_hash_string (entry->name);
-}
-
-/* Equality function for a macro_hash_entry. */
-
-static inline int
-eq_macro_entry (const void *a, const void *b)
-{
- const macro_hash_entry_t *ea = (const macro_hash_entry_t *) a;
- const macro_hash_entry_t *eb = (const macro_hash_entry_t *) b;
-
- return strcmp (ea->name, eb->name) == 0;
-}
-
-static inline macro_hash_entry_t *
-macro_entry_alloc (const char *name, macro_entry *macro)
-{
- macro_hash_entry_t *entry = XNEW (macro_hash_entry_t);
- entry->name = name;
- entry->macro = macro;
- return entry;
-}
-
-static inline macro_entry *
-macro_entry_find (htab_t table, const char *name)
-{
- macro_hash_entry_t needle = { name, NULL };
- macro_hash_entry_t *entry = htab_find (table, &needle);
- return entry != NULL ? entry->macro : NULL;
-}
-
-struct formal_hash_entry
-{
- const char *name;
- formal_entry *formal;
-};
-
-typedef struct formal_hash_entry formal_hash_entry_t;
-
-/* Hash function for a macro_hash_entry. */
-
-static inline hashval_t
-hash_formal_entry (const void *e)
-{
- const formal_hash_entry_t *entry = (const formal_hash_entry_t *) e;
- return htab_hash_string (entry->name);
-}
-
-/* Equality function for a formal_hash_entry. */
-
-static inline int
-eq_formal_entry (const void *a, const void *b)
-{
- const formal_hash_entry_t *ea = (const formal_hash_entry_t *) a;
- const formal_hash_entry_t *eb = (const formal_hash_entry_t *) b;
-
- return strcmp (ea->name, eb->name) == 0;
-}
-
-static inline formal_hash_entry_t *
-formal_entry_alloc (const char *name, formal_entry *formal)
-{
- formal_hash_entry_t *entry = XNEW (formal_hash_entry_t);
- entry->name = name;
- entry->formal = formal;
- return entry;
-}
-
-static inline formal_entry *
-formal_entry_find (htab_t table, const char *name)
-{
- formal_hash_entry_t needle = { name, NULL };
- formal_hash_entry_t *entry = htab_find (table, &needle);
- return entry != NULL ? entry->formal : NULL;
-}
+extern htab_t macro_hash;
extern int buffer_and_nest (const char *, const char *, sb *,
size_t (*) (sb *));