OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [d10v/] [gencode.c] - Diff between revs 24 and 157

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 24 Rev 157
#include "config.h"
#include "config.h"
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <limits.h>
#include <limits.h>
#include "ansidecl.h"
#include "ansidecl.h"
#include "opcode/d10v.h"
#include "opcode/d10v.h"
 
 
static void write_header PARAMS ((void));
static void write_header PARAMS ((void));
static void write_opcodes PARAMS ((void));
static void write_opcodes PARAMS ((void));
static void write_template PARAMS ((void));
static void write_template PARAMS ((void));
 
 
int
int
main (argc, argv)
main (argc, argv)
     int argc;
     int argc;
     char *argv[];
     char *argv[];
{
{
  if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
  if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
    write_header();
    write_header();
  else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
  else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
    write_template ();
    write_template ();
  else
  else
    write_opcodes();
    write_opcodes();
  return 0;
  return 0;
}
}
 
 
 
 
static void
static void
write_header ()
write_header ()
{
{
  struct d10v_opcode *opcode;
  struct d10v_opcode *opcode;
 
 
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
    if (opcode->format != OPCODE_FAKE)
    if (opcode->format != OPCODE_FAKE)
      printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",opcode->opcode, opcode->name);
      printf("void OP_%X PARAMS ((void));\t\t/* %s */\n",opcode->opcode, opcode->name);
}
}
 
 
 
 
/* write_template creates a file all required functions, ready */
/* write_template creates a file all required functions, ready */
/* to be filled out */
/* to be filled out */
 
 
static void
static void
write_template ()
write_template ()
{
{
  struct d10v_opcode *opcode;
  struct d10v_opcode *opcode;
  int i,j;
  int i,j;
 
 
  printf ("#include \"d10v_sim.h\"\n");
  printf ("#include \"d10v_sim.h\"\n");
  printf ("#include \"simops.h\"\n");
  printf ("#include \"simops.h\"\n");
 
 
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
    {
    {
      if (opcode->format != OPCODE_FAKE)
      if (opcode->format != OPCODE_FAKE)
        {
        {
          printf("/* %s */\nvoid\nOP_%X ()\n{\n",opcode->name,opcode->opcode);
          printf("/* %s */\nvoid\nOP_%X ()\n{\n",opcode->name,opcode->opcode);
 
 
          /* count operands */
          /* count operands */
          j = 0;
          j = 0;
          for (i=0;i<6;i++)
          for (i=0;i<6;i++)
            {
            {
              int flags = d10v_operands[opcode->operands[i]].flags;
              int flags = d10v_operands[opcode->operands[i]].flags;
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
                j++;
                j++;
            }
            }
          switch (j)
          switch (j)
            {
            {
            case 0:
            case 0:
              printf ("printf(\"   %s\\n\");\n",opcode->name);
              printf ("printf(\"   %s\\n\");\n",opcode->name);
              break;
              break;
            case 1:
            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;
              break;
            case 2:
            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;
              break;
            case 3:
            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;
              break;
            default:
            default:
              fprintf (stderr,"Too many operands: %d\n",j);
              fprintf (stderr,"Too many operands: %d\n",j);
            }
            }
          printf ("}\n\n");
          printf ("}\n\n");
        }
        }
    }
    }
}
}
 
 
 
 
long Opcodes[512];
long Opcodes[512];
static int curop=0;
static int curop=0;
 
 
check_opcodes( long op)
check_opcodes( long op)
{
{
  int i;
  int i;
 
 
  for (i=0;i<curop;i++)
  for (i=0;i<curop;i++)
    if (Opcodes[i] == op)
    if (Opcodes[i] == op)
      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
}
}
 
 
 
 
static void
static void
write_opcodes ()
write_opcodes ()
{
{
  struct d10v_opcode *opcode;
  struct d10v_opcode *opcode;
  int i, j;
  int i, j;
 
 
  /* write out opcode table */
  /* write out opcode table */
  printf ("#include \"d10v_sim.h\"\n");
  printf ("#include \"d10v_sim.h\"\n");
  printf ("#include \"simops.h\"\n\n");
  printf ("#include \"simops.h\"\n\n");
  printf ("struct simops Simops[] = {\n");
  printf ("struct simops Simops[] = {\n");
 
 
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
  for (opcode = (struct d10v_opcode *)d10v_opcodes; opcode->name; opcode++)
    {
    {
      if (opcode->format != OPCODE_FAKE)
      if (opcode->format != OPCODE_FAKE)
        {
        {
          printf ("  { %ld,%d,%ld,%d,%d,%d,%d,OP_%X,", opcode->opcode,
          printf ("  { %ld,%d,%ld,%d,%d,%d,%d,OP_%X,", opcode->opcode,
                  (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
                  (opcode->format & LONG_OPCODE) ? 1 : 0, opcode->mask, opcode->format,
                  opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
                  opcode->cycles, opcode->unit, opcode->exec_type, opcode->opcode);
 
 
          /* REMOVE ME */
          /* REMOVE ME */
          check_opcodes (opcode->opcode);
          check_opcodes (opcode->opcode);
          Opcodes[curop++] = opcode->opcode;
          Opcodes[curop++] = opcode->opcode;
 
 
          j = 0;
          j = 0;
          for (i=0;i<6;i++)
          for (i=0;i<6;i++)
            {
            {
              int flags = d10v_operands[opcode->operands[i]].flags;
              int flags = d10v_operands[opcode->operands[i]].flags;
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM) || (flags & OPERAND_ADDR))
                j++;
                j++;
            }
            }
          printf ("%d,",j);
          printf ("%d,",j);
 
 
          j = 0;
          j = 0;
          for (i=0;i<6;i++)
          for (i=0;i<6;i++)
            {
            {
              int flags = d10v_operands[opcode->operands[i]].flags;
              int flags = d10v_operands[opcode->operands[i]].flags;
              int shift = d10v_operands[opcode->operands[i]].shift;
              int shift = d10v_operands[opcode->operands[i]].shift;
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
              if ((flags & OPERAND_REG) || (flags & OPERAND_NUM)|| (flags & OPERAND_ADDR))
                {
                {
                  if (j == 0)
                  if (j == 0)
                    printf ("{");
                    printf ("{");
                  else
                  else
                    printf (", ");
                    printf (", ");
                  if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
                  if ((flags & OPERAND_REG) && (opcode->format == LONG_L))
                    shift += 15;
                    shift += 15;
                  printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
                  printf ("%d,%d,%d",shift,d10v_operands[opcode->operands[i]].bits,flags);
                  j = 1;
                  j = 1;
                }
                }
            }
            }
          if (j)
          if (j)
            printf ("}");
            printf ("}");
          printf ("},\n");
          printf ("},\n");
        }
        }
    }
    }
  printf ("{ 0,0,0,0,0,0,0,(void (*)(void))0,0,{0,0,0}},\n};\n");
  printf ("{ 0,0,0,0,0,0,0,(void (*)(void))0,0,{0,0,0}},\n};\n");
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.