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