1 /* Solaris support needed only by C/C++ frontends.
2 Copyright (C) 2004, 2005 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 2, 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 COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "coretypes.h"
37 /* cmn_err only accepts "l" and "ll". */
38 static const format_length_info cmn_err_length_specs
[] =
40 { "l", FMT_LEN_l
, STD_C89
, "ll", FMT_LEN_ll
, STD_C89
},
41 { NULL
, 0, 0, NULL
, 0, 0 }
44 static const format_flag_spec cmn_err_flag_specs
[] =
46 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89
},
47 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89
},
48 { 0, 0, 0, NULL
, NULL
, 0 }
52 static const format_flag_pair cmn_err_flag_pairs
[] =
57 static const format_char_info bitfield_string_type
=
58 { "b", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "", "cR", NULL
};
60 static const format_char_info cmn_err_char_table
[] =
62 /* C89 conversion specifiers. */
63 { "dD", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, T89_L
, T9L_LL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
64 { "oOxX",0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
65 { "u", 0, STD_C89
, { T89_UI
, BADLEN
, BADLEN
, T89_UL
, T9L_ULL
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
66 { "c", 0, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", NULL
},
67 { "p", 1, STD_C89
, { T89_V
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "c", NULL
},
68 { "s", 1, STD_C89
, { T89_C
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "cR", NULL
},
69 { "b", 0, STD_C89
, { T89_I
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
, BADLEN
}, "w", "", &bitfield_string_type
},
70 { NULL
, 0, 0, NOLENGTHS
, NULL
, NULL
, NULL
}
73 const format_kind_info solaris_format_types
[] = {
74 { "cmn_err", cmn_err_length_specs
, cmn_err_char_table
, "", NULL
,
75 cmn_err_flag_specs
, cmn_err_flag_pairs
,
76 FMT_FLAG_ARG_CONVERT
|FMT_FLAG_EMPTY_PREC_OK
,
78 &integer_type_node
, &integer_type_node
82 /* Handle #pragma align ALIGNMENT (VAR [, VAR]...) */
85 solaris_pragma_align (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
91 if (pragma_lex (&x
) != CPP_NUMBER
92 || pragma_lex (&t
) != CPP_OPEN_PAREN
)
94 warning (0, "malformed %<#pragma align%>, ignoring");
98 low
= TREE_INT_CST_LOW (x
);
99 if (TREE_INT_CST_HIGH (x
) != 0
100 || (low
!= 1 && low
!= 2 && low
!= 4 && low
!= 8 && low
!= 16
101 && low
!= 32 && low
!= 64 && low
!= 128))
103 warning (0, "invalid alignment for %<#pragma align%>, ignoring");
107 ttype
= pragma_lex (&t
);
108 if (ttype
!= CPP_NAME
)
110 warning (0, "malformed %<#pragma align%>, ignoring");
116 tree decl
= identifier_global_value (t
);
117 if (decl
&& DECL_P (decl
))
118 warning (0, "%<#pragma align%> must appear before the declaration of "
119 "%D, ignoring", decl
);
121 solaris_pending_aligns
= tree_cons (t
, build_tree_list (NULL
, x
),
122 solaris_pending_aligns
);
124 ttype
= pragma_lex (&t
);
125 if (ttype
== CPP_COMMA
)
127 ttype
= pragma_lex (&t
);
128 if (ttype
!= CPP_NAME
)
130 warning (0, "malformed %<#pragma align%>");
134 else if (ttype
== CPP_CLOSE_PAREN
)
136 if (pragma_lex (&t
) != CPP_EOF
)
137 warning (0, "junk at end of %<#pragma align%>");
142 warning (0, "malformed %<#pragma align%>");
148 /* Handle #pragma init (function [, function]...) */
151 solaris_pragma_init (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
154 enum cpp_ttype ttype
;
156 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
158 warning (0, "malformed %<#pragma init%>, ignoring");
162 ttype
= pragma_lex (&t
);
163 if (ttype
!= CPP_NAME
)
165 warning (0, "malformed %<#pragma init%>, ignoring");
171 tree decl
= identifier_global_value (t
);
172 if (decl
&& DECL_P (decl
))
174 tree init_list
= build_tree_list (get_identifier ("init"),
176 tree attrs
= tree_cons (get_identifier ("used"), NULL
, init_list
);
177 decl_attributes (&decl
, attrs
, 0);
180 solaris_pending_inits
= tree_cons (t
, NULL
, solaris_pending_inits
);
182 ttype
= pragma_lex (&t
);
183 if (ttype
== CPP_COMMA
)
185 ttype
= pragma_lex (&t
);
186 if (ttype
!= CPP_NAME
)
188 warning (0, "malformed %<#pragma init%>");
192 else if (ttype
== CPP_CLOSE_PAREN
)
194 if (pragma_lex (&t
) != CPP_EOF
)
195 warning (0, "junk at end of %<#pragma init%>");
200 warning (0, "malformed %<#pragma init%>");
206 /* Handle #pragma fini (function [, function]...) */
209 solaris_pragma_fini (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
212 enum cpp_ttype ttype
;
214 if (pragma_lex (&t
) != CPP_OPEN_PAREN
)
216 warning (0, "malformed %<#pragma fini%>, ignoring");
220 ttype
= pragma_lex (&t
);
221 if (ttype
!= CPP_NAME
)
223 warning (0, "malformed %<#pragma fini%>, ignoring");
229 tree decl
= identifier_global_value (t
);
230 if (decl
&& DECL_P (decl
))
232 tree fini_list
= build_tree_list (get_identifier ("fini"),
234 tree attrs
= tree_cons (get_identifier ("used"), NULL
, fini_list
);
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
);