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