]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
S12Z: GAS: New option --mdollar-hex.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 22 May 2019 05:16:14 +0000 (07:16 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 22 May 2019 06:13:36 +0000 (08:13 +0200)
This option (also implied by --traditional) causes '$' to introduce
literal hexadecimal constants, rather than the modern convention '0x'.

gas/
* config/tc-s12z.c (s12z_strtol): New function. (md_show_usage): Update.
(md_parse_option): new case OPTION_DOLLAR_HEX. (s12z_init_after_args):
(<global>): Use s12z_strtol instead of strtol.
* doc/c-s12z.texi (S12Z Options): Document new option -mdollar-hex.
* testsuite/gas/s12z/dollar-hex.d: New file.
* testsuite/gas/s12z/dollar-hex.s: New file.
* testsuite/gas/s12z/s12z.exp: Add them.

gas/ChangeLog
gas/config/tc-s12z.c
gas/doc/c-s12z.texi
gas/testsuite/gas/s12z/dollar-hex.d [new file with mode: 0644]
gas/testsuite/gas/s12z/dollar-hex.s [new file with mode: 0644]
gas/testsuite/gas/s12z/s12z.exp

index 8b100367d11d4569d9704d91b9c59b08e2841b51..f851663258137dd1a3bb9f370b7bcb6687beaee9 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-22  John Darrington <john@darrington.wattle.id.au>
+
+       * config/tc-s12z.c (s12z_strtol): New function. (md_show_usage): Update.
+       (md_parse_option): new case OPTION_DOLLAR_HEX. (s12z_init_after_args):
+       (<global>): Use s12z_strtol instead of strtol.
+       * doc/c-s12z.texi (S12Z Options): Document new option -mdollar-hex.
+       * testsuite/gas/s12z/dollar-hex.d: New file.
+       * testsuite/gas/s12z/dollar-hex.s: New file.
+       * testsuite/gas/s12z/s12z.exp: Add them.
+
 2019-05-21  Sudakshina Das  <sudi.das@arm.com>
 
        * config/tc-arm.c (parse_operands): Update case OP_RVC to
index 568f7b593caf357add7b1ac8bda4f448cf80c439..67e88d277a8babc0f0e46262e67ad544db2bd35d 100644 (file)
@@ -39,6 +39,50 @@ const char FLT_CHARS[] = "dD";
 
 static char *fail_line_pointer;
 
+/* A wrapper around the standard library's strtol.
+   It converts STR into an integral value.
+   This wrapper deals with literal_prefix_dollar_hex.  */
+static long
+s12z_strtol (const char *str, char ** endptr)
+{
+  int base = 0;
+  bool negative = false;
+
+  long result = 0;
+
+  char *start = (char *) str;
+
+  /* In the case where literal_prefix_dollar_hex is TRUE the sign has
+  to be handled explicitly.  Otherwise the string will not be
+  recognised as an integer.  */
+  if (str[0] == '-')
+    {
+      negative = true;
+      ++str;
+    }
+  else if (str[0] == '+')
+    {
+      ++str;
+    }
+
+  if (literal_prefix_dollar_hex && (str[0] == '$'))
+    {
+      base = 16;
+      str++;
+    }
+
+  result = strtol (str, endptr, base);
+  if (*endptr == str)
+    {
+      *endptr = start;
+    }
+  if (negative)
+    result = -result;
+
+  return result;
+}
+
+
 \f
 /* Options and initialization.  */
 
@@ -46,7 +90,10 @@ const char *md_shortopts = "";
 
 struct option md_longopts[] =
   {
-   {"mreg-prefix", required_argument, NULL, OPTION_MD_BASE},
+#define OPTION_REG_PREFIX (OPTION_MD_BASE)
+   {"mreg-prefix", required_argument, NULL, OPTION_REG_PREFIX},
+#define OPTION_DOLLAR_HEX (OPTION_MD_BASE + 1)
+   {"mdollar-hex", no_argument, NULL, OPTION_DOLLAR_HEX},
    {NULL, no_argument, NULL, 0}
   };
 
@@ -98,10 +145,9 @@ s12z_listing_header (void)
 void
 md_show_usage (FILE *stream)
 {
-  fprintf (stream,
-      _("\ns12z options:\n"
-       "  -mreg-prefix=PREFIX     set a prefix used to indicate register names (default none)"
-        "\n"));
+  fputs (_("\ns12z options:\n"), stream);
+  fputs (_("  -mreg-prefix=PREFIX     set a prefix used to indicate register names (default none)\n"), stream);
+  fputs (_("  -mdollar-hex            the prefix '$' instead of '0x' is used to indicate literal hexadecimal constants\n"), stream);
 }
 
 void
@@ -114,9 +160,12 @@ md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
-    case OPTION_MD_BASE:
+    case OPTION_REG_PREFIX:
       register_prefix = xstrdup (arg);
       break;
+    case OPTION_DOLLAR_HEX:
+      literal_prefix_dollar_hex = TRUE;
+      break;
     default:
       return 0;
     }
