Skip to content

Commit

Permalink
gas/
Browse files Browse the repository at this point in the history
2005-01-31  Jan Beulich  <[email protected]>

	* macro.c (do_formals): Adjust to no longer accept empty parameter
	names.
	(define_macro): Adjust to no longer accept empty macro name, garbage
	following the parameters, or macros that were previously defined.
	* read.c (s_bad_end): Declare.
	(potable): Add endm. Handler for endr and endm is s_bad_end.
	(s_bad_end): Rename from s_bad_endr. Adjust to handle both .endm
	and .endr.
	* read.h (s_bad_endr): Remove.

gas/testsuite/
2005-01-31  Jan Beulich  <[email protected]>

	* gas/macros/badarg.[ls]: New.
	* gas/macros/end.[ls]: New.
	* gas/macros/redef.[ls]: New.
	* gas/macros/macros.exp (run_list_test): Copy from elsewhere.
	Run new tests.
  • Loading branch information
Jan Beulich committed Jan 31, 2005
1 parent e87b291 commit 057f53c
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 20 deletions.
12 changes: 12 additions & 0 deletions gas/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2005-01-31 Jan Beulich <[email protected]>

* macro.c (do_formals): Adjust to no longer accept empty parameter
names.
(define_macro): Adjust to no longer accept empty macro name, garbage
following the parameters, or macros that were previously defined.
* read.c (s_bad_end): Declare.
(potable): Add endm. Handler for endr and endm is s_bad_end.
(s_bad_end): Rename from s_bad_endr. Adjust to handle both .endm
and .endr.
* read.h (s_bad_endr): Remove.

2005-01-31 Jan Beulich <[email protected]>

* config/tc-ia64.c (parse_operands): Parse all specified operands,
Expand Down
49 changes: 35 additions & 14 deletions gas/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,37 +435,45 @@ do_formals (macro_entry *macro, int idx, sb *in)

