1 /* Define builtin-in macros for the C family front ends.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "coretypes.h"
33 #include "except.h" /* For USING_SJLJ_EXCEPTIONS. */
35 #include "tm_p.h" /* Target prototypes. */
38 #ifndef TARGET_OS_CPP_BUILTINS
39 # define TARGET_OS_CPP_BUILTINS()
42 #ifndef TARGET_OBJFMT_CPP_BUILTINS
43 # define TARGET_OBJFMT_CPP_BUILTINS()
46 #ifndef REGISTER_PREFIX
47 #define REGISTER_PREFIX ""
50 /* Non-static as some targets don't use it. */
51 void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
52 static void builtin_define_with_value_n (const char *, const char *,
54 static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
55 static void builtin_define_with_hex_fp_value (const char *, tree,
59 static void builtin_define_stdint_macros (void);
60 static void builtin_define_type_max (const char *, tree, int);
61 static void builtin_define_type_precision (const char *, tree);
62 static void builtin_define_type_sizeof (const char *, tree);
63 static void builtin_define_float_constants (const char *,
67 static void define__GNUC__ (void);
69 /* Define NAME with value TYPE precision. */
71 builtin_define_type_precision (const char *name, tree type)
73 builtin_define_with_int_value (name, TYPE_PRECISION (type));
76 /* Define NAME with value TYPE size_unit. */
78 builtin_define_type_sizeof (const char *name, tree type)
80 builtin_define_with_int_value (name,
81 tree_low_cst (TYPE_SIZE_UNIT (type), 1));
84 /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
87 builtin_define_float_constants (const char *name_prefix,
88 const char *fp_suffix,
92 /* Used to convert radix-based values to base 10 values in several cases.
94 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
95 least 6 significant digits for correct results. Using the fraction
96 formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
97 intermediate; perhaps someone can find a better approximation, in the
98 mean time, I suspect using doubles won't harm the bootstrap here. */
100 const double log10_2 = .30102999566398119521;
102 const struct real_format *fmt;
104 char name[64], buf[128];
105 int dig, min_10_exp, max_10_exp;
108 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
109 gcc_assert (fmt->b != 10);
111 /* The radix of the exponent representation. */
112 if (type == float_type_node)
113 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
116 /* The number of radix digits, p, in the floating-point significand. */
117 sprintf (name, "__%s_MANT_DIG__", name_prefix);
118 builtin_define_with_int_value (name, fmt->p);
120 /* The number of decimal digits, q, such that any floating-point number
121 with q decimal digits can be rounded into a floating-point number with
122 p radix b digits and back again without change to the q decimal digits,
124 p log10 b if b is a power of 10
125 floor((p - 1) log10 b) otherwise
127 dig = (fmt->p - 1) * log10_b;
128 sprintf (name, "__%s_DIG__", name_prefix);
129 builtin_define_with_int_value (name, dig);
131 /* The minimum negative int x such that b**(x-1) is a normalized float. */
132 sprintf (name, "__%s_MIN_EXP__", name_prefix);
133 sprintf (buf, "(%d)", fmt->emin);
134 builtin_define_with_value (name, buf, 0);
136 /* The minimum negative int x such that 10**x is a normalized float,
138 ceil (log10 (b ** (emin - 1)))
139 = ceil (log10 (b) * (emin - 1))
141 Recall that emin is negative, so the integer truncation calculates
142 the ceiling, not the floor, in this case. */
143 min_10_exp = (fmt->emin - 1) * log10_b;
144 sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
145 sprintf (buf, "(%d)", min_10_exp);
146 builtin_define_with_value (name, buf, 0);
148 /* The maximum int x such that b**(x-1) is a representable float. */
149 sprintf (name, "__%s_MAX_EXP__", name_prefix);
150 builtin_define_with_int_value (name, fmt->emax);
152 /* The maximum int x such that 10**x is in the range of representable
153 finite floating-point numbers,
155 floor (log10((1 - b**-p) * b**emax))
156 = floor (log10(1 - b**-p) + log10(b**emax))
157 = floor (log10(1 - b**-p) + log10(b)*emax)
159 The safest thing to do here is to just compute this number. But since
160 we don't link cc1 with libm, we cannot. We could implement log10 here
161 a series expansion, but that seems too much effort because:
163 Note that the first term, for all extant p, is a number exceedingly close
164 to zero, but slightly negative. Note that the second term is an integer
165 scaling an irrational number, and that because of the floor we are only
166 interested in its integral portion.
168 In order for the first term to have any effect on the integral portion
169 of the second term, the second term has to be exceedingly close to an
170 integer itself (e.g. 123.000000000001 or something). Getting a result
171 that close to an integer requires that the irrational multiplicand have
172 a long series of zeros in its expansion, which doesn't occur in the
173 first 20 digits or so of log10(b).
175 Hand-waving aside, crunching all of the sets of constants above by hand
176 does not yield a case for which the first term is significant, which
177 in the end is all that matters. */
178 max_10_exp = fmt->emax * log10_b;
179 sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
180 builtin_define_with_int_value (name, max_10_exp);
182 /* The number of decimal digits, n, such that any floating-point number
183 can be rounded to n decimal digits and back again without change to
186 p * log10(b) if b is a power of 10
187 ceil(1 + p * log10(b)) otherwise
189 The only macro we care about is this number for the widest supported
190 floating type, but we want this value for rendering constants below. */
192 double d_decimal_dig = 1 + fmt->p * log10_b;
193 decimal_dig = d_decimal_dig;
194 if (decimal_dig < d_decimal_dig)
197 if (type == long_double_type_node)
198 builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
200 /* Since, for the supported formats, B is always a power of 2, we
201 construct the following numbers directly as a hexadecimal
203 get_max_float (fmt, buf, sizeof (buf));
205 sprintf (name, "__%s_MAX__", name_prefix);
206 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
208 /* The minimum normalized positive floating-point number,
210 sprintf (name, "__%s_MIN__", name_prefix);
211 sprintf (buf, "0x1p%d", fmt->emin - 1);
212 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
214 /* The difference between 1 and the least value greater than 1 that is
215 representable in the given floating point type, b**(1-p). */
216 sprintf (name, "__%s_EPSILON__", name_prefix);
217 if (fmt->pnan < fmt->p)
218 /* This is an IBM extended double format, so 1.0 + any double is
219 representable precisely. */
220 sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
222 sprintf (buf, "0x1p%d", 1 - fmt->p);
223 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
225 /* For C++ std::numeric_limits<T>::denorm_min. The minimum denormalized
226 positive floating-point number, b**(emin-p). Zero for formats that
227 don't support denormals. */
228 sprintf (name, "__%s_DENORM_MIN__", name_prefix);
231 sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
232 builtin_define_with_hex_fp_value (name, type, decimal_dig,
233 buf, fp_suffix, fp_cast);
237 sprintf (buf, "0.0%s", fp_suffix);
238 builtin_define_with_value (name, buf, 0);
241 sprintf (name, "__%s_HAS_DENORM__", name_prefix);
242 builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
244 /* For C++ std::numeric_limits<T>::has_infinity. */
245 sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
246 builtin_define_with_int_value (name,
247 MODE_HAS_INFINITIES (TYPE_MODE (type)));
248 /* For C++ std::numeric_limits<T>::has_quiet_NaN. We do not have a
249 predicate to distinguish a target that has both quiet and
250 signalling NaNs from a target that has only quiet NaNs or only
251 signalling NaNs, so we assume that a target that has any kind of
252 NaN has quiet NaNs. */
253 sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
254 builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
257 /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
259 builtin_define_decimal_float_constants (const char *name_prefix,
263 const struct real_format *fmt;
264 char name[64], buf[128], *p;
267 fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
269 /* The number of radix digits, p, in the significand. */
270 sprintf (name, "__%s_MANT_DIG__", name_prefix);
271 builtin_define_with_int_value (name, fmt->p);
273 /* The minimum negative int x such that b**(x-1) is a normalized float. */
274 sprintf (name, "__%s_MIN_EXP__", name_prefix);
275 sprintf (buf, "(%d)", fmt->emin);
276 builtin_define_with_value (name, buf, 0);
278 /* The maximum int x such that b**(x-1) is a representable float. */
279 sprintf (name, "__%s_MAX_EXP__", name_prefix);
280 builtin_define_with_int_value (name, fmt->emax);
282 /* Compute the minimum representable value. */
283 sprintf (name, "__%s_MIN__", name_prefix);
284 sprintf (buf, "1E%d%s", fmt->emin, suffix);
285 builtin_define_with_value (name, buf, 0);
287 /* Compute the maximum representable value. */
288 sprintf (name, "__%s_MAX__", name_prefix);
290 for (digits = fmt->p; digits; digits--)
293 if (digits == fmt->p)
297 /* fmt->p plus 1, to account for the decimal point. */
298 sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax, suffix);
299 builtin_define_with_value (name, buf, 0);
301 /* Compute epsilon (the difference between 1 and least value greater
302 than 1 representable). */
303 sprintf (name, "__%s_EPSILON__", name_prefix);
304 sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
305 builtin_define_with_value (name, buf, 0);
307 /* Minimum denormalized postive decimal value. */
308 sprintf (name, "__%s_DEN__", name_prefix);
310 for (digits = fmt->p; digits > 1; digits--)
313 if (digits == fmt->p)
317 sprintf (&buf[fmt->p], "1E%d%s", fmt->emin, suffix);
318 builtin_define_with_value (name, buf, 0);
321 /* Define __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__. */
323 define__GNUC__ (void)
325 /* The format of the version string, enforced below, is
326 ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)? */
327 const char *q, *v = version_string;
329 while (*v && !ISDIGIT (*v))
331 gcc_assert (*v && (v <= version_string || v[-1] == '-'));
336 builtin_define_with_value_n ("__GNUC__", q, v - q);
337 if (c_dialect_cxx ())
338 builtin_define_with_value_n ("__GNUG__", q, v - q);
340 gcc_assert (*v == '.' && ISDIGIT (v[1]));
345 builtin_define_with_value_n ("__GNUC_MINOR__", q, v - q);
349 gcc_assert (ISDIGIT (v[1]));
353 builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", q, v - q);
356 builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1);
358 gcc_assert (!*v || *v == ' ' || *v == '-');
361 /* Define macros used by <stdint.h>. Currently only defines limits
362 for intmax_t, used by the testsuite. */
364 builtin_define_stdint_macros (void)
367 if (intmax_type_node == long_long_integer_type_node)
369 else if (intmax_type_node == long_integer_type_node)
371 else if (intmax_type_node == integer_type_node)
375 builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long);
378 /* Hook that registers front end and target-specific built-ins. */
380 c_cpp_builtins (cpp_reader *pfile)
382 /* -undef turns off target-specific built-ins. */
388 /* For stddef.h. They require macros defined in c-common.c. */
389 c_stddef_cpp_builtins ();
391 if (c_dialect_cxx ())
393 if (flag_weak && SUPPORTS_ONE_ONLY)
394 cpp_define (pfile, "__GXX_WEAK__=1");
396 cpp_define (pfile, "__GXX_WEAK__=0");
398 cpp_define (pfile, "__DEPRECATED");
399 if (cxx_dialect == cxx0x)
400 cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
402 /* Note that we define this for C as well, so that we know if
403 __attribute__((cleanup)) will interface with EH. */
405 cpp_define (pfile, "__EXCEPTIONS");
407 /* Represents the C++ ABI version, always defined so it can be used while
408 preprocessing C and assembler. */
409 if (flag_abi_version == 0)
410 /* Use a very large value so that:
412 #if __GXX_ABI_VERSION >= <value for version X>
414 will work whether the user explicitly says "-fabi-version=x" or
415 "-fabi-version=0". Do not use INT_MAX because that will be
416 different from system to system. */
417 builtin_define_with_int_value ("__GXX_ABI_VERSION", 999999);
418 else if (flag_abi_version == 1)
419 /* Due to a historical accident, this version had the value
421 builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
423 /* Newer versions have values 1002, 1003, .... */
424 builtin_define_with_int_value ("__GXX_ABI_VERSION",
425 1000 + flag_abi_version);
427 /* libgcc needs to know this. */
428 if (USING_SJLJ_EXCEPTIONS)
429 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
431 /* limits.h needs to know these. */
432 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0);
433 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0);
434 builtin_define_type_max ("__INT_MAX__", integer_type_node, 0);
435 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1);
436 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2);
437 builtin_define_type_max ("__WCHAR_MAX__", wchar_type_node, 0);
439 builtin_define_type_precision ("__CHAR_BIT__", char_type_node);
441 /* stdint.h (eventually) and the testsuite need to know these. */
442 builtin_define_stdint_macros ();
444 /* float.h needs to know these. */
446 builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
447 TARGET_FLT_EVAL_METHOD);
449 /* And decfloat.h needs this. */
450 builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
451 TARGET_DEC_EVAL_METHOD);
453 builtin_define_float_constants ("FLT", "F", "%s", float_type_node);
454 /* Cast the double precision constants when single precision constants are
455 specified. The correct result is computed by the compiler when using
456 macros that include a cast. This has the side-effect of making the value
457 unusable in const expressions. */
458 if (flag_single_precision_constant)
459 builtin_define_float_constants ("DBL", "L", "((double)%s)", double_type_node);
461 builtin_define_float_constants ("DBL", "", "%s", double_type_node);
462 builtin_define_float_constants ("LDBL", "L", "%s", long_double_type_node);
464 /* For decfloat.h. */
465 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
466 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
467 builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
469 /* For use in assembly language. */
470 builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
471 builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
474 builtin_define_with_value ("__VERSION__", version_string, 1);
476 if (flag_gnu89_inline)
477 cpp_define (pfile, "__GNUC_GNU_INLINE__");
479 cpp_define (pfile, "__GNUC_STDC_INLINE__");
481 /* Definitions for LP64 model. */
482 if (TYPE_PRECISION (long_integer_type_node) == 64
483 && POINTER_SIZE == 64
484 && TYPE_PRECISION (integer_type_node) == 32)
486 cpp_define (pfile, "_LP64");
487 cpp_define (pfile, "__LP64__");
490 /* Other target-independent built-ins determined by command-line
493 cpp_define (pfile, "__OPTIMIZE_SIZE__");
495 cpp_define (pfile, "__OPTIMIZE__");
497 if (fast_math_flags_set_p ())
498 cpp_define (pfile, "__FAST_MATH__");
499 if (flag_really_no_inline)
500 cpp_define (pfile, "__NO_INLINE__");
501 if (flag_signaling_nans)
502 cpp_define (pfile, "__SUPPORT_SNAN__");
503 if (flag_finite_math_only)
504 cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
506 cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
509 builtin_define_with_int_value ("__pic__", flag_pic);
510 builtin_define_with_int_value ("__PIC__", flag_pic);
514 builtin_define_with_int_value ("__pie__", flag_pie);
515 builtin_define_with_int_value ("__PIE__", flag_pie);
519 cpp_define (pfile, "__STRICT_ANSI__");
521 if (!flag_signed_char)
522 cpp_define (pfile, "__CHAR_UNSIGNED__");
524 if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
525 cpp_define (pfile, "__WCHAR_UNSIGNED__");
527 /* Tell source code if the compiler makes sync_compare_and_swap
528 builtins available. */
529 #ifdef HAVE_sync_compare_and_swapqi
530 if (HAVE_sync_compare_and_swapqi)
531 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
534 #ifdef HAVE_sync_compare_and_swaphi
535 if (HAVE_sync_compare_and_swaphi)
536 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
539 #ifdef HAVE_sync_compare_and_swapsi
540 if (HAVE_sync_compare_and_swapsi)
541 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
544 #ifdef HAVE_sync_compare_and_swapdi
545 if (HAVE_sync_compare_and_swapdi)
546 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
549 #ifdef HAVE_sync_compare_and_swapti
550 if (HAVE_sync_compare_and_swapti)
551 cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
554 /* Make the choice of ObjC runtime visible to source code. */
555 if (c_dialect_objc () && flag_next_runtime)
556 cpp_define (pfile, "__NEXT_RUNTIME__");
558 /* Show the availability of some target pragmas. */
559 if (flag_mudflap || targetm.handle_pragma_redefine_extname)
560 cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
562 if (targetm.handle_pragma_extern_prefix)
563 cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX");
565 /* Make the choice of the stack protector runtime visible to source code.
566 The macro names and values here were chosen for compatibility with an
567 earlier implementation, i.e. ProPolice. */
568 if (flag_stack_protect == 2)
569 cpp_define (pfile, "__SSP_ALL__=2");
570 else if (flag_stack_protect == 1)
571 cpp_define (pfile, "__SSP__=1");
574 cpp_define (pfile, "_OPENMP=200505");
577 cpp_define (pfile, "__GFORTRAN__=1");
579 builtin_define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
580 builtin_define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
581 builtin_define_type_sizeof ("__SIZEOF_LONG_LONG__",
582 long_long_integer_type_node);
583 builtin_define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
584 builtin_define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
585 builtin_define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
586 builtin_define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
587 builtin_define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);
588 builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
589 builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
590 builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
591 unsigned_ptrdiff_type_node);
592 /* ptr_type_node can't be used here since ptr_mode is only set when
593 toplev calls backend_init which is not done with -E switch. */
594 builtin_define_with_int_value ("__SIZEOF_POINTER__",
595 POINTER_SIZE / BITS_PER_UNIT);
597 /* A straightforward target hook doesn't work, because of problems
598 linking that hook's body when part of non-C front ends. */
599 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
600 # define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
601 # define builtin_define(TXT) cpp_define (pfile, TXT)
602 # define builtin_assert(TXT) cpp_assert (pfile, TXT)
603 TARGET_CPU_CPP_BUILTINS ();
604 TARGET_OS_CPP_BUILTINS ();
605 TARGET_OBJFMT_CPP_BUILTINS ();
607 /* Support the __declspec keyword by turning them into attributes.
608 Note that the current way we do this may result in a collision
609 with predefined attributes later on. This can be solved by using
610 one attribute, say __declspec__, and passing args to it. The
611 problem with that approach is that args are not accumulated: each
612 new appearance would clobber any existing args. */
614 builtin_define ("__declspec(x)=__attribute__((x))");
616 /* If decimal floating point is supported, tell the user if the
617 alternate format (BID) is used instead of the standard (DPD)
619 if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
620 cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
623 /* Pass an object-like macro. If it doesn't lie in the user's
624 namespace, defines it unconditionally. Otherwise define a version
625 with two leading underscores, and another version with two leading
626 and trailing underscores, and define the original only if an ISO
627 standard was not nominated.
629 e.g. passing "unix" defines "__unix", "__unix__" and possibly
630 "unix". Passing "_mips" defines "__mips", "__mips__" and possibly
633 builtin_define_std (const char *macro)
635 size_t len = strlen (macro);
636 char *buff = (char *) alloca (len + 5);
640 /* prepend __ (or maybe just _) if in user's namespace. */
641 memcpy (p, macro, len + 1);
642 if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
649 cpp_define (parse_in, p);
651 /* If it was in user's namespace... */
654 /* Define the macro with leading and following __. */
660 cpp_define (parse_in, p);
662 /* Finally, define the original macro if permitted. */
664 cpp_define (parse_in, macro);
668 /* Pass an object-like macro and a value to define it to. The third
669 parameter says whether or not to turn the value into a string
672 builtin_define_with_value (const char *macro, const char *expansion, int is_str)
675 size_t mlen = strlen (macro);
676 size_t elen = strlen (expansion);
677 size_t extra = 2; /* space for an = and a NUL */
680 extra += 2; /* space for two quote marks */
682 buf = (char *) alloca (mlen + elen + extra);
684 sprintf (buf, "%s=\"%s\"", macro, expansion);
686 sprintf (buf, "%s=%s", macro, expansion);
688 cpp_define (parse_in, buf);
691 /* Pass an object-like macro and a value to define it to. The third
692 parameter is the length of the expansion. */
694 builtin_define_with_value_n (const char *macro, const char *expansion, size_t elen)
697 size_t mlen = strlen (macro);
699 /* Space for an = and a NUL. */
700 buf = (char *) alloca (mlen + elen + 2);
701 memcpy (buf, macro, mlen);
703 memcpy (buf + mlen + 1, expansion, elen);
704 buf[mlen + elen + 1] = '\0';
706 cpp_define (parse_in, buf);
709 /* Pass an object-like macro and an integer value to define it to. */
711 builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
714 size_t mlen = strlen (macro);
716 size_t extra = 2; /* space for = and NUL. */
718 buf = (char *) alloca (mlen + vlen + extra);
719 memcpy (buf, macro, mlen);
721 sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
723 cpp_define (parse_in, buf);
726 /* Pass an object-like macro a hexadecimal floating-point value. */
728 builtin_define_with_hex_fp_value (const char *macro,
729 tree type ATTRIBUTE_UNUSED, int digits,
731 const char *fp_suffix,
734 REAL_VALUE_TYPE real;
735 char dec_str[64], buf1[256], buf2[256];
737 /* Hex values are really cool and convenient, except that they're
738 not supported in strict ISO C90 mode. First, the "p-" sequence
739 is not valid as part of a preprocessor number. Second, we get a
740 pedwarn from the preprocessor, which has no context, so we can't
741 suppress the warning with __extension__.
743 So instead what we do is construct the number in hex (because
744 it's easy to get the exact correct value), parse it as a real,
745 then print it back out as decimal. */
747 real_from_string (&real, hex_str);
748 real_to_decimal (dec_str, &real, sizeof (dec_str), digits, 0);
750 /* Assemble the macro in the following fashion
751 macro = fp_cast [dec_str fp_suffix] */
752 sprintf (buf1, "%s%s", dec_str, fp_suffix);
753 sprintf (buf2, fp_cast, buf1);
754 sprintf (buf1, "%s=%s", macro, buf2);
756 cpp_define (parse_in, buf1);
759 /* Define MAX for TYPE based on the precision of the type. IS_LONG is
760 1 for type "long" and 2 for "long long". We have to handle
761 unsigned types, since wchar_t might be unsigned. */
764 builtin_define_type_max (const char *macro, tree type, int is_long)
766 static const char *const values[]
769 "2147483647", "4294967295",
770 "9223372036854775807", "18446744073709551615",
771 "170141183460469231731687303715884105727",
772 "340282366920938463463374607431768211455" };
773 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
775 const char *value, *suffix;
779 /* Pre-rendering the values mean we don't have to futz with printing a
780 multi-word decimal value. There are also a very limited number of
781 precisions that we support, so it's really a waste of time. */
782 switch (TYPE_PRECISION (type))
784 case 8: idx = 0; break;
785 case 16: idx = 2; break;
786 case 32: idx = 4; break;
787 case 64: idx = 6; break;
788 case 128: idx = 8; break;
789 default: gcc_unreachable ();
792 value = values[idx + TYPE_UNSIGNED (type)];
793 suffix = suffixes[is_long * 2 + TYPE_UNSIGNED (type)];
795 buf = (char *) alloca (strlen (macro) + 1 + strlen (value)
796 + strlen (suffix) + 1);
797 sprintf (buf, "%s=%s%s", macro, value, suffix);
799 cpp_define (parse_in, buf);