diff mbox

[AVR] : Bit of Cleanup [1/3]: Test string for prefix

Message ID 4E564DCB.50900@gjlay.de
State New
Headers show

Commit Message

Georg-Johann Lay Aug. 25, 2011, 1:27 p.m. UTC
Georg-Johann Lay wrote:
> These are three small patches to clean up the avr BE a bit:
> 
> #1: Use custom macro to test of a string starts with given prefix
> 
> #2: Let avr_regno_reg_class return smallest register class
> 
> #3: Replace/remove superfluous byte_immediate_operand and some protos.
> 
> All patches tested without regression.
> 
> Ok to install them?
> 
> Johann

	* config/avr/avr.c (STR_PREFIX_P): New Define.
	(avr_asm_declare_function_name): Use it.
	(avr_asm_named_section): Use it.
	(avr_section_type_flags): Use it.

Comments

Weddington, Eric Aug. 25, 2011, 1:41 p.m. UTC | #1
> -----Original Message-----
> From: Georg-Johann Lay [mailto:avr@gjlay.de]
> Sent: Thursday, August 25, 2011 7:28 AM
> To: gcc-patches@gcc.gnu.org
> Cc: Denis Chertykov; Weddington, Eric
> Subject: Re: [Patch,AVR]: Bit of Cleanup [1/3]: Test string for prefix
> 
> Georg-Johann Lay wrote:
> > These are three small patches to clean up the avr BE a bit:
> >
> > #1: Use custom macro to test of a string starts with given prefix
> >
> > #2: Let avr_regno_reg_class return smallest register class
> >
> > #3: Replace/remove superfluous byte_immediate_operand and some protos.
> >
> > All patches tested without regression.
> >
> > Ok to install them?
> >

Ok for #1.
diff mbox

Patch

Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 178035)
+++ config/avr/avr.c	(working copy)
@@ -51,6 +51,9 @@ 
 /* Maximal allowed offset for an address in the LD command */
 #define MAX_LD_OFFSET(MODE) (64 - (signed)GET_MODE_SIZE (MODE))
 
+/* Return true if STR starts with PREFIX and false, otherwise.  */
+#define STR_PREFIX_P(STR,PREFIX) (0 == strncmp (STR, PREFIX, strlen (PREFIX)))
+
 static void avr_option_override (void);
 static int avr_naked_function_p (tree);
 static int interrupt_function_p (tree);
@@ -4852,7 +4855,7 @@  avr_asm_declare_function_name (FILE *fil
 
   if (cfun->machine->is_interrupt)
     {
-      if (strncmp (name, "__vector", strlen ("__vector")) != 0)
+      if (!STR_PREFIX_P (name, "__vector"))
         {
           warning_at (DECL_SOURCE_LOCATION (decl), 0,
                       "%qs appears to be a misspelled interrupt handler",
@@ -4861,7 +4864,7 @@  avr_asm_declare_function_name (FILE *fil
     }
   else if (cfun->machine->is_signal)
     {
-      if (strncmp (name, "__vector", strlen ("__vector")) != 0)
+      if (!STR_PREFIX_P (name, "__vector"))
         {
            warning_at (DECL_SOURCE_LOCATION (decl), 0,
                        "%qs appears to be a misspelled signal handler",
@@ -5116,12 +5119,12 @@  static void
 avr_asm_named_section (const char *name, unsigned int flags, tree decl)
 {
   if (!avr_need_copy_data_p)
-    avr_need_copy_data_p = (0 == strncmp (name, ".data", 5)
-                            || 0 == strncmp (name, ".rodata", 7)
-                            || 0 == strncmp (name, ".gnu.linkonce.d", 15));
+    avr_need_copy_data_p = (STR_PREFIX_P (name, ".data")
+                            || STR_PREFIX_P (name, ".rodata")
+                            || STR_PREFIX_P (name, ".gnu.linkonce.d"));
   
   if (!avr_need_clear_bss_p)
-    avr_need_clear_bss_p = (0 == strncmp (name, ".bss", 4));
+    avr_need_clear_bss_p = STR_PREFIX_P (name, ".bss");
   
   default_elf_asm_named_section (name, flags, decl);
 }
@@ -5131,7 +5134,7 @@  avr_section_type_flags (tree decl, const
 {
   unsigned int flags = default_section_type_flags (decl, name, reloc);
 
-  if (strncmp (name, ".noinit", 7) == 0)
+  if (STR_PREFIX_P (name, ".noinit"))
     {
       if (decl && TREE_CODE (decl) == VAR_DECL
 	  && DECL_INITIAL (decl) == NULL_TREE)
@@ -5141,7 +5144,7 @@  avr_section_type_flags (tree decl, const
 		 ".noinit section");
     }
 
-  if (0 == strncmp (name, ".progmem.data", strlen (".progmem.data")))
+  if (STR_PREFIX_P (name, ".progmem.data"))
     flags &= ~SECTION_WRITE;
   
   return flags;