aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2010-06-11 20:37:34 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2010-06-11 20:37:34 +0200
commit8e680db5b64c74ef131f7eb6a50902cf2134f845 (patch)
tree202ae75e58b19cf2da840d299ec67598a6eef33b /gcc
parent7b14477e384de8841d377e3c3254f9f3bcc9aecb (diff)
downloadgcc-8e680db5b64c74ef131f7eb6a50902cf2134f845.zip
gcc-8e680db5b64c74ef131f7eb6a50902cf2134f845.tar.gz
gcc-8e680db5b64c74ef131f7eb6a50902cf2134f845.tar.bz2
cpplib.h (struct cpp_callbacks): Add user_builtin_macro callback.
* include/cpplib.h (struct cpp_callbacks): Add user_builtin_macro callback. (enum cpp_builtin_type): Add BT_FIRST_USER and BT_LAST_USER. (cpp_macro_definition): Remove const qual from second argument. * macro.c (enter_macro_context): Call user_builtin_macro callback for NODE_BUILTIN !NODE_USED macros. (warn_of_redefinition): Likewise. Remove const qual from second argument. (cpp_macro_definition): Likewise. * pch.c (write_macdef, save_macros): Call user_builtin_macro callback for NODE_BUILTIN !NODE_USED macros. * c-family/c-cppbuiltin.c: Include cpp-id-data.h. (lazy_hex_fp_values, lazy_hex_fp_value_count): New variables. (lazy_hex_fp_value): New function. (builtin_define_with_hex_fp_value): Provide definitions lazily. * Makefile.in (c-family/c-cppbuiltin.o): Depend on $(CPP_ID_DATA_H). From-SVN: r160626
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/c-family/c-cppbuiltin.c70
3 files changed, 78 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5d32047..c52a81b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-10 Jakub Jelinek <jakub@redhat.com>
+
+ * c-family/c-cppbuiltin.c: Include cpp-id-data.h.
+ (lazy_hex_fp_values, lazy_hex_fp_value_count): New variables.
+ (lazy_hex_fp_value): New function.
+ (builtin_define_with_hex_fp_value): Provide definitions lazily.
+ * Makefile.in (c-family/c-cppbuiltin.o): Depend on $(CPP_ID_DATA_H).
+
2010-06-11 Sebastian Pop <sebastian.pop@amd.com>
PR middle-end/44483
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c47ee95..0d4f746 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2081,7 +2081,7 @@ c-family/c-common.o : c-family/c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
c-family/c-cppbuiltin.o : c-family/c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TM_H) $(TREE_H) version.h $(C_COMMON_H) $(C_PRAGMA_H) \
$(FLAGS_H) $(TOPLEV_H) output.h $(EXCEPT_H) $(TREE_H) $(TARGET_H) \
- $(TM_P_H) $(BASEVER) debug.h
+ $(TM_P_H) $(BASEVER) debug.h $(CPP_ID_DATA_H)
$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \
-DBASEVER=$(BASEVER_s) $< $(OUTPUT_OPTION)
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 6bbdb46..4ed6975 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1,5 +1,5 @@
/* Define builtin-in macros for the C family front ends.
- Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GCC.
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h"
#include "tm_p.h" /* For TARGET_CPU_CPP_BUILTINS & friends. */
#include "target.h"
+#include "cpp-id-data.h"
#ifndef TARGET_OS_CPP_BUILTINS
# define TARGET_OS_CPP_BUILTINS()
@@ -946,6 +947,50 @@ builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
cpp_define (parse_in, buf);
}
+/* builtin_define_with_hex_fp_value is very expensive, so the following
+ array and function allows it to be done lazily when __DBL_MAX__
+ etc. is first used. */
+
+static struct
+{
+ const char *hex_str;
+ cpp_macro *macro;
+ enum machine_mode mode;
+ int digits;
+ const char *fp_suffix;
+} lazy_hex_fp_values[12];
+static int lazy_hex_fp_value_count;
+
+static bool
+lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
+ cpp_hashnode *node)
+{
+ REAL_VALUE_TYPE real;
+ char dec_str[64], buf1[256];
+ unsigned int idx;
+ if (node->value.builtin < BT_FIRST_USER
+ || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
+ return false;
+
+ idx = node->value.builtin - BT_FIRST_USER;
+ real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
+ real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
+ lazy_hex_fp_values[idx].digits, 0,
+ lazy_hex_fp_values[idx].mode);
+
+ sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
+ node->flags &= ~(NODE_BUILTIN | NODE_USED);
+ node->value.macro = lazy_hex_fp_values[idx].macro;
+ for (idx = 0; idx < node->value.macro->count; idx++)
+ if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
+ break;
+ gcc_assert (idx < node->value.macro->count);
+ node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
+ node->value.macro->exp.tokens[idx].val.str.text
+ = (const unsigned char *) xstrdup (buf1);
+ return true;
+}
+
/* Pass an object-like macro a hexadecimal floating-point value. */
static void
builtin_define_with_hex_fp_value (const char *macro,
@@ -957,6 +1002,29 @@ builtin_define_with_hex_fp_value (const char *macro,
REAL_VALUE_TYPE real;
char dec_str[64], buf1[256], buf2[256];
+ /* This is very expensive, so if possible expand them lazily. */
+ if (lazy_hex_fp_value_count < 12
+ && flag_dump_macros == 0
+ && !cpp_get_options (parse_in)->traditional)
+ {
+ struct cpp_hashnode *node;
+ if (lazy_hex_fp_value_count == 0)
+ cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
+ sprintf (buf2, fp_cast, "1.1");
+ sprintf (buf1, "%s=%s", macro, buf2);
+ cpp_define (parse_in, buf1);
+ node = C_CPP_HASHNODE (get_identifier (macro));
+ lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str = xstrdup (hex_str);
+ lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
+ lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
+ lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
+ lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
+ node->flags |= NODE_BUILTIN;
+ node->value.builtin = BT_FIRST_USER + lazy_hex_fp_value_count;
+ lazy_hex_fp_value_count++;
+ return;
+ }
+
/* Hex values are really cool and convenient, except that they're
not supported in strict ISO C90 mode. First, the "p-" sequence
is not valid as part of a preprocessor number. Second, we get a