]>
Commit | Line | Data |
---|---|---|
c3edd394 | 1 | /* v850 specific, C compiler specific functions. |
2f83c7d6 | 2 | Copyright (C) 2000, 2007 Free Software Foundation, Inc. |
c3edd394 NC |
3 | Contributed by Jeff Law (law@cygnus.com). |
4 | ||
301ee2f3 | 5 | This file is part of GCC. |
c3edd394 | 6 | |
301ee2f3 | 7 | GCC is free software; you can redistribute it and/or modify |
c3edd394 | 8 | it under the terms of the GNU General Public License as published by |
2f83c7d6 | 9 | the Free Software Foundation; either version 3, or (at your option) |
c3edd394 NC |
10 | any later version. |
11 | ||
301ee2f3 | 12 | GCC is distributed in the hope that it will be useful, |
c3edd394 NC |
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 | |
2f83c7d6 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
c3edd394 NC |
20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
4977bab6 ZW |
23 | #include "coretypes.h" |
24 | #include "tm.h" | |
c3edd394 NC |
25 | #include "cpplib.h" |
26 | #include "tree.h" | |
27 | #include "c-pragma.h" | |
c3edd394 NC |
28 | #include "toplev.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 | \f | |
59f3507d NN |
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); | |
c3edd394 NC |
39 | \f |
40 | /* Push a data area onto the stack. */ | |
41 | ||
42 | static int | |
59f3507d | 43 | push_data_area (v850_data_area data_area) |
c3edd394 NC |
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 | |
59f3507d | 63 | pop_data_area (v850_data_area data_area) |
c3edd394 NC |
64 | { |
65 | if (data_area_stack == NULL) | |
b9b8dde3 DD |
66 | warning (OPT_Wpragmas, "#pragma GHS endXXXX found without " |
67 | "previous startXXX"); | |
c3edd394 | 68 | else if (data_area != data_area_stack->data_area) |
b9b8dde3 DD |
69 | warning (OPT_Wpragmas, "#pragma GHS endXXX does not match " |
70 | "previous startXXX"); | |
c3edd394 NC |
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 | ||
91d231cb | 88 | static void |
59f3507d | 89 | mark_current_function_as_interrupt (void) |
c3edd394 NC |
90 | { |
91 | tree name; | |
92 | ||
93 | if (current_function_decl == NULL_TREE) | |
94 | { | |
d4ee4d25 | 95 | warning (0, "cannot set interrupt attribute: no current function"); |
1943c2c1 | 96 | return; |
c3edd394 NC |
97 | } |
98 | ||
99 | name = get_identifier ("interrupt"); | |
100 | ||
101 | if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE) | |
102 | { | |
d4ee4d25 | 103 | warning (0, "cannot set interrupt attribute: no such identifier"); |
1943c2c1 | 104 | return; |
c3edd394 NC |
105 | } |
106 | ||
91d231cb JM |
107 | decl_attributes (¤t_function_decl, |
108 | tree_cons (name, NULL_TREE, NULL_TREE), 0); | |
c3edd394 NC |
109 | } |
110 | ||
111 | \f | |
112 | /* Support for GHS pragmata. */ | |
113 | ||
114 | void | |
59f3507d | 115 | ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
116 | { |
117 | int repeat; | |
118 | ||
119 | /* #pragma ghs section [name = alias [, name = alias [, ...]]] */ | |
120 | do | |
121 | { | |
122 | tree x; | |
123 | enum cpp_ttype type; | |
124 | const char *sect, *alias; | |
125 | enum GHS_section_kind kind; | |
126 | ||
75ce3d48 | 127 | type = pragma_lex (&x); |
c3edd394 NC |
128 | |
129 | if (type == CPP_EOF && !repeat) | |
130 | goto reset; | |
131 | else if (type == CPP_NAME) | |
132 | sect = IDENTIFIER_POINTER (x); | |
133 | else | |
134 | goto bad; | |
135 | repeat = 0; | |
136 | ||
75ce3d48 | 137 | if (pragma_lex (&x) != CPP_EQ) |
c3edd394 | 138 | goto bad; |
75ce3d48 | 139 | if (pragma_lex (&x) != CPP_NAME) |
c3edd394 NC |
140 | goto bad; |
141 | ||
142 | alias = IDENTIFIER_POINTER (x); | |
143 | ||
75ce3d48 | 144 | type = pragma_lex (&x); |
c3edd394 NC |
145 | if (type == CPP_COMMA) |
146 | repeat = 1; | |
147 | else if (type != CPP_EOF) | |
b9b8dde3 | 148 | warning (OPT_Wpragmas, "junk at end of #pragma ghs section"); |
c3edd394 NC |
149 | |
150 | if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA; | |
151 | else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT; | |
152 | else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA; | |
153 | else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA; | |
154 | else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA; | |
155 | else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA; | |
156 | else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA; | |
157 | else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA; | |
158 | else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA; | |
159 | /* According to GHS beta documentation, the following should not be | |
160 | allowed! */ | |
161 | else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS; | |
162 | else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA; | |
163 | else | |
164 | { | |
d4ee4d25 | 165 | warning (0, "unrecognized section name \"%s\"", sect); |
c3edd394 NC |
166 | return; |
167 | } | |
168 | ||
169 | if (streq (alias, "default")) | |
170 | GHS_current_section_names [kind] = NULL; | |
171 | else | |
172 | GHS_current_section_names [kind] = | |
173 | build_string (strlen (alias) + 1, alias); | |
174 | } | |
175 | while (repeat); | |
176 | ||
177 | return; | |
178 | ||
179 | bad: | |
b9b8dde3 | 180 | warning (OPT_Wpragmas, "malformed #pragma ghs section"); |
c3edd394 NC |
181 | return; |
182 | ||
183 | reset: | |
184 | /* #pragma ghs section \n: Reset all section names back to their defaults. */ | |
185 | { | |
186 | int i; | |
187 | ||
188 | for (i = COUNT_OF_GHS_SECTION_KINDS; i--;) | |
189 | GHS_current_section_names [i] = NULL; | |
190 | } | |
191 | } | |
192 | ||
193 | void | |
59f3507d | 194 | ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
195 | { |
196 | tree x; | |
197 | ||
75ce3d48 | 198 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 199 | warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt"); |
c3edd394 NC |
200 | |
201 | mark_current_function_as_interrupt (); | |
202 | } | |
203 | ||
204 | void | |
59f3507d | 205 | ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
206 | { |
207 | tree x; | |
208 | ||
75ce3d48 | 209 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 210 | warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda"); |
c3edd394 NC |
211 | |
212 | push_data_area (DATA_AREA_TDA); | |
213 | } | |
214 | ||
215 | void | |
59f3507d | 216 | ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
217 | { |
218 | tree x; | |
219 | ||
75ce3d48 | 220 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 221 | warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda"); |
c3edd394 NC |
222 | |
223 | push_data_area (DATA_AREA_SDA); | |
224 | } | |
225 | ||
226 | void | |
59f3507d | 227 | ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
228 | { |
229 | tree x; | |
230 | ||
75ce3d48 | 231 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 232 | warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda"); |
c3edd394 NC |
233 | |
234 | push_data_area (DATA_AREA_ZDA); | |
235 | } | |
236 | ||
237 | void | |
59f3507d | 238 | ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
239 | { |
240 | tree x; | |
241 | ||
75ce3d48 | 242 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 243 | warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda"); |
c3edd394 NC |
244 | |
245 | pop_data_area (DATA_AREA_TDA); | |
246 | } | |
247 | ||
248 | void | |
59f3507d | 249 | ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
250 | { |
251 | tree x; | |
252 | ||
75ce3d48 | 253 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 254 | warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda"); |
c3edd394 NC |
255 | |
256 | pop_data_area (DATA_AREA_SDA); | |
257 | } | |
258 | ||
259 | void | |
59f3507d | 260 | ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED) |
c3edd394 NC |
261 | { |
262 | tree x; | |
263 | ||
75ce3d48 | 264 | if (pragma_lex (&x) != CPP_EOF) |
b9b8dde3 | 265 | warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda"); |
c3edd394 NC |
266 | |
267 | pop_data_area (DATA_AREA_ZDA); | |
268 | } |