o Wordwrap usage messages from sim-options
[deliverable/binutils-gdb.git] / sim / v850 / gencode.c
index 37f41b8b980acb9e029fb843689ba9f98efd0200..05ce8666b6879cd20431be27b5d6770969776fb5 100644 (file)
@@ -1,17 +1,24 @@
-#include "v850_sim.h"
+#include <stdio.h>
+#include <ctype.h>
+#include "ansidecl.h"
+#include "opcode/v850.h"
+#include <limits.h>
 
 static void write_header PARAMS ((void));
 static void write_opcodes PARAMS ((void));
 static void write_template PARAMS ((void));
 
+long Opcodes[512];
+static int curop=0;
+
 int
 main (argc, argv)
      int argc;
      char *argv[];
 {
-  if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
+  if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
     write_header();
-  else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
+  else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
     write_template ();
   else
     write_opcodes();
@@ -25,7 +32,8 @@ write_header ()
   struct v850_opcode *opcode;
 
   for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
-    printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",opcode->opcode, opcode->name);
+    printf("int OP_%X PARAMS ((void));\t\t/* %s */\n",
+          opcode->opcode, opcode->name);
 }
 
 
@@ -38,12 +46,13 @@ write_template ()
   struct v850_opcode *opcode;
   int i,j;
 
+  printf ("#include \"sim-main.h\"\n");
   printf ("#include \"v850_sim.h\"\n");
   printf ("#include \"simops.h\"\n");
 
   for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
     {
-      printf("/* %s */\nvoid\nOP_%X ()\n{\n",opcode->name,opcode->opcode);
+      printf("/* %s */\nvoid\nOP_%X (void)\n{\n", opcode->name, opcode->opcode);
          
       /* count operands */
       j = 0;
@@ -57,56 +66,44 @@ write_template ()
       switch (j)
        {
        case 0:
-         printf ("printf(\"   %s\\n\");\n",opcode->name);
+         printf ("printf(\"   %s\\n\");\n", opcode->name);
          break;
        case 1:
-         printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",opcode->name);
+         printf ("printf(\"   %s\\t%%x\\n\", OP[0]);\n", opcode->name);
          break;
        case 2:
-         printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",opcode->name);
+         printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
+                 opcode->name);
          break;
        case 3:
-         printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",opcode->name);
+         printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
+                 opcode->name);
          break;
        default:
-         fprintf (stderr,"Too many operands: %d\n",j);
+         fprintf (stderr,"Too many operands: %d\n", j);
        }
       printf ("}\n\n");
     }
 }
 
-
-long Opcodes[512];
-static int curop=0;
-
-check_opcodes( long op)
-{
-  int i;
-
-  for (i=0;i<curop;i++)
-    if (Opcodes[i] == op)
-      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
-}
-
-
 static void
 write_opcodes ()
 {
   struct v850_opcode *opcode;
   int i, j;
+  int numops;
   
   /* write out opcode table */
+  printf ("#include \"sim-main.h\"\n");
   printf ("#include \"v850_sim.h\"\n");
   printf ("#include \"simops.h\"\n\n");
   printf ("struct simops Simops[] = {\n");
   
   for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
     {
-      printf ("  { %ld,%ld,OP_%X,",
+      printf ("  { 0x%x,0x%x,OP_%X,",
              opcode->opcode, opcode->mask, opcode->opcode);
       
-      /* REMOVE ME */
-      check_opcodes (opcode->opcode);
       Opcodes[curop++] = opcode->opcode;
 
       /* count operands */
@@ -121,6 +118,7 @@ write_opcodes ()
       printf ("%d,{",j);
          
       j = 0;
+      numops = 0;
       for (i = 0; i < 6; i++)
        {
          int flags = v850_operands[opcode->operands[i]].flags;
@@ -130,15 +128,22 @@ write_opcodes ()
            {
              if (j)
                printf (", ");
-#if 0
-             if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
-               shift += 15;
-#endif
-             printf ("%d,%d,%d",shift,v850_operands[opcode->operands[i]].bits,flags);
+             printf ("%d,%d,%d", shift,
+                     v850_operands[opcode->operands[i]].bits,flags);
              j = 1;
+             numops++;
            }
        }
+
+      switch (numops)
+       {
+       case 0:
+         printf ("0,0,0");
+       case 1:
+         printf (",0,0,0");
+       }
+
       printf ("}},\n");
     }
-  printf ("{ 0,0,NULL,0,{ }},\n};\n");
+  printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n");
 }
This page took 0.024975 seconds and 4 git commands to generate.