1 /* Define builtin-in macros for all front ends that perform preprocessing
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "cpp-id-data.h"
28 #include "cppbuiltin.h"
32 /* Parse a BASEVER version string of the format "major.minor.patchlevel"
33 or "major.minor" to extract its components. */
35 parse_basever (int *major
, int *minor
, int *patchlevel
)
37 static int s_major
= -1, s_minor
, s_patchlevel
;
40 if (sscanf (BASEVER
, "%d.%d.%d", &s_major
, &s_minor
, &s_patchlevel
) != 3)
42 sscanf (BASEVER
, "%d.%d", &s_major
, &s_minor
);
53 *patchlevel
= s_patchlevel
;
57 /* Define __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ and __VERSION__. */
59 define__GNUC__ (cpp_reader
*pfile
)
61 int major
, minor
, patchlevel
;
63 parse_basever (&major
, &minor
, &patchlevel
);
64 cpp_define_formatted (pfile
, "__GNUC__=%d", major
);
65 cpp_define_formatted (pfile
, "__GNUC_MINOR__=%d", minor
);
66 cpp_define_formatted (pfile
, "__GNUC_PATCHLEVEL__=%d", patchlevel
);
67 cpp_define_formatted (pfile
, "__VERSION__=\"%s\"", version_string
);
68 cpp_define_formatted (pfile
, "__ATOMIC_RELAXED=%d", MEMMODEL_RELAXED
);
69 cpp_define_formatted (pfile
, "__ATOMIC_SEQ_CST=%d", MEMMODEL_SEQ_CST
);
70 cpp_define_formatted (pfile
, "__ATOMIC_ACQUIRE=%d", MEMMODEL_ACQUIRE
);
71 cpp_define_formatted (pfile
, "__ATOMIC_RELEASE=%d", MEMMODEL_RELEASE
);
72 cpp_define_formatted (pfile
, "__ATOMIC_ACQ_REL=%d", MEMMODEL_ACQ_REL
);
73 cpp_define_formatted (pfile
, "__ATOMIC_CONSUME=%d", MEMMODEL_CONSUME
);
77 /* Define various built-in CPP macros that depend on language-independent
80 define_builtin_macros_for_compilation_flags (cpp_reader
*pfile
)
84 cpp_define_formatted (pfile
, "__pic__=%d", flag_pic
);
85 cpp_define_formatted (pfile
, "__PIC__=%d", flag_pic
);
89 cpp_define_formatted (pfile
, "__pie__=%d", flag_pie
);
90 cpp_define_formatted (pfile
, "__PIE__=%d", flag_pie
);
94 cpp_define (pfile
, "__SANITIZE_ADDRESS__");
97 cpp_define (pfile
, "__OPTIMIZE_SIZE__");
99 cpp_define (pfile
, "__OPTIMIZE__");
101 if (fast_math_flags_set_p (&global_options
))
102 cpp_define (pfile
, "__FAST_MATH__");
103 if (flag_signaling_nans
)
104 cpp_define (pfile
, "__SUPPORT_SNAN__");
106 cpp_define_formatted (pfile
, "__FINITE_MATH_ONLY__=%d",
107 flag_finite_math_only
);
111 /* Define built-in macros for LP64 targets. */
113 define_builtin_macros_for_lp64 (cpp_reader
*pfile
)
115 if (TYPE_PRECISION (long_integer_type_node
) == 64
116 && POINTER_SIZE
== 64
117 && TYPE_PRECISION (integer_type_node
) == 32)
119 cpp_define (pfile
, "_LP64");
120 cpp_define (pfile
, "__LP64__");
125 /* Define macros for size of basic C types. */
127 define_builtin_macros_for_type_sizes (cpp_reader
*pfile
)
129 #define define_type_sizeof(NAME, TYPE) \
130 cpp_define_formatted (pfile, NAME"="HOST_WIDE_INT_PRINT_DEC, \
131 tree_low_cst (TYPE_SIZE_UNIT (TYPE), 1))
133 define_type_sizeof ("__SIZEOF_INT__", integer_type_node
);
134 define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node
);
135 define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node
);
136 define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node
);
137 define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node
);
138 define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node
);
139 define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node
);
140 define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node
);
142 #undef define_type_sizeof
144 cpp_define_formatted (pfile
, "__CHAR_BIT__=%u",
145 TYPE_PRECISION (char_type_node
));
146 cpp_define_formatted (pfile
, "__BIGGEST_ALIGNMENT__=%d",
147 BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
);
149 /* Define constants useful for implementing endian.h. */
150 cpp_define (pfile
, "__ORDER_LITTLE_ENDIAN__=1234");
151 cpp_define (pfile
, "__ORDER_BIG_ENDIAN__=4321");
152 cpp_define (pfile
, "__ORDER_PDP_ENDIAN__=3412");
154 if (WORDS_BIG_ENDIAN
== BYTES_BIG_ENDIAN
)
155 cpp_define_formatted (pfile
, "__BYTE_ORDER__=%s",
157 ? "__ORDER_BIG_ENDIAN__"
158 : "__ORDER_LITTLE_ENDIAN__"));
161 /* Assert that we're only dealing with the PDP11 case. */
162 gcc_assert (!BYTES_BIG_ENDIAN
);
163 gcc_assert (WORDS_BIG_ENDIAN
);
165 cpp_define (pfile
, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__");
168 cpp_define_formatted (pfile
, "__FLOAT_WORD_ORDER__=%s",
169 (targetm
.float_words_big_endian ()
170 ? "__ORDER_BIG_ENDIAN__"
171 : "__ORDER_LITTLE_ENDIAN__"));
173 /* ptr_type_node can't be used here since ptr_mode is only set when
174 toplev calls backend_init which is not done with -E switch. */
175 cpp_define_formatted (pfile
, "__SIZEOF_POINTER__=%d",
176 POINTER_SIZE
/ BITS_PER_UNIT
);
180 /* Define macros builtins common to all language performing CPP
183 define_language_independent_builtin_macros (cpp_reader
*pfile
)
185 define__GNUC__ (pfile
);
186 define_builtin_macros_for_compilation_flags (pfile
);
187 define_builtin_macros_for_lp64 (pfile
);
188 define_builtin_macros_for_type_sizes (pfile
);