Remove duplicate code and provide a function for generating internally consistent...
authorNick Clifton <nickc@redhat.com>
Thu, 6 May 2004 11:01:48 +0000 (11:01 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 6 May 2004 11:01:48 +0000 (11:01 +0000)
gas/ChangeLog
gas/as.h
gas/config/tc-alpha.c
gas/config/tc-arc.c
gas/config/tc-mn10200.c
gas/config/tc-mn10300.c
gas/config/tc-ppc.c
gas/config/tc-s390.c
gas/config/tc-v850.c
gas/messages.c

index 6e7dc19..0433a7c 100644 (file)
@@ -1,3 +1,21 @@
+2004-05-06  Nick Clifton  <nickc@redhat.com>
+
+       * messages (as_internal_value_out_of_range): Print a message about
+       a value being out of range.  Be consistent about whether the
+       values are printed in decimal or hexadecimal.
+       (as_warn_value_out_of_range): Generate a warning message about an
+       out of range value.
+       (as_bad_value_out_of_range): Generate an error message about an
+       out of range value.
+       * as.h: Prototype the new functions.
+       * config/tc-alpha.c (insert_operand): Use new function.
+       * config/tc-arc.c (arc_insert_operand): Likewise.
+       * config/tc-mn10200.c (mn10200_insert_operand): Likewise.
+       * config/tc-mn10300.c (mn10300_insert_operand): Likewise.
+       * config/tc-ppc.c (ppc_insert_operand): Likewise.
+       * config/tc-s390.c (s390_insert_operand): Likewise.
+       * config/tc-v850.c (v850_insert_operand): Likewise.
+
 2004-05-05  Alexandre Oliva  <aoliva@redhat.com>
 
        * configure.in: Set em=linux for frv-*-*linux*.
index 890ecd8..1f9fd60 100644 (file)
--- a/gas/as.h
+++ b/gas/as.h
@@ -562,6 +562,9 @@ void sprint_value (char *buf, addressT value);
 int had_errors (void);
 int had_warnings (void);
 
+void as_warn_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, unsigned);
+void as_bad_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, unsigned);
+
 void print_version_id (void);
 char *app_push (void);
 char *atof_ieee (char *str, int what_kind, LITTLENUM_TYPE * words);
index 9360047..7e553fb 100644 (file)
@@ -2373,17 +2373,7 @@ insert_operand (insn, operand, val, file, line)
        }
 
       if (val < min || val > max)
-       {
-         const char *err =
-           _("operand out of range (%s not between %d and %d)");
-         char buf[sizeof (val) * 3 + 2];
-
-         sprint_value (buf, val);
-         if (file)
-           as_warn_where (file, line, err, buf, min, max);
-         else
-           as_warn (err, buf, min, max);
-       }
+       as_warn_value_out_of_range (_("operand"), val, min, max, file, line);
     }
 
   if (operand->insert)
index 60cfa34..be1e93c 100644 (file)
@@ -328,17 +328,7 @@ arc_insert_operand (insn, operand, mods, reg, val, file, line)
        test = val;
 
       if (test < (offsetT) min || test > (offsetT) max)
-       {
-         const char *err =
-           "operand out of range (%s not between %ld and %ld)";
-         char buf[100];
-
-         sprint_value (buf, test);
-         if (file == (char *) NULL)
-           as_warn (err, buf, min, max);
-         else
-           as_warn_where (file, line, err, buf, min, max);
-       }
+       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
     }
 
   if (operand->insert)
index 6420694..64dd099 100644 (file)
@@ -1342,17 +1342,7 @@ mn10200_insert_operand (insnp, extensionp, operand, val, file, line, shift)
       test = val;
 
       if (test < (offsetT) min || test > (offsetT) max)
-        {
-          const char *err =
-            _("operand out of range (%s not between %ld and %ld)");
-          char buf[100];
-
-          sprint_value (buf, test);
-          if (file == (char *) NULL)
-            as_warn (err, buf, min, max);
-          else
-            as_warn_where (file, line, err, buf, min, max);
-        }
+       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
     }
 
   if ((operand->flags & MN10200_OPERAND_EXTENDED) == 0)
index 8324646..36e6a05 100644 (file)
@@ -2584,17 +2584,7 @@ mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
       test = val;
 
       if (test < (offsetT) min || test > (offsetT) max)
-       {
-         const char *err =
-           _("operand out of range (%s not between %ld and %ld)");
-         char buf[100];
-
-         sprint_value (buf, test);
-         if (file == (char *) NULL)
-           as_warn (err, buf, min, max);
-         else
-           as_warn_where (file, line, err, buf, min, max);
-       }
+       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
     }
 
   if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
index 66366a5..fe66d2b 100644 (file)
@@ -1457,14 +1457,7 @@ ppc_insert_operand (insn, operand, val, file, line)
        test = val;
 
       if (test < (offsetT) min || test > (offsetT) max)
