Add -Wshadow to the gcc command line options used when compiling the binutils.
[deliverable/binutils-gdb.git] / bfd / xtensa-isa.c
index 68d33c699a0ab6ccad8da2df07f0308d6192fe27..26deaaa7eac342ad20d8164a6b5ab69c3bab96c5 100644 (file)
@@ -1,11 +1,11 @@
 /* Configurable Xtensa ISA support.
 /* Configurable Xtensa ISA support.
-   Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This file is part of BFD, the Binary File Descriptor library.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 
-#include "bfd.h"
 #include "sysdep.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "libbfd.h"
 #include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 #include "libbfd.h"
 #include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
@@ -63,6 +64,7 @@ xtensa_isa_error_msg (xtensa_isa isa __attribute__ ((unused)))
       } \
   } while (0)
 
       } \
   } while (0)
 
+
 \f
 /* Instruction buffers.  */
 
 \f
 /* Instruction buffers.  */
 
@@ -406,10 +408,15 @@ xtensa_isa_length_from_chars (xtensa_isa isa, const unsigned char *cp)
 int
 xtensa_isa_num_pipe_stages (xtensa_isa isa) 
 {
 int
 xtensa_isa_num_pipe_stages (xtensa_isa isa) 
 {
-  int num_opcodes, num_uses;
   xtensa_opcode opcode;
   xtensa_funcUnit_use *use;
   xtensa_opcode opcode;
   xtensa_funcUnit_use *use;
-  int i, stage, max_stage = XTENSA_UNDEFINED;
+  int num_opcodes, num_uses;
+  int i, stage;
+  static int max_stage = XTENSA_UNDEFINED;
+
+  /* Only compute the value once.  */
+  if (max_stage != XTENSA_UNDEFINED)
+    return max_stage + 1;
 
   num_opcodes = xtensa_isa_num_opcodes (isa);
   for (opcode = 0; opcode < num_opcodes; opcode++)
 
   num_opcodes = xtensa_isa_num_opcodes (isa);
   for (opcode = 0; opcode < num_opcodes; opcode++)
@@ -653,7 +660,7 @@ xtensa_opcode
 xtensa_opcode_lookup (xtensa_isa isa, const char *opname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
 xtensa_opcode_lookup (xtensa_isa isa, const char *opname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
-  xtensa_lookup_entry entry, *result;
+  xtensa_lookup_entry entry, *result = 0;
 
   if (!opname || !*opname)
     {
 
   if (!opname || !*opname)
     {
@@ -662,9 +669,13 @@ xtensa_opcode_lookup (xtensa_isa isa, const char *opname)
       return XTENSA_UNDEFINED;
     }
 
       return XTENSA_UNDEFINED;
     }
 
-  entry.key = opname;
-  result = bsearch (&entry, intisa->opname_lookup_table, intisa->num_opcodes,
-                   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+  if (intisa->num_opcodes != 0)
+    {
+      entry.key = opname;
+      result = bsearch (&entry, intisa->opname_lookup_table,
+                       intisa->num_opcodes, sizeof (xtensa_lookup_entry),
+                       xtensa_isa_name_compare);
+    }
 
   if (!result)
     {
 
   if (!result)
     {
@@ -691,12 +702,12 @@ xtensa_opcode_decode (xtensa_isa isa, xtensa_format fmt, int slot,
   slot_id = intisa->formats[fmt].slot_id[slot];
 
   opc = (intisa->slots[slot_id].opcode_decode_fn) (slotbuf);
   slot_id = intisa->formats[fmt].slot_id[slot];
 
   opc = (intisa->slots[slot_id].opcode_decode_fn) (slotbuf);
-  if (opc == XTENSA_UNDEFINED)
-    {
-      xtisa_errno = xtensa_isa_bad_opcode;
-      strcpy (xtisa_error_msg, "cannot decode opcode");
-    }
-  return opc;
+  if (opc != XTENSA_UNDEFINED)
+    return opc;
+
+  xtisa_errno = xtensa_isa_bad_opcode;
+  strcpy (xtisa_error_msg, "cannot decode opcode");
+  return XTENSA_UNDEFINED;
 }
 
 
 }
 
 
@@ -1017,15 +1028,14 @@ xtensa_operand_encode (xtensa_isa isa, xtensa_opcode opc, int opnd,
   uint32 test_val, orig_val;
 
   intop = get_operand (intisa, opc, opnd);
   uint32 test_val, orig_val;
 
   intop = get_operand (intisa, opc, opnd);
-  if (!intop) return -1;
+  if (!intop)
+    return -1;
 
   if (!intop->encode)
     {
       /* This is a default operand for a field.  How can we tell if the
         value fits in the field?  Write the value into the field,
         read it back, and then make sure we get the same value.  */
 
   if (!intop->encode)
     {
       /* This is a default operand for a field.  How can we tell if the
         value fits in the field?  Write the value into the field,
         read it back, and then make sure we get the same value.  */
-
-      xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
       static xtensa_insnbuf tmpbuf = 0;
       int slot_id;
 
       static xtensa_insnbuf tmpbuf = 0;
       int slot_id;
 
@@ -1070,9 +1080,9 @@ xtensa_operand_encode (xtensa_isa isa, xtensa_opcode opc, int opnd,
      was successfully encoded is to decode it and check if it matches
      the original value.  */
   orig_val = *valp;
      was successfully encoded is to decode it and check if it matches
      the original value.  */
   orig_val = *valp;
-  if ((*intop->encode) (valp) ||
-      (test_val = *valp, (*intop->decode) (&test_val)) ||
-      test_val != orig_val)
+  if ((*intop->encode) (valp)
+      || (test_val = *valp, (*intop->decode) (&test_val))
+      || test_val != orig_val)
     {
       xtisa_errno = xtensa_isa_bad_value;
       sprintf (xtisa_error_msg, "cannot encode operand value 0x%08x", *valp);
     {
       xtisa_errno = xtensa_isa_bad_value;
       sprintf (xtisa_error_msg, "cannot encode operand value 0x%08x", *valp);
@@ -1288,6 +1298,7 @@ xtensa_stateOperand_inout (xtensa_isa isa, xtensa_opcode opc, int stOp)
   return iclass->stateOperands[stOp].inout;
 }
 
   return iclass->stateOperands[stOp].inout;
 }
 
+
 \f
 /* Interface Operands.  */
 
 \f
 /* Interface Operands.  */
 
@@ -1438,6 +1449,7 @@ xtensa_regfile_num_entries (xtensa_isa isa, xtensa_regfile rf)
   return intisa->regfiles[rf].num_entries;
 }
 
   return intisa->regfiles[rf].num_entries;
 }
 
+
 \f
 /* Processor States.  */
 
 \f
 /* Processor States.  */
 
@@ -1457,7 +1469,7 @@ xtensa_state
 xtensa_state_lookup (xtensa_isa isa, const char *name)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
 xtensa_state_lookup (xtensa_isa isa, const char *name)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
-  xtensa_lookup_entry entry, *result;
+  xtensa_lookup_entry entry, *result = 0;
 
   if (!name || !*name)
     {
 
   if (!name || !*name)
     {
@@ -1466,9 +1478,12 @@ xtensa_state_lookup (xtensa_isa isa, const char *name)
       return XTENSA_UNDEFINED;
     }
 
       return XTENSA_UNDEFINED;
     }
 
-  entry.key = name;
-  result = bsearch (&entry, intisa->state_lookup_table, intisa->num_states,
-                   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+  if (intisa->num_states != 0)
+    {
+      entry.key = name;
+      result = bsearch (&entry, intisa->state_lookup_table, intisa->num_states,
+                       sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+    }
 
   if (!result)
     {
 
   if (!result)
     {
@@ -1509,6 +1524,18 @@ xtensa_state_is_exported (xtensa_isa isa, xtensa_state st)
   return 0;
 }
 
   return 0;
 }
 
+
+int
+xtensa_state_is_shared_or (xtensa_isa isa, xtensa_state st)
+{
+  xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
+  CHECK_STATE (intisa, st, XTENSA_UNDEFINED);
+  if ((intisa->states[st].flags & XTENSA_STATE_IS_SHARED_OR) != 0)
+    return 1;
+  return 0;
+}
+
+
 \f
 /* Sysregs.  */
 
 \f
 /* Sysregs.  */
 
@@ -1548,7 +1575,7 @@ xtensa_sysreg
 xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
 xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
-  xtensa_lookup_entry entry, *result;
+  xtensa_lookup_entry entry, *result = 0;
 
   if (!name || !*name)
     {
 
   if (!name || !*name)
     {
@@ -1557,9 +1584,13 @@ xtensa_sysreg_lookup_name (xtensa_isa isa, const char *name)
       return XTENSA_UNDEFINED;
     }
 
       return XTENSA_UNDEFINED;
     }
 
-  entry.key = name;
-  result = bsearch (&entry, intisa->sysreg_lookup_table, intisa->num_sysregs,
-                   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+  if (intisa->num_sysregs != 0)
+    {
+      entry.key = name;
+      result = bsearch (&entry, intisa->sysreg_lookup_table,
+                       intisa->num_sysregs, sizeof (xtensa_lookup_entry),
+                       xtensa_isa_name_compare);
+    }
 
   if (!result)
     {
 
   if (!result)
     {
@@ -1600,6 +1631,7 @@ xtensa_sysreg_is_user (xtensa_isa isa, xtensa_sysreg sysreg)
   return 0;
 }
 
   return 0;
 }
 
+
 \f
 /* Interfaces.  */
 
 \f
 /* Interfaces.  */
 
@@ -1619,7 +1651,7 @@ xtensa_interface
 xtensa_interface_lookup (xtensa_isa isa, const char *ifname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
 xtensa_interface_lookup (xtensa_isa isa, const char *ifname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
-  xtensa_lookup_entry entry, *result;
+  xtensa_lookup_entry entry, *result = 0;
 
   if (!ifname || !*ifname)
     {
 
   if (!ifname || !*ifname)
     {
@@ -1628,10 +1660,13 @@ xtensa_interface_lookup (xtensa_isa isa, const char *ifname)
       return XTENSA_UNDEFINED;
     }
 
       return XTENSA_UNDEFINED;
     }
 
-  entry.key = ifname;
-  result = bsearch (&entry, intisa->interface_lookup_table,
-                   intisa->num_interfaces,
-                   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+  if (intisa->num_interfaces != 0)
+    {
+      entry.key = ifname;
+      result = bsearch (&entry, intisa->interface_lookup_table,
+                       intisa->num_interfaces, sizeof (xtensa_lookup_entry),
+                       xtensa_isa_name_compare);
+    }
 
   if (!result)
     {
 
   if (!result)
     {
@@ -1690,6 +1725,7 @@ xtensa_interface_class_id (xtensa_isa isa, xtensa_interface intf)
   return intisa->interfaces[intf].class_id;
 }
 
   return intisa->interfaces[intf].class_id;
 }
 
+
 \f
 /* Functional Units.  */
 
 \f
 /* Functional Units.  */
 
@@ -1709,7 +1745,7 @@ xtensa_funcUnit
 xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
 xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname)
 {
   xtensa_isa_internal *intisa = (xtensa_isa_internal *) isa;
-  xtensa_lookup_entry entry, *result;
+  xtensa_lookup_entry entry, *result = 0;
 
   if (!fname || !*fname)
     {
 
   if (!fname || !*fname)
     {
@@ -1718,10 +1754,13 @@ xtensa_funcUnit_lookup (xtensa_isa isa, const char *fname)
       return XTENSA_UNDEFINED;
     }
 
       return XTENSA_UNDEFINED;
     }
 
-  entry.key = fname;
-  result = bsearch (&entry, intisa->funcUnit_lookup_table,
-                   intisa->num_funcUnits,
-                   sizeof (xtensa_lookup_entry), xtensa_isa_name_compare);
+  if (intisa->num_funcUnits != 0)
+    {
+      entry.key = fname;
+      result = bsearch (&entry, intisa->funcUnit_lookup_table,
+                       intisa->num_funcUnits, sizeof (xtensa_lookup_entry),
+                       xtensa_isa_name_compare);
+    }
 
   if (!result)
     {
 
   if (!result)
     {
This page took 0.026848 seconds and 4 git commands to generate.