real.c (real_to_decimal): Accept BUF_SIZE and CROP_TRAILING_ZEROS as arguments.

gcc/
        * real.c (real_to_decimal): Accept BUF_SIZE and CROP_TRAILING_ZEROS
        as arguments.  Bound DIGITS by the available buffer size.
        (real_to_hexadecimal): Likewise.
        * real.h (real_to_decimal, real_to_hexadecimal): Update prototypes.
        (REAL_VALUE_TO_DECIMAL): Remove.
        * c-common.c, c-pretty-print.c, print-rtl.c, print-tree.c,
        sched-vis.c, config/arc/arc.c, config/c4x/c4x.c, config/fr30/fr30.c,
        config/i370/i370.h, config/i386/i386.c, config/i960/i960.c,
        config/ip2k/ip2k.c, config/m32r/m32r.c, config/m68hc11/m68hc11.c,
        config/m68k/hp320.h, config/m68k/m68k.h, config/m68k/sun2o4.h,
        config/m68k/sun3.h, config/mips/mips.c, config/ns32k/ns32k.c,
        config/pdp11/pdp11.h, config/vax/vax.h: Update all callers to
        use real_to_decimal directly, and with the proper arguments.
        * doc/tm.texi (REAL_VALUE_TO_DECIMAL): Remove.

gcc/cp/
        * error.c (dump_expr): Use real_to_decimal directly, and with
        the new arguments.

gcc/f/
        * target.h (ffetarget_print_real1, ffetarget_print_real2): Use
        real_to_decimal directly, and with the new arguments.

From-SVN: r58187
This commit is contained in:
Richard Henderson 2002-10-15 17:40:39 -07:00 committed by Richard Henderson
parent ba0bb02d1d
commit da6eec72f5
30 changed files with 149 additions and 129 deletions

View file

@ -1,3 +1,20 @@
2002-10-15 Richard Henderson <rth@redhat.com>
* real.c (real_to_decimal): Accept BUF_SIZE and CROP_TRAILING_ZEROS
as arguments. Bound DIGITS by the available buffer size.
(real_to_hexadecimal): Likewise.
* real.h (real_to_decimal, real_to_hexadecimal): Update prototypes.
(REAL_VALUE_TO_DECIMAL): Remove.
* c-common.c, c-pretty-print.c, print-rtl.c, print-tree.c,
sched-vis.c, config/arc/arc.c, config/c4x/c4x.c, config/fr30/fr30.c,
config/i370/i370.h, config/i386/i386.c, config/i960/i960.c,
config/ip2k/ip2k.c, config/m32r/m32r.c, config/m68hc11/m68hc11.c,
config/m68k/hp320.h, config/m68k/m68k.h, config/m68k/sun2o4.h,
config/m68k/sun3.h, config/mips/mips.c, config/ns32k/ns32k.c,
config/pdp11/pdp11.h, config/vax/vax.h: Update all callers to
use real_to_decimal directly, and with the proper arguments.
* doc/tm.texi (REAL_VALUE_TO_DECIMAL): Remove.
2002-10-15 Jim Wilson <wilson@redhat.com>
* reload1.c (merge_assigned_reloads): After converting overlapping

View file

@ -5100,7 +5100,7 @@ builtin_define_with_hex_fp_value (macro, type, digits, hex_str, fp_suffix)
then print it back out as decimal. */
real_from_string (&real, hex_str);
real_to_decimal (dec_str, &real, digits);
real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0);
sprintf (buf, "%s=%s%s", macro, dec_str, fp_suffix);
cpp_define (parse_in, buf);

View file

@ -469,7 +469,8 @@ pp_c_real_literal (ppi, r)
c_pretty_printer ppi;
tree r;
{
REAL_VALUE_TO_DECIMAL (TREE_REAL_CST (r), pp_buffer (ppi)->digit_buffer, -1);
real_to_decimal (pp_buffer (ppi)->digit_buffer, &TREE_REAL_CST (r),
sizeof (pp_buffer (ppi)->digit_buffer), 0, 1);
pp_identifier (ppi, pp_buffer(ppi)->digit_buffer);
}

