Bernhard Rosenkraenzer | c83ebe5 | 2012-09-18 21:38:03 +0159 | [diff] [blame] | 1 | /* Copyright (C) 2009, 2010 |
| 2 | Free Software Foundation, Inc. |
| 3 | Contributed by Anatoly Sokolov (aesok@post.ru) |
| 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 | /* Not included in avr.c since this requires C front end. */ |
| 22 | |
| 23 | #include "config.h" |
| 24 | #include "system.h" |
| 25 | #include "coretypes.h" |
| 26 | #include "tm.h" |
| 27 | #include "tm_p.h" |
| 28 | #include "cpplib.h" |
| 29 | #include "tree.h" |
| 30 | #include "c-family/c-common.h" |
| 31 | #include "langhooks.h" |
| 32 | |
| 33 | |
| 34 | /* Implement `REGISTER_TARGET_PRAGMAS'. */ |
| 35 | |
| 36 | void |
| 37 | avr_register_target_pragmas (void) |
| 38 | { |
| 39 | int i; |
| 40 | |
| 41 | gcc_assert (ADDR_SPACE_GENERIC == ADDR_SPACE_RAM); |
| 42 | |
| 43 | /* Register address spaces. The order must be the same as in the respective |
| 44 | enum from avr.h (or designated initialized must be used in avr.c). */ |
| 45 | |
| 46 | for (i = 0; avr_addrspace[i].name; i++) |
| 47 | { |
| 48 | gcc_assert (i == avr_addrspace[i].id); |
| 49 | |
| 50 | if (!ADDR_SPACE_GENERIC_P (i)) |
| 51 | c_register_addr_space (avr_addrspace[i].name, avr_addrspace[i].id); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* Transorm LO into uppercase and write the result to UP. |
| 57 | You must provide enough space for UP. Return UP. */ |
| 58 | |
| 59 | static char* |
| 60 | avr_toupper (char *up, const char *lo) |
| 61 | { |
| 62 | char *up0 = up; |
| 63 | |
| 64 | for (; *lo; lo++, up++) |
| 65 | *up = TOUPPER (*lo); |
| 66 | |
| 67 | *up = '\0'; |
| 68 | |
| 69 | return up0; |
| 70 | } |
| 71 | |
| 72 | /* Worker function for TARGET_CPU_CPP_BUILTINS. */ |
| 73 | |
| 74 | static const char *const avr_builtin_name[] = |
| 75 | { |
| 76 | #define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) NAME, |
| 77 | #include "builtins.def" |
| 78 | #undef DEF_BUILTIN |
| 79 | NULL |
| 80 | }; |
| 81 | |
| 82 | void |
| 83 | avr_cpu_cpp_builtins (struct cpp_reader *pfile) |
| 84 | { |
| 85 | int i; |
| 86 | |
| 87 | builtin_define_std ("AVR"); |
| 88 | |
| 89 | if (avr_current_arch->macro) |
| 90 | cpp_define_formatted (pfile, "__AVR_ARCH__=%s", avr_current_arch->macro); |
Bernhard Rosenkraenzer | 7d3ad0b | 2012-10-23 01:39:53 +0159 | [diff] [blame^] | 91 | if (avr_current_device->macro) |
| 92 | cpp_define (pfile, avr_current_device->macro); |
Bernhard Rosenkraenzer | c83ebe5 | 2012-09-18 21:38:03 +0159 | [diff] [blame] | 93 | if (AVR_HAVE_RAMPD) cpp_define (pfile, "__AVR_HAVE_RAMPD__"); |
| 94 | if (AVR_HAVE_RAMPX) cpp_define (pfile, "__AVR_HAVE_RAMPX__"); |
| 95 | if (AVR_HAVE_RAMPY) cpp_define (pfile, "__AVR_HAVE_RAMPY__"); |
| 96 | if (AVR_HAVE_RAMPZ) cpp_define (pfile, "__AVR_HAVE_RAMPZ__"); |
| 97 | if (AVR_HAVE_ELPM) cpp_define (pfile, "__AVR_HAVE_ELPM__"); |
| 98 | if (AVR_HAVE_ELPMX) cpp_define (pfile, "__AVR_HAVE_ELPMX__"); |
| 99 | if (AVR_HAVE_MOVW) cpp_define (pfile, "__AVR_HAVE_MOVW__"); |
| 100 | if (AVR_HAVE_LPMX) cpp_define (pfile, "__AVR_HAVE_LPMX__"); |
| 101 | |
| 102 | if (avr_current_arch->asm_only) |
| 103 | cpp_define (pfile, "__AVR_ASM_ONLY__"); |
| 104 | if (AVR_HAVE_MUL) |
| 105 | { |
| 106 | cpp_define (pfile, "__AVR_ENHANCED__"); |
| 107 | cpp_define (pfile, "__AVR_HAVE_MUL__"); |
| 108 | } |
| 109 | if (avr_current_arch->have_jmp_call) |
| 110 | { |
| 111 | cpp_define (pfile, "__AVR_MEGA__"); |
| 112 | cpp_define (pfile, "__AVR_HAVE_JMP_CALL__"); |
| 113 | } |
| 114 | if (AVR_XMEGA) |
| 115 | cpp_define (pfile, "__AVR_XMEGA__"); |
| 116 | if (avr_current_arch->have_eijmp_eicall) |
| 117 | { |
| 118 | cpp_define (pfile, "__AVR_HAVE_EIJMP_EICALL__"); |
| 119 | cpp_define (pfile, "__AVR_3_BYTE_PC__"); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | cpp_define (pfile, "__AVR_2_BYTE_PC__"); |
| 124 | } |
| 125 | |
| 126 | if (AVR_HAVE_8BIT_SP) |
| 127 | cpp_define (pfile, "__AVR_HAVE_8BIT_SP__"); |
| 128 | else |
| 129 | cpp_define (pfile, "__AVR_HAVE_16BIT_SP__"); |
| 130 | |
| 131 | if (avr_sp8) |
| 132 | cpp_define (pfile, "__AVR_SP8__"); |
| 133 | |
| 134 | if (AVR_HAVE_SPH) |
| 135 | cpp_define (pfile, "__AVR_HAVE_SPH__"); |
| 136 | |
| 137 | if (TARGET_NO_INTERRUPTS) |
| 138 | cpp_define (pfile, "__NO_INTERRUPTS__"); |
| 139 | |
| 140 | if (avr_current_device->errata_skip) |
| 141 | { |
| 142 | cpp_define (pfile, "__AVR_ERRATA_SKIP__"); |
| 143 | |
| 144 | if (avr_current_arch->have_jmp_call) |
| 145 | cpp_define (pfile, "__AVR_ERRATA_SKIP_JMP_CALL__"); |
| 146 | } |
| 147 | |
| 148 | cpp_define_formatted (pfile, "__AVR_SFR_OFFSET__=0x%x", |
| 149 | avr_current_arch->sfr_offset); |
| 150 | |
| 151 | #ifdef WITH_AVRLIBC |
| 152 | cpp_define (pfile, "__WITH_AVRLIBC__"); |
| 153 | #endif /* WITH_AVRLIBC */ |
| 154 | |
| 155 | /* Define builtin macros so that the user can easily query if or if not |
| 156 | non-generic address spaces (and which) are supported. |
| 157 | This is only supported for C. For C++, a language extension is needed |
| 158 | (as mentioned in ISO/IEC DTR 18037; Annex F.2) which is not |
| 159 | implemented in GCC up to now. */ |
| 160 | |
| 161 | if (!strcmp (lang_hooks.name, "GNU C")) |
| 162 | { |
| 163 | for (i = 0; avr_addrspace[i].name; i++) |
| 164 | if (!ADDR_SPACE_GENERIC_P (i) |
| 165 | /* Only supply __FLASH<n> macro if the address space is reasonable |
| 166 | for this target. The address space qualifier itself is still |
| 167 | supported, but using it will throw an error. */ |
| 168 | && avr_addrspace[i].segment < avr_current_device->n_flash) |
| 169 | { |
| 170 | const char *name = avr_addrspace[i].name; |
| 171 | char *Name = (char*) alloca (1 + strlen (name)); |
| 172 | |
| 173 | cpp_define_formatted (pfile, "%s=%s", |
| 174 | avr_toupper (Name, name), name); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /* Define builtin macros so that the user can easily query if or |
| 179 | if not a specific builtin is available. */ |
| 180 | |
| 181 | for (i = 0; avr_builtin_name[i]; i++) |
| 182 | { |
| 183 | const char *name = avr_builtin_name[i]; |
| 184 | char *Name = (char*) alloca (1 + strlen (name)); |
| 185 | |
| 186 | cpp_define (pfile, avr_toupper (Name, name)); |
| 187 | } |
| 188 | |
| 189 | /* Builtin macros for the __int24 and __uint24 type. */ |
| 190 | |
| 191 | cpp_define (pfile, "__INT24_MAX__=8388607L"); |
| 192 | cpp_define (pfile, "__INT24_MIN__=(-__INT24_MAX__-1)"); |
| 193 | cpp_define (pfile, "__UINT24_MAX__=16777215UL"); |
| 194 | } |