diff options
author | Nick Clifton <nickc@redhat.com> | 2004-05-06 11:01:48 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2004-05-06 11:01:48 +0000 |
commit | e59763172f0ba262bc2b0452db6fb816c457bba3 (patch) | |
tree | 3dbbd1d7f9491655b38ef50a0b936f2b94be763d /gas/messages.c | |
parent | 41cf0c62851dd766a7c2558c396a7babdc657d86 (diff) | |
download | binutils-gdb-e59763172f0ba262bc2b0452db6fb816c457bba3.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.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/gas/messages.c b/gas/messages.c index 005cd22d417..99e20a1a814 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); +} |