1 /* v850 specific, C compiler specific functions.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Contributed by Jeff Law (law@cygnus.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 "cpplib.h"
26 #include "tree.h"
27 #include "c-family/c-pragma.h"
28 #include "diagnostic-core.h"
29 #include "ggc.h"
30 #include "tm_p.h"
31
32 #ifndef streq
33 #define streq(a,b) (strcmp (a, b) == 0)
34 #endif
35
36 static int pop_data_area (v850_data_area);
37 static int push_data_area (v850_data_area);
38 static void mark_current_function_as_interrupt (void);
39
40 /* Push a data area onto the stack. */
41
42 static int
push_data_area(v850_data_area data_area)43 push_data_area (v850_data_area data_area)
44 {
45 data_area_stack_element * elem;
46
47 elem = (data_area_stack_element *) xmalloc (sizeof (* elem));
48
49 if (elem == NULL)
50 return 0;
51
52 elem->prev = data_area_stack;
53 elem->data_area = data_area;
54
55 data_area_stack = elem;
56
57 return 1;
58 }
59
60 /* Remove a data area from the stack. */
61
62 static int
pop_data_area(v850_data_area data_area)63 pop_data_area (v850_data_area data_area)
64 {
65 if (data_area_stack == NULL)
66 warning (OPT_Wpragmas, "#pragma GHS endXXXX found without "
67 "previous startXXX");
68 else if (data_area != data_area_stack->data_area)
69 warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
70 "previous startXXX");
71 else
72 {
73 data_area_stack_element * elem;
74
75 elem = data_area_stack;
76 data_area_stack = data_area_stack->prev;
77
78 free (elem);
79
80 return 1;
81 }
82
83 return 0;
84 }
85
86 /* Set the machine specific 'interrupt' attribute on the current function. */
87
88 static void
mark_current_function_as_interrupt(void)89 mark_current_function_as_interrupt (void)
90 {
91 tree name;
92
93 if (current_function_decl == NULL_TREE)
94 {
95 warning (0, "cannot set interrupt attribute: no current function");
96 return;
97 }
98
99 name = get_identifier ("interrupt");
100
101 if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
102 {
103 warning (0, "cannot set interrupt attribute: no such identifier");
104 return;
105 }
106
107 decl_attributes (¤t_function_decl,
108 tree_cons (name, NULL_TREE, NULL_TREE), 0);
109 }
110
111
112 /* Support for GHS pragmata. */
113
114 void
ghs_pragma_section(cpp_reader * pfile ATTRIBUTE_UNUSED)115 ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
116 {
117 int repeat = 0;
118
119 /* #pragma ghs section [name = alias [, name = alias [, ...]]] */
120 do
121 {
122 tree x;
123 enum cpp_ttype type;
124 tree sect_ident;
125 const char *sect, *alias;
126 enum GHS_section_kind kind;
127
128 type = pragma_lex (&x);
129
130 if (type == CPP_EOF && !repeat)
131 goto reset;
132 else if (type == CPP_NAME)
133 {
134 sect_ident = x;
135 sect = IDENTIFIER_POINTER (sect_ident);
136 }
137 else
138 goto bad;
139 repeat = 0;
140
141 if (pragma_lex (&x) != CPP_EQ)
142 goto bad;
143 if (pragma_lex (&x) != CPP_NAME)
144 goto bad;
145
146 alias = IDENTIFIER_POINTER (x);
147
148 type = pragma_lex (&x);
149 if (type == CPP_COMMA)
150 repeat = 1;
151 else if (type != CPP_EOF)
152 warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
153
154 if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA;
155 else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT;
156 else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA;
157 else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA;
158 else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA;
159 else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA;
160 else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA;
161 else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA;
162 else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA;
163 /* According to GHS beta documentation, the following should not be
164 allowed! */
165 else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS;
166 else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA;
167 else
168 {
169 warning (0, "unrecognized section name %qE", sect_ident);
170 return;
171 }
172
173 if (streq (alias, "default"))
174 GHS_current_section_names [kind] = NULL;
175 else
176 GHS_current_section_names [kind] =
177 build_string (strlen (alias) + 1, alias);
178 }
179 while (repeat);
180
181 return;
182
183 bad:
184 warning (OPT_Wpragmas, "malformed #pragma ghs section");
185 return;
186
187 reset:
188 /* #pragma ghs section \n: Reset all section names back to their defaults. */
189 {
190 int i;
191
192 for (i = COUNT_OF_GHS_SECTION_KINDS; i--;)
193 GHS_current_section_names [i] = NULL;
194 }
195 }
196
197 void
ghs_pragma_interrupt(cpp_reader * pfile ATTRIBUTE_UNUSED)198 ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED)
199 {
200 tree x;
201
202 if (pragma_lex (&x) != CPP_EOF)
203 warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
204
205 mark_current_function_as_interrupt ();
206 }
207
208 void
ghs_pragma_starttda(cpp_reader * pfile ATTRIBUTE_UNUSED)209 ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED)
210 {
211 tree x;
212
213 if (pragma_lex (&x) != CPP_EOF)
214 warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
215
216 push_data_area (DATA_AREA_TDA);
217 }
218
219 void
ghs_pragma_startsda(cpp_reader * pfile ATTRIBUTE_UNUSED)220 ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
221 {
222 tree x;
223
224 if (pragma_lex (&x) != CPP_EOF)
225 warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
226
227 push_data_area (DATA_AREA_SDA);
228 }
229
230 void
ghs_pragma_startzda(cpp_reader * pfile ATTRIBUTE_UNUSED)231 ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
232 {
233 tree x;
234
235 if (pragma_lex (&x) != CPP_EOF)
236 warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
237
238 push_data_area (DATA_AREA_ZDA);
239 }
240
241 void
ghs_pragma_endtda(cpp_reader * pfile ATTRIBUTE_UNUSED)242 ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED)
243 {
244 tree x;
245
246 if (pragma_lex (&x) != CPP_EOF)
247 warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
248
249 pop_data_area (DATA_AREA_TDA);
250 }
251
252 void
ghs_pragma_endsda(cpp_reader * pfile ATTRIBUTE_UNUSED)253 ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
254 {
255 tree x;
256
257 if (pragma_lex (&x) != CPP_EOF)
258 warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
259
260 pop_data_area (DATA_AREA_SDA);
261 }
262
263 void
ghs_pragma_endzda(cpp_reader * pfile ATTRIBUTE_UNUSED)264 ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
265 {
266 tree x;
267
268 if (pragma_lex (&x) != CPP_EOF)
269 warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
270
271 pop_data_area (DATA_AREA_ZDA);
272 }
273