]>
Commit | Line | Data |
---|---|---|
41acdfa4 | 1 | /* Define builtin-in macros for all front ends that perform preprocessing |
d353bf18 | 2 | Copyright (C) 2010-2015 Free Software Foundation, Inc. |
41acdfa4 | 3 | |
4 | This file is part of GCC. | |
5 | ||
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 | |
9 | version. | |
10 | ||
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 | |
14 | for more details. | |
15 | ||
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/>. */ | |
19 | ||
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
23 | #include "tm.h" | |
b20a8bb4 | 24 | #include "alias.h" |
25 | #include "symtab.h" | |
41acdfa4 | 26 | #include "tree.h" |
27 | #include "version.h" | |
28 | #include "flags.h" | |
41acdfa4 | 29 | #include "cpp-id-data.h" |
30 | #include "cppbuiltin.h" | |
7a45b3f9 | 31 | #include "target.h" |
41acdfa4 | 32 | |
33 | ||
34 | /* Parse a BASEVER version string of the format "major.minor.patchlevel" | |
35 | or "major.minor" to extract its components. */ | |
36 | void | |
37 | parse_basever (int *major, int *minor, int *patchlevel) | |
38 | { | |
39 | static int s_major = -1, s_minor, s_patchlevel; | |
40 | ||
41 | if (s_major == -1) | |
42 | if (sscanf (BASEVER, "%d.%d.%d", &s_major, &s_minor, &s_patchlevel) != 3) | |
43 | { | |
44 | sscanf (BASEVER, "%d.%d", &s_major, &s_minor); | |
45 | s_patchlevel = 0; | |
46 | } | |
47 | ||
48 | if (major) | |
49 | *major = s_major; | |
50 | ||
51 | if (minor) | |
52 | *minor = s_minor; | |
53 | ||
54 | if (patchlevel) | |
55 | *patchlevel = s_patchlevel; | |
56 | } | |
57 | ||
58 | ||
59 | /* Define __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ and __VERSION__. */ | |
60 | static void | |
61 | define__GNUC__ (cpp_reader *pfile) | |
62 | { | |
63 | int major, minor, patchlevel; | |
64 | ||
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); | |
1cd6e20d | 70 | cpp_define_formatted (pfile, "__ATOMIC_RELAXED=%d", MEMMODEL_RELAXED); |
71 | cpp_define_formatted (pfile, "__ATOMIC_SEQ_CST=%d", MEMMODEL_SEQ_CST); | |
72 | cpp_define_formatted (pfile, "__ATOMIC_ACQUIRE=%d", MEMMODEL_ACQUIRE); | |
73 | cpp_define_formatted (pfile, "__ATOMIC_RELEASE=%d", MEMMODEL_RELEASE); | |
74 | cpp_define_formatted (pfile, "__ATOMIC_ACQ_REL=%d", MEMMODEL_ACQ_REL); | |
75 | cpp_define_formatted (pfile, "__ATOMIC_CONSUME=%d", MEMMODEL_CONSUME); | |
41acdfa4 | 76 | } |
77 | ||
78 | ||
79 | /* Define various built-in CPP macros that depend on language-independent | |
80 | compilation flags. */ | |
81 | static void | |
82 | define_builtin_macros_for_compilation_flags (cpp_reader *pfile) | |
83 | { | |
84 | if (flag_pic) | |
85 | { | |
86 | cpp_define_formatted (pfile, "__pic__=%d", flag_pic); | |
87 | cpp_define_formatted (pfile, "__PIC__=%d", flag_pic); | |
88 | } | |
89 | if (flag_pie) | |
90 | { | |
91 | cpp_define_formatted (pfile, "__pie__=%d", flag_pie); | |
92 | cpp_define_formatted (pfile, "__PIE__=%d", flag_pie); | |
93 | } | |
94 | ||
9e46467d | 95 | if (flag_sanitize & SANITIZE_ADDRESS) |
3ff4192e | 96 | cpp_define (pfile, "__SANITIZE_ADDRESS__"); |
97 | ||
41acdfa4 | 98 | if (optimize_size) |
99 | cpp_define (pfile, "__OPTIMIZE_SIZE__"); | |
100 | if (optimize) | |
101 | cpp_define (pfile, "__OPTIMIZE__"); | |
102 | ||
cc4fa57a | 103 | if (fast_math_flags_set_p (&global_options)) |
41acdfa4 | 104 | cpp_define (pfile, "__FAST_MATH__"); |
105 | if (flag_signaling_nans) | |
106 | cpp_define (pfile, "__SUPPORT_SNAN__"); | |
86b9f14b | 107 | if (!flag_errno_math) |
108 | cpp_define (pfile, "__NO_MATH_ERRNO__"); | |
41acdfa4 | 109 | |
110 | cpp_define_formatted (pfile, "__FINITE_MATH_ONLY__=%d", | |
111 | flag_finite_math_only); | |
a89e6c15 | 112 | if (flag_cilkplus) |
d037099f | 113 | cpp_define (pfile, "__cilk=200"); |
058a1b7a | 114 | |
115 | if (flag_check_pointer_bounds) | |
116 | cpp_define (pfile, "__CHKP__"); | |
41acdfa4 | 117 | } |
118 | ||
119 | ||
120 | /* Define built-in macros for LP64 targets. */ | |
121 | static void | |
122 | define_builtin_macros_for_lp64 (cpp_reader *pfile) | |
123 | { | |
124 | if (TYPE_PRECISION (long_integer_type_node) == 64 | |
125 | && POINTER_SIZE == 64 | |
126 | && TYPE_PRECISION (integer_type_node) == 32) | |
127 | { | |
128 | cpp_define (pfile, "_LP64"); | |
129 | cpp_define (pfile, "__LP64__"); | |
130 | } | |
131 | } | |
132 | ||
133 | ||
134 | /* Define macros for size of basic C types. */ | |
135 | static void | |
136 | define_builtin_macros_for_type_sizes (cpp_reader *pfile) | |
137 | { | |
138 | #define define_type_sizeof(NAME, TYPE) \ | |
f03df321 | 139 | cpp_define_formatted (pfile, NAME"=" HOST_WIDE_INT_PRINT_DEC, \ |
6a0712d4 | 140 | tree_to_uhwi (TYPE_SIZE_UNIT (TYPE))) |
41acdfa4 | 141 | |
142 | define_type_sizeof ("__SIZEOF_INT__", integer_type_node); | |
143 | define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node); | |
144 | define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node); | |
145 | define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node); | |
146 | define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node); | |
147 | define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node); | |
148 | define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node); | |
149 | define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node); | |
150 | ||
151 | #undef define_type_sizeof | |
152 | ||
153 | cpp_define_formatted (pfile, "__CHAR_BIT__=%u", | |
154 | TYPE_PRECISION (char_type_node)); | |
155 | cpp_define_formatted (pfile, "__BIGGEST_ALIGNMENT__=%d", | |
156 | BIGGEST_ALIGNMENT / BITS_PER_UNIT); | |
157 | ||
f6e5e456 | 158 | /* Define constants useful for implementing endian.h. */ |
159 | cpp_define (pfile, "__ORDER_LITTLE_ENDIAN__=1234"); | |
160 | cpp_define (pfile, "__ORDER_BIG_ENDIAN__=4321"); | |
161 | cpp_define (pfile, "__ORDER_PDP_ENDIAN__=3412"); | |
162 | ||
163 | if (WORDS_BIG_ENDIAN == BYTES_BIG_ENDIAN) | |
164 | cpp_define_formatted (pfile, "__BYTE_ORDER__=%s", | |
165 | (WORDS_BIG_ENDIAN | |
166 | ? "__ORDER_BIG_ENDIAN__" | |
167 | : "__ORDER_LITTLE_ENDIAN__")); | |
168 | else | |
169 | { | |
170 | /* Assert that we're only dealing with the PDP11 case. */ | |
9282e471 | 171 | gcc_assert (!BYTES_BIG_ENDIAN); |
172 | gcc_assert (WORDS_BIG_ENDIAN); | |
f6e5e456 | 173 | |
174 | cpp_define (pfile, "__BYTE_ORDER__=__ORDER_PDP_ENDIAN__"); | |
175 | } | |
176 | ||
e8b06528 | 177 | cpp_define_formatted (pfile, "__FLOAT_WORD_ORDER__=%s", |
7a45b3f9 | 178 | (targetm.float_words_big_endian () |
e8b06528 | 179 | ? "__ORDER_BIG_ENDIAN__" |
180 | : "__ORDER_LITTLE_ENDIAN__")); | |
181 | ||
41acdfa4 | 182 | /* ptr_type_node can't be used here since ptr_mode is only set when |
183 | toplev calls backend_init which is not done with -E switch. */ | |
184 | cpp_define_formatted (pfile, "__SIZEOF_POINTER__=%d", | |
4765975c | 185 | 1 << ceil_log2 ((POINTER_SIZE + BITS_PER_UNIT - 1) / BITS_PER_UNIT)); |
41acdfa4 | 186 | } |
187 | ||
188 | ||
189 | /* Define macros builtins common to all language performing CPP | |
190 | preprocessing. */ | |
191 | void | |
192 | define_language_independent_builtin_macros (cpp_reader *pfile) | |
193 | { | |
194 | define__GNUC__ (pfile); | |
195 | define_builtin_macros_for_compilation_flags (pfile); | |
196 | define_builtin_macros_for_lp64 (pfile); | |
197 | define_builtin_macros_for_type_sizes (pfile); | |
198 | } |