annotate gcc/wide-int-print.cc @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
kono
parents:
diff changeset
1 /* Printing operations with very long integers.
kono
parents:
diff changeset
2 Copyright (C) 2012-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
kono
parents:
diff changeset
9 Free Software Foundation; either version 3, or (at your option) any
kono
parents:
diff changeset
10 later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT
kono
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 /*
kono
parents:
diff changeset
26 * public printing routines.
kono
parents:
diff changeset
27 */
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 #define BLOCKS_NEEDED(PREC) \
kono
parents:
diff changeset
30 (((PREC) + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 void
kono
parents:
diff changeset
33 print_dec (const wide_int_ref &wi, char *buf, signop sgn)
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 if (sgn == SIGNED)
kono
parents:
diff changeset
36 print_decs (wi, buf);
kono
parents:
diff changeset
37 else
kono
parents:
diff changeset
38 print_decu (wi, buf);
kono
parents:
diff changeset
39 }
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 void
kono
parents:
diff changeset
42 print_dec (const wide_int_ref &wi, FILE *file, signop sgn)
kono
parents:
diff changeset
43 {
kono
parents:
diff changeset
44 if (sgn == SIGNED)
kono
parents:
diff changeset
45 print_decs (wi, file);
kono
parents:
diff changeset
46 else
kono
parents:
diff changeset
47 print_decu (wi, file);
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 /* Try to print the signed self in decimal to BUF if the number fits
kono
parents:
diff changeset
52 in a HWI. Other print in hex. */
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 void
kono
parents:
diff changeset
55 print_decs (const wide_int_ref &wi, char *buf)
kono
parents:
diff changeset
56 {
kono
parents:
diff changeset
57 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
kono
parents:
diff changeset
58 || (wi.get_len () == 1))
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 if (wi::neg_p (wi))
kono
parents:
diff changeset
61 sprintf (buf, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
kono
parents:
diff changeset
62 -(unsigned HOST_WIDE_INT) wi.to_shwi ());
kono
parents:
diff changeset
63 else
kono
parents:
diff changeset
64 sprintf (buf, HOST_WIDE_INT_PRINT_DEC, wi.to_shwi ());
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66 else
kono
parents:
diff changeset
67 print_hex (wi, buf);
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 /* Try to print the signed self in decimal to FILE if the number fits
kono
parents:
diff changeset
71 in a HWI. Other print in hex. */
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 void
kono
parents:
diff changeset
74 print_decs (const wide_int_ref &wi, FILE *file)
kono
parents:
diff changeset
75 {
kono
parents:
diff changeset
76 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
kono
parents:
diff changeset
77 print_decs (wi, buf);
kono
parents:
diff changeset
78 fputs (buf, file);
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 /* Try to print the unsigned self in decimal to BUF if the number fits
kono
parents:
diff changeset
82 in a HWI. Other print in hex. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 void
kono
parents:
diff changeset
85 print_decu (const wide_int_ref &wi, char *buf)
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
kono
parents:
diff changeset
88 || (wi.get_len () == 1 && !wi::neg_p (wi)))
kono
parents:
diff changeset
89 sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, wi.to_uhwi ());
kono
parents:
diff changeset
90 else
kono
parents:
diff changeset
91 print_hex (wi, buf);
kono
parents:
diff changeset
92 }
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* Try to print the signed self in decimal to FILE if the number fits
kono
parents:
diff changeset
95 in a HWI. Other print in hex. */
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 void
kono
parents:
diff changeset
98 print_decu (const wide_int_ref &wi, FILE *file)
kono
parents:
diff changeset
99 {
kono
parents:
diff changeset
100 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
kono
parents:
diff changeset
101 print_decu (wi, buf);
kono
parents:
diff changeset
102 fputs (buf, file);
kono
parents:
diff changeset
103 }
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 void
kono
parents:
diff changeset
106 print_hex (const wide_int_ref &val, char *buf)
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 if (val == 0)
kono
parents:
diff changeset
109 buf += sprintf (buf, "0x0");
kono
parents:
diff changeset
110 else
kono
parents:
diff changeset
111 {
kono
parents:
diff changeset
112 buf += sprintf (buf, "0x");
kono
parents:
diff changeset
113 int start = ROUND_DOWN (val.get_precision (), HOST_BITS_PER_WIDE_INT);
kono
parents:
diff changeset
114 int width = val.get_precision () - start;
kono
parents:
diff changeset
115 bool first_p = true;
kono
parents:
diff changeset
116 for (int i = start; i >= 0; i -= HOST_BITS_PER_WIDE_INT)
kono
parents:
diff changeset
117 {
kono
parents:
diff changeset
118 unsigned HOST_WIDE_INT uhwi = wi::extract_uhwi (val, i, width);
kono
parents:
diff changeset
119 if (!first_p)
kono
parents:
diff changeset
120 buf += sprintf (buf, HOST_WIDE_INT_PRINT_PADDED_HEX, uhwi);
kono
parents:
diff changeset
121 else if (uhwi != 0)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 buf += sprintf (buf, HOST_WIDE_INT_PRINT_HEX_PURE, uhwi);
kono
parents:
diff changeset
124 first_p = false;
kono
parents:
diff changeset
125 }
kono
parents:
diff changeset
126 width = HOST_BITS_PER_WIDE_INT;
kono
parents:
diff changeset
127 }
kono
parents:
diff changeset
128 }
kono
parents:
diff changeset
129 }
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 /* Print one big hex number to FILE. Note that some assemblers may not
kono
parents:
diff changeset
132 accept this for large modes. */
kono
parents:
diff changeset
133 void
kono
parents:
diff changeset
134 print_hex (const wide_int_ref &wi, FILE *file)
kono
parents:
diff changeset
135 {
kono
parents:
diff changeset
136 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
kono
parents:
diff changeset
137 print_hex (wi, buf);
kono
parents:
diff changeset
138 fputs (buf, file);
kono
parents:
diff changeset
139 }
kono
parents:
diff changeset
140