/* macro.c - macro support for gas
- Copyright (C) 1994-2017 Free Software Foundation, Inc.
+ Copyright (C) 1994-2020 Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
sac@cygnus.com
/* 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;
anyway, there's not an obviously better fix here. */
if (strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
{
- char *saved_input_line_pointer = input_line_pointer;
char saved_eol_char = ptr->ptr[ptr->len];
ptr->ptr[ptr->len] = '\0';
- input_line_pointer = ptr->ptr + i + 8;
+ temp_ilp (ptr->ptr + i + 8);
s_app_line (0);
+ restore_ilp ();
ptr->ptr[ptr->len] = saved_eol_char;
- input_line_pointer = saved_input_line_pointer;
ptr->len = line_start;
}
}
{
int nest = 0;
idx++;
- while ((in->ptr[idx] != '>' || nest)
- && idx < in->len)
+ while (idx < in->len
+ && (in->ptr[idx] != '>' || nest))
{
if (in->ptr[idx] == '!')
{
{
if (in->len > idx + 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
{
- while (!ISSEP (in->ptr[idx]))
+ while (idx < in->len && !ISSEP (in->ptr[idx]))
sb_add_char (out, in->ptr[idx++]);
}
else if (in->ptr[idx] == '%' && macro_alternate)
{
offsetT val;
- char buf[20];
+ char buf[64];
/* Turns the next expression into a string. */
/* xgettext: no-c-format */
{
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. */
- if (! hash_find (macro->formal_hash, name))
- hash_jam (macro->formal_hash, name, formal);
- else
- as_bad_where (macro->file,
- macro->line,
- _("A parameter named `%s' already exists for macro `%s'"),
- name,
- macro->name);
+ elt = formal_entry_alloc (name, formal);
+ if (htab_insert (macro->formal_hash, elt, 0) != NULL)
+ {
+ free (elt);
+ as_bad_where (macro->file, macro->line,
+ _("A parameter named `%s' "
+ "already exists for macro `%s'"),
+ name, macro->name);
+ }
formal->index = macro->formal_count++;
*p = formal;
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. */
- if (hash_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);
+ elt = formal_entry_alloc (name, formal);
+ if (htab_insert (macro->formal_hash, elt, 0) != NULL)
+ {
+ free (elt);
+ as_bad_where (macro->file, macro->line,
+ _("Reserved word `%s' used as parameter in macro `%s'"),
+ name, macro->name);
+ }
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))
- error = _("Macro `%s' was already defined");
if (!error)
- error = hash_jam (macro_hash, macro->name, (void *) macro);
+ {
+ 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 (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;
{
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);
- if (! hash_find (formal_hash, name))
+ elt = formal_entry_alloc (name, f);
+ if (htab_insert (formal_hash, elt, 0) != NULL)
+ {
+ free (elt);
+ as_bad_where (macro->file, macro->line + macro_line,
+ _("`%s' was already used as parameter "
+ "(or another local) name"), name);
+ del_formal (f);
+ }
+ else
{
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;
- }
- else
- {
- as_bad_where (macro->file,
- macro->line + macro_line,
- _("`%s' was already used as parameter (or another local) name"),
- name);
- del_formal (f);
}
src = sb_skip_comma (src, in);
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)
{
char *copy;
size_t i, len;
- macro_entry *macro;
+ void **slot;
+ macro_hash_entry_t needle;
len = strlen (name);
copy = XNEWVEC (char, len + 1);
copy[i] = TOLOWER (name[i]);
copy[i] = '\0';
- /* 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)
+ needle.name = copy;
+ needle.macro = NULL;
+ slot = htab_find_slot (macro_hash, &needle, NO_INSERT);
+ if (slot)
{
- hash_jam (macro_hash, copy, NULL);
- free_macro (macro);
+ free_macro (((macro_hash_entry_t *) *slot)->macro);
+ htab_clear_slot (macro_hash, slot);
}
else
as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
{
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), 0);
f.index = 1;
f.next = NULL;
}
}
- hash_die (h);
+ htab_delete (h);
sb_kill (&f.actual);
sb_kill (&f.def);
sb_kill (&f.name);