This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils 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]

[m68k]: Patch to sort opcode table into alphabetical order


This patch sorts the opcode table into alphabetical order, preserving
the order for entries that have the same name.  This will allow
for rearranging the opcode table into an order that the disassembler
would like to see(allowing for the removal of special case code to
pick some matches over others) without affecting the assembler that
wants the opcodes in alphabetical order.

It passes make check-DEJAGNU.

--
Peter Barada
peter@the-baradas.com

gas/
2004-05-26  Peter Barada  <peter@the-baradas.com>
	* config/tc-m68k.c(md_begin): Sort the opcode table into
	  alphabetical order.
	* config/tc-m68k.c(m68k_compare_opcode): New function.


Index: gas/config/tc-m68k.c
===================================================================
RCS file: /cvs/uberbaum/gas/config/tc-m68k.c,v
retrieving revision 1.52
diff -c -3 -p -r1.52 tc-m68k.c
*** gas/config/tc-m68k.c	24 May 2004 14:33:18 -0000	1.52
--- gas/config/tc-m68k.c	26 May 2004 15:32:18 -0000
*************** static struct label_line *labels;
*** 130,135 ****
--- 130,138 ----
  
  static struct label_line *current_label;
  
+ /* Pointer to list holding the opcodes sorted by name.  */
+ static struct m68k_opcode const ** m68k_sorted_opcodes;
+ 
  /* Its an arbitrary name:  This means I don't approve of it.
     See flames below.  */
  static struct obstack robyn;
*************** md_assemble (str)
*** 4113,4118 ****
--- 4116,4143 ----
      }
  }
  
+ /* Comparison function used by qsort to rank the opcode entries by
+    name.  */
+ 
+ static int
+ m68k_compare_opcode(const void *v1, const void *v2)
+ {
+   struct m68k_opcode *op1, *op2;
+   int ret;
+ 
+   op1 = *(struct m68k_opcode **)v1;
+   op2 = *(struct m68k_opcode **)v2;
+ 
+   /* Compare the two names.  If different, return the comparison.  If
+      the same, return the order they are in the opcode table.  */
+   ret = strcmp (op1->name, op2->name);
+   if (ret)
+     return ret;
+   if (op1 < op2)
+     return -1;
+   return 0;
+ }
+ 
  void
  md_begin ()
  {
*************** md_begin ()
*** 4140,4145 ****
--- 4165,4181 ----
  	m68k_rel32 = 0;
      }
  
+   /* First sort the opcode table into alphabetical order to seperate
+      the order that the assembler wants to see the opcodes from the
+      order that the disassembler wants to see them. */
+   m68k_sorted_opcodes = (struct m68k_opcode const **)xmalloc(m68k_numopcodes * sizeof(struct m68k_opcode *));
+   if (!m68k_sorted_opcodes)
+     as_fatal (_("Internal Error:  Can't allocate m68k_sorted_opcodes of size %d"), m68k_numopcodes * sizeof(struct m68k_opcode *));
+   for (i=0; i<m68k_numopcodes; ++i)
+     m68k_sorted_opcodes[i] = &m68k_opcodes[i];
+   qsort(m68k_sorted_opcodes, m68k_numopcodes, sizeof(m68k_sorted_opcodes[0]),
+ 	m68k_compare_opcode);
+ 
    op_hash = hash_new ();
  
    obstack_begin (&robyn, 4000);
*************** md_begin ()
*** 4148,4154 ****
        hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
        do
  	{
! 	  ins = &m68k_opcodes[i];
  	  /* We *could* ignore insns that don't match our arch here
  	     but just leaving them out of the hash.  */
  	  slak->m_operands = ins->args;
--- 4184,4191 ----
        hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
        do
  	{
! 	  ins = m68k_sorted_opcodes[i];
! 
  	  /* We *could* ignore insns that don't match our arch here
  	     but just leaving them out of the hash.  */
  	  slak->m_operands = ins->args;
*************** md_begin ()
*** 4158,4164 ****
  	  /* This is kludgey.  */
  	  slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
  	  if (i + 1 != m68k_numopcodes
! 	      && !strcmp (ins->name, m68k_opcodes[i + 1].name))
  	    {
  	      slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  	      i++;
--- 4195,4201 ----
  	  /* This is kludgey.  */
  	  slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
  	  if (i + 1 != m68k_numopcodes
! 	      && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
  	    {
  	      slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
  	      i++;


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