[5/5] Altera Nios II: hexadecimal numbers in options

Submitted by Chung-Lin Tang on April 18, 2013, 1:49 p.m.

Details

Message ID 516FFA02.3020405@codesourcery.com
State New
Headers show

Commit Message

Chung-Lin Tang April 18, 2013, 1:49 p.m.
Altera has defined an FPU instruction set on top of the custom
instruction space provided in Nios II, but without specifying the exact
binary opcode mapping within the [0,255] space; that mapping is
specified by the user, through compiler options or target pragmas.

For ease of use in specifying the code on the command line, we are
proposing the attached patch to allow, for example '-mcustom-fadds=255'
to be written as '-mcustom-fadds=0xff'

2013-04-18  Chung-Lin Tang  <cltang@codesourcery.com>

        * opts-common.c (integral_argument): Add support for hexadecimal
        command option integer arguments. Update comments.

Comments

Joseph S. Myers April 25, 2013, 8:41 p.m.
On Thu, 18 Apr 2013, Chung-Lin Tang wrote:

> 2013-04-18  Chung-Lin Tang  <cltang@codesourcery.com>
> 
>         * opts-common.c (integral_argument): Add support for hexadecimal
>         command option integer arguments. Update comments.

You should propose this sort of non-Nios II-specific change in a separate 
thread with its own rationale for the change.

> +  /* It wasn't a decimal number - try hexadecimal.  */
> +  if (arg[0]=='0' && (arg[1]=='x' || arg[1]=='X'))

Spacing around "==".  I think you do need to check all the characters here 
as is done for decimal arguments (but using ISXDIGIT), in order to ensure 
that no locale-specific form is accepted by strtol.

Patch hide | download patch | download mbox

Index: gcc/opts-common.c
===================================================================
--- gcc/opts-common.c	(revision 407083)
+++ gcc/opts-common.c	(revision 409063)
@@ -147,7 +147,7 @@ 
   return match_wrong_lang;
 }
 
-/* If ARG is a non-negative integer made up solely of digits, return its
+/* If ARG is a non-negative decimal or hexadecimal integer, return its
    value, otherwise return -1.  */
 
 int
@@ -161,6 +161,15 @@ 
   if (*p == '\0')
     return atoi (arg);
 
+  /* It wasn't a decimal number - try hexadecimal.  */
+  if (arg[0]=='0' && (arg[1]=='x' || arg[1]=='X'))
+    {
+      char *endp;
+      int val = strtol (arg, &endp, 16);
+      if (*endp == '\0')
+	return val;
+    }
+
   return -1;
 }