This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] New cpp builtins for avr/


Neil Booth wrote:-

> 	* avr.c (avr_arch, extra_arch_macro): New.
> 	(enum avr_arch, avr_mcu_types): Update.
> 	(avr_override_options): Set avr_arch.
> 	* avr.h (CPP_PREDEFINES): Die.
> 	(enum avr_arch_t, avr_arch, extra_arch_macro): New.
> 	(TARGET_CPU_CPP_BUILTINS): New.
> 	(CPP_SPEC, EXTRA_SPECS): Simplify.
> 	(CPP_AVR1_SPEC, CPP_AVR2_SPEC, CPP_AVR3_SPEC, CPP_AVR4_SPEC,
> 	CPP_AVR5_SPEC): Die.

Oops, the patch I posted was an old version that doesn't compile.
Here's the one I meant to post (same ChangeLog).

Neil.

Index: avr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr.c,v
retrieving revision 1.64
diff -u -p -r1.64 avr.c
--- avr.c	19 May 2002 20:08:12 -0000	1.64
+++ avr.c	19 May 2002 21:43:24 -0000
@@ -70,6 +70,10 @@ static void   avr_encode_section_info PA
 /* Allocate registers from r25 to r8 for parameters for function calls */
 #define FIRST_CUM_REG 26
 
+/* AVR architecture type.  */
+enum avr_arch_t avr_arch = aa_avr2;
+const char *extra_arch_macro;
+
 /* Temporary register RTX (gen_rtx (REG,QImode,TMP_REGNO)) */
 rtx tmp_reg_rtx;
 
@@ -125,6 +129,8 @@ enum avr_arch {
 struct mcu_type_s {
   const char *const name;
   const enum avr_arch arch;
+  /* Must lie outside user's namespace.  NULL == no macro.  */
+  const char *macro;
 };
 
 /* List of all known AVR MCU types - if updated, it has to be kept
@@ -137,52 +143,52 @@ struct mcu_type_s {
 
 static const struct mcu_type_s avr_mcu_types[] = {
     /* Classic, <= 8K.  */
-  { "avr2",      AVR2 },
-  { "at90s2313", AVR2 },
-  { "at90s2323", AVR2 },
-  { "at90s2333", AVR2 },
-  { "at90s2343", AVR2 },
-  { "attiny22",  AVR2 },
-  { "attiny26",  AVR2 },
-  { "at90s4414", AVR2 },
-  { "at90s4433", AVR2 },
-  { "at90s4434", AVR2 },
-  { "at90s8515", AVR2 },
-  { "at90c8534", AVR2 },
-  { "at90s8535", AVR2 },
+  { "avr2",      AVR2, 0 },
+  { "at90s2313", AVR2, "__AVR_AT90S2313__" },
+  { "at90s2323", AVR2, "__AVR_AT90S2323__" },
+  { "at90s2333", AVR2, "__AVR_AT90S2333__" },
+  { "at90s2343", AVR2, "__AVR_AT90S2343__" },
+  { "attiny22",  AVR2, "__AVR_ATtiny22__" },
+  { "attiny26",  AVR2, "__AVR_ATtiny26__" },
+  { "at90s4414", AVR2, "__AVR_AT90S4414__" },
+  { "at90s4433", AVR2, "__AVR_AT90S4433__" },
+  { "at90s4434", AVR2, "__AVR_AT90S4434__" },
+  { "at90s8515", AVR2, "__AVR_AT90S8515__" },
+  { "at90c8534", AVR2, "__AVR_AT90C8534__" },
+  { "at90s8535", AVR2, "__AVR_AT90S8535__" },
     /* Classic, > 8K.  */
-  { "avr3",      AVR3 },
-  { "atmega103", AVR3 },
-  { "atmega603", AVR3 },
-  { "at43usb320", AVR3 },
-  { "at43usb355", AVR3 },
-  { "at76c711",  AVR3 },
+  { "avr3",      AVR3, NULL },
+  { "atmega103", AVR3, "__AVR_ATmega603__" },
+  { "atmega603", AVR3, "__AVR_ATmega103__" },
+  { "at43usb320", AVR3, "__AVR_AT43USB320__" },
+  { "at43usb355", AVR3, "__AVR_AT43USB355__" },
+  { "at76c711",  AVR3, "__AVR_AT76C711__" },
     /* Enhanced, <= 8K.  */
-  { "avr4",      AVR4 },
-  { "atmega8",   AVR4 },
-  { "atmega83",  AVR4 },
-  { "atmega85",  AVR4 },
-  { "atmega8515", AVR4 },
+  { "avr4",      AVR4, NULL },
+  { "atmega8",   AVR4, "__AVR_ATmega8__" },
+  { "atmega83",  AVR4, "__AVR_ATmega83__" },
+  { "atmega85",  AVR4, "__AVR_ATmega85__" },
+  { "atmega8515", AVR4, "__AVR_ATmega8515__" },
     /* Enhanced, > 8K.  */
-  { "avr5",      AVR5 },
-  { "atmega16",  AVR5 },
-  { "atmega161", AVR5 },
-  { "atmega162", AVR5 },
-  { "atmega163", AVR5 },
-  { "atmega32",  AVR5 },
-  { "atmega323", AVR5 },
-  { "atmega64",  AVR5 },
-  { "atmega128", AVR5 },
-  { "at94k",     AVR5 },
+  { "avr5",      AVR5, NULL },
+  { "atmega16",  AVR5, "__AVR_ATmega16__" },
+  { "atmega161", AVR5, "__AVR_ATmega161__" },
+  { "atmega162", AVR5, "__AVR_ATmega162__" },
+  { "atmega163", AVR5, "__AVR_ATmega163__" },
+  { "atmega32",  AVR5, "__AVR_ATmega32__" },
+  { "atmega323", AVR5, "__AVR_ATmega323__" },
+  { "atmega64",  AVR5, "__AVR_ATmega64__" },
+  { "atmega128", AVR5, "__AVR_ATmega128__" },
+  { "at94k",     AVR5, "__AVR_AT94K__" },
     /* Assembler only.  */
-  { "avr1",      AVR1 },
-  { "at90s1200", AVR1 },
-  { "attiny10",  AVR1 },
-  { "attiny11",  AVR1 },
-  { "attiny12",  AVR1 },
-  { "attiny15",  AVR1 },
-  { "attiny28",  AVR1 },
-  { NULL, 0 }
+  { "avr1",      AVR1, NULL },
+  { "at90s1200", AVR1, "__AVR_AT90S1200__" },
+  { "attiny10",  AVR1, "__AVR_ATtiny11__" }, /* Yes, tiny11.  */
+  { "attiny11",  AVR1, "__AVR_ATtiny11__" },
+  { "attiny12",  AVR1, "__AVR_ATtiny12__" },
+  { "attiny15",  AVR1, "__AVR_ATtiny15__" },
+  { "attiny28",  AVR1, "__AVR_ATtiny28__" },
+  { NULL, 0, NULL }
 };
 
 int avr_case_values_threshold = 30000;
