This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH bfin] Allow loop lablel to start with '.' and '$'
- From: Jie Zhang <jie dot zhang at analog dot com>
- To: binutils at sourceware dot org
- Date: Thu, 3 Sep 2009 23:39:11 +0800
- Subject: [PATCH bfin] Allow loop lablel to start with '.' and '$'
This patch would allow labels used in LOOP_BEGIN and LOOP_END to start
with '.' and '$'. Instead of using start_line_hook, this patch treats
LOOP_BEGIN and LOOP_END as real instructions. Committed with tests.
Jie
* config/bfin-parse.y (asm_1): Add LOOP_BEGIN and LOOP_END.
* config/tc-bfin.c (bfin_start_line_hook): Remove.
(bfin_loop_beginend): New.
* config/tc-bfin.h (bfin_start_line_hook): Don't declare.
(md_start_line_hook): Don't define.
* config/bfin-aux.h (bfin_loop_beginend): Declare.
testsuite/
* gas/bfin/loop.s, gas/bfin/loop.d: New test.
* gas/bfin/loop2.s, gas/bfin/loop2.d: New test.
* gas/bfin/loop3.s, gas/bfin/loop3.d: New test.
* gas/bfin/bfin.exp: Add the new tests.
Index: config/bfin-aux.h
===================================================================
RCS file: /cvs/src/src/gas/config/bfin-aux.h,v
retrieving revision 1.4
diff -u -p -r1.4 bfin-aux.h
--- config/bfin-aux.h 2 Sep 2009 07:24:20 -0000 1.4
+++ config/bfin-aux.h 3 Sep 2009 15:25:11 -0000
@@ -126,6 +126,9 @@ bfin_gen_loopsetup (Expr_Node *soffset,
INSTR_T
bfin_gen_loop (Expr_Node *expr, REG_T reg, int rop, REG_T preg);
+void
+bfin_loop_beginend (Expr_Node *expr, int begin);
+
INSTR_T
bfin_gen_pushpopmultiple (int dr, int pr, int d, int p, int w);
Index: config/bfin-parse.y
===================================================================
RCS file: /cvs/src/src/gas/config/bfin-parse.y,v
retrieving revision 1.28
diff -u -p -r1.28 bfin-parse.y
--- config/bfin-parse.y 2 Sep 2009 08:57:38 -0000 1.28
+++ config/bfin-parse.y 3 Sep 2009 15:25:11 -0000
@@ -3525,6 +3525,27 @@ asm_1:
else
return yyerror ("Bad register or values for LOOP");
}
+
+/* LOOP_BEGIN. */
+ | LOOP_BEGIN expr
+ {
+ if (!IS_RELOC ($2))
+ return yyerror ("Invalid expression in LOOP_BEGIN statement");
+
+ bfin_loop_beginend ($2, 1);
+ $$ = 0;
+ }
+
+/* LOOP_END. */
+ | LOOP_END expr
+ {
+ if (!IS_RELOC ($2))
+ return yyerror ("Invalid expression in LOOP_END statement");
+
+ bfin_loop_beginend ($2, 0);
+ $$ = 0;
+ }
+
/* pseudoDEBUG. */
| DBG
Index: config/tc-bfin.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-bfin.c,v
retrieving revision 1.26
diff -u -p -r1.26 tc-bfin.c
--- config/tc-bfin.c 2 Sep 2009 07:24:20 -0000 1.26
+++ config/tc-bfin.c 3 Sep 2009 15:25:11 -0000
@@ -1016,123 +1016,6 @@ bfin_fix_adjustable (fixS *fixP)
}
}
-
-/* Handle the LOOP_BEGIN and LOOP_END statements.
- Parse the Loop_Begin/Loop_End and create a label. */
-void
-bfin_start_line_hook ()
-{
- bfd_boolean maybe_begin = FALSE;
- bfd_boolean maybe_end = FALSE;
-
- char *c1, *label_name;
- symbolS *line_label;
- char *c = input_line_pointer;
- int cr_num = 0;
-
- while (ISSPACE (*c))
- {
- if (*c == '\n')
- cr_num++;
- c++;
- }
-
- /* Look for Loop_Begin or Loop_End statements. */
-
- if (*c != 'L' && *c != 'l')
- return;
-
- c++;
- if (*c != 'O' && *c != 'o')
- return;
-
- c++;
- if (*c != 'O' && *c != 'o')
- return;
-
- c++;
- if (*c != 'P' && *c != 'p')
- return;
-
- c++;
- if (*c != '_')
- return;
-
- c++;
- if (*c == 'E' || *c == 'e')
- maybe_end = TRUE;
- else if (*c == 'B' || *c == 'b')
- maybe_begin = TRUE;
- else
- return;
-
- if (maybe_end)
- {
- c++;
- if (*c != 'N' && *c != 'n')
- return;
-
- c++;
- if (*c != 'D' && *c != 'd')
- return;
- }
-
- if (maybe_begin)
- {
- c++;
- if (*c != 'E' && *c != 'e')
- return;
-
- c++;
- if (*c != 'G' && *c != 'g')
- return;
-
- c++;
- if (*c != 'I' && *c != 'i')
- return;
-
- c++;
- if (*c != 'N' && *c != 'n')
- return;
- }
-
- c++;
- while (ISSPACE (*c)) c++;
- c1 = c;
- while (ISALPHA (*c) || ISDIGIT (*c) || *c == '_') c++;
-
- if (input_line_pointer[-1] == '\n')
- bump_line_counters ();
-
- while (cr_num--)
- bump_line_counters ();
-
- input_line_pointer = c;
- if (maybe_end)
- {
- label_name = (char *) xmalloc ((c - c1) + strlen ("__END") + 5);
- label_name[0] = 0;
- strcat (label_name, "L$L$");
- strncat (label_name, c1, c-c1);
- strcat (label_name, "__END");
- }
- else /* maybe_begin. */
- {
- label_name = (char *) xmalloc ((c - c1) + strlen ("__BEGIN") + 5);
- label_name[0] = 0;
- strcat (label_name, "L$L$");
- strncat (label_name, c1, c-c1);
- strcat (label_name, "__BEGIN");
- }
-
- line_label = colon (label_name);
-
- /* Loop_End follows the last instruction in the loop.
- Adjust label address. */
- if (maybe_end)
- ((struct local_symbol *) line_label)->lsy_value -= last_insn_size;
-}
-
/* Special extra functions that help bfin-parse.y perform its job. */
struct obstack mempool;
@@ -2145,6 +2028,31 @@ bfin_gen_loop (Expr_Node *expr, REG_T re
return bfin_gen_loopsetup(lbegin, reg, rop, lend, preg);
}
+void
+bfin_loop_beginend (Expr_Node *expr, int begin)
+{
+ const char *loopsym;
+ char *label_name;
+ symbolS *line_label;
+ const char *suffix = begin ? "__BEGIN" : "__END";
+
+ loopsym = expr->value.s_value;
+ label_name = (char *) xmalloc (strlen (loopsym) + strlen (suffix) + 5);
+
+ label_name[0] = 0;
+
+ strcat (label_name, "L$L$");
+ strcat (label_name, loopsym);
+ strcat (label_name, suffix);
+
+ line_label = colon (label_name);
+
+ /* LOOP_END follows the last instruction in the loop.
+ Adjust label address. */
+ if (!begin)
+ ((struct local_symbol *) line_label)->lsy_value -= last_insn_size;
+}
+
bfd_boolean
bfin_eol_in_insn (char *line)
{
Index: config/tc-bfin.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-bfin.h,v
retrieving revision 1.9
diff -u -p -r1.9 tc-bfin.h
--- config/tc-bfin.h 2 Sep 2009 07:24:20 -0000 1.9
+++ config/tc-bfin.h 3 Sep 2009 15:25:11 -0000
@@ -39,10 +39,8 @@
#define WORKING_DOT_WORD
-extern void bfin_start_line_hook (void);
extern bfd_boolean bfin_start_label (char *, char *);
-#define md_start_line_hook() bfin_start_line_hook()
#define md_number_to_chars number_to_chars_littleendian
#define md_convert_frag(b,s,f) as_fatal ("bfin convert_frag\n");
Index: testsuite/gas/bfin/bfin.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/bfin/bfin.exp,v
retrieving revision 1.6
diff -u -p -r1.6 bfin.exp
--- testsuite/gas/bfin/bfin.exp 11 Aug 2009 18:28:30 -0000 1.6
+++ testsuite/gas/bfin/bfin.exp 3 Sep 2009 15:25:11 -0000
@@ -20,6 +20,9 @@ if [istarget bfin*-*-*] {
run_dump_test "load"
run_dump_test "logical"
run_dump_test "logical2"
+ run_dump_test "loop"
+ run_dump_test "loop2"
+ run_dump_test "loop3"
run_dump_test "misc"
run_dump_test "move"
run_dump_test "move2"
Index: testsuite/gas/bfin/loop.d
===================================================================
RCS file: testsuite/gas/bfin/loop.d
diff -N testsuite/gas/bfin/loop.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop.d 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,7 @@
+#readelf: --relocs
+#name: loop
+
+Relocation section '\.rela\.text' .*:
+.*
+.* R_BFIN_GOT17M4 0+00 _foo \+ 0
+.* R_BFIN_PCREL24 0+00 _bar \+ 0
Index: testsuite/gas/bfin/loop.s
===================================================================
RCS file: testsuite/gas/bfin/loop.s
diff -N testsuite/gas/bfin/loop.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop.s 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,5 @@
+ LOOP bug LC0 = P0>>1;
+ LOOP_BEGIN bug;
+ R0 = [P3+_foo@GOT17M4];
+ LOOP_END bug;
+ call _bar;
Index: testsuite/gas/bfin/loop2.d
===================================================================
RCS file: testsuite/gas/bfin/loop2.d
diff -N testsuite/gas/bfin/loop2.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop2.d 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,7 @@
+#readelf: --relocs
+#name: loop2
+
+Relocation section '\.rela\.text' .*:
+.*
+.* R_BFIN_GOT17M4 0+00 _foo \+ 0
+.* R_BFIN_PCREL24 0+00 _bar \+ 0
Index: testsuite/gas/bfin/loop2.s
===================================================================
RCS file: testsuite/gas/bfin/loop2.s
diff -N testsuite/gas/bfin/loop2.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop2.s 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,5 @@
+ LOOP .bug LC0 = P0>>1;
+ LOOP_BEGIN .bug;
+ R0 = [P3+_foo@GOT17M4];
+ LOOP_END .bug;
+ call _bar;
Index: testsuite/gas/bfin/loop3.d
===================================================================
RCS file: testsuite/gas/bfin/loop3.d
diff -N testsuite/gas/bfin/loop3.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop3.d 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,7 @@
+#readelf: --relocs
+#name: loop3
+
+Relocation section '\.rela\.text' .*:
+.*
+.* R_BFIN_GOT17M4 0+00 _foo \+ 0
+.* R_BFIN_PCREL24 0+00 _bar \+ 0
Index: testsuite/gas/bfin/loop3.s
===================================================================
RCS file: testsuite/gas/bfin/loop3.s
diff -N testsuite/gas/bfin/loop3.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/bfin/loop3.s 3 Sep 2009 15:25:11 -0000
@@ -0,0 +1,5 @@
+ LOOP $bug LC0 = P0>>1;
+ LOOP_BEGIN $bug;
+ R0 = [P3+_foo@GOT17M4];
+ LOOP_END $bug;
+ call _bar;