/* The macro hash table. */
-struct hash_control *macro_hash;
+struct htab *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 = 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;
}
/* 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,
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;
formal = formal->next;
del_formal (f);
}
- hash_die (macro->formal_hash);
+ htab_delete (macro->formal_hash);
sb_kill (¯o->sub);
free (macro);
}
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))
/* 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;
/* 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;
&& (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)
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;
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];
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
{
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,
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;
}
}
/* 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'"),
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);
}
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)
/* 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
{
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);
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;
}
}
- hash_die (h);
+ htab_delete (h);
sb_kill (&f.actual);
sb_kill (&f.def);
sb_kill (&f.name);
sb sub; /* Substitution text. */
int formal_count; /* Number of formal args. */
formal_entry *formals; /* Pointer to list of formal_structs. */
- struct hash_control *formal_hash; /* Hash table of formals. */
+ struct htab *formal_hash; /* Hash table of formals. */
const char *name; /* Macro name. */
const char *file; /* File the macro was defined in. */
unsigned int line; /* Line number of definition. */
/* The macro hash table. */
-extern struct hash_control *macro_hash;
+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 int buffer_and_nest (const char *, const char *, sb *,
size_t (*) (sb *));