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 5 This file is part of GCC. 6 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 3, or (at your option) 10 any later version. 11 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. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING3. If not see 19 <http://www.gnu.org/licenses/>. */ 20 21 #include "config.h" 22 #include "system.h" 23 #include "coretypes.h" 24 #include "tm.h" 25 #include "hash-set.h" 26 #include "machmode.h" 27 #include "vec.h" 28 #include "double-int.h" 29 #include "input.h" 30 #include "alias.h" 31 #include "symtab.h" 32 #include "wide-int.h" 33 #include "inchash.h" 34 #include "tree.h" 35 #include "stringpool.h" 36 #include "attribs.h" 37 #include "tm_p.h" 38 #include "cpplib.h" 39 #include "c-family/c-common.h" 40 #include "target.h" 41 42 /* Handle machine specific pragmas to be semi-compatible with Renesas 43 compiler. */ 44 45 /* Add ATTR to the attributes of the current function. If there is no 46 such function, save it to be added to the attributes of the next 47 function. */ 48 static void 49 sh_add_function_attribute (const char *attr) 50 { 51 tree id = get_identifier (attr); 52 53 if (current_function_decl) 54 decl_attributes (¤t_function_decl, 55 tree_cons (id, NULL_TREE, NULL_TREE), 0); 56 else 57 { 58 *sh_deferred_function_attributes_tail 59 = tree_cons (id, NULL_TREE, *sh_deferred_function_attributes_tail); 60 sh_deferred_function_attributes_tail 61 = &TREE_CHAIN (*sh_deferred_function_attributes_tail); 62 } 63 } 64 65 void 66 sh_pr_interrupt (struct cpp_reader *pfile ATTRIBUTE_UNUSED) 67 { 68 sh_add_function_attribute ("interrupt_handler"); 69 } 70 71 void 72 sh_pr_trapa (struct cpp_reader *pfile ATTRIBUTE_UNUSED) 73 { 74 sh_add_function_attribute ("trapa_handler"); 75 } 76 77 void 78 sh_pr_nosave_low_regs (struct cpp_reader *pfile ATTRIBUTE_UNUSED) 79 { 80 sh_add_function_attribute ("nosave_low_regs"); 81 } 82 83 #define builtin_define(TXT) cpp_define (pfile, TXT) 84 #define builtin_assert(TXT) cpp_assert (pfile, TXT) 85 86 /* Implement the TARGET_CPU_CPP_BUILTINS macro */ 87 void 88 sh_cpu_cpp_builtins (cpp_reader* pfile) 89 { 90 builtin_define ("__sh__"); 91 builtin_assert ("cpu=sh"); 92 builtin_assert ("machine=sh"); 93 switch ((int) sh_cpu) 94 { 95 case PROCESSOR_SH1: 96 builtin_define ("__sh1__"); 97 builtin_define ("__SH1__"); 98 break; 99 case PROCESSOR_SH2: 100 builtin_define ("__sh2__"); 101 builtin_define ("__SH2__"); 102 break; 103 case PROCESSOR_SH2E: 104 builtin_define ("__SH2E__"); 105 break; 106 case PROCESSOR_SH2A: 107 builtin_define ("__SH2A__"); 108 if (TARGET_SH2A_DOUBLE) 109 builtin_define (TARGET_FPU_SINGLE 110 ? "__SH2A_SINGLE__" : "__SH2A_DOUBLE__"); 111 else 112 builtin_define (TARGET_FPU_ANY 113 ? "__SH2A_SINGLE_ONLY__" : "__SH2A_NOFPU__"); 114 break; 115 case PROCESSOR_SH3: 116 builtin_define ("__sh3__"); 117 builtin_define ("__SH3__"); 118 if (TARGET_HARD_SH4) 119 builtin_define ("__SH4_NOFPU__"); 120 break; 121 case PROCESSOR_SH3E: 122 builtin_define (TARGET_HARD_SH4 ? "__SH4_SINGLE_ONLY__" : "__SH3E__"); 123 break; 124 case PROCESSOR_SH4: 125 builtin_define (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__"); 126 break; 127 case PROCESSOR_SH4A: \ 128 builtin_define ("__SH4A__"); 129 builtin_define (TARGET_SH4 130 ? (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__") 131 : TARGET_FPU_ANY ? "__SH4_SINGLE_ONLY__" 132 : "__SH4_NOFPU__"); 133 break; 134 case PROCESSOR_SH5: 135 { 136 builtin_define_with_value ("__SH5__", 137 TARGET_SHMEDIA64 ? "64" : "32", 0); 138 builtin_define_with_value ("__SHMEDIA__", 139 TARGET_SHMEDIA ? "1" : "0", 0); 140 if (! TARGET_FPU_DOUBLE) 141 builtin_define ("__SH4_NOFPU__"); 142 } 143 } 144 if (TARGET_FPU_ANY) 145 builtin_define ("__SH_FPU_ANY__"); 146 if (TARGET_FPU_DOUBLE) 147 builtin_define ("__SH_FPU_DOUBLE__"); 148 if (TARGET_HITACHI) 149 builtin_define ("__HITACHI__"); 150 if (TARGET_FMOVD) 151 builtin_define ("__FMOVD_ENABLED__"); 152 builtin_define (TARGET_LITTLE_ENDIAN 153 ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__"); 154 155 cpp_define_formatted (pfile, "__SH_ATOMIC_MODEL_%s__", 156 selected_atomic_model ().cdef_name); 157 } 158