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