* omp-low.c (lower_omp_target): Remove unreachable code & merge
[official-gcc.git] / gcc / wide-int-print.cc
blobcdc35367ff675ea823a0a9543cfcd26e104e147c
1 /* Printing operations with very long integers.
2 Copyright (C) 2012-2015 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 "tm.h"
25 #include "wide-int-print.h"
28 * public printing routines.
31 #define BLOCKS_NEEDED(PREC) \
32 (((PREC) + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
34 void
35 print_dec (const wide_int_ref &wi, char *buf, signop sgn)
37 if (sgn == SIGNED)
38 print_decs (wi, buf);
39 else
40 print_decu (wi, buf);
43 void
44 print_dec (const wide_int_ref &wi, FILE *file, signop sgn)
46 if (sgn == SIGNED)
47 print_decs (wi, file);
48 else
49 print_decu (wi, file);
53 /* Try to print the signed self in decimal to BUF if the number fits
54 in a HWI. Other print in hex. */
56 void
57 print_decs (const wide_int_ref &wi, char *buf)
59 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
60 || (wi.get_len () == 1))
62 if (wi::neg_p (wi))
63 sprintf (buf, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
64 -(unsigned HOST_WIDE_INT) wi.to_shwi ());
65 else
66 sprintf (buf, HOST_WIDE_INT_PRINT_DEC, wi.to_shwi ());
68 else
69 print_hex (wi, buf);
72 /* Try to print the signed self in decimal to FILE if the number fits
73 in a HWI. Other print in hex. */
75 void
76 print_decs (const wide_int_ref &wi, FILE *file)
78 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
79 print_decs (wi, buf);
80 fputs (buf, file);
83 /* Try to print the unsigned self in decimal to BUF if the number fits
84 in a HWI. Other print in hex. */
86 void
87 print_decu (const wide_int_ref &wi, char *buf)
89 if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
90 || (wi.get_len () == 1 && !wi::neg_p (wi)))
91 sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, wi.to_uhwi ());
92 else
93 print_hex (wi, buf);
96 /* Try to print the signed self in decimal to FILE if the number fits
97 in a HWI. Other print in hex. */
99 void
100 print_decu (const wide_int_ref &wi, FILE *file)
102 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
103 print_decu (wi, buf);
104 fputs (buf, file);
107 void
108 print_hex (const wide_int_ref &wi, char *buf)
110 int i = wi.get_len ();
112 if (wi == 0)
113 buf += sprintf (buf, "0x0");
114 else
116 if (wi::neg_p (wi))
118 int j;
119 /* If the number is negative, we may need to pad value with
120 0xFFF... because the leading elements may be missing and
121 we do not print a '-' with hex. */
122 buf += sprintf (buf, "0x");
123 for (j = BLOCKS_NEEDED (wi.get_precision ()); j > i; j--)
124 buf += sprintf (buf, HOST_WIDE_INT_PRINT_PADDED_HEX, (HOST_WIDE_INT) -1);
127 else
128 buf += sprintf (buf, "0x" HOST_WIDE_INT_PRINT_HEX_PURE, wi.elt (--i));
130 while (--i >= 0)
131 buf += sprintf (buf, HOST_WIDE_INT_PRINT_PADDED_HEX, wi.elt (i));
135 /* Print one big hex number to FILE. Note that some assemblers may not
136 accept this for large modes. */
137 void
138 print_hex (const wide_int_ref &wi, FILE *file)
140 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
141 print_hex (wi, buf);
142 fputs (buf, file);