sol2-c.c 7.4 KB

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