View file

@ -1741,14 +1741,13 @@ arc_print_operand (file, x, code)
return;
case 'A' :
{
REAL_VALUE_TYPE d;
char str[30];
if (GET_CODE (x) != CONST_DOUBLE
|| GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
abort ();
REAL_VALUE_FROM_CONST_DOUBLE (d, x);
REAL_VALUE_TO_DECIMAL (d, str, -1);
real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
fprintf (file, "%s", str);
return;
}

View file

@ -1960,10 +1960,9 @@ c4x_print_operand (file, op, letter)
case CONST_DOUBLE:
{
char str[64];
REAL_VALUE_TYPE r;
REAL_VALUE_FROM_CONST_DOUBLE (r, op);
REAL_VALUE_TO_DECIMAL (r, str, -1);
real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (op),
sizeof (str), 0, 1);
fprintf (file, "%s", str);
}
break;

View file

@ -553,11 +553,10 @@ fr30_print_operand (file, x, code)
output_operand_lossage ("fr30_print_operand: invalid %%F code");
else
{
REAL_VALUE_TYPE d;
char str[30];
REAL_VALUE_FROM_CONST_DOUBLE (d, x);
REAL_VALUE_TO_DECIMAL (d, str, 8);
real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x),
sizeof (str), 0, 1);
fputs (str, file);
}
return;

View file

