]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/binutils-tumbl.git/commitdiff
* config/tc-z8k.c (whatreg): Add comment describing function.
authorChristian Groessler <chris@groessler.org>
Fri, 8 Dec 2006 22:15:11 +0000 (22:15 +0000)
committerChristian Groessler <chris@groessler.org>
Fri, 8 Dec 2006 22:15:11 +0000 (22:15 +0000)
        Return NULL if symbol name characters follow the register number.
        (parse_reg): Use NULL instead of 0 for pointer values.  Stop
        processing if whatreg returned NULL.

gas/ChangeLog
gas/config/tc-z8k.c

index 2a9b0769026352d710768a8c8ade3800a4523273..fa89abe5a3926444e8b8e42b56932b9fe863beef 100644 (file)
@@ -1,3 +1,10 @@
+2006-12-08  Christian Groessler  <chris@groessler.org>
+
+       * config/tc-z8k.c (whatreg): Add comment describing function.
+       Return NULL if symbol name characters follow the register number.
+       (parse_reg): Use NULL instead of 0 for pointer values.  Stop
+       processing if whatreg returned NULL.
+
 2006-12-07  Kazu Hirata  <kazu@codesourcery.com>
 
        * config/tc-m68k.c: Update uses of EF_M68K_*.
index cd6510c99da8869b36888135c727c30e280d751e..e3893668ff10f2a9b256cabead85a8d85672585b 100644 (file)
@@ -196,19 +196,34 @@ static int the_ctrl;
 static int the_flags;
 static int the_interrupt;
 
+/* Determine register number.  src points to the ascii number
+   (after "rl", "rh", "r", "rr", or "rq").  If a character
+   outside the set of {0,',',')','('} follows the number,
+   return NULL to indicate that it's not a valid register
+   number.  */
+
 static char *
 whatreg (unsigned int *reg, char *src)
 {
+  unsigned int new_reg;
+
+  /* src[0] is already known to be a digit.  */
   if (ISDIGIT (src[1]))
     {
-      *reg = (src[0] - '0') * 10 + src[1] - '0';
-      return src + 2;
+      new_reg = (src[0] - '0') * 10 + src[1] - '0';
+      src += 2;
     }
   else
     {
-      *reg = (src[0] - '0');
-      return src + 1;
+      new_reg = (src[0] - '0');
+      src += 1;
     }
+
+  if (src[0] != 0 && src[0] != ',' && src[0] != '(' && src[0] != ')')
+    return NULL;
+
+  *reg = new_reg;
+  return src;
 }
 
 /* Parse operands
@@ -231,7 +246,7 @@ whatreg (unsigned int *reg, char *src)
 static char *
 parse_reg (char *src, int *mode, unsigned int *reg)
 {
-  char *res = 0;
+  char *res = NULL;
   char regno;
 
   /* Check for stack pointer "sp" alias.  */
@@ -257,9 +272,11 @@ parse_reg (char *src, int *mode, unsigned int *reg)
       if (src[1] == 'r' || src[1] == 'R')
        {
          if (src[2] < '0' || src[2] > '9')
-           return res;  /* Assume no register name but a label starting with 'rr'.  */
+           return NULL;        /* Assume no register name but a label starting with 'rr'.  */
          *mode = CLASS_REG_LONG;
          res = whatreg (reg, src + 2);
+         if (res == NULL)
+           return NULL;        /* Not a valid register name.  */
          regno = *reg;
          if (regno > 14)
            as_bad (_("register rr%d out of range"), regno);
@@ -269,9 +286,11 @@ parse_reg (char *src, int *mode, unsigned int *reg)
       else if (src[1] == 'h' || src[1] == 'H')
        {
          if (src[2] < '0' || src[2] > '9')
-           return res;  /* Assume no register name but a label starting with 'rh'.  */
+           return NULL;        /* Assume no register name but a label starting with 'rh'.  */
          *mode = CLASS_REG_BYTE;
          res = whatreg (reg, src + 2);
+         if (res == NULL)
+           return NULL;        /* Not a valid register name.  */
          regno = *reg;
          if (regno > 7)
            as_bad (_("register rh%d out of range"), regno);
@@ -279,9 +298,11 @@ parse_reg (char *src, int *mode, unsigned int *reg)
       else if (src[1] == 'l' || src[1] == 'L')
        {
          if (src[2] < '0' || src[2] > '9')
-           return res;  /* Assume no register name but a label starting with 'rl'.  */
+           return NULL;        /* Assume no register name but a label starting with 'rl'.  */
          *mode = CLASS_REG_BYTE;
          res = whatreg (reg, src + 2);
+         if (res == NULL)
+           return NULL;        /* Not a valid register name.  */
          regno = *reg;
          if (regno > 7)
            as_bad (_("register rl%d out of range"), regno);
@@ -290,9 +311,11 @@ parse_reg (char *src, int *mode, unsigned int *reg)
       else if (src[1] == 'q' || src[1] == 'Q')
        {
          if (src[2] < '0' || src[2] > '9')
-           return res;  /* Assume no register name but a label starting with 'rq'.  */
+           return NULL;        /* Assume no register name but a label starting with 'rq'.  */
          *mode = CLASS_REG_QUAD;
          res = whatreg (reg, src + 2);
+         if (res == NULL)
+           return NULL;        /* Not a valid register name.  */
          regno = *reg;
          if (regno > 12)
            as_bad (_("register rq%d out of range"), regno);
@@ -302,9 +325,11 @@ parse_reg (char *src, int *mode, unsigned int *reg)
       else
        {
          if (src[1] < '0' || src[1] > '9')
-           return res;  /* Assume no register name but a label starting with 'r'.  */
+           return NULL;        /* Assume no register name but a label starting with 'r'.  */
          *mode = CLASS_REG_WORD;
          res = whatreg (reg, src + 1);
+         if (res == NULL)
+           return NULL;        /* Not a valid register name.  */
          regno = *reg;
          if (regno > 15)
            as_bad (_("register r%d out of range"), regno);