1 /* Solaris support needed only by C/C++ frontends.
2 Copyright (C) 2004, 2005, 2007, 2009, 2010 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 "c-family/c-format.h"
32 #include "c-family/c-pragma.h"
33 #include "c-family/c-common.h"
35 /* cmn_err only accepts "l" and "ll". */
36 static const format_length_info cmn_err_length_specs
[] =
38 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C89
, 0 },
39 { NULL
, FMT_LEN_none
, STD_C89
, NULL
, FMT_LEN_none
, STD_C89
, 0 }
42 static const format_flag_spec cmn_err_flag_specs
[] =
44 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
45 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
46 { 0, 0, 0, NULL
, NULL
, STD_C89
}
50 static const format_flag_pair cmn_err_flag_pairs
[] =
55 static const format_char_info bitfield_string_type
=
56 { "b", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
};
58 static const format_char_info cmn_err_char_table
[] =
60 /* C89 conversion specifiers. */
61 { "dD", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
62 { "oOxX",0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
63 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
64 { "c", 0, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
65 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "c", NULL
},
66 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "cR", NULL
},
67 { "b", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", &bitfield_string_type
},
68 { NULL
, 0, STD_C89
, NOLENGTHS
, NULL
, NULL
, NULL
}
71 const format_kind_info solaris_format_types
[] = {
72 { "cmn_err", cmn_err_length_specs
, cmn_err_char_table
, "", NULL
,
73 cmn_err_flag_specs
, cmn_err_flag_pairs
,
74 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_EMPTY_PREC_OK
,
76 &integer_type_node
, &integer_type_node
80 /* Handle #pragma align ALIGNMENT (VAR [, VAR]...) */
83 solaris_pragma_align (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
89 if (pragma_lex (&x
) != CPP_NUMBER
90 || pragma_lex (&t
) != CPP_OPEN_PAREN
)
92 warning (0, "malformed %<#pragma align%>, ignoring");
96 low
= TREE_INT_CST_LOW (x
);
97 if (TREE_INT_CST_HIGH (x
) != 0
98 || (low
!= 1 && low
!= 2 && low
!= 4 && low
!= 8 && low
!= 16
99 && low
!= 32 && low
!= 64 && low
!= 128))
101 warning (0, "invalid alignment for %<#pragma align%>, ignoring");
105 ttype
= pragma_lex (&t
);
106 if (ttype
!= CPP_NAME
)
108 warning (0, "malformed %<#pragma align%>, ignoring");
114 tree decl
= identifier_global_value (t
);
115 if (decl
&& DECL_P (decl
))
116 warning (0, "%<#pragma align%> must appear before the declaration of "
117 "%D, ignoring", decl
);
119 solaris_pending_aligns
= tree_cons (t
, build_tree_list (NULL
, x
),
120 solaris_pending_aligns
);
122 ttype
= pragma_lex (&t
);
123 if (ttype
== CPP_COMMA
)
125 ttype
= pragma_lex (&t
);
126 if (ttype
!= CPP_NAME
)
128 warning (0, "malformed %<#pragma align%>");
132 else if (ttype
== CPP_CLOSE_PAREN
)
134 if (pragma_lex (&t
) != CPP_EOF
)
135 warning (0, "junk at end of %<#pragma align%>");
140 warning (0, "malformed %<#pragma align%>");
146 /* Handle #pragma init (function [, function]...) */
149 solaris_pragma_init (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
152 enum cpp_ttype ttype
;
154 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
156 warning (0, "malformed %<#pragma init%>, ignoring");
160 ttype
= pragma_lex (&t
);
161 if (ttype
!= CPP_NAME
)
163 warning (0, "malformed %<#pragma init%>, ignoring");
169 tree decl
= identifier_global_value (t
);
170 if (decl
&& DECL_P (decl
))
172 tree attrs
= build_tree_list (get_identifier ("init"),
174 TREE_USED (decl
) = 1;
175 DECL_PRESERVE_P (decl
) = 1;
176 decl_attributes (&decl
, attrs
, 0);
179 solaris_pending_inits
= tree_cons (t
, NULL
, solaris_pending_inits
);
181 ttype
= pragma_lex (&t
);
182 if (ttype
== CPP_COMMA
)
184 ttype
= pragma_lex (&t
);
185 if (ttype
!= CPP_NAME
)
187 warning (0, "malformed %<#pragma init%>");
191 else if (ttype
== CPP_CLOSE_PAREN
)
193 if (pragma_lex (&t
) != CPP_EOF
)
194 warning (0, "junk at end of %<#pragma init%>");
199 warning (0, "malformed %<#pragma init%>");
205 /* Handle #pragma fini (function [, function]...) */
208 solaris_pragma_fini (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
211 enum cpp_ttype ttype
;
213 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
215 warning (0, "malformed %<#pragma fini%>, ignoring");
219 ttype
= pragma_lex (&t
);
220 if (ttype
!= CPP_NAME
)
222 warning (0, "malformed %<#pragma fini%>, ignoring");
228 tree decl
= identifier_global_value (t
);
229 if (decl
&& DECL_P (decl
))
231 tree attrs
= build_tree_list (get_identifier ("fini"),
233 TREE_USED (decl
) = 1;
234 DECL_PRESERVE_P (decl
) = 1;
235 decl_attributes (&decl
, attrs
, 0);
238 solaris_pending_finis
= tree_cons (t
, NULL
, solaris_pending_finis
);
240 ttype
= pragma_lex (&t
);
241 if (ttype
== CPP_COMMA
)
243 ttype
= pragma_lex (&t
);
244 if (ttype
!= CPP_NAME
)
246 warning (0, "malformed %<#pragma fini%>");
250 else if (ttype
== CPP_CLOSE_PAREN
)
252 if (pragma_lex (&t
) != CPP_EOF
)
253 warning (0, "junk at end of %<#pragma fini%>");
258 warning (0, "malformed %<#pragma fini%>");
264 /* Register Solaris-specific #pragma directives. */
267 solaris_register_pragmas (void)
269 c_register_pragma_with_expansion (0, "align", solaris_pragma_align
);
270 c_register_pragma (0, "init", solaris_pragma_init
);
271 c_register_pragma (0, "fini", solaris_pragma_fini
);