use rtx_insn * more in reorg.c
[official-gcc.git] / gcc / config / mep / mep-pragma.c
blobf5bd20c2806d4c71b7d8bf444a81f0607f5822aa
1 /* Definitions of Toshiba Media Processor
2 Copyright (C) 2001-2015 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "diagnostic-core.h"
36 #include "c-family/c-pragma.h"
37 #include "cpplib.h"
38 #include "hard-reg-set.h"
39 #include "output.h" /* for decode_reg_name */
40 #include "mep-protos.h"
41 #include "input.h"
42 #include "function.h"
43 #define MAX_RECOG_OPERANDS 10
44 #include "reload.h"
45 #include "target.h"
47 enum cw_which { CW_AVAILABLE, CW_CALL_SAVED };
49 /* This is normally provided by rtl.h but we can't include that file
50 here. It's safe to copy the definition here because we're only
51 using it internally; the value isn't passed to functions outside
52 this file. */
53 #ifndef INVALID_REGNUM
54 #define INVALID_REGNUM (~(unsigned int) 0)
55 #endif
57 static enum cpp_ttype
58 mep_pragma_lex (tree *valp)
60 enum cpp_ttype t = pragma_lex (valp);
61 if (t == CPP_EOF)
62 t = CPP_PRAGMA_EOL;
63 return t;
66 static void
67 mep_pragma_io_volatile (cpp_reader *reader ATTRIBUTE_UNUSED)
69 /* On off. */
70 tree val;
71 enum cpp_ttype type;
72 const char * str;
74 type = mep_pragma_lex (&val);
75 if (type == CPP_NAME)
77 str = IDENTIFIER_POINTER (val);
79 type = mep_pragma_lex (&val);
80 if (type != CPP_PRAGMA_EOL)
81 warning (0, "junk at end of #pragma io_volatile");
83 if (strcmp (str, "on") == 0)
85 target_flags |= MASK_IO_VOLATILE;
86 return;
88 if (strcmp (str, "off") == 0)
90 target_flags &= ~ MASK_IO_VOLATILE;
91 return;
95 error ("#pragma io_volatile takes only on or off");
98 static unsigned int
99 parse_cr_reg (const char * str)
101 unsigned int regno;
103 regno = decode_reg_name (str);
104 if (regno >= FIRST_PSEUDO_REGISTER)
105 return INVALID_REGNUM;
107 /* Verify that the regno is in CR_REGS. */
108 if (! TEST_HARD_REG_BIT (reg_class_contents[CR_REGS], regno))
109 return INVALID_REGNUM;
110 return regno;
113 static bool
114 parse_cr_set (HARD_REG_SET * set)
116 tree val;
117 enum cpp_ttype type;
118 unsigned int last_regno = INVALID_REGNUM;
119 bool do_range = false;
121 CLEAR_HARD_REG_SET (*set);
123 while ((type = mep_pragma_lex (&val)) != CPP_PRAGMA_EOL)
125 if (type == CPP_COMMA)
127 last_regno = INVALID_REGNUM;
128 do_range = false;
130 else if (type == CPP_ELLIPSIS)
132 if (last_regno == INVALID_REGNUM)
134 error ("invalid coprocessor register range");
135 return false;
137 do_range = true;
139 else if (type == CPP_NAME || type == CPP_STRING)
141 const char *str;
142 unsigned int regno, i;
144 if (TREE_CODE (val) == IDENTIFIER_NODE)
145 str = IDENTIFIER_POINTER (val);
146 else if (TREE_CODE (val) == STRING_CST)
147 str = TREE_STRING_POINTER (val);
148 else
149 gcc_unreachable ();
151 regno = parse_cr_reg (str);
152 if (regno == INVALID_REGNUM)
154 error ("invalid coprocessor register %qE", val);
155 return false;
158 if (do_range)
160 if (last_regno > regno)
161 i = regno, regno = last_regno;
162 else
163 i = last_regno;
164 do_range = false;
166 else
167 last_regno = i = regno;
169 while (i <= regno)
171 SET_HARD_REG_BIT (*set, i);
172 i++;
175 else
177 error ("malformed coprocessor register");
178 return false;
181 return true;
184 static void
185 mep_pragma_coprocessor_which (enum cw_which cw_which)
187 HARD_REG_SET set;
189 /* Process the balance of the pragma and turn it into a hard reg set. */
190 if (! parse_cr_set (&set))
191 return;
193 /* Process the collected hard reg set. */
194 switch (cw_which)
196 case CW_AVAILABLE:
198 int i;
199 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
200 if (TEST_HARD_REG_BIT (set, i))
201 fixed_regs[i] = 0;
203 break;
205 case CW_CALL_SAVED:
207 int i;
208 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
209 if (TEST_HARD_REG_BIT (set, i))
210 fixed_regs[i] = call_used_regs[i] = 0;
212 break;
214 default:
215 gcc_unreachable ();
218 /* Fix up register class hierarchy. */
219 mep_save_register_info ();
220 mep_reinit_regs ();
222 if (cfun == 0)
224 init_dummy_function_start ();
225 init_caller_save ();
226 expand_dummy_function_end ();
228 else
230 init_caller_save ();
234 static void
235 mep_pragma_coprocessor_width (void)
237 tree val;
238 enum cpp_ttype type;
239 HOST_WIDE_INT i;
241 type = mep_pragma_lex (&val);
242 switch (type)
244 case CPP_NUMBER:
245 if (! tree_fits_uhwi_p (val))
246 break;
247 i = tree_to_uhwi (val);
248 /* This pragma no longer has any effect. */
249 #if 0
250 if (i == 32)
251 target_flags &= ~MASK_64BIT_CR_REGS;
252 else if (i == 64)
253 target_flags |= MASK_64BIT_CR_REGS;
254 else
255 break;
256 targetm.init_builtins ();
257 #else
258 if (i != 32 && i != 64)
259 break;
260 #endif
262 type = mep_pragma_lex (&val);
263 if (type != CPP_PRAGMA_EOL)
264 warning (0, "junk at end of #pragma GCC coprocessor width");
265 return;
267 default:
268 break;
271 error ("#pragma GCC coprocessor width takes only 32 or 64");
274 static void
275 mep_pragma_coprocessor_subclass (void)
277 tree val;
278 enum cpp_ttype type;
279 HARD_REG_SET set;
280 int class_letter;
281 enum reg_class rclass;
283 type = mep_pragma_lex (&val);
284 if (type != CPP_CHAR)
285 goto syntax_error;
286 class_letter = tree_to_uhwi (val);
287 switch (class_letter)
289 case 'A':
290 rclass = USER0_REGS;
291 break;
292 case 'B':
293 rclass = USER1_REGS;
294 break;
295 case 'C':
296 rclass = USER2_REGS;
297 break;
298 case 'D':
299 rclass = USER3_REGS;
300 break;
301 default:
302 error ("#pragma GCC coprocessor subclass letter must be in [ABCD]");
303 return;
305 if (reg_class_size[rclass] > 0)
307 error ("#pragma GCC coprocessor subclass '%c' already defined",
308 class_letter);
309 return;
312 type = mep_pragma_lex (&val);
313 if (type != CPP_EQ)
314 goto syntax_error;
316 if (! parse_cr_set (&set))
317 return;
319 /* Fix up register class hierarchy. */
320 COPY_HARD_REG_SET (reg_class_contents[rclass], set);
321 mep_init_regs ();
322 return;
324 syntax_error:
325 error ("malformed #pragma GCC coprocessor subclass");
328 static void
329 mep_pragma_disinterrupt (cpp_reader *reader ATTRIBUTE_UNUSED)
331 tree val;
332 enum cpp_ttype type;
333 int saw_one = 0;
335 for (;;)
337 type = mep_pragma_lex (&val);
338 if (type == CPP_COMMA)
339 continue;
340 if (type != CPP_NAME)
341 break;
342 mep_note_pragma_disinterrupt (IDENTIFIER_POINTER (val));
343 saw_one = 1;
345 if (!saw_one || type != CPP_PRAGMA_EOL)
347 error ("malformed #pragma disinterrupt");
348 return;
352 static void
353 mep_pragma_coprocessor (cpp_reader *reader ATTRIBUTE_UNUSED)
355 tree val;
356 enum cpp_ttype type;
358 type = mep_pragma_lex (&val);
359 if (type != CPP_NAME)
361 error ("malformed #pragma GCC coprocessor");
362 return;
365 if (!TARGET_COP)
366 error ("coprocessor not enabled");
368 if (strcmp (IDENTIFIER_POINTER (val), "available") == 0)
369 mep_pragma_coprocessor_which (CW_AVAILABLE);
370 else if (strcmp (IDENTIFIER_POINTER (val), "call_saved") == 0)
371 mep_pragma_coprocessor_which (CW_CALL_SAVED);
372 else if (strcmp (IDENTIFIER_POINTER (val), "width") == 0)
373 mep_pragma_coprocessor_width ();
374 else if (strcmp (IDENTIFIER_POINTER (val), "subclass") == 0)
375 mep_pragma_coprocessor_subclass ();
376 else
377 error ("unknown #pragma GCC coprocessor %E", val);
380 static void
381 mep_pragma_call (cpp_reader *reader ATTRIBUTE_UNUSED)
383 tree val;
384 enum cpp_ttype type;
385 int saw_one = 0;
387 for (;;)
389 type = mep_pragma_lex (&val);
390 if (type == CPP_COMMA)
391 continue;
392 if (type != CPP_NAME)
393 break;
394 mep_note_pragma_call (IDENTIFIER_POINTER (val));
395 saw_one = 1;
397 if (!saw_one || type != CPP_PRAGMA_EOL)
399 error ("malformed #pragma call");
400 return;
404 void
405 mep_register_pragmas (void)
407 c_register_pragma ("custom", "io_volatile", mep_pragma_io_volatile);
408 c_register_pragma ("GCC", "coprocessor", mep_pragma_coprocessor);
409 c_register_pragma (0, "disinterrupt", mep_pragma_disinterrupt);
410 c_register_pragma (0, "call", mep_pragma_call);