@@ -223,16 +229,20 @@ avr_override_options ()
 	fprintf (stderr,"   %s\n", t->name);
     }
 
+  extra_arch_macro = t->macro;
+
   switch (t->arch)
     {
     case AVR1:
+      avr_arch = aa_avr1;
     default:
       error ("MCU `%s' not supported", avr_mcu_name);
-      /* ... fall through ... */
-    case AVR2: avr_enhanced_p = 0; avr_mega_p = 0; break;
-    case AVR3: avr_enhanced_p = 0; avr_mega_p = 1; break;
-    case AVR4: avr_enhanced_p = 1; avr_mega_p = 0; break;
-    case AVR5: avr_enhanced_p = 1; avr_mega_p = 1; break;
+      avr_enhanced_p = 0; avr_mega_p = 0;
+      break;
+    case AVR2: avr_arch = aa_avr2; avr_enhanced_p = 0; avr_mega_p = 0; break;
+    case AVR3: avr_arch = aa_avr3; avr_enhanced_p = 0; avr_mega_p = 1; break;
+    case AVR4: avr_arch = aa_avr4; avr_enhanced_p = 1; avr_mega_p = 0; break;
+    case AVR5: avr_arch = aa_avr5; avr_enhanced_p = 1; avr_mega_p = 1; break;
     }
 
   if (optimize && !TARGET_NO_TABLEJUMP)
Index: avr.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr.h,v
retrieving revision 1.53
diff -u -p -r1.53 avr.h
--- avr.h	19 May 2002 07:55:32 -0000	1.53
+++ avr.h	19 May 2002 21:43:34 -0000
@@ -22,8 +22,47 @@ Boston, MA 02111-1307, USA.  */
 
 /* Names to predefine in the preprocessor for this target machine. */
 