@ -1371,21 +1371,21 @@ enum reg_class
else \
{ \
char buf[50]; \
REAL_VALUE_TYPE rval; \
REAL_VALUE_FROM_CONST_DOUBLE(rval, XV); \
REAL_VALUE_TO_DECIMAL (rval, buf, -1); \
if (GET_MODE (XV) == SFmode) \
{ \
mvs_page_lit += 4; \
real_to_decimal (buf, CONST_DOUBLE_REAL_VALUE (XV), \
sizeof (buf), 0, 1); \
fprintf (FILE, "=E'%s'", buf); \
} \
else \
if (GET_MODE (XV) == DFmode) \
else if (GET_MODE (XV) == DFmode) \
{ \
mvs_page_lit += 8; \
real_to_decimal (buf, CONST_DOUBLE_REAL_VALUE (XV), \
sizeof (buf), 0, 1); \
fprintf (FILE, "=D'%s'", buf); \
} \
else /* VOIDmode !?!? strange but true ... */ \
else /* VOIDmode */ \
{ \
mvs_page_lit += 8; \
fprintf (FILE, "=XL8'%08X%08X'", \
@ -1665,21 +1665,21 @@ enum reg_class
else \
{ \
char buf[50]; \
REAL_VALUE_TYPE rval; \
REAL_VALUE_FROM_CONST_DOUBLE(rval, XV); \
REAL_VALUE_TO_DECIMAL (rval, buf, -1); \
if (GET_MODE (XV) == SFmode) \
{ \
mvs_page_lit += 4; \
real_to_decimal (buf, CONST_DOUBLE_REAL_VALUE (XV), \
sizeof (buf), 0, 1); \
fprintf (FILE, "=E'%s'", buf); \
} \
else \
if (GET_MODE (XV) == DFmode) \
else if (GET_MODE (XV) == DFmode) \
{ \
mvs_page_lit += 8; \
real_to_decimal (buf, CONST_DOUBLE_REAL_VALUE (XV), \
sizeof (buf), 0, 1); \
fprintf (FILE, "=D'%s'", buf); \
} \
else /* VOIDmode !?!? strange but true ... */ \
else /* VOIDmode */ \
{ \
mvs_page_lit += 8; \
fprintf (FILE, "=XL8'%08X%08X'", \

View file

@ -6742,22 +6742,18 @@ print_operand (file, x, code)
/* These float cases don't actually occur as immediate operands. */
else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
{
REAL_VALUE_TYPE r;
char dstr[30];
REAL_VALUE_FROM_CONST_DOUBLE (r, x);
REAL_VALUE_TO_DECIMAL (r, dstr, -1);
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
fprintf (file, "%s", dstr);
}
else if (GET_CODE (x) == CONST_DOUBLE
&& (GET_MODE (x) == XFmode || GET_MODE (x) == TFmode))
{
REAL_VALUE_TYPE r;
char dstr[30];
REAL_VALUE_FROM_CONST_DOUBLE (r, x);
REAL_VALUE_TO_DECIMAL (r, dstr, -1);
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
fprintf (file, "%s", dstr);
}

View file

@ -1785,7 +1785,6 @@ i960_print_operand (file, x, code)
}
else if (rtxcode == CONST_DOUBLE)
{
REAL_VALUE_TYPE d;
char dstr[30];
if (x == CONST0_RTX (GET_MODE (x)))
@ -1799,8 +1798,7 @@ i960_print_operand (file, x, code)
return;
}
REAL_VALUE_FROM_CONST_DOUBLE (d, x);
REAL_VALUE_TO_DECIMAL (d, dstr, -1);
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
fprintf (file, "0f%s", dstr);
return;
}

View file

@ -3072,8 +3072,9 @@ asm_output_float (file, n)
char dstr[100];
REAL_VALUE_TO_TARGET_SINGLE (n, val);
REAL_VALUE_TO_DECIMAL (n, dstr, -1);
fprintf (file, "\t.long 0x%08lx\t/* %s */\n",val, dstr);
real_to_decimal (dstr, &n, sizeof (dstr), 0, 1);
fprintf (file, "\t.long 0x%08lx\t/* %s */\n", val, dstr);
}
/* Sets section name for declaration DECL. */

View file

@ -2311,14 +2311,13 @@ m32r_print_operand (file, x, code)
case 'A' :
{
REAL_VALUE_TYPE d;
char str[30];
if (GET_CODE (x) != CONST_DOUBLE
|| GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
fatal_insn ("bad insn for 'A'", x);
REAL_VALUE_FROM_CONST_DOUBLE (d, x);
REAL_VALUE_TO_DECIMAL (d, str, -1);
real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
fprintf (file, "%s", str);
return;
}

View file

@ -2260,11 +2260,10 @@ print_operand (file, op, letter)
else if (GET_CODE (op) == CONST_DOUBLE
&& (GET_MODE (op) == DFmode || GET_MODE (op) == XFmode))
{
REAL_VALUE_TYPE r;
char dstr[30];
REAL_VALUE_FROM_CONST_DOUBLE (r, op);
REAL_VALUE_TO_DECIMAL (r, dstr, -1);
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (op),
sizeof (dstr), 0, 1);
asm_fprintf (file, "%I0r%s", dstr);
}
else

View file

@ -300,7 +300,7 @@ do { \
if (CODE == 'f') \
{ \
char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, 9); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 9, 0); \
fprintf ((FILE), "&0f%s", dstr); \
} \
else \
@ -317,7 +317,7 @@ do { \
#undef ASM_OUTPUT_DOUBLE_OPERAND
#define ASM_OUTPUT_DOUBLE_OPERAND(FILE,VALUE) \
do { char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
fprintf (FILE, "&0f%s", dstr); \
} while (0)
@ -326,7 +326,7 @@ do { \
#undef ASM_OUTPUT_LONG_DOUBLE_OPERAND
#define ASM_OUTPUT_LONG_DOUBLE_OPERAND(FILE,VALUE) \
do { char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
fprintf (FILE, "&0f%s", dstr); \
} while (0)
@ -351,15 +351,11 @@ do { \
{ REAL_VALUE_TYPE r; long l; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
PRINT_OPERAND_FLOAT (CODE, FILE, r, l); } \
else if (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) == DFmode) \
{ REAL_VALUE_TYPE r; char dstr[30]; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
REAL_VALUE_TO_DECIMAL (r, dstr, -1); \
fprintf (FILE, "&0f%s", dstr); } \
else if (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) == XFmode) \
{ REAL_VALUE_TYPE r; char dstr[30]; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
REAL_VALUE_TO_DECIMAL (r, dstr, -1); \
else if (GET_CODE (X) == CONST_DOUBLE \
&& (GET_MODE (X) == DFmode || GET_MODE (X) == XFmode)) \
{ char dstr[30]; \
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (X), \
sizeof (dstr), 0, 1); \
fprintf (FILE, "&0f%s", dstr); } \
else { putc ('&', FILE); output_addr_const (FILE, X); }}
#endif

View file

@ -1823,7 +1823,7 @@ __transfer_from_trampoline () \
if (CODE == 'f') \
{ \
char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, 9); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 9, 0); \
asm_fprintf ((FILE), "%I0r%s", dstr); \
} \
else \
@ -1838,7 +1838,7 @@ __transfer_from_trampoline () \
This macro is a 68k-specific macro. */
#define ASM_OUTPUT_DOUBLE_OPERAND(FILE,VALUE) \
do { char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
asm_fprintf (FILE, "%I0r%s", dstr); \
} while (0)
@ -1846,7 +1846,7 @@ __transfer_from_trampoline () \
generated by m68k.md. */
#define ASM_OUTPUT_LONG_DOUBLE_OPERAND(FILE,VALUE) \
do { char dstr[30]; \
REAL_VALUE_TO_DECIMAL (VALUE, dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
asm_fprintf (FILE, "%I0r%s", dstr); \
} while (0)

View file

@ -121,7 +121,7 @@ Boston, MA 02111-1307, USA. */
} \
else \
{ char dstr[30]; \
REAL_VALUE_TO_DECIMAL ((VALUE), dstr, 9); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 9, 0); \
fprintf (FILE, "#0r%s", dstr); \
} \
} while (0)
@ -141,7 +141,7 @@ Boston, MA 02111-1307, USA. */
} \
else \
{ char dstr[30]; \
REAL_VALUE_TO_DECIMAL ((VALUE), dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
fprintf (FILE, "#0r%s", dstr); \
} \
} while (0)

