1 /* Define builtin-in macros for all front ends that perform preprocessing
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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 #include "cpp-id-data.h"
30 #include "cppbuiltin.h"
34 /* Parse a BASEVER version string of the format "major.minor.patchlevel"
35 or "major.minor" to extract its components. */
37 parse_basever (int *major
, int *minor
, int *patchlevel
)
39 static int s_major
= -1, s_minor
, s_patchlevel
;
42 if (sscanf (BASEVER
, "%d.%d.%d", &s_major
, &s_minor
, &s_patchlevel
) != 3)
44 sscanf (BASEVER
, "%d.%d", &s_major
, &s_minor
);
55 *patchlevel
= s_patchlevel
;
59 /* Define __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ and __VERSION__. */
61 define__GNUC__ (cpp_reader
*pfile
)
63 int major
, minor
, patchlevel
;
65 parse_basever (&major
, &minor
, &patchlevel
);
66 cpp_define_formatted (pfile
, "__GNUC__=%d", major
);
67 cpp_define_formatted (pfile
, "__GNUC_MINOR__=%d", minor
);
68 cpp_define_formatted (pfile
, "__GNUC_PATCHLEVEL__=%d", patchlevel
);
69 cpp_define_formatted (pfile
, "__VERSION__=\"%s\"", version_string
);
73 /* Define various built-in CPP macros that depend on language-independent
76 define_builtin_macros_for_compilation_flags (cpp_reader
*pfile
)
80 cpp_define_formatted (pfile
, "__pic__=%d", flag_pic
);
81 cpp_define_formatted (pfile
, "__PIC__=%d", flag_pic
);
85 cpp_define_formatted (pfile
, "__pie__=%d", flag_pie
);
86 cpp_define_formatted (pfile
, "__PIE__=%d", flag_pie
);
90 cpp_define (pfile
, "__OPTIMIZE_SIZE__");
92 cpp_define (pfile
, "__OPTIMIZE__");
94 if (fast_math_flags_set_p (&global_options
))
95 cpp_define (pfile
, "__FAST_MATH__");
96 if (flag_signaling_nans
)
97 cpp_define (pfile
, "__SUPPORT_SNAN__");
99 cpp_define_formatted (pfile
, "__FINITE_MATH_ONLY__=%d",
100 flag_finite_math_only
);
104 /* Define built-in macros for LP64 targets. */
106 define_builtin_macros_for_lp64 (cpp_reader
*pfile
)
108 if (TYPE_PRECISION (long_integer_type_node
) == 64
109 && POINTER_SIZE
== 64
110 && TYPE_PRECISION (integer_type_node
) == 32)
112 cpp_define (pfile
, "_LP64");
113 cpp_define (pfile
, "__LP64__");
118 /* Define macros for size of basic C types. */
120 define_builtin_macros_for_type_sizes (cpp_reader
*pfile
)
122 #define define_type_sizeof(NAME, TYPE) \
123 cpp_define_formatted (pfile, NAME"="HOST_WIDE_INT_PRINT_DEC, \
124 tree_low_cst (TYPE_SIZE_UNIT (TYPE), 1))
126 define_type_sizeof ("__SIZEOF_INT__", integer_type_node
);
127 define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node
);
128 define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node
);
129 define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node
);
130 define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node
);
131 define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node
);
132 define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node
);
133 define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node
);
135 #undef define_type_sizeof
137 cpp_define_formatted (pfile
, "__CHAR_BIT__=%u",
138 TYPE_PRECISION (char_type_node
));
139 cpp_define_formatted (pfile
, "__BIGGEST_ALIGNMENT__=%d",
140 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
);
142 /* Define constants useful for implementing endian.h. */
143 cpp_define (pfile
, "__ORDER_LITTLE_ENDIAN__=1234");
144 cpp_define (pfile
, "__ORDER_BIG_ENDIAN__=4321");
145 cpp_define (pfile
, "__ORDER_PDP_ENDIAN__=3412");
147 if (WORDS_BIG_ENDIAN
== BYTES_BIG_ENDIAN
)
148 cpp_define_formatted (pfile
, "__BYTE_ORDER__=%s",
150 ? "__ORDER_BIG_ENDIAN__"
151 : "__ORDER_LITTLE_ENDIAN__"));
154 /* Assert that we're only dealing with the PDP11 case. */
155 gcc_assert (!BYTES_BIG_ENDIAN
);
156 gcc_assert (WORDS_BIG_ENDIAN
);
158 cpp_define (pfile
, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__");
161 cpp_define_formatted (pfile
, "__FLOAT_WORD_ORDER__=%s",
162 (targetm
.float_words_big_endian ()
163 ? "__ORDER_BIG_ENDIAN__"
164 : "__ORDER_LITTLE_ENDIAN__"));
166 /* ptr_type_node can't be used here since ptr_mode is only set when
167 toplev calls backend_init which is not done with -E switch. */
168 cpp_define_formatted (pfile
, "__SIZEOF_POINTER__=%d",
169 POINTER_SIZE
/ BITS_PER_UNIT
);
173 /* Define macros builtins common to all language performing CPP
176 define_language_independent_builtin_macros (cpp_reader
*pfile
)
178 define__GNUC__ (pfile
);
179 define_builtin_macros_for_compilation_flags (pfile
);
180 define_builtin_macros_for_lp64 (pfile
);
181 define_builtin_macros_for_type_sizes (pfile
);