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
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
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/>. */
23 #include "coretypes.h"
28 #include "double-int.h"
35 #include "diagnostic-core.h"
36 #include "c-family/c-pragma.h"
38 #include "hard-reg-set.h"
39 #include "output.h" /* for decode_reg_name */
40 #include "mep-protos.h"
43 #define MAX_RECOG_OPERANDS 10
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
53 #ifndef INVALID_REGNUM
54 #define INVALID_REGNUM (~(unsigned int) 0)
58 mep_pragma_lex (tree
*valp
)
60 enum cpp_ttype t
= pragma_lex (valp
);
67 mep_pragma_io_volatile (cpp_reader
*reader ATTRIBUTE_UNUSED
)
74 type
= mep_pragma_lex (&val
);
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
;
88 if (strcmp (str
, "off") == 0)
90 target_flags
&= ~ MASK_IO_VOLATILE
;
95 error ("#pragma io_volatile takes only on or off");
99 parse_cr_reg (const char * str
)
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
;
114 parse_cr_set (HARD_REG_SET
* set
)
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
;
130 else if (type
== CPP_ELLIPSIS
)
132 if (last_regno
== INVALID_REGNUM
)
134 error ("invalid coprocessor register range");
139 else if (type
== CPP_NAME
|| type
== CPP_STRING
)
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
);
151 regno
= parse_cr_reg (str
);
152 if (regno
== INVALID_REGNUM
)
154 error ("invalid coprocessor register %qE", val
);
160 if (last_regno
> regno
)
161 i
= regno
, regno
= last_regno
;
167 last_regno
= i
= regno
;
171 SET_HARD_REG_BIT (*set
, i
);
177 error ("malformed coprocessor register");
185 mep_pragma_coprocessor_which (enum cw_which cw_which
)
189 /* Process the balance of the pragma and turn it into a hard reg set. */
190 if (! parse_cr_set (&set
))
193 /* Process the collected hard reg set. */
199 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; ++i
)
200 if (TEST_HARD_REG_BIT (set
, 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;
218 /* Fix up register class hierarchy. */
219 mep_save_register_info ();
224 init_dummy_function_start ();
226 expand_dummy_function_end ();
235 mep_pragma_coprocessor_width (void)
241 type
= mep_pragma_lex (&val
);
245 if (! tree_fits_uhwi_p (val
))
247 i
= tree_to_uhwi (val
);
248 /* This pragma no longer has any effect. */
251 target_flags
&= ~MASK_64BIT_CR_REGS
;
253 target_flags
|= MASK_64BIT_CR_REGS
;
256 targetm
.init_builtins ();
258 if (i
!= 32 && i
!= 64)
262 type
= mep_pragma_lex (&val
);
263 if (type
!= CPP_PRAGMA_EOL
)
264 warning (0, "junk at end of #pragma GCC coprocessor width");
271 error ("#pragma GCC coprocessor width takes only 32 or 64");
275 mep_pragma_coprocessor_subclass (void)
281 enum reg_class rclass
;
283 type
= mep_pragma_lex (&val
);
284 if (type
!= CPP_CHAR
)
286 class_letter
= tree_to_uhwi (val
);
287 switch (class_letter
)
302 error ("#pragma GCC coprocessor subclass letter must be in [ABCD]");
305 if (reg_class_size
[rclass
] > 0)
307 error ("#pragma GCC coprocessor subclass '%c' already defined",
312 type
= mep_pragma_lex (&val
);
316 if (! parse_cr_set (&set
))
319 /* Fix up register class hierarchy. */
320 COPY_HARD_REG_SET (reg_class_contents
[rclass
], set
);
325 error ("malformed #pragma GCC coprocessor subclass");
329 mep_pragma_disinterrupt (cpp_reader
*reader ATTRIBUTE_UNUSED
)
337 type
= mep_pragma_lex (&val
);
338 if (type
== CPP_COMMA
)
340 if (type
!= CPP_NAME
)
342 mep_note_pragma_disinterrupt (IDENTIFIER_POINTER (val
));
345 if (!saw_one
|| type
!= CPP_PRAGMA_EOL
)
347 error ("malformed #pragma disinterrupt");
353 mep_pragma_coprocessor (cpp_reader
*reader ATTRIBUTE_UNUSED
)
358 type
= mep_pragma_lex (&val
);
359 if (type
!= CPP_NAME
)
361 error ("malformed #pragma GCC coprocessor");
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 ();
377 error ("unknown #pragma GCC coprocessor %E", val
);
381 mep_pragma_call (cpp_reader
*reader ATTRIBUTE_UNUSED
)
389 type
= mep_pragma_lex (&val
);
390 if (type
== CPP_COMMA
)
392 if (type
!= CPP_NAME
)
394 mep_note_pragma_call (IDENTIFIER_POINTER (val
));
397 if (!saw_one
|| type
!= CPP_PRAGMA_EOL
)
399 error ("malformed #pragma call");
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
);