aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2002-06-11 20:06:30 -0700
committerRichard Henderson <rth@gcc.gnu.org>2002-06-11 20:06:30 -0700
commit676997cfd2c72fe7a5fa815d78e8a7351072c7d4 (patch)
treea51f218e63a3e610ab83885e2934f450d9444946 /gcc/c-common.c
parent116b7a5ea82b371a114209bd6b277e72ece51bc1 (diff)
downloadgcc-676997cfd2c72fe7a5fa815d78e8a7351072c7d4.zip
gcc-676997cfd2c72fe7a5fa815d78e8a7351072c7d4.tar.gz
gcc-676997cfd2c72fe7a5fa815d78e8a7351072c7d4.tar.bz2
c-common.c (builtin_define_type_max): New.
* c-common.c (builtin_define_type_max): New. (cb_register_builtins): Define __SCHAR_MAX__, __SHRT_MAX__, __INT_MAX__, __LONG_MAX__, __LONG_LONG_MAX__, __CHAR_BIT__. From Joseph S. Myers: * glimits.h: Rewrite to expect the double underscore definitions from the compiler. * config/alpha/unicosmk.h, config/avr/avr.h, config/h8300/h8300.h, config/i386/linux64.h, config/ia64/aix.h, config/ia64/hpux.h, config/ia64/ia64.h, config/m68hc11/m68hc11.h, config/m68hc11/m68hc12.h, config/mips/mips.h, config/mmix/mmix.h, config/mn10200/mn10200.h, config/pa/pa.h, config/rs6000/aix43.h, config/rs6000/aix51.h, config/rs6000/linux64.h, config/s390/linux.h, config/sh/sh.h, config/stormy16/stormy16.h: Don't define any of __SHRT_MAX__, __INT_MAX__, __LONG_MAX__, or __LONG_LONG_MAX__. From-SVN: r54544
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index eaa812d..4b9b7cf 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -365,6 +365,7 @@ static bool get_nonnull_operand PARAMS ((tree,
void builtin_define_std PARAMS ((const char *));
static void builtin_define_with_value PARAMS ((const char *, const char *,
int));
+static void builtin_define_type_max PARAMS ((const char *, tree, int));
/* Table of machine-independent attributes common to all C-like languages. */
const struct attribute_spec c_common_attribute_table[] =
@@ -4346,6 +4347,19 @@ cb_register_builtins (pfile)
builtin_define_with_value ("__WCHAR_TYPE__", MODIFIED_WCHAR_TYPE, 0);
builtin_define_with_value ("__WINT_TYPE__", WINT_TYPE, 0);
+ /* limits.h needs to know these. */
+ builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0);
+ builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0);
+ builtin_define_type_max ("__INT_MAX__", integer_type_node, 0);
+ builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1);
+ builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2);
+
+ {
+ char buf[8];
+ sprintf (buf, "%d", (int) TYPE_PRECISION (signed_char_type_node));
+ builtin_define_with_value ("__CHAR_BIT__", buf, 0);
+ }
+
/* For use in assembly language. */
builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
@@ -4457,6 +4471,54 @@ builtin_define_with_value (macro, expansion, is_str)
cpp_define (parse_in, buf);
}
+/* Define MAX for TYPE based on the precision of the type, which is assumed
+ to be signed. IS_LONG is 1 for type "long" and 2 for "long long". */
+
+static void
+builtin_define_type_max (macro, type, is_long)
+ const char *macro;
+ tree type;
+ int is_long;
+{
+ const char *value;
+ char *buf;
+ size_t mlen, vlen, extra;
+
+ /* 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:
+ value = "127";
+ break;
+ case 16:
+ value = "32767";
+ break;
+ case 32:
+ value = "2147483647";
+ break;
+ case 64:
+ value = "9223372036854775807";
+ break;
+ case 128:
+ value = "170141183460469231731687303715884105727";
+ break;
+ default:
+ abort ();
+ }
+
+ mlen = strlen (macro);
+ vlen = strlen (value);
+ extra = 2 + is_long;
+ buf = alloca (mlen + vlen + extra);
+
+ sprintf (buf, "%s=%s%s", macro, value,
+ (is_long == 1 ? "L" : is_long == 2 ? "LL" : ""));
+
+ cpp_define (parse_in, buf);
+}
+
/* Front end initialization common to C, ObjC and C++. */
const char *
c_common_init (filename)