-#define CPP_PREDEFINES "-DAVR"
-
+enum avr_arch_t {aa_avr1, aa_avr2, aa_avr3, aa_avr4, aa_avr5};
+extern enum avr_arch_t avr_arch;
+extern const char *extra_arch_macro;
+
+#define TARGET_CPU_CPP_BUILTINS() 		\
+  do						\
+    {						\
+      builtin_define_std ("AVR");		\
+      if (extra_arch_macro)			\
+	builtin_define (extra_arch_macro);	\
+      switch (avr_arch)				\
+	{					\
+	case aa_avr1:				\
+	  builtin_define ("__AVR_ARCH__=1");	\
+	  builtin_define ("__AVR_ASM_ONLY__");	\
+	  break;				\
+	case aa_avr2:				\
+	  builtin_define ("__AVR_ARCH__=2");	\
+	  break;				\
+	case aa_avr3:				\
+	  builtin_define ("__AVR_ARCH__=3");	\
+	  builtin_define ("__AVR_MEGA__");	\
+	  break;				\
+	case aa_avr4:				\
+	  builtin_define ("__AVR_ARCH__=4");	\
+	  builtin_define ("__AVR_ENHANCED__");	\
+	  break;				\
+	case aa_avr5:				\
+	  builtin_define ("__AVR_ARCH__=5");	\
+	  builtin_define ("__AVR_ENHANCED__");	\
+	  builtin_define ("__AVR_MEGA__");	\
+	  break;				\
+	}					\
+      if (TARGET_NO_INTERRUPTS)			\
+	builtin_define ("__NO_INTERRUPTS__");	\
+      if (TARGET_INT8)				\
+	builtin_define ("__INT_MAX__=127");	\
+      else					\
+	builtin_define ("__INT_MAX__=32767");	\
+    }						\
+  while (0)
 
 /* This declaration should be present. */
 extern int target_flags;
@@ -54,9 +93,6 @@ extern int target_flags;
 #define TARGET_RTL_DUMP		(target_flags & MASK_RTL_DUMP)
 #define TARGET_ALL_DEBUG 	(target_flags & MASK_ALL_DEBUG)
 
-
-
-
 #define TARGET_SWITCHES {						\
   { "order1", MASK_ORDER_1, NULL },					\
   { "order2", MASK_ORDER_2, NULL },					\
@@ -2497,51 +2533,8 @@ extern int avr_case_values_threshold;
    (and ANSI C) library functions `memcpy' and `memset' rather than
    the BSD functions `bcopy' and `bzero'.  */
 
