summaryrefslogtreecommitdiff
path: root/gas/messages.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2004-05-06 11:01:48 +0000
committerNick Clifton <nickc@redhat.com>2004-05-06 11:01:48 +0000
commit5dbbc20a3e09aaa4251a10086c6cd18149f2bb92 (patch)
tree0e038d9ad18264a3b9ebd3c0ac852abd44312c82 /gas/messages.c
parent64e73a78dc231b50c3b290aee324163102b013fc (diff)
downloadbinutils-redhat-5dbbc20a3e09aaa4251a10086c6cd18149f2bb92.tar.gz
Remove duplicate code and provide a function for generating internally consistent 'value out of range' messages
Diffstat (limited to 'gas/messages.c')
-rw-r--r--gas/messages.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/gas/messages.c b/gas/messages.c
index 005cd22d41..99e20a1a81 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -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);
+}