diff options
author | Jan Beulich <jbeulich@novell.com> | 2005-04-18 13:35:46 +0000 |
---|---|---|
committer | Jan Beulich <jbeulich@novell.com> | 2005-04-18 13:35:46 +0000 |
commit | e6ca91be4f25f03e5b7c8960c34736a31f77c549 (patch) | |
tree | e8ce5b990927fe773e5f2c5bd6e26b16402c776d /gas/macro.c | |
parent | 0f061b69fbe16702bfa68e580ee7f855ec986dcf (diff) | |
download | gdb-e6ca91be4f25f03e5b7c8960c34736a31f77c549.zip gdb-e6ca91be4f25f03e5b7c8960c34736a31f77c549.tar.gz gdb-e6ca91be4f25f03e5b7c8960c34736a31f77c549.tar.bz2 |
gas/
2005-04-18 Jan Beulich <jbeulich@novell.com>
* macro.c (free_token): New, freeing all the memory associated with a
macro.
(do_formals): Move initializers to ...
(define_macro): ... here.
(delete_macro): Convert passed in name to lower case. Warn when
purging macro that doesn't exist. Use hash_jam instead of hash_delete.
gas/testsuite/
2005-04-18 Jan Beulich <jbeulich@novell.com>
* gas/macros/purge.[ls]: New.
* gas/macros/macros.exp: Run new test.
Diffstat (limited to 'gas/macro.c')
-rw-r--r-- | gas/macro.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/gas/macro.c b/gas/macro.c index 4f934ae..0819404 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -77,6 +77,7 @@ static int sub_actual (int, sb *, sb *, struct hash_control *, int, sb *, int); static const char *macro_expand_body (sb *, sb *, formal_entry *, struct hash_control *, int); static const char *macro_expand (int, sb *, macro_entry *, sb *); +static void free_macro(macro_entry *); #define ISWHITE(x) ((x) == ' ' || (x) == '\t') @@ -471,8 +472,6 @@ do_formals (macro_entry *macro, int idx, sb *in) { formal_entry **p = ¯o->formals; - macro->formal_count = 0; - macro->formal_hash = hash_new (); idx = sb_skip_white (idx, in); while (idx < in->len) { @@ -568,6 +567,7 @@ define_macro (int idx, sb *in, sb *label, macro->formal_count = 0; macro->formals = 0; + macro->formal_hash = hash_new (); idx = sb_skip_white (idx, in); if (! buffer_and_nest ("MACRO", "ENDM", ¯o->sub, get_line)) @@ -1142,12 +1142,52 @@ check_macro (const char *line, sb *expand, return 1; } +/* Free the memory allocated to a macro. */ + +static void +free_macro(macro_entry *macro) +{ + formal_entry *formal; + + for (formal = macro->formals; formal; ) + { + void *ptr; + + sb_kill (&formal->name); + sb_kill (&formal->def); + sb_kill (&formal->actual); + ptr = formal; + formal = formal->next; + free (ptr); + } + hash_die (macro->formal_hash); + sb_kill (¯o->sub); + free (macro); +} + /* Delete a macro. */ void delete_macro (const char *name) { - hash_delete (macro_hash, name); + char *copy; + size_t i, len; + macro_entry *macro; + + len = strlen (name); + copy = (char *) alloca (len + 1); + for (i = 0; i < len; ++i) + copy[i] = TOLOWER (name[i]); + copy[i] = '\0'; + + /* Since hash_delete doesn't free memory, just clear out the entry. */ + if ((macro = hash_find (macro_hash, copy)) != NULL) + { + hash_jam (macro_hash, copy, NULL); + free_macro (macro); + } + else + as_warn (_("Attempt to purge non-existant macro `%s'"), copy); } /* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a |