]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/sh/sh-c.c
2015-06-17 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / config / sh / sh-c.c
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 "alias.h"
26 #include "symtab.h"
27 #include "tree.h"
28 #include "stringpool.h"
29 #include "attribs.h"
30 #include "tm_p.h"
31 #include "cpplib.h"
32 #include "c-family/c-common.h"
33 #include "target.h"
34
35 /* Handle machine specific pragmas to be semi-compatible with Renesas
36 compiler. */
37
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
46 if (current_function_decl)
47 decl_attributes (&current_function_decl,
48 tree_cons (id, NULL_TREE, NULL_TREE), 0);
49 else
50 {
51 *sh_deferred_function_attributes_tail
52 = tree_cons (id, NULL_TREE, *sh_deferred_function_attributes_tail);
53 sh_deferred_function_attributes_tail
54 = &TREE_CHAIN (*sh_deferred_function_attributes_tail);
55 }
56 }
57
58 void
59 sh_pr_interrupt (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
60 {
61 sh_add_function_attribute ("interrupt_handler");
62 }
63
64 void
65 sh_pr_trapa (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
66 {
67 sh_add_function_attribute ("trapa_handler");
68 }
69
70 void
71 sh_pr_nosave_low_regs (struct cpp_reader *pfile ATTRIBUTE_UNUSED)
72 {
73 sh_add_function_attribute ("nosave_low_regs");
74 }
75
76 #define builtin_define(TXT) cpp_define (pfile, TXT)
77 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
78
79 /* Implement the TARGET_CPU_CPP_BUILTINS macro */
80 void
81 sh_cpu_cpp_builtins (cpp_reader* pfile)
82 {
83 builtin_define ("__sh__");
84 builtin_assert ("cpu=sh");
85 builtin_assert ("machine=sh");
86 switch ((int) sh_cpu)
87 {
88 case PROCESSOR_SH1:
89 builtin_define ("__sh1__");
90 builtin_define ("__SH1__");
91 break;
92 case PROCESSOR_SH2:
93 builtin_define ("__sh2__");
94 builtin_define ("__SH2__");
95 break;
96 case PROCESSOR_SH2E:
97 builtin_define ("__SH2E__");
98 break;
99 case PROCESSOR_SH2A:
100 builtin_define ("__SH2A__");
101 if (TARGET_SH2A_DOUBLE)
102 builtin_define (TARGET_FPU_SINGLE
103 ? "__SH2A_SINGLE__" : "__SH2A_DOUBLE__");
104 else
105 builtin_define (TARGET_FPU_ANY
106 ? "__SH2A_SINGLE_ONLY__" : "__SH2A_NOFPU__");
107 break;
108 case PROCESSOR_SH3:
109 builtin_define ("__sh3__");
110 builtin_define ("__SH3__");
111 if (TARGET_HARD_SH4)
112 builtin_define ("__SH4_NOFPU__");
113 break;
114 case PROCESSOR_SH3E:
115 builtin_define (TARGET_HARD_SH4 ? "__SH4_SINGLE_ONLY__" : "__SH3E__");
116 break;
117 case PROCESSOR_SH4:
118 builtin_define (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__");
119 break;
120 case PROCESSOR_SH4A: \
121 builtin_define ("__SH4A__");
122 builtin_define (TARGET_SH4
123 ? (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__")
124 : TARGET_FPU_ANY ? "__SH4_SINGLE_ONLY__"
125 : "__SH4_NOFPU__");
126 break;
127 case PROCESSOR_SH5:
128 {
129 builtin_define_with_value ("__SH5__",
130 TARGET_SHMEDIA64 ? "64" : "32", 0);
131 builtin_define_with_value ("__SHMEDIA__",
132 TARGET_SHMEDIA ? "1" : "0", 0);
133 if (! TARGET_FPU_DOUBLE)
134 builtin_define ("__SH4_NOFPU__");
135 }
136 }
137 if (TARGET_FPU_ANY)
138 builtin_define ("__SH_FPU_ANY__");
139 if (TARGET_FPU_DOUBLE)
140 builtin_define ("__SH_FPU_DOUBLE__");
141 if (TARGET_HITACHI)
142 builtin_define ("__HITACHI__");
143 if (TARGET_FMOVD)
144 builtin_define ("__FMOVD_ENABLED__");
145 builtin_define (TARGET_LITTLE_ENDIAN
146 ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__");
147
148 cpp_define_formatted (pfile, "__SH_ATOMIC_MODEL_%s__",
149 selected_atomic_model ().cdef_name);
150 }