v850-c.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* v850 specific, C compiler specific functions.
  2. Copyright (C) 2000-2015 Free Software Foundation, Inc.
  3. Contributed by Jeff Law (law@cygnus.com).
  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 "tm.h"
  20. #include "cpplib.h"
  21. #include "hash-set.h"
  22. #include "machmode.h"
  23. #include "vec.h"
  24. #include "double-int.h"
  25. #include "input.h"
  26. #include "alias.h"
  27. #include "symtab.h"
  28. #include "wide-int.h"
  29. #include "inchash.h"
  30. #include "tree.h"
  31. #include "stringpool.h"
  32. #include "attribs.h"
  33. #include "c-family/c-pragma.h"
  34. #include "diagnostic-core.h"
  35. #include "ggc.h"
  36. #include "tm_p.h"
  37. #ifndef streq
  38. #define streq(a,b) (strcmp (a, b) == 0)
  39. #endif
  40. static int pop_data_area (v850_data_area);
  41. static int push_data_area (v850_data_area);
  42. static void mark_current_function_as_interrupt (void);
  43. /* Push a data area onto the stack. */
  44. static int
  45. push_data_area (v850_data_area data_area)
  46. {
  47. data_area_stack_element * elem;
  48. elem = (data_area_stack_element *) xmalloc (sizeof (* elem));
  49. if (elem == NULL)
  50. return 0;
  51. elem->prev = data_area_stack;
  52. elem->data_area = data_area;
  53. data_area_stack = elem;
  54. return 1;
  55. }
  56. /* Remove a data area from the stack. */
  57. static int
  58. pop_data_area (v850_data_area data_area)
  59. {
  60. if (data_area_stack == NULL)
  61. warning (OPT_Wpragmas, "#pragma GHS endXXXX found without "
  62. "previous startXXX");
  63. else if (data_area != data_area_stack->data_area)
  64. warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
  65. "previous startXXX");
  66. else
  67. {
  68. data_area_stack_element * elem;
  69. elem = data_area_stack;
  70. data_area_stack = data_area_stack->prev;
  71. free (elem);
  72. return 1;
  73. }
  74. return 0;
  75. }
  76. /* Set the machine specific 'interrupt' attribute on the current function. */
  77. static void
  78. mark_current_function_as_interrupt (void)
  79. {
  80. tree name;
  81. if (current_function_decl == NULL_TREE)
  82. {
  83. warning (0, "cannot set interrupt attribute: no current function");
  84. return;
  85. }
  86. name = get_identifier ("interrupt");
  87. if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
  88. {
  89. warning (0, "cannot set interrupt attribute: no such identifier");
  90. return;
  91. }
  92. decl_attributes (&current_function_decl,
  93. tree_cons (name, NULL_TREE, NULL_TREE), 0);
  94. }
  95. /* Support for GHS pragmata. */
  96. void
  97. ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
  98. {
  99. int repeat = 0;
  100. /* #pragma ghs section [name = alias [, name = alias [, ...]]] */
  101. do
  102. {
  103. tree x;
  104. enum cpp_ttype type;
  105. tree sect_ident;
  106. const char *sect, *alias;
  107. enum GHS_section_kind kind;
  108. type = pragma_lex (&x);
  109. if (type == CPP_EOF && !repeat)
  110. goto reset;
  111. else if (type == CPP_NAME)
  112. {
  113. sect_ident = x;
  114. sect = IDENTIFIER_POINTER (sect_ident);
  115. }
  116. else
  117. goto bad;
  118. repeat = 0;
  119. if (pragma_lex (&x) != CPP_EQ)
  120. goto bad;
  121. if (pragma_lex (&x) != CPP_NAME)
  122. goto bad;
  123. alias = IDENTIFIER_POINTER (x);
  124. type = pragma_lex (&x);
  125. if (type == CPP_COMMA)
  126. repeat = 1;
  127. else if (type != CPP_EOF)
  128. warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
  129. if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA;
  130. else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT;
  131. else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA;
  132. else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA;
  133. else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA;
  134. else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA;
  135. else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA;
  136. else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA;
  137. else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA;
  138. /* According to GHS beta documentation, the following should not be
  139. allowed! */
  140. else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS;
  141. else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA;
  142. else
  143. {
  144. warning (0, "unrecognized section name %qE", sect_ident);
  145. return;
  146. }
  147. if (streq (alias, "default"))
  148. GHS_current_section_names [kind] = NULL;
  149. else
  150. GHS_current_section_names [kind] = alias;
  151. }
  152. while (repeat);
  153. return;
  154. bad:
  155. warning (OPT_Wpragmas, "malformed #pragma ghs section");
  156. return;
  157. reset:
  158. /* #pragma ghs section \n: Reset all section names back to their defaults. */
  159. {
  160. int i;
  161. for (i = COUNT_OF_GHS_SECTION_KINDS; i--;)
  162. GHS_current_section_names [i] = NULL;
  163. }
  164. }
  165. void
  166. ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED)
  167. {
  168. tree x;
  169. if (pragma_lex (&x) != CPP_EOF)
  170. warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
  171. mark_current_function_as_interrupt ();
  172. }
  173. void
  174. ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  175. {
  176. tree x;
  177. if (pragma_lex (&x) != CPP_EOF)
  178. warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
  179. push_data_area (DATA_AREA_TDA);
  180. }
  181. void
  182. ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  183. {
  184. tree x;
  185. if (pragma_lex (&x) != CPP_EOF)
  186. warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
  187. push_data_area (DATA_AREA_SDA);
  188. }
  189. void
  190. ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  191. {
  192. tree x;
  193. if (pragma_lex (&x) != CPP_EOF)
  194. warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
  195. push_data_area (DATA_AREA_ZDA);
  196. }
  197. void
  198. ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  199. {
  200. tree x;
  201. if (pragma_lex (&x) != CPP_EOF)
  202. warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
  203. pop_data_area (DATA_AREA_TDA);
  204. }
  205. void
  206. ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  207. {
  208. tree x;
  209. if (pragma_lex (&x) != CPP_EOF)
  210. warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
  211. pop_data_area (DATA_AREA_SDA);
  212. }
  213. void
  214. ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
  215. {
  216. tree x;
  217. if (pragma_lex (&x) != CPP_EOF)
  218. warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
  219. pop_data_area (DATA_AREA_ZDA);
  220. }