xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/v850/v850-c.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /* v850 specific, C compiler specific functions.
2    Copyright (C) 2000, 2001, 2002, 2003, 2005, 2007, 2009
3    Free Software Foundation, Inc.
4    Contributed by Jeff Law (law@cygnus.com).
5 
6 This file is part of GCC.
7 
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12 
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21 
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "cpplib.h"
27 #include "tree.h"
28 #include "c-pragma.h"
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 
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);
40 
41 /* Push a data area onto the stack.  */
42 
43 static int
44 push_data_area (v850_data_area data_area)
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
64 pop_data_area (v850_data_area data_area)
65 {
66   if (data_area_stack == NULL)
67     warning (OPT_Wpragmas, "#pragma GHS endXXXX found without "
68 	     "previous startXXX");
69   else if (data_area != data_area_stack->data_area)
70     warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
71 	     "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 
89 static void
90 mark_current_function_as_interrupt (void)
91 {
92   tree name;
93 
94   if (current_function_decl ==  NULL_TREE)
95     {
96       warning (0, "cannot set interrupt attribute: no current function");
97       return;
98     }
99 
100   name = get_identifier ("interrupt");
101 
102   if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
103     {
104       warning (0, "cannot set interrupt attribute: no such identifier");
105       return;
106     }
107 
108   decl_attributes (&current_function_decl,
109 		   tree_cons (name, NULL_TREE, NULL_TREE), 0);
110 }
111 
112 
113 /* Support for GHS pragmata.  */
114 
115 void
116 ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
117 {
118   int repeat = 0;
119 
120   /* #pragma ghs section [name = alias [, name = alias [, ...]]] */
121   do
122     {
123       tree x;
124       enum cpp_ttype type;
125       tree sect_ident;
126       const char *sect, *alias;
127       enum GHS_section_kind kind;
128 
129       type = pragma_lex (&x);
130 
131       if (type == CPP_EOF && !repeat)
132 	goto reset;
133       else if (type == CPP_NAME)
134 	{
135 	  sect_ident = x;
136 	  sect = IDENTIFIER_POINTER (sect_ident);
137 	}
138       else
139 	goto bad;
140       repeat = 0;
141 
142       if (pragma_lex (&x) != CPP_EQ)
143 	goto bad;
144       if (pragma_lex (&x) != CPP_NAME)
145 	goto bad;
146 
147       alias = IDENTIFIER_POINTER (x);
148 
149       type = pragma_lex (&x);
150       if (type == CPP_COMMA)
151 	repeat = 1;
152       else if (type != CPP_EOF)
153 	warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
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 	{
170 	  warning (0, "unrecognized section name %qE", sect_ident);
171 	  return;
172 	}
173 
174       if (streq (alias, "default"))
175 	GHS_current_section_names [kind] = NULL;
176       else
177 	GHS_current_section_names [kind] =
178 	  build_string (strlen (alias) + 1, alias);
179     }
180   while (repeat);
181 
182   return;
183 
184  bad:
185   warning (OPT_Wpragmas, "malformed #pragma ghs section");
186   return;
187 
188  reset:
189   /* #pragma ghs section \n: Reset all section names back to their defaults.  */
190   {
191     int i;
192 
193     for (i = COUNT_OF_GHS_SECTION_KINDS; i--;)
194       GHS_current_section_names [i] = NULL;
195   }
196 }
197 
198 void
199 ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED)
200 {
201   tree x;
202 
203   if (pragma_lex (&x) != CPP_EOF)
204     warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
205 
206   mark_current_function_as_interrupt ();
207 }
208 
209 void
210 ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED)
211 {
212   tree x;
213 
214   if (pragma_lex (&x) != CPP_EOF)
215     warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
216 
217   push_data_area (DATA_AREA_TDA);
218 }
219 
220 void
221 ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
222 {
223   tree x;
224 
225   if (pragma_lex (&x) != CPP_EOF)
226     warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
227 
228   push_data_area (DATA_AREA_SDA);
229 }
230 
231 void
232 ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
233 {
234   tree x;
235 
236   if (pragma_lex (&x) != CPP_EOF)
237     warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
238 
239   push_data_area (DATA_AREA_ZDA);
240 }
241 
242 void
243 ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED)
244 {
245   tree x;
246 
247   if (pragma_lex (&x) != CPP_EOF)
248     warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
249 
250   pop_data_area (DATA_AREA_TDA);
251 }
252 
253 void
254 ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
255 {
256   tree x;
257 
258   if (pragma_lex (&x) != CPP_EOF)
259     warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
260 
261   pop_data_area (DATA_AREA_SDA);
262 }
263 
264 void
265 ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
266 {
267   tree x;
268 
269   if (pragma_lex (&x) != CPP_EOF)
270     warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
271 
272   pop_data_area (DATA_AREA_ZDA);
273 }
274