-#define CPP_SPEC "\
-%{!mmcu*|mmcu=avr2:%(cpp_avr2)} \
-%{mmcu=at90s2313:%(cpp_avr2) -D__AVR_AT90S2313__} \
-%{mmcu=at90s2323:%(cpp_avr2) -D__AVR_AT90S2323__} \
-%{mmcu=at90s2333:%(cpp_avr2) -D__AVR_AT90S2333__} \
-%{mmcu=at90s2343:%(cpp_avr2) -D__AVR_AT90S2343__} \
-%{mmcu=attiny22: %(cpp_avr2) -D__AVR_ATtiny22__} \
-%{mmcu=attiny26: %(cpp_avr2) -D__AVR_ATtiny26__} \
-%{mmcu=at90s4433:%(cpp_avr2) -D__AVR_AT90S4433__} \
-%{mmcu=at90s4414:%(cpp_avr2) -D__AVR_AT90S4414__} \
-%{mmcu=at90s4434:%(cpp_avr2) -D__AVR_AT90S4434__} \
-%{mmcu=at90s8515:%(cpp_avr2) -D__AVR_AT90S8515__} \
-%{mmcu=at90s8535:%(cpp_avr2) -D__AVR_AT90S8535__} \
-%{mmcu=at90c8534:%(cpp_avr2) -D__AVR_AT90C8534__} \
-%{mmcu=avr3:%(cpp_avr3)} \
-%{mmcu=atmega603:%(cpp_avr3) -D__AVR_ATmega603__} \
-%{mmcu=atmega103:%(cpp_avr3) -D__AVR_ATmega103__} \
-%{mmcu=at43usb320:%(cpp_avr3) -D__AVR_AT43USB320__} \
-%{mmcu=at43usb355:%(cpp_avr3) -D__AVR_AT43USB355__} \
-%{mmcu=at76c711: %(cpp_avr3) -D__AVR_AT76C711__} \
-%{mmcu=avr4:%(cpp_avr4)} \
-%{mmcu=atmega8:  %(cpp_avr4) -D__AVR_ATmega8__} \
-%{mmcu=atmega83: %(cpp_avr4) -D__AVR_ATmega83__} \
-%{mmcu=atmega85: %(cpp_avr4) -D__AVR_ATmega85__} \
-%{mmcu=atmega8515: %(cpp_avr4) -D__AVR_ATmega8515__} \
-%{mmcu=avr5:%(cpp_avr5)} \
-%{mmcu=atmega16: %(cpp_avr5) -D__AVR_ATmega16__} \
-%{mmcu=atmega161:%(cpp_avr5) -D__AVR_ATmega161__} \
-%{mmcu=atmega162:%(cpp_avr5) -D__AVR_ATmega162__} \
-%{mmcu=atmega163:%(cpp_avr5) -D__AVR_ATmega163__} \
-%{mmcu=atmega32: %(cpp_avr5) -D__AVR_ATmega32__} \
-%{mmcu=atmega323:%(cpp_avr5) -D__AVR_ATmega323__} \
-%{mmcu=atmega64: %(cpp_avr5) -D__AVR_ATmega64__} \
-%{mmcu=atmega128:%(cpp_avr5) -D__AVR_ATmega128__} \
-%{mmcu=at94k:    %(cpp_avr5) -D__AVR_AT94K__} \
-%{mmcu=avr1:%(cpp_avr1)} \
-%{mmcu=at90s1200:%(cpp_avr1) -D__AVR_AT90S1200__} \
-%{mmcu=attiny10|mmcu=attiny11: %(cpp_avr1) -D__AVR_ATtiny11__} \
-%{mmcu=attiny12: %(cpp_avr1) -D__AVR_ATtiny12__} \
-%{mmcu=attiny15: %(cpp_avr1) -D__AVR_ATtiny15__} \
-%{mmcu=attiny28: %(cpp_avr1) -D__AVR_ATtiny28__} \
-%{mno-interrupts:-D__NO_INTERRUPTS__} \
-%{mint8:-D__INT_MAX__=127} \
-%{!mint*:-D__INT_MAX__=32767} \
-%{posix:-D_POSIX_SOURCE}"
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}"
+
 /* A C string constant that tells the GNU CC driver program options to
    pass to CPP.  It can also specify how to translate options you
    give to GNU CC into options for GNU CC to pass to the CPP.
@@ -2684,62 +2677,11 @@ extern int avr_case_values_threshold;
 %{mmcu=atmega128:crtm128.o%s} \
 %{mmcu=at94k:crtat94k.o%s}"
 
-#define CPP_AVR1_SPEC "-D__AVR_ARCH__=1 -D__AVR_ASM_ONLY__ "
-#define CPP_AVR2_SPEC "-D__AVR_ARCH__=2 "
-#define CPP_AVR3_SPEC "-D__AVR_ARCH__=3 -D__AVR_MEGA__ "
-#define CPP_AVR4_SPEC "-D__AVR_ARCH__=4 -D__AVR_ENHANCED__ "
-#define CPP_AVR5_SPEC "-D__AVR_ARCH__=5 -D__AVR_ENHANCED__ -D__AVR_MEGA__ "
-
-#define EXTRA_SPECS                           \
-{"cpp_avr1", CPP_AVR1_SPEC},                  \
-{"cpp_avr2", CPP_AVR2_SPEC},                  \
-{"cpp_avr3", CPP_AVR3_SPEC},                  \
-{"cpp_avr4", CPP_AVR4_SPEC},                  \
-{"cpp_avr5", CPP_AVR5_SPEC},                  \
-{"crt_binutils", CRT_BINUTILS_SPECS},
+#define EXTRA_SPECS {"crt_binutils", CRT_BINUTILS_SPECS},
+
 /* Define this macro to provide additional specifications to put in
    the `specs' file that can be used in various specifications like
-   `CC1_SPEC'.
-
-   The definition should be an initializer for an array of structures,
-   containing a string constant, that defines the specification name,
-   and a string constant that provides the specification.
-
-   Do not define this macro if it does not need to do anything.
-
-   `EXTRA_SPECS' is useful when an architecture contains several
-   related targets, which have various `..._SPECS' which are similar
-   to each other, and the maintainer would like one central place to
-   keep these definitions.
-
-   For example, the PowerPC System V.4 targets use `EXTRA_SPECS' to
-   define either `_CALL_SYSV' when the System V calling sequence is
-   used or `_CALL_AIX' when the older AIX-based calling sequence is
-   used.
-
-   The `config/rs6000/rs6000.h' target file defines:
-
-   #define EXTRA_SPECS \
-   { "cpp_sysv_default", CPP_SYSV_DEFAULT },
-
-   #define CPP_SYS_DEFAULT ""
-
-   The `config/rs6000/sysv.h' target file defines:
-   #undef CPP_SPEC
-   #define CPP_SPEC \
-   "%{posix: -D_POSIX_SOURCE } \
-   %{mcall-sysv: -D_CALL_SYSV } %{mcall-aix: -D_CALL_AIX } \
-   %{!mcall-sysv: %{!mcall-aix: %(cpp_sysv_default) }} \
-   %{msoft-float: -D_SOFT_FLOAT} %{mcpu=403: -D_SOFT_FLOAT}"
-
-   #undef CPP_SYSV_DEFAULT
-   #define CPP_SYSV_DEFAULT "-D_CALL_SYSV"
-
-   while the `config/rs6000/eabiaix.h' target file defines
-   `CPP_SYSV_DEFAULT' as:
-
-   #undef CPP_SYSV_DEFAULT
-   #define CPP_SYSV_DEFAULT "-D_CALL_AIX"  */
+   `CC1_SPEC'.  */
 
 /* This is the default without any -mmcu=* option (AT90S*).  */
 #define MULTILIB_DEFAULTS { "mmcu=avr2" }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]