From 22c6ccb89e0f38a70a42fb49eb167e7857d51f5c Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 22 May 2019 07:16:14 +0200 Subject: [PATCH] S12Z: GAS: New option --mdollar-hex. 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): (): 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 | 10 +++++ gas/config/tc-s12z.c | 67 +++++++++++++++++++++++++---- gas/doc/c-s12z.texi | 13 ++++++ gas/testsuite/gas/s12z/dollar-hex.d | 16 +++++++ gas/testsuite/gas/s12z/dollar-hex.s | 4 ++ gas/testsuite/gas/s12z/s12z.exp | 1 + 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 gas/testsuite/gas/s12z/dollar-hex.d create mode 100644 gas/testsuite/gas/s12z/dollar-hex.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 8b100367d11..f8516632581 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,13 @@ +2019-05-22 John Darrington + + * config/tc-s12z.c (s12z_strtol): New function. (md_show_usage): Update. + (md_parse_option): new case OPTION_DOLLAR_HEX. (s12z_init_after_args): + (): 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 * config/tc-arm.c (parse_operands): Update case OP_RVC to diff --git a/gas/config/tc-s12z.c b/gas/config/tc-s12z.c index 568f7b593ca..67e88d277a8 100644 --- a/gas/config/tc-s12z.c +++ b/gas/config/tc-s12z.c @@ -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; +} + + /* 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; } /* 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) diff --git a/gas/doc/c-s12z.texi b/gas/doc/c-s12z.texi index b90874754c9..6cf6f25e7c4 100644 --- a/gas/doc/c-s12z.texi +++ b/gas/doc/c-s12z.texi @@ -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 index 00000000000..dbd42695ee0 --- /dev/null +++ b/gas/testsuite/gas/s12z/dollar-hex.d @@ -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 index 00000000000..57f12a9df4e --- /dev/null +++ b/gas/testsuite/gas/s12z/dollar-hex.s @@ -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 diff --git a/gas/testsuite/gas/s12z/s12z.exp b/gas/testsuite/gas/s12z/s12z.exp index cccfc6e5490..4e567f912ae 100644 --- a/gas/testsuite/gas/s12z/s12z.exp +++ b/gas/testsuite/gas/s12z/s12z.exp @@ -142,3 +142,4 @@ run_dump_test imm-dest # Miscellaneous run_dump_test reg-prefix +run_dump_test dollar-hex -- 2.30.2