Update baseline symbols for hppa-linux.
[official-gcc.git] / gcc / wide-int-print.cc
blobf3a18711e29d0d0f4cba8c2453c1c1f3c823ecc8
1 /* Printing operations with very long integers.
2 Copyright (C) 2012-2023 Free Software Foundation, Inc.
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
10 later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "pretty-print.h"
27 * public printing routines.
30 #define BLOCKS_NEEDED(PREC) \
31 (((PREC) + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
33 void
34 print_dec (const wide_int_ref &wi, char *buf, signop sgn)
36 if (sgn == SIGNED)
37 print_decs (wi, buf);
38 else
39 print_decu (wi, buf);
42 void
43 print_dec (const wide_int_ref &wi, FILE *file, signop sgn)
45 if (sgn == SIGNED)
46 print_decs (wi, file);
47 else
48 print_decu (wi, file);
52 /* Try to print the signed self in decimal to BUF if the number fits
53 in a HWI. Other print in hex. */
55 void
56 print_decs (const wide_int_ref &wi, char *buf)
58 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
59 || (wi.get_len () == 1))
61 if (wi::neg_p (wi))
62 sprintf (buf, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
63 -(unsigned HOST_WIDE_INT) wi.to_shwi ());
64 else
65 sprintf (buf, HOST_WIDE_INT_PRINT_DEC, wi.to_shwi ());
67 else
68 print_hex (wi, buf);
71 /* Try to print the signed self in decimal to FILE if the number fits
72 in a HWI. Other print in hex. */
74 void
75 print_decs (const wide_int_ref &wi, FILE *file)
77 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
78 print_decs (wi, buf);
79 fputs (buf, file);
82 /* Try to print the unsigned self in decimal to BUF if the number fits
83 in a HWI. Other print in hex. */
85 void
86 print_decu (const wide_int_ref &wi, char *buf)
88 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
89 || (wi.get_len () == 1 && !wi::neg_p (wi)))
90 sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, wi.to_uhwi ());
91 else
92 print_hex (wi, buf);
95 /* Try to print the signed self in decimal to FILE if the number fits
96 in a HWI. Other print in hex. */
98 void
99 print_decu (const wide_int_ref &wi, FILE *file)
101 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
102 print_decu (wi, buf);
103 fputs (buf, file);
106 void
107 print_hex (const wide_int_ref &val, char *buf)
109 if (val == 0)
110 buf += sprintf (buf, "0x0");
111 else
113 buf += sprintf (buf, "0x");
114 int start = ROUND_DOWN (val.get_precision (), HOST_BITS_PER_WIDE_INT);
115 int width = val.get_precision () - start;
116 bool first_p = true;
117 for (int i = start; i >= 0; i -= HOST_BITS_PER_WIDE_INT)
119 unsigned HOST_WIDE_INT uhwi = wi::extract_uhwi (val, i, width);
120 if (!first_p)
121 buf += sprintf (buf, HOST_WIDE_INT_PRINT_PADDED_HEX, uhwi);
122 else if (uhwi != 0)
124 buf += sprintf (buf, HOST_WIDE_INT_PRINT_HEX_PURE, uhwi);
125 first_p = false;
127 width = HOST_BITS_PER_WIDE_INT;
132 /* Print one big hex number to FILE. Note that some assemblers may not
133 accept this for large modes. */
134 void
135 print_hex (const wide_int_ref &wi, FILE *file)
137 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
138 print_hex (wi, buf);
139 fputs (buf, file);
142 /* Print larger precision wide_int. Not defined as inline in a header
143 together with pp_wide_int because XALLOCAVEC will make it uninlinable. */
145 void
146 pp_wide_int_large (pretty_printer *pp, const wide_int_ref &w, signop sgn)
148 unsigned int prec = w.get_precision ();
149 char *buf = XALLOCAVEC (char, (prec + 3) / 4 + 3);
150 print_dec (w, buf, sgn);
151 pp_string (pp, buf);