Remove i386_elf_emit_arch_note
[deliverable/binutils-gdb.git] / sim / cr16 / gencode.c
index bc971f8ed3b6f977edb68735ef7a0ab281eaa03a..3065ebfb4b95cecb5a92f73b86780f7bb34e5146 100644 (file)
@@ -1,5 +1,5 @@
 /* Simulation code for the CR16 processor.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
    Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
 
    This file is part of GDB, the GNU debugger.
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
  
-   You should have received a copy of the GNU General Public License along
-   with this program. If not, see <http://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU General Public License
+   along with this program. If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include "config.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <limits.h>
+#include <string.h>
 #include "ansidecl.h"
 #include "opcode/cr16.h"
 
-static void write_header PARAMS ((void));
-static void write_opcodes PARAMS ((void));
-static void write_template PARAMS ((void));
+static void write_header (void);
+static void write_opcodes (void);
+static void write_template (void);
 
 int
-main (argc, argv)
-     int argc;
-     char *argv[];
+main (int argc, char *argv[])
 {
   if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
     write_header();
@@ -45,7 +44,7 @@ main (argc, argv)
 
 
 static void
-write_header ()
+write_header (void)
 {
   int i = 0; 
 
@@ -54,17 +53,16 @@ write_header ()
 
   /* Loop over instruction table until a full match is found.  */
   for ( ; i < NUMOPCODES; i++)
-  {
-   printf("void OP_%X_%X PARAMS ((void));\t\t/* %s */\n",cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits), cr16_instruction[i].mnemonic);
-  }
+    printf("void OP_%lX_%X (void);\t\t/* %s */\n", cr16_instruction[i].match,
+          (32 - cr16_instruction[i].match_bits), cr16_instruction[i].mnemonic);
 }
 
 
-/* write_template creates a file all required functions, ready */
-/* to be filled out */
+/* write_template creates a file all required functions, 
+   ready to be filled out.  */
 
 static void
-write_template ()
+write_template (void)
 {
   int i = 0,j, k, flags;
 
@@ -74,37 +72,38 @@ write_template ()
   for ( ; i < NUMOPCODES; i++)
     {
       if (cr16_instruction[i].size != 0)
-       {
-         printf("/* %s */\nvoid\nOP_%X_%X ()\n{\n",cr16_instruction[i].mnemonic,cr16_instruction[i].match,(32 - cr16_instruction[i].match_bits));
-         
-         /* count operands */
-         j = 0;
-         for (k=0;k<5;k++)
-           {
-             if (cr16_instruction[i].operands[k].op_type == dummy)
+{
+  printf("/* %s */\nvoid\nOP_%lX_%X ()\n{\n", cr16_instruction[i].mnemonic,
+        cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits));
+  
+  /* count operands.  */
+  j = 0;
+  for (k=0;k<5;k++)
+    {
+      if (cr16_instruction[i].operands[k].op_type == dummy)
                 break;
               else
                 j++;
-           }
-         switch (j)
-           {
-           case 0:
-             printf ("printf(\"   %s\\n\");\n",cr16_instruction[i].mnemonic);
-             break;
-           case 1:
-             printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
-             break;
-           case 2:
-             printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
-             break;
-           case 3:
-             printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
-             break;
-           default:
-             fprintf (stderr,"Too many operands: %d\n",j);
-           }
-         printf ("}\n\n");
-       }
+    }
+  switch (j)
+    {
+    case 0:
+      printf ("printf(\"   %s\\n\");\n",cr16_instruction[i].mnemonic);
+      break;
+    case 1:
+      printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
+      break;
+    case 2:
+      printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
+      break;
+    case 3:
+      printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
+      break;
+    default:
+      fprintf (stderr,"Too many operands: %d\n",j);
+    }
+  printf ("}\n\n");
+}
     }
 }
 
@@ -112,71 +111,67 @@ write_template ()
 long Opcodes[512];
 static int curop=0;
 
+#if 0
+static void
 check_opcodes( long op)
 {
   int i;
 
   for (i=0;i<curop;i++)
     if (Opcodes[i] == op)
-      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
+      fprintf(stderr,"DUPLICATE OPCODES: %lx\n", op);
 }
-
+#endif
 
 static void
-write_opcodes ()
+write_opcodes (void)
 {
   int i = 0, j = 0, k;
   
-  unsigned long mask;
-  /* write out opcode table */
+  /* write out opcode table.  */
   printf ("#include \"cr16_sim.h\"\n");
   printf ("#include \"simops.h\"\n\n");
   printf ("struct simops Simops[] = {\n");
   
-  for ( ; i < NUMOPCODES; i++)
+  for (i = NUMOPCODES-1; i >= 0; --i)
     {
       if (cr16_instruction[i].size != 0)
-       {
-           printf ("  { \"%s\", %ld, %d, %d, %d, \"OP_%X_%X\", OP_%X_%X, ", 
+{
+           printf ("  { \"%s\", %u, %d, %ld, %u, \"OP_%lX_%X\", OP_%lX_%X, ", 
                     cr16_instruction[i].mnemonic, cr16_instruction[i].size, 
                     cr16_instruction[i].match_bits, cr16_instruction[i].match,
                      cr16_instruction[i].flags, ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)),
-                    (32 - cr16_instruction[i].match_bits),
+             (32 - cr16_instruction[i].match_bits),
                      ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)), (32 - cr16_instruction[i].match_bits));
       
-         j = 0;
-         for (k=0;k<5;k++)
-           {
-             if (cr16_instruction[i].operands[k].op_type == dummy)
+  j = 0;
+  for (k=0;k<5;k++)
+    {
+      if (cr16_instruction[i].operands[k].op_type == dummy)
                 break;
               else
                 j++;
-           }
-         printf ("%d, ",j);
-         
-         j = 0;
-         for (k=0;k<4;k++)
-           {
-             int flags = cr16_instruction[i].operands[k].op_type;
-             int match_bits = cr16_instruction[i].operands[k].shift;
-               {
-                 if (j == 0)
-                   printf ("{");
-                 else
-                   printf (", ");
-               //  if (cr16_instruction[i].size == 2)
-                //   match_bits += 15;
-                 printf ("{");
-                 printf ("%d,%d",cr16_instruction[i].operands[k].shift,flags);
-                 printf ("}");
-                 j = 1;
-               }
-           }
-         if (j)
-           printf ("}");
-         printf ("},\n");
-       }
     }
-  //printf (" { 0,0,0,0,(void (*)(void))0,0,{0,0,0}},\n};\n");
-  printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{0,0,0}},\n};\n");
+  printf ("%d, ",j);
+  
+  j = 0;
+  for (k=0;k<4;k++)
+    {
+      int optype = cr16_instruction[i].operands[k].op_type;
+      int shift = cr16_instruction[i].operands[k].shift;
+      if (j == 0)
+        printf ("{");
+      else
+        printf (", ");
+      printf ("{");
+      printf ("%d,%d",optype, shift);
+      printf ("}");
+      j = 1;
+   }
+ if (j)
+  printf ("}");
+ printf ("},\n");
+        }
+    }
+  printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{{0,0},{0,0},{0,0},{0,0}}},\n};\n");
 }
This page took 0.027987 seconds and 4 git commands to generate.