* gx sim prototype tweaks
[binutils-gdb.git] / sim / v850 / gencode.c
blob05ce8666b6879cd20431be27b5d6770969776fb5
1 #include <stdio.h>
2 #include <ctype.h>
3 #include "ansidecl.h"
4 #include "opcode/v850.h"
5 #include <limits.h>
7 static void write_header PARAMS ((void));
8 static void write_opcodes PARAMS ((void));
9 static void write_template PARAMS ((void));
11 long Opcodes[512];
12 static int curop=0;
14 int
15 main (argc, argv)
16 int argc;
17 char *argv[];
19 if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
20 write_header();
21 else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
22 write_template ();
23 else
24 write_opcodes();
25 return 0;
29 static void
30 write_header ()
32 struct v850_opcode *opcode;
34 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
35 printf("int OP_%X PARAMS ((void));\t\t/* %s */\n",
36 opcode->opcode, opcode->name);
40 /* write_template creates a file all required functions, ready */
41 /* to be filled out */
43 static void
44 write_template ()
46 struct v850_opcode *opcode;
47 int i,j;
49 printf ("#include \"sim-main.h\"\n");
50 printf ("#include \"v850_sim.h\"\n");
51 printf ("#include \"simops.h\"\n");
53 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
55 printf("/* %s */\nvoid\nOP_%X (void)\n{\n", opcode->name, opcode->opcode);
57 /* count operands */
58 j = 0;
59 for (i = 0; i < 6; i++)
61 int flags = v850_operands[opcode->operands[i]].flags;
63 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
64 j++;
66 switch (j)
68 case 0:
69 printf ("printf(\" %s\\n\");\n", opcode->name);
70 break;
71 case 1:
72 printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name);
73 break;
74 case 2:
75 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
76 opcode->name);
77 break;
78 case 3:
79 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
80 opcode->name);
81 break;
82 default:
83 fprintf (stderr,"Too many operands: %d\n", j);
85 printf ("}\n\n");
89 static void
90 write_opcodes ()
92 struct v850_opcode *opcode;
93 int i, j;
94 int numops;
96 /* write out opcode table */
97 printf ("#include \"sim-main.h\"\n");
98 printf ("#include \"v850_sim.h\"\n");
99 printf ("#include \"simops.h\"\n\n");
100 printf ("struct simops Simops[] = {\n");
102 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
104 printf (" { 0x%x,0x%x,OP_%X,",
105 opcode->opcode, opcode->mask, opcode->opcode);
107 Opcodes[curop++] = opcode->opcode;
109 /* count operands */
110 j = 0;
111 for (i = 0; i < 6; i++)
113 int flags = v850_operands[opcode->operands[i]].flags;
115 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
116 j++;
118 printf ("%d,{",j);
120 j = 0;
121 numops = 0;
122 for (i = 0; i < 6; i++)
124 int flags = v850_operands[opcode->operands[i]].flags;
125 int shift = v850_operands[opcode->operands[i]].shift;
127 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
129 if (j)
130 printf (", ");
131 printf ("%d,%d,%d", shift,
132 v850_operands[opcode->operands[i]].bits,flags);
133 j = 1;
134 numops++;
138 switch (numops)
140 case 0:
141 printf ("0,0,0");
142 case 1:
143 printf (",0,0,0");
146 printf ("}},\n");
148 printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n");