-       {
-         const char *err =
-           _("operand out of range (%s not between %ld and %ld)");
-         char buf[100];
-
-         sprint_value (buf, test);
-         as_bad_where (file, line, err, buf, min, max);
-       }
+       as_bad_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
     }
 
   if (operand->insert)
index 4fafbec..2cb8cf1 100644 (file)
@@ -601,21 +601,15 @@ s390_insert_operand (insn, operand, val, file, line)
       /* Check for underflow / overflow.  */
       if (uval < min || uval > max)
        {
-         const char *err =
-           "operand out of range (%s not between %ld and %ld)";
-         char buf[100];
-
          if (operand->flags & S390_OPERAND_LENGTH)
            {
              uval++;
              min++;
              max++;
            }
-         sprint_value (buf, uval);
-         if (file == (char *) NULL)
-           as_bad (err, buf, (int) min, (int) max);
-         else
-           as_bad_where (file, line, err, buf, (int) min, (int) max);
+
+         as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line);
+
          return;
        }
     }
index d53a973..b1085ac 100644 (file)
@@ -1618,10 +1618,7 @@ v850_insert_operand (insn, operand, val, file, line, str)
 
          if (val < (offsetT) min || val > (offsetT) max)
            {
-             /* xgettext:c-format  */
-             const char *err =
-               _("operand out of range (%s not between %ld and %ld)");
-             char buf[100];
+             char buf [128];
 
              /* Restore min and mix to expected values for decimal ranges.  */
              if ((operand->flags & V850_OPERAND_SIGNED)
@@ -1633,18 +1630,12 @@ v850_insert_operand (insn, operand, val, file, line, str)
                min = 0;
 
              if (str)
-               {
-                 sprintf (buf, "%s: ", str);
-
-                 sprint_value (buf + strlen (buf), val);
-               }
+               sprintf (buf, "%s: ", str);
              else
-               sprint_value (buf, val);
+               buf[0] = 0;
+             strcat (buf, _("operand"));
 
-             if (file == (char *) NULL)
-               as_warn (err, buf, min, max);
-             else
-               as_warn_where (file, line, err, buf, min, max);
+             as_bad_value_out_of_range (buf, val, (offsetT) min, (offsetT) max, file, line);
            }
        }
 
index 005cd22..99e20a1 100644 (file)
@@ -503,3 +503,84 @@ sprint_value (char *buf, valueT val)
 #endif
   abort ();
 }
+
+#define HEX_MAX_THRESHOLD      1024
+#define HEX_MIN_THRESHOLD      -(HEX_MAX_THRESHOLD)
+
+static void
+as_internal_value_out_of_range (char *    prefix,
+                               offsetT   val,
+                               offsetT   min,
+                               offsetT   max,
+                               char *    file,
+                               unsigned  line,
+                               int       bad)
+{
+  const char * err;
+
+  if (prefix == NULL)
+    prefix = "";
+
+#ifdef BFD_ASSEMBLER
+  if (   val < HEX_MAX_THRESHOLD
+      && min < HEX_MAX_THRESHOLD
+      && max < HEX_MAX_THRESHOLD
+      && val > HEX_MIN_THRESHOLD
+      && min > HEX_MIN_THRESHOLD
+      && max > HEX_MIN_THRESHOLD)
+#endif
+    {
+      /* xgettext:c-format  */
+      err = _("%s out of range (%d is not between %d and %d)");
+
+      if (bad)
+       as_bad_where (file, line, err, prefix, val, min, max);
+      else
+       as_warn_where (file, line, err, prefix, val, min, max);
+    }
+#ifdef BFD_ASSEMBLER
+  else
+    {
+      char val_buf [sizeof (val) * 3 + 2];
+      char min_buf [sizeof (val) * 3 + 2];
+      char max_buf [sizeof (val) * 3 + 2];
+
+      if (sizeof (val) > sizeof (bfd_vma))
+       abort ();
+
+      sprintf_vma (val_buf, val);
+      sprintf_vma (min_buf, min);
+      sprintf_vma (max_buf, max);
+
+      /* xgettext:c-format.  */
+      err = _("%s out of range (0x%s is not between 0x%s and 0x%s)");
+
+      if (bad)
+       as_bad_where (file, line, err, prefix, val_buf, min_buf, max_buf);
+      else
+       as_warn_where (file, line, err, prefix, val_buf, min_buf, max_buf);
+    }
+#endif
+}
+
+void
+as_warn_value_out_of_range (char *   prefix,
+                          offsetT  value,
+                          offsetT  min,
+                          offsetT  max,
+                          char *   file,
+                          unsigned line)
+{
+  as_internal_value_out_of_range (prefix, value, min, max, file, line, 0);
+}
+
+void
+as_bad_value_out_of_range (char *   prefix,
+                          offsetT  value,
+                          offsetT  min,
+                          offsetT  max,
+                          char *   file,
+                          unsigned line)
+{
+  as_internal_value_out_of_range (prefix, value, min, max, file, line, 1);
+}