136ac495dSmrg /* M32C Pragma support
2*8feb0f0bSmrg Copyright (C) 2004-2020 Free Software Foundation, Inc.
336ac495dSmrg Contributed by Red Hat, Inc.
436ac495dSmrg
536ac495dSmrg This file is part of GCC.
636ac495dSmrg
736ac495dSmrg GCC is free software; you can redistribute it and/or modify
836ac495dSmrg it under the terms of the GNU General Public License as published by
936ac495dSmrg the Free Software Foundation; either version 3, or (at your option)
1036ac495dSmrg any later version.
1136ac495dSmrg
1236ac495dSmrg GCC is distributed in the hope that it will be useful,
1336ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
1436ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1536ac495dSmrg GNU General Public License for more details.
1636ac495dSmrg
1736ac495dSmrg You should have received a copy of the GNU General Public License
1836ac495dSmrg along with GCC; see the file COPYING3. If not see
1936ac495dSmrg <http://www.gnu.org/licenses/>. */
2036ac495dSmrg
21a2dc1f3fSmrg #define IN_TARGET_CODE 1
22a2dc1f3fSmrg
2336ac495dSmrg #include "config.h"
2436ac495dSmrg #include "system.h"
2536ac495dSmrg #include "coretypes.h"
2636ac495dSmrg #include "tm.h"
2736ac495dSmrg #include "c-family/c-common.h"
2836ac495dSmrg #include "c-family/c-pragma.h"
2936ac495dSmrg #include "m32c-protos.h"
3036ac495dSmrg
3136ac495dSmrg /* Implements the "GCC memregs" pragma. This pragma takes only an
3236ac495dSmrg integer, and is semantically identical to the -memregs= command
3336ac495dSmrg line option. The only catch is, the programmer should only use
3436ac495dSmrg this pragma at the beginning of the file (preferably, in some
3536ac495dSmrg project-wide header) to avoid ABI changes related to changing the
3636ac495dSmrg list of available "registers". */
3736ac495dSmrg static void
m32c_pragma_memregs(cpp_reader * reader ATTRIBUTE_UNUSED)3836ac495dSmrg m32c_pragma_memregs (cpp_reader * reader ATTRIBUTE_UNUSED)
3936ac495dSmrg {
4036ac495dSmrg /* on off */
4136ac495dSmrg tree val;
4236ac495dSmrg enum cpp_ttype type;
4336ac495dSmrg HOST_WIDE_INT i;
4436ac495dSmrg
4536ac495dSmrg type = pragma_lex (&val);
4636ac495dSmrg if (type == CPP_NUMBER)
4736ac495dSmrg {
4836ac495dSmrg if (tree_fits_uhwi_p (val))
4936ac495dSmrg {
5036ac495dSmrg i = tree_to_uhwi (val);
5136ac495dSmrg
5236ac495dSmrg type = pragma_lex (&val);
5336ac495dSmrg if (type != CPP_EOF)
5436ac495dSmrg warning (0, "junk at end of #pragma GCC memregs [0..16]");
5536ac495dSmrg
56a2dc1f3fSmrg if (i >= 0 && i <= 16)
5736ac495dSmrg {
5836ac495dSmrg if (!ok_to_change_target_memregs)
5936ac495dSmrg {
6036ac495dSmrg warning (0,
6136ac495dSmrg "#pragma GCC memregs must precede any function decls");
6236ac495dSmrg return;
6336ac495dSmrg }
6436ac495dSmrg target_memregs = i;
6536ac495dSmrg m32c_conditional_register_usage ();
6636ac495dSmrg }
6736ac495dSmrg else
6836ac495dSmrg {
6936ac495dSmrg warning (0, "#pragma GCC memregs takes a number [0..16]");
7036ac495dSmrg }
7136ac495dSmrg
7236ac495dSmrg return;
7336ac495dSmrg }
7436ac495dSmrg }
7536ac495dSmrg
7636ac495dSmrg error ("#pragma GCC memregs takes a number [0..16]");
7736ac495dSmrg }
7836ac495dSmrg
7936ac495dSmrg /* Implements the "pragma ADDRESS" pragma. This pragma takes a
8036ac495dSmrg variable name and an address, and arranges for that variable to be
8136ac495dSmrg "at" that address. The variable is also made volatile. */
8236ac495dSmrg static void
m32c_pragma_address(cpp_reader * reader ATTRIBUTE_UNUSED)8336ac495dSmrg m32c_pragma_address (cpp_reader * reader ATTRIBUTE_UNUSED)
8436ac495dSmrg {
8536ac495dSmrg /* on off */
8636ac495dSmrg tree var, addr;
8736ac495dSmrg enum cpp_ttype type;
8836ac495dSmrg
8936ac495dSmrg type = pragma_lex (&var);
9036ac495dSmrg if (type == CPP_NAME)
9136ac495dSmrg {
9236ac495dSmrg type = pragma_lex (&addr);
9336ac495dSmrg if (type == CPP_NUMBER)
9436ac495dSmrg {
9536ac495dSmrg if (var != error_mark_node)
9636ac495dSmrg {
9736ac495dSmrg unsigned uaddr = tree_to_uhwi (addr);
9836ac495dSmrg m32c_note_pragma_address (IDENTIFIER_POINTER (var), uaddr);
9936ac495dSmrg }
10036ac495dSmrg
10136ac495dSmrg type = pragma_lex (&var);
10236ac495dSmrg if (type != CPP_EOF)
10336ac495dSmrg {
10436ac495dSmrg error ("junk at end of #pragma ADDRESS");
10536ac495dSmrg }
10636ac495dSmrg return;
10736ac495dSmrg }
10836ac495dSmrg }
10936ac495dSmrg error ("malformed #pragma ADDRESS variable address");
11036ac495dSmrg }
11136ac495dSmrg
11236ac495dSmrg /* Implements REGISTER_TARGET_PRAGMAS. */
11336ac495dSmrg void
m32c_register_pragmas(void)11436ac495dSmrg m32c_register_pragmas (void)
11536ac495dSmrg {
11636ac495dSmrg c_register_pragma ("GCC", "memregs", m32c_pragma_memregs);
11736ac495dSmrg c_register_pragma (NULL, "ADDRESS", m32c_pragma_address);
11836ac495dSmrg c_register_pragma (NULL, "address", m32c_pragma_address);
11936ac495dSmrg
12036ac495dSmrg /* R8C and M16C have 16-bit pointers in a 20-bit address zpace.
12136ac495dSmrg M32C has 24-bit pointers in a 24-bit address space, so does not
12236ac495dSmrg need far pointers, but we accept the qualifier anyway, as a
12336ac495dSmrg no-op. */
12436ac495dSmrg if (TARGET_A16)
12536ac495dSmrg c_register_addr_space ("__far", ADDR_SPACE_FAR);
12636ac495dSmrg else
12736ac495dSmrg c_register_addr_space ("__far", ADDR_SPACE_GENERIC);
12836ac495dSmrg }
129