View file

@ -208,7 +208,7 @@ Boston, MA 02111-1307, USA. */
} \
else \
{ char dstr[30]; \
REAL_VALUE_TO_DECIMAL ((VALUE), dstr, 9); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 9, 0); \
asm_fprintf (FILE, "%I0r%s", dstr); \
} \
} while (0)
@ -228,7 +228,7 @@ Boston, MA 02111-1307, USA. */
} \
else \
{ char dstr[30]; \
REAL_VALUE_TO_DECIMAL ((VALUE), dstr, -1); \
real_to_decimal (dstr, &(VALUE), sizeof (dstr), 0, 1); \
asm_fprintf (FILE, "%I0r%s", dstr); \
} \
} while (0)

View file

@ -5910,12 +5910,10 @@ print_operand (file, op, letter)
else if (code == CONST_DOUBLE
&& GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT)
{
REAL_VALUE_TYPE d;
char s[60];
REAL_VALUE_FROM_CONST_DOUBLE (d, op);
REAL_VALUE_TO_DECIMAL (d, s, -1);
fprintf (file, s);
real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (op), sizeof (s), 0, 1);
fputs (s, file);
}
else if (letter == 'x' && GET_CODE (op) == CONST_INT)

View file

@ -1130,11 +1130,13 @@ print_operand (file, x, code)
{
#ifdef SEQUENT_ASM
/* Sequent likes its floating point constants as integers */
long l[2];
REAL_VALUE_TO_TARGET_DOUBLE (r, l);
fprintf (file, "0Dx%08x%08x",
CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
l[!WORDS_BIG_ENDIAN], l[WORDS_BIG_ENDIAN]);
#else
char s[30];
REAL_VALUE_TO_DECIMAL (r, s, -1);
real_to_decimal (s, &r, sizeof (s), 0, 1);
#ifdef ENCORE_ASM
fprintf (file, "0f%s", s);
#else
@ -1150,7 +1152,7 @@ print_operand (file, x, code)
fprintf (file, "0Fx%08lx", l);
#else
char s[30];
REAL_VALUE_TO_DECIMAL (r, s, -1);
real_to_decimal (s, &r, sizeof (s), 0, 1);
fprintf (file, "0f%s", s);
#endif
}

