From: Nick Clifton Date: Thu, 6 May 2004 11:01:48 +0000 (+0000) Subject: Remove duplicate code and provide a function for generating internally consistent... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e59763172f0ba262bc2b0452db6fb816c457bba3;p=binutils-gdb.git Remove duplicate code and provide a function for generating internally consistent 'value out of range' messages --- diff --git a/gas/ChangeLog b/gas/ChangeLog index 6e7dc19375e..0433a7ce35d 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,21 @@ +2004-05-06 Nick Clifton + + * 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 * configure.in: Set em=linux for frv-*-*linux*. diff --git a/gas/as.h b/gas/as.h index 890ecd8f105..1f9fd60a393 100644 --- 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); diff --git a/gas/config/tc-alpha.c b/gas/config/tc-alpha.c index 93600473ffc..7e553fbca23 100644 --- a/gas/config/tc-alpha.c +++ b/gas/config/tc-alpha.c @@ -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) diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c index 60cfa34652a..be1e93ccf26 100644 --- a/gas/config/tc-arc.c +++ b/gas/config/tc-arc.c @@ -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) diff --git a/gas/config/tc-mn10200.c b/gas/config/tc-mn10200.c index 642069493b4..64dd0992142 100644 --- a/gas/config/tc-mn10200.c +++ b/gas/config/tc-mn10200.c @@ -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) diff --git a/gas/config/tc-mn10300.c b/gas/config/tc-mn10300.c index 832464617d2..36e6a058ace 100644 --- a/gas/config/tc-mn10300.c +++ b/gas/config/tc-mn10300.c @@ -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) diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index 66366a57d23..fe66d2ba2dc 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -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) diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c index 4fafbec35fe..2cb8cf1aada 100644 --- a/gas/config/tc-s390.c +++ b/gas/config/tc-s390.c @@ -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; } } diff --git a/gas/config/tc-v850.c b/gas/config/tc-v850.c index d53a97313d7..b1085acae5f 100644 --- a/gas/config/tc-v850.c +++ b/gas/config/tc-v850.c @@ -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); } } 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); +}