* gcc-interface/trans.c (process_freeze_entity): Be prepared for a
[official-gcc.git] / gcc / config / v850 / v850-c.c
blob1855204d8984d6877b2946b93ae8084d680ac774
1 /* v850 specific, C compiler specific functions.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Jeff Law (law@cygnus.com).
5 This file is part of GCC.
7 GCC 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 3, or (at your option)
10 any later version.
12 GCC 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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "stringpool.h"
27 #include "diagnostic-core.h"
28 #include "attribs.h"
29 #include "c-family/c-pragma.h"
31 #ifndef streq
32 #define streq(a,b) (strcmp (a, b) == 0)
33 #endif
35 static int pop_data_area (v850_data_area);
36 static int push_data_area (v850_data_area);
37 static void mark_current_function_as_interrupt (void);
39 /* Push a data area onto the stack. */
41 static int
42 push_data_area (v850_data_area data_area)
44 data_area_stack_element * elem;
46 elem = (data_area_stack_element *) xmalloc (sizeof (* elem));
48 if (elem == NULL)
49 return 0;
51 elem->prev = data_area_stack;
52 elem->data_area = data_area;
54 data_area_stack = elem;
56 return 1;
59 /* Remove a data area from the stack. */
61 static int
62 pop_data_area (v850_data_area data_area)
64 if (data_area_stack == NULL)
65 warning (OPT_Wpragmas, "#pragma GHS endXXXX found without "
66 "previous startXXX");
67 else if (data_area != data_area_stack->data_area)
68 warning (OPT_Wpragmas, "#pragma GHS endXXX does not match "
69 "previous startXXX");
70 else
72 data_area_stack_element * elem;
74 elem = data_area_stack;
75 data_area_stack = data_area_stack->prev;
77 free (elem);
79 return 1;
82 return 0;
85 /* Set the machine specific 'interrupt' attribute on the current function. */
87 static void
88 mark_current_function_as_interrupt (void)
90 tree name;
92 if (current_function_decl == NULL_TREE)
94 warning (0, "cannot set interrupt attribute: no current function");
95 return;
98 name = get_identifier ("interrupt");
100 if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
102 warning (0, "cannot set interrupt attribute: no such identifier");
103 return;
106 decl_attributes (&current_function_decl,
107 tree_cons (name, NULL_TREE, NULL_TREE), 0);
111 /* Support for GHS pragmata. */
113 void
114 ghs_pragma_section (cpp_reader * pfile ATTRIBUTE_UNUSED)
116 int repeat = 0;
118 /* #pragma ghs section [name = alias [, name = alias [, ...]]] */
121 tree x;
122 enum cpp_ttype type;
123 tree sect_ident;
124 const char *sect, *alias;
125 enum GHS_section_kind kind;
127 type = pragma_lex (&x);
129 if (type == CPP_EOF && !repeat)
130 goto reset;
131 else if (type == CPP_NAME)
133 sect_ident = x;
134 sect = IDENTIFIER_POINTER (sect_ident);
136 else
137 goto bad;
138 repeat = 0;
140 if (pragma_lex (&x) != CPP_EQ)
141 goto bad;
142 if (pragma_lex (&x) != CPP_NAME)
143 goto bad;
145 alias = IDENTIFIER_POINTER (x);
147 type = pragma_lex (&x);
148 if (type == CPP_COMMA)
149 repeat = 1;
150 else if (type != CPP_EOF)
151 warning (OPT_Wpragmas, "junk at end of #pragma ghs section");
153 if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA;
154 else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT;
155 else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA;
156 else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA;
157 else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA;
158 else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA;
159 else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA;
160 else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA;
161 else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA;
162 /* According to GHS beta documentation, the following should not be
163 allowed! */
164 else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS;
165 else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA;
166 else
168 warning (0, "unrecognized section name %qE", sect_ident);
169 return;
172 if (streq (alias, "default"))
173 GHS_current_section_names [kind] = NULL;
174 else
175 GHS_current_section_names [kind] = alias;
177 while (repeat);
179 return;
181 bad:
182 warning (OPT_Wpragmas, "malformed #pragma ghs section");
183 return;
185 reset:
186 /* #pragma ghs section \n: Reset all section names back to their defaults. */
188 int i;
190 for (i = COUNT_OF_GHS_SECTION_KINDS; i--;)
191 GHS_current_section_names [i] = NULL;
195 void
196 ghs_pragma_interrupt (cpp_reader * pfile ATTRIBUTE_UNUSED)
198 tree x;
200 if (pragma_lex (&x) != CPP_EOF)
201 warning (OPT_Wpragmas, "junk at end of #pragma ghs interrupt");
203 mark_current_function_as_interrupt ();
206 void
207 ghs_pragma_starttda (cpp_reader * pfile ATTRIBUTE_UNUSED)
209 tree x;
211 if (pragma_lex (&x) != CPP_EOF)
212 warning (OPT_Wpragmas, "junk at end of #pragma ghs starttda");
214 push_data_area (DATA_AREA_TDA);
217 void
218 ghs_pragma_startsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
220 tree x;
222 if (pragma_lex (&x) != CPP_EOF)
223 warning (OPT_Wpragmas, "junk at end of #pragma ghs startsda");
225 push_data_area (DATA_AREA_SDA);
228 void
229 ghs_pragma_startzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
231 tree x;
233 if (pragma_lex (&x) != CPP_EOF)
234 warning (OPT_Wpragmas, "junk at end of #pragma ghs startzda");
236 push_data_area (DATA_AREA_ZDA);
239 void
240 ghs_pragma_endtda (cpp_reader * pfile ATTRIBUTE_UNUSED)
242 tree x;
244 if (pragma_lex (&x) != CPP_EOF)
245 warning (OPT_Wpragmas, "junk at end of #pragma ghs endtda");
247 pop_data_area (DATA_AREA_TDA);
250 void
251 ghs_pragma_endsda (cpp_reader * pfile ATTRIBUTE_UNUSED)
253 tree x;
255 if (pragma_lex (&x) != CPP_EOF)
256 warning (OPT_Wpragmas, "junk at end of #pragma ghs endsda");
258 pop_data_area (DATA_AREA_SDA);
261 void
262 ghs_pragma_endzda (cpp_reader * pfile ATTRIBUTE_UNUSED)
264 tree x;
266 if (pragma_lex (&x) != CPP_EOF)
267 warning (OPT_Wpragmas, "junk at end of #pragma ghs endzda");
269 pop_data_area (DATA_AREA_ZDA);