OSDN Git Service

* config/h8300/h8300.h (N_REG_CLASSES): Parenthesize.
[pf3gnuchains/gcc-fork.git] / gcc / config / v850 / v850-c.c
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"
24 #include "cpplib.h"
25 #include "tree.h"
26 #include "c-pragma.h"
27 #include "toplev.h"
28 #include "ggc.h"
29 #include "tm_p.h"
30
31 #ifndef streq
32 #define streq(a,b) (strcmp (a, b) == 0)
33 #endif
34 \f
35 static int  pop_data_area          PARAMS ((v850_data_area));
36 static int  push_data_area         PARAMS ((v850_data_area));
37 static void mark_current_function_as_interrupt PARAMS ((void));
38 \f
39 /* Push a data area onto the stack.  */
40
41 static int
42 push_data_area (data_area)
43      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
63 pop_data_area (data_area)
64      v850_data_area data_area;
65 {
66   if (data_area_stack == NULL)
67     warning ("#pragma GHS endXXXX found without previous startXXX");
68   else if (data_area != data_area_stack->data_area)
69     warning ("#pragma GHS endXXX does not match previous startXXX");
70   else
71     {
72       data_area_stack_element * elem;
73
74       elem = data_area_stack;
75       data_area_stack = data_area_stack->prev;
76
77       free (elem);
78
79       return 1;
80     }
81
82   return 0;
83 }
84
85 /* Set the machine specific 'interrupt' attribute on the current function.  */
86
87 static void
88 mark_current_function_as_interrupt ()
89 {
90   tree name;
91   
92   if (current_function_decl ==  NULL_TREE)
93     {
94       warning ("cannot set interrupt attribute: no current function");
95       return;
96     }
97
98   name = get_identifier ("interrupt");
99
100   if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
101     {
102       warning ("cannot set interrupt attribute: no such identifier");
103       return;
104     }
105   
106   decl_attributes (&current_function_decl,
107                    tree_cons (name, NULL_TREE, NULL_TREE), 0);
108 }
109
110 \f
111 /* Support for GHS pragmata.  */
112
113 void
114 ghs_pragma_section (pfile)
115      cpp_reader *pfile ATTRIBUTE_UNUSED;
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       
127       type = c_lex (&x);
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       
137       if (c_lex (&x) != CPP_EQ)
138         goto bad;
139       if (c_lex (&x) != CPP_NAME)
140         goto bad;
141       
142       alias = IDENTIFIER_POINTER (x);
143       
144       type = c_lex (&x);
145       if (type == CPP_COMMA)
146         repeat = 1;
147       else if (type != CPP_EOF)
148         warning ("junk at end of #pragma ghs section");
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         {
165           warning ("unrecognized section name \"%s\"", sect);
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:
180   warning ("malformed #pragma ghs section");
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
194 ghs_pragma_interrupt (pfile)
195      cpp_reader *pfile ATTRIBUTE_UNUSED;
196 {
197   tree x;
198   
199   if (c_lex (&x) != CPP_EOF)
200     warning ("junk at end of #pragma ghs interrupt");
201   
202   mark_current_function_as_interrupt ();
203 }
204
205 void
206 ghs_pragma_starttda (pfile)
207      cpp_reader *pfile ATTRIBUTE_UNUSED;
208 {
209   tree x;
210   
211   if (c_lex (&x) != CPP_EOF)
212     warning ("junk at end of #pragma ghs starttda");
213   
214   push_data_area (DATA_AREA_TDA);
215 }
216
217 void
218 ghs_pragma_startsda (pfile)
219      cpp_reader *pfile ATTRIBUTE_UNUSED;
220 {
221   tree x;
222   
223   if (c_lex (&x) != CPP_EOF)
224     warning ("junk at end of #pragma ghs startsda");
225   
226   push_data_area (DATA_AREA_SDA);
227 }
228
229 void
230 ghs_pragma_startzda (pfile)
231      cpp_reader *pfile ATTRIBUTE_UNUSED;
232 {
233   tree x;
234   
235   if (c_lex (&x) != CPP_EOF)
236     warning ("junk at end of #pragma ghs startzda");
237   
238   push_data_area (DATA_AREA_ZDA);
239 }
240
241 void
242 ghs_pragma_endtda (pfile)
243      cpp_reader *pfile ATTRIBUTE_UNUSED;
244 {
245   tree x;
246   
247   if (c_lex (&x) != CPP_EOF)
248     warning ("junk at end of #pragma ghs endtda");
249   
250   pop_data_area (DATA_AREA_TDA);
251 }
252
253 void
254 ghs_pragma_endsda (pfile)
255      cpp_reader *pfile ATTRIBUTE_UNUSED;
256 {
257   tree x;
258   
259   if (c_lex (&x) != CPP_EOF)
260     warning ("junk at end of #pragma ghs endsda");
261   
262   pop_data_area (DATA_AREA_SDA);
263 }
264
265 void
266 ghs_pragma_endzda (pfile)
267      cpp_reader *pfile ATTRIBUTE_UNUSED;
268 {
269   tree x;
270   
271   if (c_lex (&x) != CPP_EOF)
272     warning ("junk at end of #pragma ghs endzda");
273   
274   pop_data_area (DATA_AREA_ZDA);
275 }