View file

@ -1149,10 +1149,8 @@ fprintf (FILE, "$help$: . = .+8 ; space for tmp moves!\n") \
else if (GET_CODE (X) == MEM) \
output_address (XEXP (X, 0)); \
else if (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) != SImode) \
{ REAL_VALUE_TYPE r; \
char buf[30]; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
REAL_VALUE_TO_DECIMAL (r, buf, -1); \
{ char buf[30]; \
real_to_decimal (buf, CONST_DOUBLE_REAL_VALUE (X), sizeof (buf), 0, 1); \
fprintf (FILE, "$0F%s", buf); } \
else { putc ('$', FILE); output_addr_const_pdp11 (FILE, X); }}

View file

@ -1227,14 +1227,14 @@ VAX operand formatting codes:
else if (GET_CODE (X) == MEM) \
output_address (XEXP (X, 0)); \
else if (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) == SFmode) \
{ REAL_VALUE_TYPE r; char dstr[30]; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
REAL_VALUE_TO_DECIMAL (r, dstr, -1); \
{ char dstr[30]; \
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (X), \
sizeof (dstr), 0, 1); \
fprintf (FILE, "$0f%s", dstr); } \
else if (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) == DFmode) \
{ REAL_VALUE_TYPE r; char dstr[30]; \
REAL_VALUE_FROM_CONST_DOUBLE (r, X); \
REAL_VALUE_TO_DECIMAL (r, dstr, -1); \
{ char dstr[30]; \
real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (X), \
sizeof (dstr), 0, 1); \
fprintf (FILE, "$0%c%s", ASM_DOUBLE_CHAR, dstr); } \
else { putc ('$', FILE); output_addr_const (FILE, X); }}

View file

@ -1,3 +1,8 @@
2002-10-15 Richard Henderson <rth@redhat.com>
* error.c (dump_expr): Use real_to_decimal directly, and with
the new arguments.
2002-10-15 Mark Mitchell <mark@codesourcery.com>
* decl.c (reshape_init): Fix typo.

View file

@ -1508,7 +1508,8 @@ dump_expr (t, flags)
break;
case REAL_CST:
REAL_VALUE_TO_DECIMAL (TREE_REAL_CST (t), digit_buffer, -1);
real_to_decimal (digit_buffer, &TREE_REAL_CST (t),
sizeof (digit_buffer), 0, 1);
output_add_string (scratch_buffer, digit_buffer);
break;

View file

@ -6326,17 +6326,6 @@ host machine.
The array element values are designed so that you can print them out
using @code{fprintf} in the order they should appear in the target
machine's memory.
@item REAL_VALUE_TO_DECIMAL (@var{x}, @var{string}, @var{digits})
@findex REAL_VALUE_TO_DECIMAL
This macro converts @var{x}, of type @code{REAL_VALUE_TYPE}, to a
decimal number and stores it as a string into @var{string}.
You must pass, as @var{string}, the address of a long enough block
of space to hold the result.
The argument @var{digits} is the number of decimal digits to print,
or @minus{}1 to indicate ``enough'', i.e. @code{DECIMAL_DIG} for
for the target.
@end table
@node Uninitialized Data

View file

@ -1,3 +1,8 @@
2002-10-15 Richard Henderson <rth@redhat.com>
* target.h (ffetarget_print_real1, ffetarget_print_real2): Use
real_to_decimal directly, and with the new arguments.
2002-09-23 Zack Weinberg <zack@codesourcery.com>
* Make-lang.in (g77spec.o): Don't depend on f/version.h.

View file

