This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Modifying comment character on SVR4 gas target
On Tue, Nov 01, 2005 at 10:57:07AM -0800, Ian Lance Taylor wrote:
> > I'd like to add an option similar to m68k's --bitwise-or to change the
> > comment character.
Here's a patch.
regards,
john
2005-11-02 John Levon <levon@movementarian.org>
* config/tc-i386.h (tc_comment_chars): Define.
* config/tc-i386.c (line_comment_chars): Use '/'
unconditionally.
(i386_comment_chars): Add.
(md_parse_options): Process OPTION_DIVIDE.
(md_show_usage): Describe --divide option.
* doc/c-i386.texi: Document --divide option.
* testsuite/gas/i386/i386.exp (run_divide_test): Define
and call for SVR4 platforms.
* testsuite/gas/i386/svr4_comments.s: Add.
diff -u -a -p -r1.200 tc-i386.c
--- binutils-cvs/gas/config/tc-i386.c 26 Oct 2005 12:29:43 -0000 1.200
+++ binutils-cvs/gas/config/tc-i386.c 2 Nov 2005 16:42:06 -0000
@@ -203,10 +203,17 @@ const char extra_symbol_chars[] = "*%-([
&& !defined (TE_FreeBSD) \
&& !defined (TE_NetBSD)))
/* This array holds the chars that always start a comment. If the
- pre-processor is disabled, these aren't very useful. */
-const char comment_chars[] = "#/";
+ pre-processor is disabled, these aren't very useful. The option
+ --divide will remove '/' from this list. */
+const char *i386_comment_chars = "#/";
+#define SVR4_COMMENT_CHARS 1
#define PREFIX_SEPARATOR '\\'
+#else
+const char *i386_comment_chars = "#";
+#define PREFIX_SEPARATOR '/'
+#endif
+
/* This array holds the chars that only start a comment at the beginning of
a line. If the line seems to have the form '# 123 filename'
.line and .file directives will appear in the pre-processed output.
@@ -215,16 +222,7 @@ const char comment_chars[] = "#/";
#NO_APP at the beginning of its output.
Also note that comments started like this one will always work if
'/' isn't otherwise defined. */
-const char line_comment_chars[] = "#";
-
-#else
-/* Putting '/' here makes it impossible to use the divide operator.
- However, we need it for compatibility with SVR4 systems. */
-const char comment_chars[] = "#";
-#define PREFIX_SEPARATOR '/'
-
-const char line_comment_chars[] = "/#";
-#endif
+const char line_comment_chars[] = "#/";
const char line_separator_chars[] = ";";
@@ -5302,11 +5300,19 @@ const char *md_shortopts = "kVQ:sqn";
const char *md_shortopts = "qn";
#endif
-struct option md_longopts[] = {
#define OPTION_32 (OPTION_MD_BASE + 0)
+#ifdef SVR4_COMMENT_CHARS
+#define OPTION_DIVIDE (OPTION_MD_BASE + 1)
+#define OPTION_64 (OPTION_MD_BASE + 2)
+#else
+#define OPTION_64 (OPTION_MD_BASE + 1)
+#endif
+struct option md_longopts[] = {
{"32", no_argument, NULL, OPTION_32},
+#ifdef SVR4_COMMENT_CHARS
+ {"divide", no_argument, NULL, OPTION_DIVIDE},
+#endif
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
-#define OPTION_64 (OPTION_MD_BASE + 1)
{"64", no_argument, NULL, OPTION_64},
#endif
{NULL, no_argument, NULL, 0}
@@ -5366,6 +5372,23 @@ md_parse_option (c, arg)
break;
#endif
+#ifdef SVR4_COMMENT_CHARS
+ case OPTION_DIVIDE:
+ {
+ char *n, *t;
+ const char *s;
+
+ n = (char *) xmalloc (strlen (i386_comment_chars) + 1);
+ t = n;
+ for (s = i386_comment_chars; *s != '\0'; s++)
+ if (*s != '/')
+ *t++ = *s;
+ *t = '\0';
+ i386_comment_chars = n;
+ }
+ break;
+#endif
+
case OPTION_32:
default_arch = "i386";
break;
@@ -5387,11 +5410,19 @@ md_show_usage (stream)
-k ignored\n\
-n Do not optimize code alignment\n\
-q quieten some warnings\n\
- -s ignored\n"));
+ -s ignored\n"
+#ifdef SVR4_COMMENT_CHARS
+" --divide do not treat `/' as a comment character\n"
+#endif
+));
#else
fprintf (stream, _("\
-n Do not optimize code alignment\n\
- -q quieten some warnings\n"));
+ -q quieten some warnings\n"
+#ifdef SVR4_COMMENT_CHARS
+" --divide do not treat `/' as a comment character\n"
+#endif
+));
#endif
}
Index: binutils-cvs/gas/config/tc-i386.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.h,v
retrieving revision 1.64
diff -u -a -p -r1.64 tc-i386.h
--- binutils-cvs/gas/config/tc-i386.h 26 Oct 2005 12:29:43 -0000 1.64
+++ binutils-cvs/gas/config/tc-i386.h 2 Nov 2005 16:42:07 -0000
@@ -88,6 +88,9 @@ extern void i386_elf_emit_arch_note PARA
extern const char extra_symbol_chars[];
#define tc_symbol_chars extra_symbol_chars
+extern const char *i386_comment_chars;
+#define tc_comment_chars i386_comment_chars
+
#define MAX_OPERANDS 3 /* max operands per insn */
#define MAX_IMMEDIATE_OPERANDS 2/* max immediates per insn (lcall, ljmp) */
#define MAX_MEMORY_OPERANDS 2 /* max memory refs per insn (string ops) */
Index: binutils-cvs/gas/doc/c-i386.texi
===================================================================
RCS file: /cvs/src/src/gas/doc/c-i386.texi,v
retrieving revision 1.12
diff -u -a -p -r1.12 c-i386.texi
--- binutils-cvs/gas/doc/c-i386.texi 6 Jul 2005 19:11:01 -0000 1.12
+++ binutils-cvs/gas/doc/c-i386.texi 2 Nov 2005 16:42:08 -0000
@@ -67,6 +67,15 @@ usage and use x86-64 as target platform)
By default, x86 GAS replaces multiple nop instructions used for
alignment within code sections with multi-byte nop instructions such
as leal 0(%esi,1),%esi. This switch disables the optimization.
+
+@cindex @samp{--divide} option, i386
+@item --divide
+On SVR4-derived platforms, the character @samp{/} is treated as a comment
+character, which means that it cannot be used in expressions. The
+@samp{--divide} option turns @samp{/} into a normal character. This does
+not disable @samp{/} at the beginning of a line starting a comment, or
+affect using @samp{#} for starting a comment.
+
@end table
@node i386-Syntax
Index: binutils-cvs/gas/testsuite/gas/i386/i386.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/i386/i386.exp,v
retrieving revision 1.43
diff -u -a -p -r1.43 i386.exp
--- binutils-cvs/gas/testsuite/gas/i386/i386.exp 26 Oct 2005 12:29:44 -0000 1.43
+++ binutils-cvs/gas/testsuite/gas/i386/i386.exp 2 Nov 2005 16:42:11 -0000
@@ -14,6 +14,24 @@ proc run_list_test { name opts } {
pass $testname
}
+proc run_divide_test { } {
+ global srcdir subdir
+ global AS
+ global ASFLAGS
+
+ set tmp_ASFLAGS "$ASFLAGS"
+ set ASFLAGS "$ASFLAGS --divide"
+
+ set testname "i386 svr4_comment"
+ set file "$srcdir/$subdir/svr4_comment"
+ if [string match "" [lindex [gas_run svr4_comment.s "-o /dev/null" ""] 0]] {
+ pass $testname
+ } else {
+ fail $testname
+ }
+ set ASFLAGS "$tmp_ASFLAGS"
+}
+
proc gas_64_check { } {
global NM
global NMFLAGS
@@ -32,6 +50,13 @@ proc gas_32_check { } {
return [regexp "targets:.*i386" $nm_help]
}
+proc divide_check { } {
+ global AS
+ global srcdir
+
+ catch "exec $srcdir/lib/run $AS --target-help" as_target_help
+ return [regexp "divide" $as_target_help]
+}
if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_32_check]] then {
@@ -118,6 +143,10 @@ if [expr ([istarget "i*86-*-*"] || [ist
run_dump_test "secrel"
}
+ if { [divide_check] } then {
+ run_divide_test
+ }
+
set ASFLAGS "$old_ASFLAGS"
}
@@ -158,5 +187,9 @@ if [expr ([istarget "i*86-*-*"] || [ista
run_dump_test "mixed-mode-reloc64"
}
+ if { [divide_check] } then {
+ run_divide_test
+ }
+
set ASFLAGS "$old_ASFLAGS"
}
--- /dev/null 2005-10-23 14:22:06.054079640 +0000
+++ binutils-cvs/gas/testsuite/gas/i386/svr4_comment.s 2005-11-02 16:34:26.000000000 +0000
@@ -0,0 +1,4 @@
+start:
+ .long 1,2,3,a
+/ This comment should still be allowed, but the divide must remain a divide in the next line
+ a=(.-start)/4-1 # comment