Add real SIM_DESC arg to v850 simulator.
[deliverable/binutils-gdb.git] / sim / v850 / gencode.c
CommitLineData
9cdd2c6d
AC
1#include <stdio.h>
2#include <ctype.h>
3#include "ansidecl.h"
4#include "opcode/v850.h"
5#include <limits.h>
22c1c7dd
JL
6
7static void write_header PARAMS ((void));
8static void write_opcodes PARAMS ((void));
9static void write_template PARAMS ((void));
10
9fca2fd3
JL
11long Opcodes[512];
12static int curop=0;
13
22c1c7dd
JL
14int
15main (argc, argv)
16 int argc;
17 char *argv[];
18{
9fca2fd3 19 if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
22c1c7dd 20 write_header();
9fca2fd3 21 else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
22c1c7dd
JL
22 write_template ();
23 else
24 write_opcodes();
25 return 0;
26}
27
28
29static void
30write_header ()
31{
32 struct v850_opcode *opcode;
33
34 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
f7fcba7a 35 printf("int OP_%X PARAMS ((void));\t\t/* %s */\n",
9fca2fd3 36 opcode->opcode, opcode->name);
22c1c7dd
JL
37}
38
39
40/* write_template creates a file all required functions, ready */
41/* to be filled out */
42
43static void
44write_template ()
45{
46 struct v850_opcode *opcode;
47 int i,j;
48
9cdd2c6d 49 printf ("#include \"sim-main.h\"\n");
22c1c7dd
JL
50 printf ("#include \"v850_sim.h\"\n");
51 printf ("#include \"simops.h\"\n");
52
53 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
54 {
9cdd2c6d 55 printf("/* %s */\nvoid\nOP_%X (void)\n{\n", opcode->name, opcode->opcode);
22c1c7dd
JL
56
57 /* count operands */
58 j = 0;
59 for (i = 0; i < 6; i++)
60 {
61 int flags = v850_operands[opcode->operands[i]].flags;
62
63 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
64 j++;
65 }
66 switch (j)
67 {
68 case 0:
9fca2fd3 69 printf ("printf(\" %s\\n\");\n", opcode->name);
22c1c7dd
JL
70 break;
71 case 1:
9fca2fd3 72 printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name);
22c1c7dd
JL
73 break;
74 case 2:
9fca2fd3
JL
75 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
76 opcode->name);
22c1c7dd
JL
77 break;
78 case 3:
9fca2fd3
JL
79 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
80 opcode->name);
22c1c7dd
JL
81 break;
82 default:
9fca2fd3 83 fprintf (stderr,"Too many operands: %d\n", j);
22c1c7dd
JL
84 }
85 printf ("}\n\n");
86 }
87}
88
22c1c7dd
JL
89static void
90write_opcodes ()
91{
92 struct v850_opcode *opcode;
93 int i, j;
96851909 94 int numops;
22c1c7dd
JL
95
96 /* write out opcode table */
9cdd2c6d 97 printf ("#include \"sim-main.h\"\n");
22c1c7dd
JL
98 printf ("#include \"v850_sim.h\"\n");
99 printf ("#include \"simops.h\"\n\n");
100 printf ("struct simops Simops[] = {\n");
101
102 for (opcode = (struct v850_opcode *)v850_opcodes; opcode->name; opcode++)
103 {
88777ce2 104 printf (" { 0x%x,0x%x,OP_%X,",
22c1c7dd
JL
105 opcode->opcode, opcode->mask, opcode->opcode);
106
22c1c7dd
JL
107 Opcodes[curop++] = opcode->opcode;
108
109 /* count operands */
110 j = 0;
111 for (i = 0; i < 6; i++)
112 {
113 int flags = v850_operands[opcode->operands[i]].flags;
114
115 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
116 j++;
117 }
118 printf ("%d,{",j);
119
120 j = 0;
96851909 121 numops = 0;
22c1c7dd
JL
122 for (i = 0; i < 6; i++)
123 {
124 int flags = v850_operands[opcode->operands[i]].flags;
125 int shift = v850_operands[opcode->operands[i]].shift;
126
127 if (flags & (V850_OPERAND_REG | V850_OPERAND_SRG | V850_OPERAND_CC))
128 {
129 if (j)
130 printf (", ");
9fca2fd3
JL
131 printf ("%d,%d,%d", shift,
132 v850_operands[opcode->operands[i]].bits,flags);
22c1c7dd 133 j = 1;
96851909 134 numops++;
22c1c7dd
JL
135 }
136 }
96851909
SG
137
138 switch (numops)
139 {
140 case 0:
141 printf ("0,0,0");
142 case 1:
143 printf (",0,0,0");
144 }
145
22c1c7dd
JL
146 printf ("}},\n");
147 }
96851909 148 printf ("{ 0,0,NULL,0,{0,0,0,0,0,0}},\n};\n");
22c1c7dd 149}
This page took 0.055513 seconds and 4 git commands to generate.