Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-cppbuiltin.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
53 static void builtin_define_with_hex_fp_value (const char *, tree, | 53 static void builtin_define_with_hex_fp_value (const char *, tree, |
54 int, const char *, | 54 int, const char *, |
55 const char *, | 55 const char *, |
56 const char *); | 56 const char *); |
57 static void builtin_define_stdint_macros (void); | 57 static void builtin_define_stdint_macros (void); |
58 static void builtin_define_type_max (const char *, tree, int); | 58 static void builtin_define_constants (const char *, tree); |
59 static void builtin_define_type_max (const char *, tree); | |
60 static void builtin_define_type_minmax (const char *, const char *, tree); | |
59 static void builtin_define_type_precision (const char *, tree); | 61 static void builtin_define_type_precision (const char *, tree); |
60 static void builtin_define_type_sizeof (const char *, tree); | 62 static void builtin_define_type_sizeof (const char *, tree); |
61 static void builtin_define_float_constants (const char *, | 63 static void builtin_define_float_constants (const char *, |
62 const char *, | 64 const char *, |
63 const char *, | 65 const char *, |
64 tree); | 66 tree); |
65 static void define__GNUC__ (void); | 67 static void define__GNUC__ (void); |
66 | 68 |
80 } | 82 } |
81 | 83 |
82 /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX, | 84 /* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX, |
83 and FP_CAST. */ | 85 and FP_CAST. */ |
84 static void | 86 static void |
85 builtin_define_float_constants (const char *name_prefix, | 87 builtin_define_float_constants (const char *name_prefix, |
86 const char *fp_suffix, | 88 const char *fp_suffix, |
87 const char *fp_cast, | 89 const char *fp_cast, |
88 tree type) | 90 tree type) |
89 { | 91 { |
90 /* Used to convert radix-based values to base 10 values in several cases. | 92 /* Used to convert radix-based values to base 10 values in several cases. |
91 | 93 |
92 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at | 94 In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at |
96 mean time, I suspect using doubles won't harm the bootstrap here. */ | 98 mean time, I suspect using doubles won't harm the bootstrap here. */ |
97 | 99 |
98 const double log10_2 = .30102999566398119521; | 100 const double log10_2 = .30102999566398119521; |
99 double log10_b; | 101 double log10_b; |
100 const struct real_format *fmt; | 102 const struct real_format *fmt; |
103 const struct real_format *ldfmt; | |
101 | 104 |
102 char name[64], buf[128]; | 105 char name[64], buf[128]; |
103 int dig, min_10_exp, max_10_exp; | 106 int dig, min_10_exp, max_10_exp; |
104 int decimal_dig; | 107 int decimal_dig; |
105 | 108 |
106 fmt = REAL_MODE_FORMAT (TYPE_MODE (type)); | 109 fmt = REAL_MODE_FORMAT (TYPE_MODE (type)); |
107 gcc_assert (fmt->b != 10); | 110 gcc_assert (fmt->b != 10); |
111 ldfmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node)); | |
112 gcc_assert (ldfmt->b != 10); | |
108 | 113 |
109 /* The radix of the exponent representation. */ | 114 /* The radix of the exponent representation. */ |
110 if (type == float_type_node) | 115 if (type == float_type_node) |
111 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b); | 116 builtin_define_with_int_value ("__FLT_RADIX__", fmt->b); |
112 log10_b = log10_2; | 117 log10_b = log10_2; |
185 ceil(1 + p * log10(b)) otherwise | 190 ceil(1 + p * log10(b)) otherwise |
186 | 191 |
187 The only macro we care about is this number for the widest supported | 192 The only macro we care about is this number for the widest supported |
188 floating type, but we want this value for rendering constants below. */ | 193 floating type, but we want this value for rendering constants below. */ |
189 { | 194 { |
190 double d_decimal_dig = 1 + fmt->p * log10_b; | 195 double d_decimal_dig |
196 = 1 + (fmt->p < ldfmt->p ? ldfmt->p : fmt->p) * log10_b; | |
191 decimal_dig = d_decimal_dig; | 197 decimal_dig = d_decimal_dig; |
192 if (decimal_dig < d_decimal_dig) | 198 if (decimal_dig < d_decimal_dig) |
193 decimal_dig++; | 199 decimal_dig++; |
194 } | 200 } |
195 if (type == long_double_type_node) | 201 if (type == long_double_type_node) |
197 | 203 |
198 /* Since, for the supported formats, B is always a power of 2, we | 204 /* Since, for the supported formats, B is always a power of 2, we |
199 construct the following numbers directly as a hexadecimal | 205 construct the following numbers directly as a hexadecimal |
200 constants. */ | 206 constants. */ |
201 get_max_float (fmt, buf, sizeof (buf)); | 207 get_max_float (fmt, buf, sizeof (buf)); |
202 | 208 |
203 sprintf (name, "__%s_MAX__", name_prefix); | 209 sprintf (name, "__%s_MAX__", name_prefix); |
204 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); | 210 builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast); |
205 | 211 |
206 /* The minimum normalized positive floating-point number, | 212 /* The minimum normalized positive floating-point number, |
207 b**(emin-1). */ | 213 b**(emin-1). */ |
252 builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type))); | 258 builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type))); |
253 } | 259 } |
254 | 260 |
255 /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */ | 261 /* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */ |
256 static void | 262 static void |
257 builtin_define_decimal_float_constants (const char *name_prefix, | 263 builtin_define_decimal_float_constants (const char *name_prefix, |
258 const char *suffix, | 264 const char *suffix, |
259 tree type) | 265 tree type) |
260 { | 266 { |
261 const struct real_format *fmt; | 267 const struct real_format *fmt; |
262 char name[64], buf[128], *p; | 268 char name[64], buf[128], *p; |
263 int digits; | 269 int digits; |
278 builtin_define_with_int_value (name, fmt->emax); | 284 builtin_define_with_int_value (name, fmt->emax); |
279 | 285 |
280 /* Compute the minimum representable value. */ | 286 /* Compute the minimum representable value. */ |
281 sprintf (name, "__%s_MIN__", name_prefix); | 287 sprintf (name, "__%s_MIN__", name_prefix); |
282 sprintf (buf, "1E%d%s", fmt->emin - 1, suffix); | 288 sprintf (buf, "1E%d%s", fmt->emin - 1, suffix); |
283 builtin_define_with_value (name, buf, 0); | 289 builtin_define_with_value (name, buf, 0); |
284 | 290 |
285 /* Compute the maximum representable value. */ | 291 /* Compute the maximum representable value. */ |
286 sprintf (name, "__%s_MAX__", name_prefix); | 292 sprintf (name, "__%s_MAX__", name_prefix); |
287 p = buf; | 293 p = buf; |
288 for (digits = fmt->p; digits; digits--) | 294 for (digits = fmt->p; digits; digits--) |
292 *p++ = '.'; | 298 *p++ = '.'; |
293 } | 299 } |
294 *p = 0; | 300 *p = 0; |
295 /* fmt->p plus 1, to account for the decimal point and fmt->emax | 301 /* fmt->p plus 1, to account for the decimal point and fmt->emax |
296 minus 1 because the digits are nines, not 1.0. */ | 302 minus 1 because the digits are nines, not 1.0. */ |
297 sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix); | 303 sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix); |
298 builtin_define_with_value (name, buf, 0); | 304 builtin_define_with_value (name, buf, 0); |
299 | 305 |
300 /* Compute epsilon (the difference between 1 and least value greater | 306 /* Compute epsilon (the difference between 1 and least value greater |
301 than 1 representable). */ | 307 than 1 representable). */ |
302 sprintf (name, "__%s_EPSILON__", name_prefix); | 308 sprintf (name, "__%s_EPSILON__", name_prefix); |
311 *p++ = '0'; | 317 *p++ = '0'; |
312 if (digits == fmt->p) | 318 if (digits == fmt->p) |
313 *p++ = '.'; | 319 *p++ = '.'; |
314 } | 320 } |
315 *p = 0; | 321 *p = 0; |
316 sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix); | 322 sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix); |
317 builtin_define_with_value (name, buf, 0); | 323 builtin_define_with_value (name, buf, 0); |
318 } | 324 } |
319 | 325 |
320 /* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */ | 326 /* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX. */ |
321 | 327 |
388 | 394 |
389 if (c_dialect_cxx ()) | 395 if (c_dialect_cxx ()) |
390 cpp_define_formatted (parse_in, "__GNUG__=%d", major); | 396 cpp_define_formatted (parse_in, "__GNUG__=%d", major); |
391 } | 397 } |
392 | 398 |
393 /* Define macros used by <stdint.h>. Currently only defines limits | 399 /* Define macros used by <stdint.h>. */ |
394 for intmax_t, used by the testsuite. */ | |
395 static void | 400 static void |
396 builtin_define_stdint_macros (void) | 401 builtin_define_stdint_macros (void) |
397 { | 402 { |
398 int intmax_long; | 403 builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node); |
399 if (intmax_type_node == long_long_integer_type_node) | 404 builtin_define_constants ("__INTMAX_C", intmax_type_node); |
400 intmax_long = 2; | 405 builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node); |
401 else if (intmax_type_node == long_integer_type_node) | 406 builtin_define_constants ("__UINTMAX_C", uintmax_type_node); |
402 intmax_long = 1; | 407 if (sig_atomic_type_node) |
403 else if (intmax_type_node == integer_type_node) | 408 builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__", |
404 intmax_long = 0; | 409 sig_atomic_type_node); |
405 else | 410 if (int8_type_node) |
406 gcc_unreachable (); | 411 builtin_define_type_max ("__INT8_MAX__", int8_type_node); |
407 builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node, intmax_long); | 412 if (int16_type_node) |
413 builtin_define_type_max ("__INT16_MAX__", int16_type_node); | |
414 if (int32_type_node) | |
415 builtin_define_type_max ("__INT32_MAX__", int32_type_node); | |
416 if (int64_type_node) | |
417 builtin_define_type_max ("__INT64_MAX__", int64_type_node); | |
418 if (uint8_type_node) | |
419 builtin_define_type_max ("__UINT8_MAX__", uint8_type_node); | |
420 if (uint16_type_node) | |
421 builtin_define_type_max ("__UINT16_MAX__", uint16_type_node); | |
422 if (c_uint32_type_node) | |
423 builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node); | |
424 if (c_uint64_type_node) | |
425 builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node); | |
426 if (int_least8_type_node) | |
427 { | |
428 builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node); | |
429 builtin_define_constants ("__INT8_C", int_least8_type_node); | |
430 } | |
431 if (int_least16_type_node) | |
432 { | |
433 builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node); | |
434 builtin_define_constants ("__INT16_C", int_least16_type_node); | |
435 } | |
436 if (int_least32_type_node) | |
437 { | |
438 builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node); | |
439 builtin_define_constants ("__INT32_C", int_least32_type_node); | |
440 } | |
441 if (int_least64_type_node) | |
442 { | |
443 builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node); | |
444 builtin_define_constants ("__INT64_C", int_least64_type_node); | |
445 } | |
446 if (uint_least8_type_node) | |
447 { | |
448 builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node); | |
449 builtin_define_constants ("__UINT8_C", uint_least8_type_node); | |
450 } | |
451 if (uint_least16_type_node) | |
452 { | |
453 builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node); | |
454 builtin_define_constants ("__UINT16_C", uint_least16_type_node); | |
455 } | |
456 if (uint_least32_type_node) | |
457 { | |
458 builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node); | |
459 builtin_define_constants ("__UINT32_C", uint_least32_type_node); | |
460 } | |
461 if (uint_least64_type_node) | |
462 { | |
463 builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node); | |
464 builtin_define_constants ("__UINT64_C", uint_least64_type_node); | |
465 } | |
466 if (int_fast8_type_node) | |
467 builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node); | |
468 if (int_fast16_type_node) | |
469 builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node); | |
470 if (int_fast32_type_node) | |
471 builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node); | |
472 if (int_fast64_type_node) | |
473 builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node); | |
474 if (uint_fast8_type_node) | |
475 builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node); | |
476 if (uint_fast16_type_node) | |
477 builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node); | |
478 if (uint_fast32_type_node) | |
479 builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node); | |
480 if (uint_fast64_type_node) | |
481 builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node); | |
482 if (intptr_type_node) | |
483 builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node); | |
484 if (uintptr_type_node) | |
485 builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node); | |
408 } | 486 } |
409 | 487 |
410 /* Adjust the optimization macros when a #pragma GCC optimization is done to | 488 /* Adjust the optimization macros when a #pragma GCC optimization is done to |
411 reflect the current level. */ | 489 reflect the current level. */ |
412 void | 490 void |
512 | 590 |
513 /* libgcc needs to know this. */ | 591 /* libgcc needs to know this. */ |
514 if (USING_SJLJ_EXCEPTIONS) | 592 if (USING_SJLJ_EXCEPTIONS) |
515 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__"); | 593 cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__"); |
516 | 594 |
517 /* limits.h needs to know these. */ | 595 /* limits.h and stdint.h need to know these. */ |
518 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node, 0); | 596 builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node); |
519 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node, 0); | 597 builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node); |
520 builtin_define_type_max ("__INT_MAX__", integer_type_node, 0); | 598 builtin_define_type_max ("__INT_MAX__", integer_type_node); |
521 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node, 1); | 599 builtin_define_type_max ("__LONG_MAX__", long_integer_type_node); |
522 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node, 2); | 600 builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node); |
523 builtin_define_type_max ("__WCHAR_MAX__", wchar_type_node, 0); | 601 builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__", |
602 underlying_wchar_type_node); | |
603 builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node); | |
604 builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node); | |
605 builtin_define_type_max ("__SIZE_MAX__", size_type_node); | |
524 | 606 |
525 builtin_define_type_precision ("__CHAR_BIT__", char_type_node); | 607 builtin_define_type_precision ("__CHAR_BIT__", char_type_node); |
526 | 608 |
527 /* stdint.h (eventually) and the testsuite need to know these. */ | 609 /* stdint.h and the testsuite need to know these. */ |
528 builtin_define_stdint_macros (); | 610 builtin_define_stdint_macros (); |
529 | 611 |
530 /* float.h needs to know these. */ | 612 /* float.h needs to know these. */ |
531 | 613 |
532 builtin_define_with_int_value ("__FLT_EVAL_METHOD__", | 614 builtin_define_with_int_value ("__FLT_EVAL_METHOD__", |
535 /* And decfloat.h needs this. */ | 617 /* And decfloat.h needs this. */ |
536 builtin_define_with_int_value ("__DEC_EVAL_METHOD__", | 618 builtin_define_with_int_value ("__DEC_EVAL_METHOD__", |
537 TARGET_DEC_EVAL_METHOD); | 619 TARGET_DEC_EVAL_METHOD); |
538 | 620 |
539 builtin_define_float_constants ("FLT", "F", "%s", float_type_node); | 621 builtin_define_float_constants ("FLT", "F", "%s", float_type_node); |
540 /* Cast the double precision constants when single precision constants are | 622 /* Cast the double precision constants. This is needed when single |
541 specified. The correct result is computed by the compiler when using | 623 precision constants are specified or when pragma FLOAT_CONST_DECIMAL64 |
542 macros that include a cast. This has the side-effect of making the value | 624 is used. The correct result is computed by the compiler when using |
543 unusable in const expressions. */ | 625 macros that include a cast. */ |
544 if (flag_single_precision_constant) | 626 builtin_define_float_constants ("DBL", "L", "((double)%s)", double_type_node); |
545 builtin_define_float_constants ("DBL", "L", "((double)%s)", double_type_node); | |
546 else | |
547 builtin_define_float_constants ("DBL", "", "%s", double_type_node); | |
548 builtin_define_float_constants ("LDBL", "L", "%s", long_double_type_node); | 627 builtin_define_float_constants ("LDBL", "L", "%s", long_double_type_node); |
549 | 628 |
550 /* For decfloat.h. */ | 629 /* For decfloat.h. */ |
551 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node); | 630 builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node); |
552 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node); | 631 builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node); |
701 /* Make the choice of ObjC runtime visible to source code. */ | 780 /* Make the choice of ObjC runtime visible to source code. */ |
702 if (c_dialect_objc () && flag_next_runtime) | 781 if (c_dialect_objc () && flag_next_runtime) |
703 cpp_define (pfile, "__NEXT_RUNTIME__"); | 782 cpp_define (pfile, "__NEXT_RUNTIME__"); |
704 | 783 |
705 /* Show the availability of some target pragmas. */ | 784 /* Show the availability of some target pragmas. */ |
706 if (flag_mudflap || targetm.handle_pragma_redefine_extname) | 785 cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME"); |
707 cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME"); | |
708 | 786 |
709 if (targetm.handle_pragma_extern_prefix) | 787 if (targetm.handle_pragma_extern_prefix) |
710 cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX"); | 788 cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX"); |
711 | 789 |
712 /* Make the choice of the stack protector runtime visible to source code. | 790 /* Make the choice of the stack protector runtime visible to source code. |
855 | 933 |
856 /* Pass an object-like macro a hexadecimal floating-point value. */ | 934 /* Pass an object-like macro a hexadecimal floating-point value. */ |
857 static void | 935 static void |
858 builtin_define_with_hex_fp_value (const char *macro, | 936 builtin_define_with_hex_fp_value (const char *macro, |
859 tree type, int digits, | 937 tree type, int digits, |
860 const char *hex_str, | 938 const char *hex_str, |
861 const char *fp_suffix, | 939 const char *fp_suffix, |
862 const char *fp_cast) | 940 const char *fp_cast) |
863 { | 941 { |
864 REAL_VALUE_TYPE real; | 942 REAL_VALUE_TYPE real; |
865 char dec_str[64], buf1[256], buf2[256]; | 943 char dec_str[64], buf1[256], buf2[256]; |
881 /* Assemble the macro in the following fashion | 959 /* Assemble the macro in the following fashion |
882 macro = fp_cast [dec_str fp_suffix] */ | 960 macro = fp_cast [dec_str fp_suffix] */ |
883 sprintf (buf1, "%s%s", dec_str, fp_suffix); | 961 sprintf (buf1, "%s%s", dec_str, fp_suffix); |
884 sprintf (buf2, fp_cast, buf1); | 962 sprintf (buf2, fp_cast, buf1); |
885 sprintf (buf1, "%s=%s", macro, buf2); | 963 sprintf (buf1, "%s=%s", macro, buf2); |
886 | 964 |
887 cpp_define (parse_in, buf1); | 965 cpp_define (parse_in, buf1); |
888 } | 966 } |
889 | 967 |
890 /* Define MAX for TYPE based on the precision of the type. IS_LONG is | 968 /* Return a string constant for the suffix for a value of type TYPE |
891 1 for type "long" and 2 for "long long". We have to handle | 969 promoted according to the integer promotions. The type must be one |
892 unsigned types, since wchar_t might be unsigned. */ | 970 of the standard integer type nodes. */ |
893 | 971 |
894 static void | 972 static const char * |
895 builtin_define_type_max (const char *macro, tree type, int is_long) | 973 type_suffix (tree type) |
974 { | |
975 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" }; | |
976 int unsigned_suffix; | |
977 int is_long; | |
978 | |
979 if (type == long_long_integer_type_node | |
980 || type == long_long_unsigned_type_node) | |
981 is_long = 2; | |
982 else if (type == long_integer_type_node | |
983 || type == long_unsigned_type_node) | |
984 is_long = 1; | |
985 else if (type == integer_type_node | |
986 || type == unsigned_type_node | |
987 || type == short_integer_type_node | |
988 || type == short_unsigned_type_node | |
989 || type == signed_char_type_node | |
990 || type == unsigned_char_type_node | |
991 /* ??? "char" is not a signed or unsigned integer type and | |
992 so is not permitted for the standard typedefs, but some | |
993 systems use it anyway. */ | |
994 || type == char_type_node) | |
995 is_long = 0; | |
996 else | |
997 gcc_unreachable (); | |
998 | |
999 unsigned_suffix = TYPE_UNSIGNED (type); | |
1000 if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) | |
1001 unsigned_suffix = 0; | |
1002 return suffixes[is_long * 2 + unsigned_suffix]; | |
1003 } | |
1004 | |
1005 /* Define MACRO as a <stdint.h> constant-suffix macro for TYPE. */ | |
1006 static void | |
1007 builtin_define_constants (const char *macro, tree type) | |
1008 { | |
1009 const char *suffix; | |
1010 char *buf; | |
1011 | |
1012 suffix = type_suffix (type); | |
1013 | |
1014 if (suffix[0] == 0) | |
1015 { | |
1016 buf = (char *) alloca (strlen (macro) + 6); | |
1017 sprintf (buf, "%s(c)=c", macro); | |
1018 } | |
1019 else | |
1020 { | |
1021 buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1); | |
1022 sprintf (buf, "%s(c)=c ## %s", macro, suffix); | |
1023 } | |
1024 | |
1025 cpp_define (parse_in, buf); | |
1026 } | |
1027 | |
1028 /* Define MAX for TYPE based on the precision of the type. */ | |
1029 | |
1030 static void | |
1031 builtin_define_type_max (const char *macro, tree type) | |
1032 { | |
1033 builtin_define_type_minmax (NULL, macro, type); | |
1034 } | |
1035 | |
1036 /* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the | |
1037 precision of the type. */ | |
1038 | |
1039 static void | |
1040 builtin_define_type_minmax (const char *min_macro, const char *max_macro, | |
1041 tree type) | |
896 { | 1042 { |
897 static const char *const values[] | 1043 static const char *const values[] |
898 = { "127", "255", | 1044 = { "127", "255", |
899 "32767", "65535", | 1045 "32767", "65535", |
900 "2147483647", "4294967295", | 1046 "2147483647", "4294967295", |
901 "9223372036854775807", "18446744073709551615", | 1047 "9223372036854775807", "18446744073709551615", |
902 "170141183460469231731687303715884105727", | 1048 "170141183460469231731687303715884105727", |
903 "340282366920938463463374607431768211455" }; | 1049 "340282366920938463463374607431768211455" }; |
904 static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" }; | |
905 | 1050 |
906 const char *value, *suffix; | 1051 const char *value, *suffix; |
907 char *buf; | 1052 char *buf; |
908 size_t idx; | 1053 size_t idx; |
909 | 1054 |
919 case 128: idx = 8; break; | 1064 case 128: idx = 8; break; |
920 default: gcc_unreachable (); | 1065 default: gcc_unreachable (); |
921 } | 1066 } |
922 | 1067 |
923 value = values[idx + TYPE_UNSIGNED (type)]; | 1068 value = values[idx + TYPE_UNSIGNED (type)]; |
924 suffix = suffixes[is_long * 2 + TYPE_UNSIGNED (type)]; | 1069 suffix = type_suffix (type); |
925 | 1070 |
926 buf = (char *) alloca (strlen (macro) + 1 + strlen (value) | 1071 buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value) |
927 + strlen (suffix) + 1); | 1072 + strlen (suffix) + 1); |
928 sprintf (buf, "%s=%s%s", macro, value, suffix); | 1073 sprintf (buf, "%s=%s%s", max_macro, value, suffix); |
929 | 1074 |
930 cpp_define (parse_in, buf); | 1075 cpp_define (parse_in, buf); |
931 } | 1076 |
1077 if (min_macro) | |
1078 { | |
1079 if (TYPE_UNSIGNED (type)) | |
1080 { | |
1081 buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1); | |
1082 sprintf (buf, "%s=0%s", min_macro, suffix); | |
1083 } | |
1084 else | |
1085 { | |
1086 buf = (char *) alloca (strlen (min_macro) + 3 | |
1087 + strlen (max_macro) + 6); | |
1088 sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro); | |
1089 } | |
1090 cpp_define (parse_in, buf); | |
1091 } | |
1092 } |