Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / config / m32c / m32c-pragma.c
blobb57615265a2724c0bb85c5434270d9ef298db6b6
1 /* M32C Pragma support
2 Copyright (C) 2004, 2007 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
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 <stdio.h>
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "toplev.h"
28 #include "c-family/c-pragma.h"
29 #include "cpplib.h"
30 #include "hard-reg-set.h"
31 #include "output.h"
32 #include "m32c-protos.h"
33 #include "function.h"
34 #define MAX_RECOG_OPERANDS 10
35 #include "reload.h"
36 #include "target.h"
38 /* Implements the "GCC memregs" pragma. This pragma takes only an
39 integer, and is semantically identical to the -memregs= command
40 line option. The only catch is, the programmer should only use
41 this pragma at the beginning of the file (preferably, in some
42 project-wide header) to avoid ABI changes related to changing the
43 list of available "registers". */
44 static void
45 m32c_pragma_memregs (cpp_reader * reader ATTRIBUTE_UNUSED)
47 /* on off */
48 tree val;
49 enum cpp_ttype type;
50 HOST_WIDE_INT i;
51 static char new_number[3];
53 type = pragma_lex (&val);
54 if (type == CPP_NUMBER)
56 if (host_integerp (val, 1))
58 i = tree_low_cst (val, 1);
60 type = pragma_lex (&val);
61 if (type != CPP_EOF)
62 warning (0, "junk at end of #pragma GCC memregs [0..16]");
64 if (0 <= i && i <= 16)
66 if (!ok_to_change_target_memregs)
68 warning (0,
69 "#pragma GCC memregs must precede any function decls");
70 return;
72 new_number[0] = (i / 10) + '0';
73 new_number[1] = (i % 10) + '0';
74 new_number[2] = 0;
75 target_memregs = new_number;
76 m32c_conditional_register_usage ();
78 else
80 warning (0, "#pragma GCC memregs takes a number [0..16]");
83 return;
87 error ("#pragma GCC memregs takes a number [0..16]");
90 /* Implements the "pragma ADDRESS" pragma. This pragma takes a
91 variable name and an address, and arranges for that variable to be
92 "at" that address. The variable is also made volatile. */
93 static void
94 m32c_pragma_address (cpp_reader * reader ATTRIBUTE_UNUSED)
96 /* on off */
97 tree var, addr;
98 enum cpp_ttype type;
99 const char *var_str;
101 type = pragma_lex (&var);
102 if (type == CPP_NAME)
104 var_str = IDENTIFIER_POINTER (var);
106 type = pragma_lex (&addr);
107 if (type == CPP_NUMBER)
109 if (var != error_mark_node)
111 unsigned uaddr = tree_low_cst (addr, 1);
112 m32c_note_pragma_address (IDENTIFIER_POINTER (var), uaddr);
115 type = pragma_lex (&var);
116 if (type != CPP_EOF)
118 error ("junk at end of #pragma ADDRESS");
120 return;
123 error ("malformed #pragma ADDRESS variable address");
126 /* Implements REGISTER_TARGET_PRAGMAS. */
127 void
128 m32c_register_pragmas (void)
130 c_register_pragma ("GCC", "memregs", m32c_pragma_memregs);
131 c_register_pragma (NULL, "ADDRESS", m32c_pragma_address);
132 c_register_pragma (NULL, "address", m32c_pragma_address);