1 /* Solaris support needed only by C/C++ frontends.
2 Copyright (C) 2004-2015 Free Software Foundation, Inc.
3 Contributed by CodeSourcery, LLC.
5 This file is part of GCC.
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)
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.
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"
28 #include "stringpool.h"
33 #include "c-family/c-format.h"
37 #include "c-family/c-pragma.h"
38 #include "c-family/c-common.h"
40 /* cmn_err only accepts "l" and "ll". */
41 static const format_length_info cmn_err_length_specs
[] =
43 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C89
, 0 },
44 { NULL
, FMT_LEN_none
, STD_C89
, NULL
, FMT_LEN_none
, STD_C89
, 0 }
47 static const format_flag_spec cmn_err_flag_specs
[] =
49 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
50 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
51 { 0, 0, 0, NULL
, NULL
, STD_C89
}
55 static const format_flag_pair cmn_err_flag_pairs
[] =
60 static const format_char_info bitfield_string_type
=
61 { "b", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
};
63 static const format_char_info cmn_err_char_table
[] =
65 /* C89 conversion specifiers. */
66 { "dD", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
67 { "oOxX",0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
68 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
69 { "c", 0, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
70 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "c", NULL
},
71 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "cR", NULL
},
72 { "b", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", &bitfield_string_type
},
73 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
76 EXPORTED_CONST format_kind_info solaris_format_types
[] = {
77 { "cmn_err", cmn_err_length_specs
, cmn_err_char_table
, "", NULL
,
78 cmn_err_flag_specs
, cmn_err_flag_pairs
,
79 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_EMPTY_PREC_OK
,
81 &integer_type_node
, &integer_type_node
85 /* Handle #pragma align ALIGNMENT (VAR [, VAR]...) */
88 solaris_pragma_align (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
92 unsigned HOST_WIDE_INT low
;
94 if (pragma_lex (&x
) != CPP_NUMBER
95 || pragma_lex (&t
) != CPP_OPEN_PAREN
)
97 warning (0, "malformed %<#pragma align%>, ignoring");
101 low
= TREE_INT_CST_LOW (x
);
102 if (!tree_fits_uhwi_p (x
)
103 || (low
!= 1 && low
!= 2 && low
!= 4 && low
!= 8 && low
!= 16
104 && low
!= 32 && low
!= 64 && low
!= 128))
106 warning (0, "invalid alignment for %<#pragma align%>, ignoring");
110 ttype
= pragma_lex (&t
);
111 if (ttype
!= CPP_NAME
)
113 warning (0, "malformed %<#pragma align%>, ignoring");
119 tree decl
= identifier_global_value (t
);
120 if (decl
&& DECL_P (decl
))
121 warning (0, "%<#pragma align%> must appear before the declaration of "
122 "%D, ignoring", decl
);
124 solaris_pending_aligns
= tree_cons (t
, build_tree_list (NULL
, x
),
125 solaris_pending_aligns
);
127 ttype
= pragma_lex (&t
);
128 if (ttype
== CPP_COMMA
)
130 ttype
= pragma_lex (&t
);
131 if (ttype
!= CPP_NAME
)
133 warning (0, "malformed %<#pragma align%>");
137 else if (ttype
== CPP_CLOSE_PAREN
)
139 if (pragma_lex (&t
) != CPP_EOF
)
140 warning (0, "junk at end of %<#pragma align%>");
145 warning (0, "malformed %<#pragma align%>");
151 /* Handle #pragma init (function [, function]...) */
154 solaris_pragma_init (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
157 enum cpp_ttype ttype
;
159 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
161 warning (0, "malformed %<#pragma init%>, ignoring");
165 ttype
= pragma_lex (&t
);
166 if (ttype
!= CPP_NAME
)
168 warning (0, "malformed %<#pragma init%>, ignoring");
174 tree decl
= identifier_global_value (t
);
175 if (decl
&& DECL_P (decl
))
177 tree attrs
= build_tree_list (get_identifier ("init"),
179 TREE_USED (decl
) = 1;
180 DECL_PRESERVE_P (decl
) = 1;
181 decl_attributes (&decl
, attrs
, 0);
184 solaris_pending_inits
= tree_cons (t
, NULL
, solaris_pending_inits
);
186 ttype
= pragma_lex (&t
);
187 if (ttype
== CPP_COMMA
)
189 ttype
= pragma_lex (&t
);
190 if (ttype
!= CPP_NAME
)
192 warning (0, "malformed %<#pragma init%>");
196 else if (ttype
== CPP_CLOSE_PAREN
)
198 if (pragma_lex (&t
) != CPP_EOF
)
199 warning (0, "junk at end of %<#pragma init%>");
204 warning (0, "malformed %<#pragma init%>");
210 /* Handle #pragma fini (function [, function]...) */
213 solaris_pragma_fini (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
216 enum cpp_ttype ttype
;
218 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
220 warning (0, "malformed %<#pragma fini%>, ignoring");
224 ttype
= pragma_lex (&t
);
225 if (ttype
!= CPP_NAME
)
227 warning (0, "malformed %<#pragma fini%>, ignoring");
233 tree decl
= identifier_global_value (t
);
234 if (decl
&& DECL_P (decl
))
236 tree attrs
= build_tree_list (get_identifier ("fini"),
238 TREE_USED (decl
) = 1;
239 DECL_PRESERVE_P (decl
) = 1;
240 decl_attributes (&decl
, attrs
, 0);
243 solaris_pending_finis
= tree_cons (t
, NULL
, solaris_pending_finis
);
245 ttype
= pragma_lex (&t
);
246 if (ttype
== CPP_COMMA
)
248 ttype
= pragma_lex (&t
);
249 if (ttype
!= CPP_NAME
)
251 warning (0, "malformed %<#pragma fini%>");
255 else if (ttype
== CPP_CLOSE_PAREN
)
257 if (pragma_lex (&t
) != CPP_EOF
)
258 warning (0, "junk at end of %<#pragma fini%>");
263 warning (0, "malformed %<#pragma fini%>");
269 /* Register Solaris-specific #pragma directives. */
272 solaris_register_pragmas (void)
274 c_register_pragma_with_expansion (0, "align", solaris_pragma_align
);
275 c_register_pragma (0, "init", solaris_pragma_init
);
276 c_register_pragma (0, "fini", solaris_pragma_fini
);