[avr] Add device name to cpp_builtins

Message ID 20140723080440.GA28575@atmel.com
State New
Headers show

Commit Message

Senthil Kumar Selvaraj July 23, 2014, 8:04 a.m.
The below patch adds a new preprocessor define for the device name
(__AVR_DEVICE_NAME__) that was passed to the compiler.

While the device name macro (say __AVR_ATmega128__) can be used to 
check for a specific device, there is no way right now for code 
to get the device name it is being compiled against (without checking
for every possible device).

This patch is groundwork for embedding device information in a note
section (see binutils ml discussion
https://www.sourceware.org/ml/binutils/2014-07/msg00146.html), so that
utilities that operate on the ELF file do not have to hardcode
device information themselves.

If ok, could someone apply please? I don't have commit access.

Regards
Senthil

2014-07-23  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

	* config/avr/avr-c.c (avr_cpu_cpp_builtins): Add __AVR_DEVICE_NAME__.

Comments

Denis Chertykov July 24, 2014, 6:41 p.m. | #1
2014-07-23 12:04 GMT+04:00 Senthil Kumar Selvaraj
<senthil_kumar.selvaraj@atmel.com>:
> The below patch adds a new preprocessor define for the device name
> (__AVR_DEVICE_NAME__) that was passed to the compiler.
>
> While the device name macro (say __AVR_ATmega128__) can be used to
> check for a specific device, there is no way right now for code
> to get the device name it is being compiled against (without checking
> for every possible device).
>
> This patch is groundwork for embedding device information in a note
> section (see binutils ml discussion
> https://www.sourceware.org/ml/binutils/2014-07/msg00146.html), so that
> utilities that operate on the ELF file do not have to hardcode
> device information themselves.
>
> If ok, could someone apply please? I don't have commit access.
>
> Regards
> Senthil
>
> 2014-07-23  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
>
>         * config/avr/avr-c.c (avr_cpu_cpp_builtins): Add __AVR_DEVICE_NAME__.
>

Committed.

Denis.
Georg-Johann Lay July 28, 2014, 6:09 p.m. | #2
Senthil Kumar Selvaraj schrieb:
> The below patch adds a new preprocessor define for the device name
> (__AVR_DEVICE_NAME__) that was passed to the compiler.
> 
> While the device name macro (say __AVR_ATmega128__) can be used to 
> check for a specific device, there is no way right now for code 
> to get the device name it is being compiled against (without checking
> for every possible device).

Shouldn't this also be added to the documentation?
There's a section "AVR Built-in Macros" in the manual.

Johann

> This patch is groundwork for embedding device information in a note
> section (see binutils ml discussion
> https://www.sourceware.org/ml/binutils/2014-07/msg00146.html), so that
> utilities that operate on the ELF file do not have to hardcode
> device information themselves.
> 
> If ok, could someone apply please? I don't have commit access.
> 
> Regards
> Senthil

Patch

diff --git gcc/config/avr/avr-c.c gcc/config/avr/avr-c.c
index c6a2f1f..7c9f758 100644
--- gcc/config/avr/avr-c.c
+++ gcc/config/avr/avr-c.c
@@ -299,7 +299,10 @@  avr_cpu_cpp_builtins (struct cpp_reader *pfile)
   if (avr_current_arch->macro)
     cpp_define_formatted (pfile, "__AVR_ARCH__=%s", avr_current_arch->macro);
   if (avr_current_device->macro)
-    cpp_define (pfile, avr_current_device->macro);
+    {
+      cpp_define (pfile, avr_current_device->macro);
+      cpp_define_formatted (pfile, "__AVR_DEVICE_NAME__=%s", avr_current_device->name);
+    }
   if (AVR_HAVE_RAMPD)    cpp_define (pfile, "__AVR_HAVE_RAMPD__");
   if (AVR_HAVE_RAMPX)    cpp_define (pfile, "__AVR_HAVE_RAMPX__");
   if (AVR_HAVE_RAMPY)    cpp_define (pfile, "__AVR_HAVE_RAMPY__");