re PR target/44754 (m32c_pragma_memregs / m32c_pragma_address warnings)
[gcc.git] / gcc / config / m32c / m32c-pragma.c
1 /* M32C Pragma support
2 Copyright (C) 2004, 2007 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #include <stdio.h>
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "c-family/c-pragma.h"
28 #include "c-family/c-common.h"
29 #include "diagnostic-core.h"
30 #include "toplev.h"
31 #include "cpplib.h"
32 #include "hard-reg-set.h"
33 #include "output.h"
34 #include "m32c-protos.h"
35 #include "function.h"
36 #define MAX_RECOG_OPERANDS 10
37 #include "reload.h"
38 #include "target.h"
39
40 /* Implements the "GCC memregs" pragma. This pragma takes only an
41 integer, and is semantically identical to the -memregs= command
42 line option. The only catch is, the programmer should only use
43 this pragma at the beginning of the file (preferably, in some
44 project-wide header) to avoid ABI changes related to changing the
45 list of available "registers". */
46 static void
47 m32c_pragma_memregs (cpp_reader * reader ATTRIBUTE_UNUSED)
48 {
49 /* on off */
50 tree val;
51 enum cpp_ttype type;
52 HOST_WIDE_INT i;
53
54 type = pragma_lex (&val);
55 if (type == CPP_NUMBER)
56 {
57 if (host_integerp (val, 1))
58 {
59 i = tree_low_cst (val, 1);
60
61 type = pragma_lex (&val);
62 if (type != CPP_EOF)
63 warning (0, "junk at end of #pragma GCC memregs [0..16]");
64
65 if (0 <= i && i <= 16)
66 {
67 if (!ok_to_change_target_memregs)
68 {
69 warning (0,
70 "#pragma GCC memregs must precede any function decls");
71 return;
72 }
73 target_memregs = i;
74 m32c_conditional_register_usage ();
75 }
76 else
77 {
78 warning (0, "#pragma GCC memregs takes a number [0..16]");
79 }
80
81 return;
82 }
83 }
84
85 error ("#pragma GCC memregs takes a number [0..16]");
86 }
87
88 /* Implements the "pragma ADDRESS" pragma. This pragma takes a
89 variable name and an address, and arranges for that variable to be
90 "at" that address. The variable is also made volatile. */
91 static void
92 m32c_pragma_address (cpp_reader * reader ATTRIBUTE_UNUSED)
93 {
94 /* on off */
95 tree var, addr;
96 enum cpp_ttype type;
97
98 type = pragma_lex (&var);
99 if (type == CPP_NAME)
100 {
101 type = pragma_lex (&addr);
102 if (type == CPP_NUMBER)
103 {
104 if (var != error_mark_node)
105 {
106 unsigned uaddr = tree_low_cst (addr, 1);
107 m32c_note_pragma_address (IDENTIFIER_POINTER (var), uaddr);
108 }
109
110 type = pragma_lex (&var);
111 if (type != CPP_EOF)
112 {
113 error ("junk at end of #pragma ADDRESS");
114 }
115 return;
116 }
117 }
118 error ("malformed #pragma ADDRESS variable address");
119 }
120
121 /* Implements REGISTER_TARGET_PRAGMAS. */
122 void
123 m32c_register_pragmas (void)
124 {
125 c_register_pragma ("GCC", "memregs", m32c_pragma_memregs);
126 c_register_pragma (NULL, "ADDRESS", m32c_pragma_address);
127 c_register_pragma (NULL, "address", m32c_pragma_address);
128
129 /* R8C and M16C have 16-bit pointers in a 20-bit address zpace.
130 M32C has 24-bit pointers in a 24-bit address space, so does not
131 need far pointers, but we accept the qualifier anyway, as a
132 no-op. */
133 if (TARGET_A16)
134 c_register_addr_space ("__far", ADDR_SPACE_FAR);
135 else
136 c_register_addr_space ("__far", ADDR_SPACE_GENERIC);
137 }