]>
Commit | Line | Data |
---|---|---|
c3edd394 NC |
1 | /* v850 specific, C compiler specific functions. |
2 | Copyright (C) 2000 Free Software Foundation, Inc. | |
3 | Contributed by Jeff Law (law@cygnus.com). | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC 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 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC 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 GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
4977bab6 ZW |
24 | #include "coretypes.h" |
25 | #include "tm.h" | |
c3edd394 NC |
26 | #include "cpplib.h" |
27 | #include "tree.h" | |
28 | #include "c-pragma.h" | |
c3edd394 NC |
29 | #include "toplev.h" |
30 | #include "ggc.h" | |
31 | #include "tm_p.h" | |
32 | ||
33 | #ifndef streq | |
34 | #define streq(a,b) (strcmp (a, b) == 0) | |
35 | #endif | |
36 | \f | |
37 | static int pop_data_area PARAMS ((v850_data_area)); | |
38 | static int push_data_area PARAMS ((v850_data_area)); | |
91d231cb | 39 | static void mark_current_function_as_interrupt PARAMS ((void)); |
c3edd394 NC |
40 | \f |
41 | /* Push a data area onto the stack. */ | |
42 | ||
43 | static int | |
44 | push_data_area (data_area) | |
45 | 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 (data_area) | |
66 | v850_data_area data_area; | |
67 | { | |
68 | if (data_area_stack == NULL) | |
69 | warning ("#pragma GHS endXXXX found without previous startXXX"); | |
70 | else if (data_area != data_area_stack->data_area) | |
71 | warning ("#pragma GHS endXXX does not match previous startXXX"); | |
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 |
c3edd394 NC |
90 | mark_current_function_as_interrupt () |
91 | { | |
92 | tree name; | |
93 | ||
94 | if (current_function_decl == NULL_TREE) | |
95 | { | |
c725bd79 | 96 | warning ("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 | { | |
c725bd79 | 104 | warning ("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 | |
116 | ghs_pragma_section (pfile) | |
117 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
118 | { | |
119 | int repeat; | |
120 | ||
121 | /* #pragma ghs section [name = alias [, name = alias [, ...]]] */ | |
122 | do | |
123 | { | |
124 | tree x; | |
125 | enum cpp_ttype type; | |
126 | const char *sect, *alias; | |
127 | enum GHS_section_kind kind; | |
128 | ||
129 | type = c_lex (&x); | |
130 | ||
131 | if (type == CPP_EOF && !repeat) | |
132 | goto reset; | |
133 | else if (type == CPP_NAME) | |
134 | sect = IDENTIFIER_POINTER (x); | |
135 | else | |
136 | goto bad; | |
137 | repeat = 0; | |
138 | ||
139 | if (c_lex (&x) != CPP_EQ) | |
140 | goto bad; | |
141 | if (c_lex (&x) != CPP_NAME) | |
142 | goto bad; | |
143 | ||
144 | alias = IDENTIFIER_POINTER (x); | |
145 | ||
146 | type = c_lex (&x); | |
147 | if (type == CPP_COMMA) | |
148 | repeat = 1; | |
149 | else if (type != CPP_EOF) | |
150 | warning ("junk at end of #pragma ghs section"); | |
151 | ||
152 | if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA; | |
153 | else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT; | |
154 | else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA; | |
155 | else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA; | |
156 | else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA; | |
157 | else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA; | |
158 | else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA; | |
159 | else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA; | |
160 | else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA; | |
161 | /* According to GHS beta documentation, the following should not be | |
162 | allowed! */ | |
163 | else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS; | |
164 | else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA; | |
165 | else | |
166 | { | |
1737c953 | 167 | warning ("unrecognized section name \"%s\"", sect); |
c3edd394 NC |
168 | return; |
169 | } | |
170 | ||
171 | if (streq (alias, "default")) | |
172 | GHS_current_section_names [kind] = NULL; | |
173 | else | |
174 | GHS_current_section_names [kind] = | |
175 | build_string (strlen (alias) + 1, alias); | |
176 | } | |
177 | while (repeat); | |
178 | ||
179 | return; | |
180 | ||
181 | bad: | |
182 | warning ("malformed #pragma ghs section"); | |
183 | return; | |
184 | ||
185 | reset: | |
186 | /* #pragma ghs section \n: Reset all section names back to their defaults. */ | |
187 | { | |
188 | int i; | |
189 | ||
190 | for (i = COUNT_OF_GHS_SECTION_KINDS; i--;) | |
191 | GHS_current_section_names [i] = NULL; | |
192 | } | |
193 | } | |
194 | ||
195 | void | |
196 | ghs_pragma_interrupt (pfile) | |
197 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
198 | { | |
199 | tree x; | |
200 | ||
201 | if (c_lex (&x) != CPP_EOF) | |
202 | warning ("junk at end of #pragma ghs interrupt"); | |
203 | ||
204 | mark_current_function_as_interrupt (); | |
205 | } | |
206 | ||
207 | void | |
208 | ghs_pragma_starttda (pfile) | |
209 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
210 | { | |
211 | tree x; | |
212 | ||
213 | if (c_lex (&x) != CPP_EOF) | |
214 | warning ("junk at end of #pragma ghs starttda"); | |
215 | ||
216 | push_data_area (DATA_AREA_TDA); | |
217 | } | |
218 | ||
219 | void | |
220 | ghs_pragma_startsda (pfile) | |
221 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
222 | { | |
223 | tree x; | |
224 | ||
225 | if (c_lex (&x) != CPP_EOF) | |
226 | warning ("junk at end of #pragma ghs startsda"); | |
227 | ||
228 | push_data_area (DATA_AREA_SDA); | |
229 | } | |
230 | ||
231 | void | |
232 | ghs_pragma_startzda (pfile) | |
233 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
234 | { | |
235 | tree x; | |
236 | ||
237 | if (c_lex (&x) != CPP_EOF) | |
238 | warning ("junk at end of #pragma ghs startzda"); | |
239 | ||
240 | push_data_area (DATA_AREA_ZDA); | |
241 | } | |
242 | ||
243 | void | |
244 | ghs_pragma_endtda (pfile) | |
245 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
246 | { | |
247 | tree x; | |
248 | ||
249 | if (c_lex (&x) != CPP_EOF) | |
250 | warning ("junk at end of #pragma ghs endtda"); | |
251 | ||
252 | pop_data_area (DATA_AREA_TDA); | |
253 | } | |
254 | ||
255 | void | |
256 | ghs_pragma_endsda (pfile) | |
257 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
258 | { | |
259 | tree x; | |
260 | ||
261 | if (c_lex (&x) != CPP_EOF) | |
262 | warning ("junk at end of #pragma ghs endsda"); | |
263 | ||
264 | pop_data_area (DATA_AREA_SDA); | |
265 | } | |
266 | ||
267 | void | |
268 | ghs_pragma_endzda (pfile) | |
269 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
270 | { | |
271 | tree x; | |
272 | ||
273 | if (c_lex (&x) != CPP_EOF) | |
274 | warning ("junk at end of #pragma ghs endzda"); | |
275 | ||
276 | pop_data_area (DATA_AREA_ZDA); | |
277 | } |