]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/sol2-c.c
fe36eb913725d66fa7e97e6e6101c8a002f422f1
[thirdparty/gcc.git] / gcc / config / sol2-c.c
1 /* Solaris support needed only by C/C++ frontends.
2 Copyright (C) 2004-2015 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3, or (at your option)
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
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "alias.h"
25 #include "tree.h"
26 #include "options.h"
27 #include "stringpool.h"
28 #include "attribs.h"
29 #include "tm.h"
30 #include "tm_p.h"
31
32 #include "c-family/c-format.h"
33 #include "intl.h"
34
35 #include "cpplib.h"
36 #include "c-family/c-pragma.h"
37 #include "c-family/c-common.h"
38
39 /* cmn_err only accepts "l" and "ll". */
40 static const format_length_info cmn_err_length_specs[] =
41 {
42 { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 },
43 { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }
44 };
45
46 static const format_flag_spec cmn_err_flag_specs[] =
47 {
48 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
49 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
50 { 0, 0, 0, NULL, NULL, STD_C89 }
51 };
52
53
54 static const format_flag_pair cmn_err_flag_pairs[] =
55 {
56 { 0, 0, 0, 0 }
57 };
58
59 static const format_char_info bitfield_string_type =
60 { "b", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL };
61
62 static const format_char_info cmn_err_char_table[] =
63 {
64 /* C89 conversion specifiers. */
65 { "dD", 0, STD_C89, { T89_I, BADLEN, BADLEN, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
66 { "oOxX",0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
67 { "u", 0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
68 { "c", 0, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
69 { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "c", NULL },
70 { "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "cR", NULL },
71 { "b", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", &bitfield_string_type },
72 { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
73 };
74
75 EXPORTED_CONST format_kind_info solaris_format_types[] = {
76 { "cmn_err", cmn_err_length_specs, cmn_err_char_table, "", NULL,
77 cmn_err_flag_specs, cmn_err_flag_pairs,
78 FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
79 'w', 0, 0, 0, 'L', 0,
80 &integer_type_node, &integer_type_node
81 }
82 };
83
84 /* Handle #pragma align ALIGNMENT (VAR [, VAR]...) */
85
86 static void
87 solaris_pragma_align (cpp_reader *pfile ATTRIBUTE_UNUSED)
88 {
89 tree t, x;
90 enum cpp_ttype ttype;
91 unsigned HOST_WIDE_INT low;
92
93 if (pragma_lex (&x) != CPP_NUMBER
94 || pragma_lex (&t) != CPP_OPEN_PAREN)
95 {
96 warning (0, "malformed %<#pragma align%>, ignoring");
97 return;
98 }
99
100 low = TREE_INT_CST_LOW (x);
101 if (!tree_fits_uhwi_p (x)
102 || (low != 1 && low != 2 && low != 4 && low != 8 && low != 16
103 && low != 32 && low != 64 && low != 128))
104 {
105 warning (0, "invalid alignment for %<#pragma align%>, ignoring");
106 return;
107 }
108
109 ttype = pragma_lex (&t);
110 if (ttype != CPP_NAME)
111 {
112 warning (0, "malformed %<#pragma align%>, ignoring");
113 return;
114 }
115
116 while (1)
117 {
118 tree decl = identifier_global_value (t);
119 if (decl && DECL_P (decl))
120 warning (0, "%<#pragma align%> must appear before the declaration of "
121 "%D, ignoring", decl);
122 else
123 solaris_pending_aligns = tree_cons (t, build_tree_list (NULL, x),
124 solaris_pending_aligns);
125
126 ttype = pragma_lex (&t);
127 if (ttype == CPP_COMMA)
128 {
129 ttype = pragma_lex (&t);
130 if (ttype != CPP_NAME)
131 {
132 warning (0, "malformed %<#pragma align%>");
133 return;
134 }
135 }
136 else if (ttype == CPP_CLOSE_PAREN)
137 {
138 if (pragma_lex (&t) != CPP_EOF)
139 warning (0, "junk at end of %<#pragma align%>");
140 return;
141 }
142 else
143 {
144 warning (0, "malformed %<#pragma align%>");
145 return;
146 }
147 }
148 }
149
150 /* Handle #pragma init (function [, function]...) */
151
152 static void
153 solaris_pragma_init (cpp_reader *pfile ATTRIBUTE_UNUSED)
154 {
155 tree t;
156 enum cpp_ttype ttype;
157
158 if (pragma_lex (&t) != CPP_OPEN_PAREN)
159 {
160 warning (0, "malformed %<#pragma init%>, ignoring");
161 return;
162 }
163
164 ttype = pragma_lex (&t);
165 if (ttype != CPP_NAME)
166 {
167 warning (0, "malformed %<#pragma init%>, ignoring");
168 return;
169 }
170
171 while (1)
172 {
173 tree decl = identifier_global_value (t);
174 if (decl && DECL_P (decl))
175 {
176 tree attrs = build_tree_list (get_identifier ("init"),
177 NULL);
178 TREE_USED (decl) = 1;
179 DECL_PRESERVE_P (decl) = 1;
180 decl_attributes (&decl, attrs, 0);
181 }
182 else
183 solaris_pending_inits = tree_cons (t, NULL, solaris_pending_inits);
184
185 ttype = pragma_lex (&t);
186 if (ttype == CPP_COMMA)
187 {
188 ttype = pragma_lex (&t);
189 if (ttype != CPP_NAME)
190 {
191 warning (0, "malformed %<#pragma init%>");
192 return;
193 }
194 }
195 else if (ttype == CPP_CLOSE_PAREN)
196 {
197 if (pragma_lex (&t) != CPP_EOF)
198 warning (0, "junk at end of %<#pragma init%>");
199 return;
200 }
201 else
202 {
203 warning (0, "malformed %<#pragma init%>");
204 return;
205 }
206 }
207 }
208
209 /* Handle #pragma fini (function [, function]...) */
210
211 static void
212 solaris_pragma_fini (cpp_reader *pfile ATTRIBUTE_UNUSED)
213 {
214 tree t;
215 enum cpp_ttype ttype;
216
217 if (pragma_lex (&t) != CPP_OPEN_PAREN)
218 {
219 warning (0, "malformed %<#pragma fini%>, ignoring");
220 return;
221 }
222
223 ttype = pragma_lex (&t);
224 if (ttype != CPP_NAME)
225 {
226 warning (0, "malformed %<#pragma fini%>, ignoring");
227 return;
228 }
229
230 while (1)
231 {
232 tree decl = identifier_global_value (t);
233 if (decl && DECL_P (decl))
234 {
235 tree attrs = build_tree_list (get_identifier ("fini"),
236 NULL);
237 TREE_USED (decl) = 1;
238 DECL_PRESERVE_P (decl) = 1;
239 decl_attributes (&decl, attrs, 0);
240 }
241 else
242 solaris_pending_finis = tree_cons (t, NULL, solaris_pending_finis);
243
244 ttype = pragma_lex (&t);
245 if (ttype == CPP_COMMA)
246 {
247 ttype = pragma_lex (&t);
248 if (ttype != CPP_NAME)
249 {
250 warning (0, "malformed %<#pragma fini%>");
251 return;
252 }
253 }
254 else if (ttype == CPP_CLOSE_PAREN)
255 {
256 if (pragma_lex (&t) != CPP_EOF)
257 warning (0, "junk at end of %<#pragma fini%>");
258 return;
259 }
260 else
261 {
262 warning (0, "malformed %<#pragma fini%>");
263 return;
264 }
265 }
266 }
267
268 /* Register Solaris-specific #pragma directives. */
269
270 void
271 solaris_register_pragmas (void)
272 {
273 c_register_pragma_with_expansion (0, "align", solaris_pragma_align);
274 c_register_pragma (0, "init", solaris_pragma_init);
275 c_register_pragma (0, "fini", solaris_pragma_fini);
276 }