sh-c.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Pragma handling for GCC for Renesas / SuperH SH.
  2. Copyright (C) 1993-2015 Free Software Foundation, Inc.
  3. Contributed by Joern Rennecke <joern.rennecke@st.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 "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 "stringpool.h"
  31. #include "attribs.h"
  32. #include "tm_p.h"
  33. #include "cpplib.h"
  34. #include "c-family/c-common.h"
  35. #include "target.h"
  36. /* Handle machine specific pragmas to be semi-compatible with Renesas
  37. compiler. */
  38. /* Add ATTR to the attributes of the current function. If there is no
  39. such function, save it to be added to the attributes of the next
  40. function. */
  41. static void
  42. sh_add_function_attribute (const char *attr)
  43. {
  44. tree id = get_identifier (attr);
  45. if (current_function_decl)
  46. decl_attributes (&current_function_decl,
  47. tree_cons (id, NULL_TREE, NULL_TREE), 0);
  48. else
  49. {
  50. *sh_deferred_function_attributes_tail
  51. = tree_cons (id, NULL_TREE, *sh_deferred_function_attributes_tail);
  52. sh_deferred_function_attributes_tail
  53. = &TREE_CHAIN (*sh_deferred_function_attributes_tail);
  54. }
  55. }
  56. void
  57. sh_pr_interrupt (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
  58. {
  59. sh_add_function_attribute ("interrupt_handler");
  60. }
  61. void
  62. sh_pr_trapa (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
  63. {
  64. sh_add_function_attribute ("trapa_handler");
  65. }
  66. void
  67. sh_pr_nosave_low_regs (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
  68. {
  69. sh_add_function_attribute ("nosave_low_regs");
  70. }
  71. #define builtin_define(TXT) cpp_define (pfile, TXT)
  72. #define builtin_assert(TXT) cpp_assert (pfile, TXT)
  73. /* Implement the TARGET_CPU_CPP_BUILTINS macro */
  74. void
  75. sh_cpu_cpp_builtins (cpp_reader* pfile)
  76. {
  77. builtin_define ("__sh__");
  78. builtin_assert ("cpu=sh");
  79. builtin_assert ("machine=sh");
  80. switch ((int) sh_cpu)
  81. {
  82. case PROCESSOR_SH1:
  83. builtin_define ("__sh1__");
  84. builtin_define ("__SH1__");
  85. break;
  86. case PROCESSOR_SH2:
  87. builtin_define ("__sh2__");
  88. builtin_define ("__SH2__");
  89. break;
  90. case PROCESSOR_SH2E:
  91. builtin_define ("__SH2E__");
  92. break;
  93. case PROCESSOR_SH2A:
  94. builtin_define ("__SH2A__");
  95. if (TARGET_SH2A_DOUBLE)
  96. builtin_define (TARGET_FPU_SINGLE
  97. ? "__SH2A_SINGLE__" : "__SH2A_DOUBLE__");
  98. else
  99. builtin_define (TARGET_FPU_ANY
  100. ? "__SH2A_SINGLE_ONLY__" : "__SH2A_NOFPU__");
  101. break;
  102. case PROCESSOR_SH3:
  103. builtin_define ("__sh3__");
  104. builtin_define ("__SH3__");
  105. if (TARGET_HARD_SH4)
  106. builtin_define ("__SH4_NOFPU__");
  107. break;
  108. case PROCESSOR_SH3E:
  109. builtin_define (TARGET_HARD_SH4 ? "__SH4_SINGLE_ONLY__" : "__SH3E__");
  110. break;
  111. case PROCESSOR_SH4:
  112. builtin_define (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__");
  113. break;
  114. case PROCESSOR_SH4A: \
  115. builtin_define ("__SH4A__");
  116. builtin_define (TARGET_SH4
  117. ? (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__")
  118. : TARGET_FPU_ANY ? "__SH4_SINGLE_ONLY__"
  119. : "__SH4_NOFPU__");
  120. break;
  121. case PROCESSOR_SH5:
  122. {
  123. builtin_define_with_value ("__SH5__",
  124. TARGET_SHMEDIA64 ? "64" : "32", 0);
  125. builtin_define_with_value ("__SHMEDIA__",
  126. TARGET_SHMEDIA ? "1" : "0", 0);
  127. if (! TARGET_FPU_DOUBLE)
  128. builtin_define ("__SH4_NOFPU__");
  129. }
  130. }
  131. if (TARGET_FPU_ANY)
  132. builtin_define ("__SH_FPU_ANY__");
  133. if (TARGET_FPU_DOUBLE)
  134. builtin_define ("__SH_FPU_DOUBLE__");
  135. if (TARGET_HITACHI)
  136. builtin_define ("__HITACHI__");
  137. if (TARGET_FMOVD)
  138. builtin_define ("__FMOVD_ENABLED__");
  139. builtin_define (TARGET_LITTLE_ENDIAN
  140. ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__");
  141. cpp_define_formatted (pfile, "__SH_ATOMIC_MODEL_%s__",
  142. selected_atomic_model ().cdef_name);
  143. }