mep-pragma.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* Definitions of Toshiba Media Processor
  2. Copyright (C) 2001-2015 Free Software Foundation, Inc.
  3. Contributed by Red Hat, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. 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 "hash-set.h"
  21. #include "machmode.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "diagnostic-core.h"
  31. #include "c-family/c-pragma.h"
  32. #include "cpplib.h"
  33. #include "hard-reg-set.h"
  34. #include "output.h" /* for decode_reg_name */
  35. #include "mep-protos.h"
  36. #include "input.h"
  37. #include "function.h"
  38. #define MAX_RECOG_OPERANDS 10
  39. #include "reload.h"
  40. #include "target.h"
  41. enum cw_which { CW_AVAILABLE, CW_CALL_SAVED };
  42. /* This is normally provided by rtl.h but we can't include that file
  43. here. It's safe to copy the definition here because we're only
  44. using it internally; the value isn't passed to functions outside
  45. this file. */
  46. #ifndef INVALID_REGNUM
  47. #define INVALID_REGNUM (~(unsigned int) 0)
  48. #endif
  49. static enum cpp_ttype
  50. mep_pragma_lex (tree *valp)
  51. {
  52. enum cpp_ttype t = pragma_lex (valp);
  53. if (t == CPP_EOF)
  54. t = CPP_PRAGMA_EOL;
  55. return t;
  56. }
  57. static void
  58. mep_pragma_io_volatile (cpp_reader *reader ATTRIBUTE_UNUSED)
  59. {
  60. /* On off. */
  61. tree val;
  62. enum cpp_ttype type;
  63. const char * str;
  64. type = mep_pragma_lex (&val);
  65. if (type == CPP_NAME)
  66. {
  67. str = IDENTIFIER_POINTER (val);
  68. type = mep_pragma_lex (&val);
  69. if (type != CPP_PRAGMA_EOL)
  70. warning (0, "junk at end of #pragma io_volatile");
  71. if (strcmp (str, "on") == 0)
  72. {
  73. target_flags |= MASK_IO_VOLATILE;
  74. return;
  75. }
  76. if (strcmp (str, "off") == 0)
  77. {
  78. target_flags &= ~ MASK_IO_VOLATILE;
  79. return;
  80. }
  81. }
  82. error ("#pragma io_volatile takes only on or off");
  83. }
  84. static unsigned int
  85. parse_cr_reg (const char * str)
  86. {
  87. unsigned int regno;
  88. regno = decode_reg_name (str);
  89. if (regno >= FIRST_PSEUDO_REGISTER)
  90. return INVALID_REGNUM;
  91. /* Verify that the regno is in CR_REGS. */
  92. if (! TEST_HARD_REG_BIT (reg_class_contents[CR_REGS], regno))
  93. return INVALID_REGNUM;
  94. return regno;
  95. }
  96. static bool
  97. parse_cr_set (HARD_REG_SET * set)
  98. {
  99. tree val;
  100. enum cpp_ttype type;
  101. unsigned int last_regno = INVALID_REGNUM;
  102. bool do_range = false;
  103. CLEAR_HARD_REG_SET (*set);
  104. while ((type = mep_pragma_lex (&val)) != CPP_PRAGMA_EOL)
  105. {
  106. if (type == CPP_COMMA)
  107. {
  108. last_regno = INVALID_REGNUM;
  109. do_range = false;
  110. }
  111. else if (type == CPP_ELLIPSIS)
  112. {
  113. if (last_regno == INVALID_REGNUM)
  114. {
  115. error ("invalid coprocessor register range");
  116. return false;
  117. }
  118. do_range = true;
  119. }
  120. else if (type == CPP_NAME || type == CPP_STRING)
  121. {
  122. const char *str;
  123. unsigned int regno, i;
  124. if (TREE_CODE (val) == IDENTIFIER_NODE)
  125. str = IDENTIFIER_POINTER (val);
  126. else if (TREE_CODE (val) == STRING_CST)
  127. str = TREE_STRING_POINTER (val);
  128. else
  129. gcc_unreachable ();
  130. regno = parse_cr_reg (str);
  131. if (regno == INVALID_REGNUM)
  132. {
  133. error ("invalid coprocessor register %qE", val);
  134. return false;
  135. }
  136. if (do_range)
  137. {
  138. if (last_regno > regno)
  139. i = regno, regno = last_regno;
  140. else
  141. i = last_regno;
  142. do_range = false;
  143. }
  144. else
  145. last_regno = i = regno;
  146. while (i <= regno)
  147. {
  148. SET_HARD_REG_BIT (*set, i);
  149. i++;
  150. }
  151. }
  152. else
  153. {
  154. error ("malformed coprocessor register");
  155. return false;
  156. }
  157. }
  158. return true;
  159. }
  160. static void
  161. mep_pragma_coprocessor_which (enum cw_which cw_which)
  162. {
  163. HARD_REG_SET set;
  164. /* Process the balance of the pragma and turn it into a hard reg set. */
  165. if (! parse_cr_set (&set))
  166. return;
  167. /* Process the collected hard reg set. */
  168. switch (cw_which)
  169. {
  170. case CW_AVAILABLE:
  171. {
  172. int i;
  173. for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
  174. if (TEST_HARD_REG_BIT (set, i))
  175. fixed_regs[i] = 0;
  176. }
  177. break;
  178. case CW_CALL_SAVED:
  179. {
  180. int i;
  181. for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
  182. if (TEST_HARD_REG_BIT (set, i))
  183. fixed_regs[i] = call_used_regs[i] = 0;
  184. }
  185. break;
  186. default:
  187. gcc_unreachable ();
  188. }
  189. /* Fix up register class hierarchy. */
  190. mep_save_register_info ();
  191. mep_reinit_regs ();
  192. if (cfun == 0)
  193. {
  194. init_dummy_function_start ();
  195. init_caller_save ();
  196. expand_dummy_function_end ();
  197. }
  198. else
  199. {
  200. init_caller_save ();
  201. }
  202. }
  203. static void
  204. mep_pragma_coprocessor_width (void)
  205. {
  206. tree val;
  207. enum cpp_ttype type;
  208. HOST_WIDE_INT i;
  209. type = mep_pragma_lex (&val);
  210. switch (type)
  211. {
  212. case CPP_NUMBER:
  213. if (! tree_fits_uhwi_p (val))
  214. break;
  215. i = tree_to_uhwi (val);
  216. /* This pragma no longer has any effect. */
  217. #if 0
  218. if (i == 32)
  219. target_flags &= ~MASK_64BIT_CR_REGS;
  220. else if (i == 64)
  221. target_flags |= MASK_64BIT_CR_REGS;
  222. else
  223. break;
  224. targetm.init_builtins ();
  225. #else
  226. if (i != 32 && i != 64)
  227. break;
  228. #endif
  229. type = mep_pragma_lex (&val);
  230. if (type != CPP_PRAGMA_EOL)
  231. warning (0, "junk at end of #pragma GCC coprocessor width");
  232. return;
  233. default:
  234. break;
  235. }
  236. error ("#pragma GCC coprocessor width takes only 32 or 64");
  237. }
  238. static void
  239. mep_pragma_coprocessor_subclass (void)
  240. {
  241. tree val;
  242. enum cpp_ttype type;
  243. HARD_REG_SET set;
  244. int class_letter;
  245. enum reg_class rclass;
  246. type = mep_pragma_lex (&val);
  247. if (type != CPP_CHAR)
  248. goto syntax_error;
  249. class_letter = tree_to_uhwi (val);
  250. switch (class_letter)
  251. {
  252. case 'A':
  253. rclass = USER0_REGS;
  254. break;
  255. case 'B':
  256. rclass = USER1_REGS;
  257. break;
  258. case 'C':
  259. rclass = USER2_REGS;
  260. break;
  261. case 'D':
  262. rclass = USER3_REGS;
  263. break;
  264. default:
  265. error ("#pragma GCC coprocessor subclass letter must be in [ABCD]");
  266. return;
  267. }
  268. if (reg_class_size[rclass] > 0)
  269. {
  270. error ("#pragma GCC coprocessor subclass '%c' already defined",
  271. class_letter);
  272. return;
  273. }
  274. type = mep_pragma_lex (&val);
  275. if (type != CPP_EQ)
  276. goto syntax_error;
  277. if (! parse_cr_set (&set))
  278. return;
  279. /* Fix up register class hierarchy. */
  280. COPY_HARD_REG_SET (reg_class_contents[rclass], set);
  281. mep_init_regs ();
  282. return;
  283. syntax_error:
  284. error ("malformed #pragma GCC coprocessor subclass");
  285. }
  286. static void
  287. mep_pragma_disinterrupt (cpp_reader *reader ATTRIBUTE_UNUSED)
  288. {
  289. tree val;
  290. enum cpp_ttype type;
  291. int saw_one = 0;
  292. for (;;)
  293. {
  294. type = mep_pragma_lex (&val);
  295. if (type == CPP_COMMA)
  296. continue;
  297. if (type != CPP_NAME)
  298. break;
  299. mep_note_pragma_disinterrupt (IDENTIFIER_POINTER (val));
  300. saw_one = 1;
  301. }
  302. if (!saw_one || type != CPP_PRAGMA_EOL)
  303. {
  304. error ("malformed #pragma disinterrupt");
  305. return;
  306. }
  307. }
  308. static void
  309. mep_pragma_coprocessor (cpp_reader *reader ATTRIBUTE_UNUSED)
  310. {
  311. tree val;
  312. enum cpp_ttype type;
  313. type = mep_pragma_lex (&val);
  314. if (type != CPP_NAME)
  315. {
  316. error ("malformed #pragma GCC coprocessor");
  317. return;
  318. }
  319. if (!TARGET_COP)
  320. error ("coprocessor not enabled");
  321. if (strcmp (IDENTIFIER_POINTER (val), "available") == 0)
  322. mep_pragma_coprocessor_which (CW_AVAILABLE);
  323. else if (strcmp (IDENTIFIER_POINTER (val), "call_saved") == 0)
  324. mep_pragma_coprocessor_which (CW_CALL_SAVED);
  325. else if (strcmp (IDENTIFIER_POINTER (val), "width") == 0)
  326. mep_pragma_coprocessor_width ();
  327. else if (strcmp (IDENTIFIER_POINTER (val), "subclass") == 0)
  328. mep_pragma_coprocessor_subclass ();
  329. else
  330. error ("unknown #pragma GCC coprocessor %E", val);
  331. }
  332. static void
  333. mep_pragma_call (cpp_reader *reader ATTRIBUTE_UNUSED)
  334. {
  335. tree val;
  336. enum cpp_ttype type;
  337. int saw_one = 0;
  338. for (;;)
  339. {
  340. type = mep_pragma_lex (&val);
  341. if (type == CPP_COMMA)
  342. continue;
  343. if (type != CPP_NAME)
  344. break;
  345. mep_note_pragma_call (IDENTIFIER_POINTER (val));
  346. saw_one = 1;
  347. }
  348. if (!saw_one || type != CPP_PRAGMA_EOL)
  349. {
  350. error ("malformed #pragma call");
  351. return;
  352. }
  353. }
  354. void
  355. mep_register_pragmas (void)
  356. {
  357. c_register_pragma ("custom", "io_volatile", mep_pragma_io_volatile);
  358. c_register_pragma ("GCC", "coprocessor", mep_pragma_coprocessor);
  359. c_register_pragma (0, "disinterrupt", mep_pragma_disinterrupt);
  360. c_register_pragma (0, "call", mep_pragma_call);
  361. }