1 /* Copyright (C) 2009-2013 Free Software Foundation, Inc.
2 Contributed by Anatoly Sokolov (aesok@post.ru)
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* Not included in avr.c since this requires C front end. */
24 #include "coretypes.h"
29 #include "c-family/c-common.h"
30 #include "langhooks.h"
33 /* Implement `REGISTER_TARGET_PRAGMAS'. */
36 avr_register_target_pragmas (void)
40 gcc_assert (ADDR_SPACE_GENERIC
== ADDR_SPACE_RAM
);
42 /* Register address spaces. The order must be the same as in the respective
43 enum from avr.h (or designated initializers must be used in avr.c). */
45 for (i
= 0; i
< ADDR_SPACE_COUNT
; i
++)
47 gcc_assert (i
== avr_addrspace
[i
].id
);
49 if (!ADDR_SPACE_GENERIC_P (i
))
50 c_register_addr_space (avr_addrspace
[i
].name
, avr_addrspace
[i
].id
);
55 /* Transform LO into uppercase and write the result to UP.
56 You must provide enough space for UP. Return UP. */
59 avr_toupper (char *up
, const char *lo
)
63 for (; *lo
; lo
++, up
++)
71 /* Worker function for TARGET_CPU_CPP_BUILTINS. */
73 static const char *const avr_builtin_name
[] =
75 #define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE) NAME,
76 #include "builtins.def"
82 avr_cpu_cpp_builtins (struct cpp_reader
*pfile
)
86 builtin_define_std ("AVR");
88 if (avr_current_arch
->macro
)
89 cpp_define_formatted (pfile
, "__AVR_ARCH__=%s", avr_current_arch
->macro
);
90 if (avr_current_device
->macro
)
91 cpp_define (pfile
, avr_current_device
->macro
);
92 if (AVR_HAVE_RAMPD
) cpp_define (pfile
, "__AVR_HAVE_RAMPD__");
93 if (AVR_HAVE_RAMPX
) cpp_define (pfile
, "__AVR_HAVE_RAMPX__");
94 if (AVR_HAVE_RAMPY
) cpp_define (pfile
, "__AVR_HAVE_RAMPY__");
95 if (AVR_HAVE_RAMPZ
) cpp_define (pfile
, "__AVR_HAVE_RAMPZ__");
96 if (AVR_HAVE_ELPM
) cpp_define (pfile
, "__AVR_HAVE_ELPM__");
97 if (AVR_HAVE_ELPMX
) cpp_define (pfile
, "__AVR_HAVE_ELPMX__");
98 if (AVR_HAVE_MOVW
) cpp_define (pfile
, "__AVR_HAVE_MOVW__");
99 if (AVR_HAVE_LPMX
) cpp_define (pfile
, "__AVR_HAVE_LPMX__");
101 if (avr_current_arch
->asm_only
)
102 cpp_define (pfile
, "__AVR_ASM_ONLY__");
105 cpp_define (pfile
, "__AVR_ENHANCED__");
106 cpp_define (pfile
, "__AVR_HAVE_MUL__");
108 if (avr_current_arch
->have_jmp_call
)
110 cpp_define (pfile
, "__AVR_MEGA__");
111 cpp_define (pfile
, "__AVR_HAVE_JMP_CALL__");
114 cpp_define (pfile
, "__AVR_XMEGA__");
115 if (avr_current_arch
->have_eijmp_eicall
)
117 cpp_define (pfile
, "__AVR_HAVE_EIJMP_EICALL__");
118 cpp_define (pfile
, "__AVR_3_BYTE_PC__");
122 cpp_define (pfile
, "__AVR_2_BYTE_PC__");
125 if (AVR_HAVE_8BIT_SP
)
126 cpp_define (pfile
, "__AVR_HAVE_8BIT_SP__");
128 cpp_define (pfile
, "__AVR_HAVE_16BIT_SP__");
131 cpp_define (pfile
, "__AVR_SP8__");
134 cpp_define (pfile
, "__AVR_HAVE_SPH__");
136 if (TARGET_NO_INTERRUPTS
)
137 cpp_define (pfile
, "__NO_INTERRUPTS__");
139 if (avr_current_device
->errata_skip
)
141 cpp_define (pfile
, "__AVR_ERRATA_SKIP__");
143 if (avr_current_arch
->have_jmp_call
)
144 cpp_define (pfile
, "__AVR_ERRATA_SKIP_JMP_CALL__");
147 cpp_define_formatted (pfile
, "__AVR_SFR_OFFSET__=0x%x",
148 avr_current_arch
->sfr_offset
);
151 cpp_define (pfile
, "__WITH_AVRLIBC__");
152 #endif /* WITH_AVRLIBC */
154 /* Define builtin macros so that the user can easily query whether
155 non-generic address spaces (and which) are supported or not.
156 This is only supported for C. For C++, a language extension is needed
157 (as mentioned in ISO/IEC DTR 18037; Annex F.2) which is not
158 implemented in GCC up to now. */
160 if (!strcmp (lang_hooks
.name
, "GNU C"))
162 for (i
= 0; i
< ADDR_SPACE_COUNT
; i
++)
163 if (!ADDR_SPACE_GENERIC_P (i
)
164 /* Only supply __FLASH<n> macro if the address space is reasonable
165 for this target. The address space qualifier itself is still
166 supported, but using it will throw an error. */
167 && avr_addrspace
[i
].segment
< avr_current_device
->n_flash
)
169 const char *name
= avr_addrspace
[i
].name
;
170 char *Name
= (char*) alloca (1 + strlen (name
));
172 cpp_define (pfile
, avr_toupper (Name
, name
));
176 /* Define builtin macros so that the user can easily query whether or
177 not a specific builtin is available. */
179 for (i
= 0; avr_builtin_name
[i
]; i
++)
181 const char *name
= avr_builtin_name
[i
];
182 char *Name
= (char*) alloca (1 + strlen (name
));
184 cpp_define (pfile
, avr_toupper (Name
, name
));
187 /* Builtin macros for the __int24 and __uint24 type. */
189 cpp_define_formatted (pfile
, "__INT24_MAX__=8388607%s",
190 INT_TYPE_SIZE
== 8 ? "LL" : "L");
191 cpp_define (pfile
, "__INT24_MIN__=(-__INT24_MAX__-1)");
192 cpp_define_formatted (pfile
, "__UINT24_MAX__=16777215%s",
193 INT_TYPE_SIZE
== 8 ? "ULL" : "UL");