]>
Commit | Line | Data |
---|---|---|
a2bec818 | 1 | /* Solaris support needed only by C/C++ frontends. |
a5544970 | 2 | Copyright (C) 2004-2019 Free Software Foundation, Inc. |
a2bec818 DJ |
3 | Contributed by CodeSourcery, LLC. |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
2f83c7d6 | 9 | the Free Software Foundation; either version 3, or (at your option) |
a2bec818 DJ |
10 | any later version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
2f83c7d6 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
a2bec818 DJ |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
e11c4407 AM |
24 | #include "tm.h" |
25 | #include "c-family/c-common.h" | |
d8a2d370 DN |
26 | #include "stringpool.h" |
27 | #include "attribs.h" | |
a2bec818 | 28 | |
39dabefd | 29 | #include "c-family/c-format.h" |
a2bec818 DJ |
30 | #include "intl.h" |
31 | ||
39dabefd | 32 | #include "c-family/c-pragma.h" |
07a43492 | 33 | |
a2bec818 DJ |
34 | /* cmn_err only accepts "l" and "ll". */ |
35 | static const format_length_info cmn_err_length_specs[] = | |
36 | { | |
0e6748ab RO |
37 | { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 }, |
38 | { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 } | |
a2bec818 DJ |
39 | }; |
40 | ||
41 | static const format_flag_spec cmn_err_flag_specs[] = | |
42 | { | |
e0d22278 MS |
43 | { 'w', 0, 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 }, |
44 | { 'L', 0, 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 }, | |
45 | { 0, 0, 0, 0, NULL, NULL, STD_C89 } | |
a2bec818 DJ |
46 | }; |
47 | ||
48 | ||
49 | static const format_flag_pair cmn_err_flag_pairs[] = | |
50 | { | |
51 | { 0, 0, 0, 0 } | |
52 | }; | |
53 | ||
54 | static const format_char_info bitfield_string_type = | |
55 | { "b", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL }; | |
56 | ||
57 | static const format_char_info cmn_err_char_table[] = | |
58 | { | |
59 | /* C89 conversion specifiers. */ | |
60 | { "dD", 0, STD_C89, { T89_I, BADLEN, BADLEN, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL }, | |
61 | { "oOxX",0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL }, | |
62 | { "u", 0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL }, | |
63 | { "c", 0, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL }, | |
11559c75 | 64 | { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "c", NULL }, |
a2bec818 | 65 | { "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "cR", NULL }, |
7a9430c0 | 66 | { "b", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", &bitfield_string_type }, |
81f40b79 | 67 | { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } |
a2bec818 DJ |
68 | }; |
69 | ||
5b6d595b | 70 | EXPORTED_CONST format_kind_info solaris_format_types[] = { |
a2bec818 DJ |
71 | { "cmn_err", cmn_err_length_specs, cmn_err_char_table, "", NULL, |
72 | cmn_err_flag_specs, cmn_err_flag_pairs, | |
73 | FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK, | |
9cef5f55 | 74 | 'w', 0, 0, 0, 'L', 0, |
a2bec818 DJ |
75 | &integer_type_node, &integer_type_node |
76 | } | |
77 | }; | |
07a43492 DJ |
78 | |
79 | /* Handle #pragma align ALIGNMENT (VAR [, VAR]...) */ | |
80 | ||
81 | static void | |
82 | solaris_pragma_align (cpp_reader *pfile ATTRIBUTE_UNUSED) | |
83 | { | |
84 | tree t, x; | |
85 | enum cpp_ttype ttype; | |
807e902e | 86 | unsigned HOST_WIDE_INT low; |
07a43492 | 87 | |
75ce3d48 RH |
88 | if (pragma_lex (&x) != CPP_NUMBER |
89 | || pragma_lex (&t) != CPP_OPEN_PAREN) | |
07a43492 | 90 | { |
d4ee4d25 | 91 | warning (0, "malformed %<#pragma align%>, ignoring"); |
07a43492 DJ |
92 | return; |
93 | } | |
94 | ||
95 | low = TREE_INT_CST_LOW (x); | |
807e902e | 96 | if (!tree_fits_uhwi_p (x) |
07a43492 DJ |
97 | || (low != 1 && low != 2 && low != 4 && low != 8 && low != 16 |
98 | && low != 32 && low != 64 && low != 128)) | |
99 | { | |
d4ee4d25 | 100 | warning (0, "invalid alignment for %<#pragma align%>, ignoring"); |
07a43492 DJ |
101 | return; |
102 | } | |
103 | ||
75ce3d48 | 104 | ttype = pragma_lex (&t); |
07a43492 DJ |
105 | if (ttype != CPP_NAME) |
106 | { | |
d4ee4d25 | 107 | warning (0, "malformed %<#pragma align%>, ignoring"); |
07a43492 DJ |
108 | return; |
109 | } | |
110 | ||
111 | while (1) | |
112 | { | |
113 | tree decl = identifier_global_value (t); | |
6615c446 | 114 | if (decl && DECL_P (decl)) |
d4ee4d25 | 115 | warning (0, "%<#pragma align%> must appear before the declaration of " |
ea494cd7 | 116 | "%qD, ignoring", decl); |
07a43492 DJ |
117 | else |
118 | solaris_pending_aligns = tree_cons (t, build_tree_list (NULL, x), | |
119 | solaris_pending_aligns); | |
120 | ||
75ce3d48 | 121 | ttype = pragma_lex (&t); |
07a43492 DJ |
122 | if (ttype == CPP_COMMA) |
123 | { | |
75ce3d48 | 124 | ttype = pragma_lex (&t); |
07a43492 DJ |
125 | if (ttype != CPP_NAME) |
126 | { | |
d4ee4d25 | 127 | warning (0, "malformed %<#pragma align%>"); |
07a43492 DJ |
128 | return; |
129 | } | |
130 | } | |
131 | else if (ttype == CPP_CLOSE_PAREN) | |
132 | { | |
75ce3d48 | 133 | if (pragma_lex (&t) != CPP_EOF) |
d4ee4d25 | 134 | warning (0, "junk at end of %<#pragma align%>"); |
07a43492 DJ |
135 | return; |
136 | } | |
137 | else | |
138 | { | |
d4ee4d25 | 139 | warning (0, "malformed %<#pragma align%>"); |
07a43492 DJ |
140 | return; |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | /* Handle #pragma init (function [, function]...) */ | |
146 | ||
147 | static void | |
148 | solaris_pragma_init (cpp_reader *pfile ATTRIBUTE_UNUSED) | |
149 | { | |
150 | tree t; | |
151 | enum cpp_ttype ttype; | |
152 | ||
75ce3d48 | 153 | if (pragma_lex (&t) != CPP_OPEN_PAREN) |
07a43492 | 154 | { |
d4ee4d25 | 155 | warning (0, "malformed %<#pragma init%>, ignoring"); |
07a43492 DJ |
156 | return; |
157 | } | |
158 | ||
75ce3d48 | 159 | ttype = pragma_lex (&t); |
07a43492 DJ |
160 | if (ttype != CPP_NAME) |
161 | { | |
d4ee4d25 | 162 | warning (0, "malformed %<#pragma init%>, ignoring"); |
07a43492 DJ |
163 | return; |
164 | } | |
165 | ||
166 | while (1) | |
167 | { | |
168 | tree decl = identifier_global_value (t); | |
6615c446 | 169 | if (decl && DECL_P (decl)) |
07a43492 | 170 | { |
b42186f1 MS |
171 | tree attrs = build_tree_list (get_identifier ("init"), |
172 | NULL); | |
173 | TREE_USED (decl) = 1; | |
174 | DECL_PRESERVE_P (decl) = 1; | |
07a43492 DJ |
175 | decl_attributes (&decl, attrs, 0); |
176 | } | |
177 | else | |
178 | solaris_pending_inits = tree_cons (t, NULL, solaris_pending_inits); | |
179 | ||
75ce3d48 | 180 | ttype = pragma_lex (&t); |
07a43492 DJ |
181 | if (ttype == CPP_COMMA) |
182 | { | |
75ce3d48 | 183 | ttype = pragma_lex (&t); |
07a43492 DJ |
184 | if (ttype != CPP_NAME) |
185 | { | |
d4ee4d25 | 186 | warning (0, "malformed %<#pragma init%>"); |
07a43492 DJ |
187 | return; |
188 | } | |
189 | } | |
190 | else if (ttype == CPP_CLOSE_PAREN) | |
191 | { | |
75ce3d48 | 192 | if (pragma_lex (&t) != CPP_EOF) |
d4ee4d25 | 193 | warning (0, "junk at end of %<#pragma init%>"); |
07a43492 DJ |
194 | return; |
195 | } | |
196 | else | |
197 | { | |
d4ee4d25 | 198 | warning (0, "malformed %<#pragma init%>"); |
07a43492 DJ |
199 | return; |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | /* Handle #pragma fini (function [, function]...) */ | |
205 | ||
206 | static void | |
207 | solaris_pragma_fini (cpp_reader *pfile ATTRIBUTE_UNUSED) | |
208 | { | |
209 | tree t; | |
210 | enum cpp_ttype ttype; | |
211 | ||
75ce3d48 | 212 | if (pragma_lex (&t) != CPP_OPEN_PAREN) |
07a43492 | 213 | { |
d4ee4d25 | 214 | warning (0, "malformed %<#pragma fini%>, ignoring"); |
07a43492 DJ |
215 | return; |
216 | } | |
217 | ||
75ce3d48 | 218 | ttype = pragma_lex (&t); |
07a43492 DJ |
219 | if (ttype != CPP_NAME) |
220 | { | |
d4ee4d25 | 221 | warning (0, "malformed %<#pragma fini%>, ignoring"); |
07a43492 DJ |
222 | return; |
223 | } | |
224 | ||
225 | while (1) | |
226 | { | |
227 | tree decl = identifier_global_value (t); | |
6615c446 | 228 | if (decl && DECL_P (decl)) |
07a43492 | 229 | { |
b42186f1 MS |
230 | tree attrs = build_tree_list (get_identifier ("fini"), |
231 | NULL); | |
232 | TREE_USED (decl) = 1; | |
233 | DECL_PRESERVE_P (decl) = 1; | |
07a43492 DJ |
234 | decl_attributes (&decl, attrs, 0); |
235 | } | |
236 | else | |
237 | solaris_pending_finis = tree_cons (t, NULL, solaris_pending_finis); | |
238 | ||
75ce3d48 | 239 | ttype = pragma_lex (&t); |
07a43492 DJ |
240 | if (ttype == CPP_COMMA) |
241 | { | |
75ce3d48 | 242 | ttype = pragma_lex (&t); |
07a43492 DJ |
243 | if (ttype != CPP_NAME) |
244 | { | |
d4ee4d25 | 245 | warning (0, "malformed %<#pragma fini%>"); |
07a43492 DJ |
246 | return; |
247 | } | |
248 | } | |
249 | else if (ttype == CPP_CLOSE_PAREN) | |
250 | { | |
75ce3d48 | 251 | if (pragma_lex (&t) != CPP_EOF) |
d4ee4d25 | 252 | warning (0, "junk at end of %<#pragma fini%>"); |
07a43492 DJ |
253 | return; |
254 | } | |
255 | else | |
256 | { | |
d4ee4d25 | 257 | warning (0, "malformed %<#pragma fini%>"); |
07a43492 DJ |
258 | return; |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 | /* Register Solaris-specific #pragma directives. */ | |
264 | ||
265 | void | |
266 | solaris_register_pragmas (void) | |
267 | { | |
b5b3e36a | 268 | c_register_pragma_with_expansion (0, "align", solaris_pragma_align); |
07a43492 DJ |
269 | c_register_pragma (0, "init", solaris_pragma_init); |
270 | c_register_pragma (0, "fini", solaris_pragma_fini); | |
271 | } |