1997-09-03 04:10:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "ansidecl.h"
|
|
|
|
#include "opcode/v850.h"
|
|
|
|
#include <limits.h>
|
1996-08-29 01:06:42 +00:00
|
|
|
|
|
|
|
static void write_header PARAMS ((void));
|
|
|
|
static void write_opcodes PARAMS ((void));
|
|
|
|
static void write_template PARAMS ((void));
|
|
|
|
|
1996-09-03 18:31:48 +00:00
|
|
|
long Opcodes[512];
|
|
|
|
static int curop=0;
|
|
|
|
|
1996-08-29 01:06:42 +00:00
|
|
|
int
|
|
|
|
main (argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
1996-09-03 18:31:48 +00:00
|
|
|
if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
|
1996-08-29 01:06:42 +00:00
|
|
|
write_header();
|
1996-09-03 18:31:48 +00:00
|
|
|
else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
|
1996-08-29 01:06:42 +00:00
|
|
|
write_template ();
|
|
|
|
else
|
|
|
|
write_opcodes();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
write_header ()
|
|
|
|
{
|
|
|
|
struct v850_opcode *opcode;
|
|
|
|
|
|
|
|
for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
|
1997-08-14 02:13:32 +00:00
|
|
|
printf("int OP_%X PARAMS ((void));\t\t/* %s */\n",
|
1996-09-03 18:31:48 +00:00
|
|
|
opcode->opcode, opcode->name);
|
1996-08-29 01:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* write_template creates a file all required functions, ready */
|
|
|
|
/* to be filled out */
|
|
|
|
|
|
|
|
static void
|
|
|
|
write_template ()
|
|
|
|
{
|
|
|
|
struct v850_opcode *opcode;
|
|
|
|
int i,j;
|
|
|
|
|
1997-09-03 04:10:33 +00:00
|
|
|
printf ("#include \"sim-main.h\"\n");
|
1996-08-29 01:06:42 +00:00
|
|
|
printf ("#include \"v850_sim.h\"\n");
|
|
|
|
printf ("#include \"simops.h\"\n");
|
|
|
|
|
|
|
|
for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
|
|
|
|
{
|
1997-09-03 04:10:33 +00:00
|
|
|
printf("/* %s */\nvoid\nOP_%X (void)\n{\n", opcode->name, opcode->opcode);
|
1996-08-29 01:06:42 +00:00
|
|
|
|
|
|
|
/* count operands */
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
int flags = v850_operands[opcode->operands[i]].flags;
|
|
|
|
|
|
|
|
if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
switch (j)
|
|
|
|
{
|
|
|
|
case 0:
|
1996-09-03 18:31:48 +00:00
|
|
|
printf ("printf(\" %s\\n\");\n", opcode->name);
|
1996-08-29 01:06:42 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
1996-09-03 18:31:48 +00:00
|
|
|
printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name);
|
1996-08-29 01:06:42 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1996-09-03 18:31:48 +00:00
|
|
|
printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
|
|
|
|
opcode->name);
|
1996-08-29 01:06:42 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
1996-09-03 18:31:48 +00:00
|
|
|
printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
|
|
|
|
opcode->name);
|
1996-08-29 01:06:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
1996-09-03 18:31:48 +00:00
|
|
|
fprintf (stderr,"Too many operands: %d\n", j);
|
1996-08-29 01:06:42 +00:00
|
|
|
}
|
|
|
|
printf ("}\n\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
write_opcodes ()
|
|
|
|
{
|
|
|
|
struct v850_opcode *opcode;
|
|
|
|
int i, j;
|
1996-10-24 17:39:30 +00:00
|
|
|
int numops;
|
1996-08-29 01:06:42 +00:00
|
|
|
|
|
|
|
/* write out opcode table */
|
1997-09-03 04:10:33 +00:00
|
|
|
printf ("#include \"sim-main.h\"\n");
|
1996-08-29 01:06:42 +00:00
|
|
|
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++)
|
|
|
|
{
|
1996-09-28 01:38:45 +00:00
|
|
|
printf (" { 0x%x,0x%x,OP_%X,",
|
1996-08-29 01:06:42 +00:00
|
|
|
opcode->opcode, opcode->mask, opcode->opcode);
|
|
|
|
|
|
|
|
Opcodes[curop++] = opcode->opcode;
|
|
|
|
|
|
|
|
/* count operands */
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
int flags = v850_operands[opcode->operands[i]].flags;
|
|
|
|
|
|
|
|
if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
printf ("%d,{",j);
|
|
|
|
|
|
|
|
j = 0;
|
1996-10-24 17:39:30 +00:00
|
|
|
numops = 0;
|
1996-08-29 01:06:42 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
int flags = v850_operands[opcode->operands[i]].flags;
|
|
|
|
int shift = v850_operands[opcode->operands[i]].shift;
|
|
|
|
|
|
|
|
if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
|
|
|
|
{
|
|
|
|
if (j)
|
|
|
|
printf (", ");
|
1996-09-03 18:31:48 +00:00
|
|
|
printf ("%d,%d,%d", shift,
|
|
|
|
v850_operands[opcode->operands[i]].bits,flags);
|
1996-08-29 01:06:42 +00:00
|
|
|
j = 1;
|
1996-10-24 17:39:30 +00:00
|
|
|
numops++;
|
1996-08-29 01:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-24 17:39:30 +00:00
|
|
|
|
|
|
|
switch (numops)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
printf ("0,0,0");
|
|
|
|
case 1:
|
|
|
|
printf (",0,0,0");
|
|
|
|
}
|
|
|
|
|
1996-08-29 01:06:42 +00:00
|
|
|
printf ("}},\n");
|
|
|
|
}
|
1996-10-24 17:39:30 +00:00
|
|
|
printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n");
|
1996-08-29 01:06:42 +00:00
|
|
|
}
|