@ -1469,13 +1469,15 @@ void *ffetarget_memcpy_ (void *dst, void *src, size_t len);
#define ffetarget_print_real1(f,l) \
({ REAL_VALUE_TYPE lr; \
lr = ffetarget_cvt_r1_to_rv_ ((l)); \
REAL_VALUE_TO_DECIMAL (lr, ffetarget_string_, -1); \
real_to_decimal (ffetarget_string_, &lr \
sizeof(ffetarget_string_), 0, 1); \
fputs (ffetarget_string_, (f)); \
})
#define ffetarget_print_real2(f,l) \
({ REAL_VALUE_TYPE lr; \
lr = ffetarget_cvt_r2_to_rv_ (&((l).v[0])); \
REAL_VALUE_TO_DECIMAL (lr, ffetarget_string_, -1); \
real_to_decimal (ffetarget_string_, &lr, \
sizeof(ffetarget_string_), 0, 1); \
fputs (ffetarget_string_, (f)); \
})
#define ffetarget_real1_one(res) ffetarget_cvt_rv_to_r1_ (dconst1, *(res))

View file

@ -524,10 +524,12 @@ print_rtx (in_rtx)
{
char s[60];
real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx), -1);
real_to_decimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
sizeof (s), 0, 1);
fprintf (outfile, " %s", s);
real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx), -1);
real_to_hexadecimal (s, CONST_DOUBLE_REAL_VALUE (in_rtx),
sizeof (s), 0, 1);
fprintf (outfile, " [%s]", s);
}
break;

View file

@ -131,9 +131,8 @@ print_node_brief (file, prefix, node, indent)
fprintf (file, " Nan");
else
{
char string[100];
REAL_VALUE_TO_DECIMAL (d, string, -1);
char string[60];
real_to_decimal (string, &d, sizeof (string), 0, 1);
fprintf (file, " %s", string);
}
}
@ -684,9 +683,8 @@ print_node (file, prefix, node, indent)
fprintf (file, " Nan");
else
{
char string[100];
REAL_VALUE_TO_DECIMAL (d, string, -1);
char string[64];
real_to_decimal (string, &d, sizeof (string), 0, 1);
fprintf (file, " %s", string);
}
}

View file

