summaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authordj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-08 03:08:12 +0000
committerdj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-08 03:08:12 +0000
commit33c8dcfe6b6e9772a380c86e4d175f6e08fb75c8 (patch)
tree16396db3dbbac6550036c70c766d8f824908bc7c /gcc/c-family
parent14b1b0c38937c2cd65ace34bd4780179ddc33b99 (diff)
downloadgcc-33c8dcfe6b6e9772a380c86e4d175f6e08fb75c8.tar.gz
* c-cppbuiltin.c (print_bits_of_hex): New.
(builtin_define_type_minmax): Print values using hex so as not to require a pre-computed list of string values. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210202 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-cppbuiltin.c75
2 files changed, 58 insertions, 23 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 4673a16b10c..b7c65d35ff2 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-05-07 DJ Delorie <dj@redhat.com>
+
+ * c-cppbuiltin.c (print_bits_of_hex): New.
+ (builtin_define_type_minmax): Print values using hex so as not to
+ require a pre-computed list of string values.
+
2014-05-06 Kenneth Zadeck <zadeck@naturalbridge.com>
Mike Stump <mikestump@comcast.net>
Richard Sandiford <rdsandiford@googlemail.com>
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 2f2e7bae824..d07c9809eab 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1288,6 +1288,50 @@ builtin_define_type_max (const char *macro, tree type)
builtin_define_type_minmax (NULL, macro, type);
}
+/* Given a value with COUNT LSBs set, fill BUF with a hexidecimal
+ representation of that value. For example, a COUNT of 10 would
+ return "0x3ff". */
+
+static void
+print_bits_of_hex (char *buf, int bufsz, int count)
+{
+ gcc_assert (bufsz > 3);
+ *buf++ = '0';
+ *buf++ = 'x';
+ bufsz -= 2;
+
+ gcc_assert (count > 0);
+
+ switch (count % 4) {
+ case 0:
+ break;
+ case 1:
+ *buf++ = '1';
+ bufsz --;
+ count -= 1;
+ break;
+ case 2:
+ *buf++ = '3';
+ bufsz --;
+ count -= 2;
+ break;
+ case 3:
+ *buf++ = '7';
+ bufsz --;
+ count -= 3;
+ break;
+ }
+ while (count >= 4)
+ {
+ gcc_assert (bufsz > 1);
+ *buf++ = 'f';
+ bufsz --;
+ count -= 4;
+ }
+ gcc_assert (bufsz > 0);
+ *buf++ = 0;
+}
+
/* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
precision of the type. */
@@ -1295,32 +1339,17 @@ static void
builtin_define_type_minmax (const char *min_macro, const char *max_macro,
tree type)
{
- static const char *const values[]
- = { "127", "255",
- "32767", "65535",
- "2147483647", "4294967295",
- "9223372036854775807", "18446744073709551615",
- "170141183460469231731687303715884105727",
- "340282366920938463463374607431768211455" };
-
- const char *value, *suffix;
+#define PBOH_SZ (MAX_BITSIZE_MODE_ANY_INT/4+4)
+ char value[PBOH_SZ];
+
+ const char *suffix;
char *buf;
- size_t idx;
+ int bits;
- /* Pre-rendering the values mean we don't have to futz with printing a
- multi-word decimal value. There are also a very limited number of
- precisions that we support, so it's really a waste of time. */
- switch (TYPE_PRECISION (type))
- {
- case 8: idx = 0; break;
- case 16: idx = 2; break;
- case 32: idx = 4; break;
- case 64: idx = 6; break;
- case 128: idx = 8; break;
- default: gcc_unreachable ();
- }
+ bits = TYPE_PRECISION (type) + (TYPE_UNSIGNED (type) ? 0 : -1);
+
+ print_bits_of_hex (value, PBOH_SZ, bits);
- value = values[idx + TYPE_UNSIGNED (type)];
suffix = type_suffix (type);
buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)