@@ -150,6 +199,8 @@ md_begin (void)
 void
 s12z_init_after_args (void)
 {
+  if (flag_traditional_format)
+    literal_prefix_dollar_hex = TRUE;
 }
 \f
 /* Builtin help.  */
@@ -198,7 +249,7 @@ lex_constant (long *v)
     }
 
   errno = 0;
-  *v = strtol (p, &end, 0);
+  *v = s12z_strtol (p, &end);
   if (errno == 0 && end != p)
     {
       input_line_pointer = end;
@@ -716,7 +767,7 @@ lex_offset (long *val)
   p++;
 
   errno = 0;
-  *val = strtol (p, &end, 0);
+  *val = s12z_strtol (p, &end);
   if (errno == 0)
     {
       if (negative)
index b90874754c9d3e6e4c48fb1575353bcad54287eb..6cf6f25e7c4622ac607348ff13a3ad15d6cb1735 100644 (file)
@@ -38,6 +38,19 @@ string @var{pfx}.
 
 For an explanation of what this means and why it might be needed,
 see @ref{S12Z Register Notation}.
+
+
+@item -mdollar-hex
+@cindex @samp{-mdollar-hex} option, dollar-hex
+@cindex hexadecimal prefix, S12Z
+The @samp{-mdollar-hex} option affects the way that literal hexadecimal constants
+are represented.  When this option is specified, the assembler will consider
+the @samp{$} character as the start of a hexadecimal integer constant.  Without
+this option, the standard value of @samp{0x} is expected.
+
+If you use this option, then you cannot have symbol names starting with @samp{$}.
+@samp{-mdollar-hex} is implied if the @samp{--traditional-format}
+(@pxref{traditional-format}) is used.
 @end table
 
 @node S12Z Syntax
diff --git a/gas/testsuite/gas/s12z/dollar-hex.d b/gas/testsuite/gas/s12z/dollar-hex.d
new file mode 100644 (file)
index 0000000..dbd4269
--- /dev/null
@@ -0,0 +1,16 @@
+#objdump: -d
+#name:    Dollar sign as literal hex prefix
+#source:  dollar-hex.s --mdollar-hex
+
+tmpdir/dollar-hex.o:     file format elf32-s12z
+
+
+Disassembly of section .text:
+
+00000000 <.text>:
+   0:  1c bc e0 18     mov.b d0, \(24,s\)
+   4:  dc fa 12 34     neg.b 1193046
+   8:  56 
+   9:  98 12 34 56     ld x, #1193046
+   d:  aa e1 dd        jmp \(-35,s\)
+
diff --git a/gas/testsuite/gas/s12z/dollar-hex.s b/gas/testsuite/gas/s12z/dollar-hex.s
new file mode 100644 (file)
index 0000000..57f12a9
--- /dev/null
@@ -0,0 +1,4 @@
+       mov.b d0, ($18,s)
+       neg.b $123456
+       ld x, #$123456
+       jmp   (-$23, s)         ; Make sure this isn't misinterpreted as the start of a predecrement operand
index cccfc6e5490d936bb70ddc37fc8e7de137f04618..4e567f912aee192a3fbd48d75fb8a67b43093e95 100644 (file)
@@ -142,3 +142,4 @@ run_dump_test imm-dest
 # Miscellaneous
 
 run_dump_test reg-prefix
+run_dump_test dollar-hex