@ -1397,23 +1397,26 @@ real_to_integer2 (plow, phigh, r)
}
/* Render R as a decimal floating point constant. Emit DIGITS significant
digits in the result. If DIGITS <= 0, choose the maximum for the
representation. If DIGITS < 0, strip trailing zeros. */
digits in the result, bounded by BUF_SIZE. If DIGITS is 0, choose the
maximum for the representation. If CROP_TRAILING_ZEROS, strip trailing
zeros. */
#define M_LOG10_2 0.30102999566398119521
void
real_to_decimal (str, r_orig, digits)
real_to_decimal (str, r_orig, buf_size, digits, crop_trailing_zeros)
char *str;
const REAL_VALUE_TYPE *r_orig;
int digits;
size_t buf_size, digits;
int crop_trailing_zeros;
{
REAL_VALUE_TYPE r;
const REAL_VALUE_TYPE *one, *ten;
int dec_exp, max_digits, d, cmp_half;
int dec_exp, d, cmp_half;
size_t max_digits;
char *p, *first, *last;
char exp_buf[16];
bool sign;
bool crop_trailing_zeros;
r = *r_orig;
switch (r.class)
@ -1434,11 +1437,6 @@ real_to_decimal (str, r_orig, digits)
abort ();
}
max_digits = SIGNIFICAND_BITS * M_LOG10_2;
crop_trailing_zeros = digits < 0;
if (digits <= 0 || digits > max_digits)
digits = max_digits;
one = real_digit (1);
ten = ten_to_ptwo (0);
@ -1468,6 +1466,21 @@ real_to_decimal (str, r_orig, digits)
if (sign)
*p++ = '-';
first = p++;
sprintf (exp_buf, "e%+d", dec_exp);
/* Bound the number of digits printed by the size of the representation. */
max_digits = SIGNIFICAND_BITS * M_LOG10_2;
if (digits == 0 || digits > max_digits)
digits = max_digits;
/* Bound the number of digits printed by the size of the output buffer. */
max_digits = buf_size - strlen (exp_buf) - sign - 1;
if (max_digits > buf_size)
abort ();
if (digits > max_digits)
digits = max_digits;
while (1)
{
d = real_to_integer ((const REAL_VALUE_TYPE *) &r);
@ -1514,22 +1527,25 @@ real_to_decimal (str, r_orig, digits)
while (last > first + 3 && last[-1] == '0')
last--;
sprintf (last, "e%+d", dec_exp);
strcpy (last, exp_buf);
}
/* Render R as a hexadecimal floating point constant. Emit DIGITS
significant digits in the result. If DIGITS <= 0, choose the maximum
for the representation. If DIGITS < 0, strip trailing zeros. */
significant digits in the result, bounded by BUF_SIZE. If DIGITS is 0,
choose the maximum for the representation. If CROP_TRAILING_ZEROS,
strip trailing zeros. */
void
real_to_hexadecimal (str, r, digits)
real_to_hexadecimal (str, r, buf_size, digits, crop_trailing_zeros)
char *str;
const REAL_VALUE_TYPE *r;
int digits;
size_t buf_size, digits;
int crop_trailing_zeros;
{
int i, j, exp = r->exp;
char *p, *first;
bool crop_trailing_zeros;
char exp_buf[16];
size_t max_digits;
switch (r->class)
{
@ -1549,10 +1565,18 @@ real_to_hexadecimal (str, r, digits)
abort ();
}
crop_trailing_zeros = digits < 0;
if (digits <= 0)
if (digits == 0)
digits = SIGNIFICAND_BITS / 4;
/* Bound the number of digits printed by the size of the output buffer. */
sprintf (exp_buf, "p%+d", exp);
max_digits = buf_size - strlen (exp_buf) - r->sign - 4 - 1;
if (max_digits > buf_size)
abort ();
if (digits > max_digits)
digits = max_digits;
p = str;
if (r->sign)
*p++ = '-';
@ -1572,7 +1596,7 @@ real_to_hexadecimal (str, r, digits)
out:
if (crop_trailing_zeros)
while (p > first + 2 && p[-1] == '0')
while (p > first + 1 && p[-1] == '0')
p--;
sprintf (p, "p%+d", exp);

View file

@ -176,11 +176,11 @@ extern bool exact_real_truncate PARAMS ((enum machine_mode,
/* Render R as a decimal floating point constant. */
extern void real_to_decimal PARAMS ((char *, const REAL_VALUE_TYPE *,
int));
size_t, size_t, int));
/* Render R as a hexadecimal floating point constant. */
extern void real_to_hexadecimal PARAMS ((char *, const REAL_VALUE_TYPE *,
int));
size_t, size_t, int));
/* Render R as an integer. */
extern HOST_WIDE_INT real_to_integer PARAMS ((const REAL_VALUE_TYPE *));
@ -267,9 +267,6 @@ extern const struct real_format c4x_extended_format;
#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
((OUT) = real_to_target (NULL, &(IN), mode_for_size (32, MODE_FLOAT, 0)))
#define REAL_VALUE_TO_DECIMAL(r, s, dig) \
real_to_decimal (s, &(r), dig)
#define REAL_VALUE_FROM_INT(r, lo, hi, mode) \
real_from_integer (&(r), mode, lo, hi, 0)

View file

@ -562,12 +562,7 @@ print_value (buf, x, verbose)
break;
case CONST_DOUBLE:
if (FLOAT_MODE_P (GET_MODE (x)))
{
REAL_VALUE_TYPE r;
REAL_VALUE_FROM_CONST_DOUBLE (r, x);
REAL_VALUE_TO_DECIMAL(r, t, 6);
}
real_to_decimal (t, CONST_DOUBLE_REAL_VALUE (x), sizeof (t), 0, 1);
else
sprintf (t, "<0x%lx,0x%lx>", (long) XWINT (x, 2), (long) XWINT (x, 3));
cur = safe_concat (buf, cur, t);