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