macro->formal_count = 0;
macro->formal_hash = hash_new ();
idx = sb_skip_white (idx, in);
while (idx < in->len)
{
formal_entry *formal;
int cidx;

formal = (formal_entry *) xmalloc (sizeof (formal_entry));

sb_new (&formal->name);
sb_new (&formal->def);
sb_new (&formal->actual);

idx = sb_skip_white (idx, in);
idx = get_token (idx, in, &formal->name);
if (formal->name.len == 0)
break;
{
if (macro->formal_count)
--idx;
break;
}
idx = sb_skip_white (idx, in);
if (formal->name.len)
/* This is a formal. */
if (idx < in->len && in->ptr[idx] == '=')
{
/* This is a formal. */
if (idx < in->len && in->ptr[idx] == '=')
{
/* Got a default. */
idx = get_any_string (idx + 1, in, &formal->def, 1, 0);
}
/* Got a default. */
idx = get_any_string (idx + 1, in, &formal->def, 1, 0);
idx = sb_skip_white (idx, in);
}

/* Add to macro's hash table. */
hash_jam (macro->formal_hash, sb_terminate (&formal->name), formal);

formal->index = macro->formal_count;
formal->index = macro->formal_count++;
cidx = idx;
idx = sb_skip_comma (idx, in);
macro->formal_count++;
if (idx != cidx && idx >= in->len)
{
idx = cidx;
break;
}
*p = formal;
p = &formal->next;
*p = NULL;
Expand Down Expand Up @@ -533,8 +541,9 @@ define_macro (int idx, sb *in, sb *label,
{
/* It's the label: MACRO (formals,...) sort */
idx = do_formals (macro, idx + 1, in);
if (in->ptr[idx] != ')')
if (idx >= in->len || in->ptr[idx] != ')')
return _("missing ) after formals");
idx = sb_skip_white (idx + 1, in);
}
else
{
Expand All @@ -544,15 +553,27 @@ define_macro (int idx, sb *in, sb *label,
}
else
{
int cidx;

idx = get_token (idx, in, &name);
idx = sb_skip_comma (idx, in);
idx = do_formals (macro, idx, in);
if (name.len == 0)
return _("Missing macro name");
cidx = sb_skip_white (idx, in);
idx = sb_skip_comma (cidx, in);
if (idx == cidx || idx < in->len)
idx = do_formals (macro, idx, in);
else
idx = cidx;
}
if (idx < in->len)
return _("Bad macro parameter list");

/* And stick it in the macro hash table. */
for (idx = 0; idx < name.len; idx++)
name.ptr[idx] = TOLOWER (name.ptr[idx]);
namestr = sb_terminate (&name);
if (hash_find (macro_hash, namestr))
return _("Macro with this name was already defined");
hash_jam (macro_hash, namestr, (PTR) macro);

macro_defined = 1;
Expand Down
14 changes: 9 additions & 5 deletions gas/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static int dwarf_file_string;
static void do_align (int, char *, int, int);
static void s_align (int, int);
static void s_altmacro (int);
static void s_bad_end (int);
static int hex_float (int, char *);
static segT get_known_segmented_expression (expressionS * expP);
static void pobegin (void);
Expand Down Expand Up @@ -298,7 +299,8 @@ static const pseudo_typeS potable[] = {
{"endc", s_endif, 0},
{"endfunc", s_func, 1},
{"endif", s_endif, 0},
{"endr", s_bad_endr, 0},
{"endm", s_bad_end, 0},
{"endr", s_bad_end, 1},
/* endef */
{"equ", s_set, 0},
{"equiv", s_set, 1},
Expand Down Expand Up @@ -2659,12 +2661,14 @@ s_purgem (int ignore ATTRIBUTE_UNUSED)
demand_empty_rest_of_line ();
}

/* Handle the .rept pseudo-op. */
/* Handle the .endm/.endr pseudo-ops. */

void
s_bad_endr (int ignore ATTRIBUTE_UNUSED)
static void
s_bad_end (int endr)
{
as_warn (_(".endr encountered without preceeding .rept, .irc, or .irp"));
as_warn (_(".end%c encountered without preceeding %s"),
endr ? 'r' : 'm',
endr ? ".rept, .irp, or .irpc" : ".macro");
demand_empty_rest_of_line ();
}

Expand Down
1 change: 0 additions & 1 deletion gas/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ extern symbolS *s_lcomm_internal (int, symbolS *, addressT);
extern void s_app_file_string (char *, int);
extern void s_app_file (int);
extern void s_app_line (int);
extern void s_bad_endr (int);
extern void s_comm (int);
extern void s_data (int);
extern void s_desc (int);
Expand Down
8 changes: 8 additions & 0 deletions gas/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2005-01-31 Jan Beulich <[email protected]>

* gas/macros/badarg.[ls]: New.
* gas/macros/end.[ls]: New.
* gas/macros/redef.[ls]: New.
* gas/macros/macros.exp (run_list_test): Copy from elsewhere.
Run new tests.

2005-01-31 Jan Beulich <[email protected]>

* gas/ia64/operands.[ls]: New.
Expand Down
7 changes: 7 additions & 0 deletions gas/testsuite/gas/macros/badarg.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.*: Assembler messages:
.*:1: Error: .*
.*:4: Error: .*
.*:7: Error: .*
.*:10: Error: .*
.*:13: Error: .*
.*:16: Error: .*
17 changes: 17 additions & 0 deletions gas/testsuite/gas/macros/badarg.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.macro
.endm

.macro ,arg1
.endm

.macro m1,
.endm

.macro m2,,
.endm

.macro m3,arg1,
.endm

.macro m4,,arg2
.endm
3 changes: 3 additions & 0 deletions gas/testsuite/gas/macros/end.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*: Assembler messages:
.*:1: Warning: \.endm .* \.macro
.*:2: Warning: \.endr .* (\.rept|\.irpc?).*(\.rept|\.irpc?).*(\.rept|\.irpc?)
2 changes: 2 additions & 0 deletions gas/testsuite/gas/macros/end.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.endm
.endr
17 changes: 17 additions & 0 deletions gas/testsuite/gas/macros/macros.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Run some tests of gas macros.

proc run_list_test { name opts } {
global srcdir subdir
set testname "macros $name"
set file $srcdir/$subdir/$name
gas_run ${name}.s $opts ">&dump.out"
if { [regexp_diff "dump.out" "${file}.l"] } then {
fail $testname
verbose "output is [file_contents "dump.out"]" 2
return
}
pass $testname
}

if { ![istarget hppa*-*-*] || [istarget *-*-linux*] } {
run_dump_test test1
}
Expand Down Expand Up @@ -47,3 +60,7 @@ run_dump_test app1
run_dump_test app2
run_dump_test app3
run_dump_test app4

run_list_test badarg ""
run_list_test end ""
run_list_test redef ""
2 changes: 2 additions & 0 deletions gas/testsuite/gas/macros/redef.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*: Assembler messages:
.*:3: Error: .*
4 changes: 4 additions & 0 deletions gas/testsuite/gas/macros/redef.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.macro m
.endm
.macro m
.endm

0 comments on commit 057f53c

Please sign in to comment.