Prototype common device framework. Plenty more work to go.
[deliverable/binutils-gdb.git] / sim / mn10300 / gencode.c
CommitLineData
05ccbdfd
JL
1#include "mn10300_sim.h"
2
3static void write_header PARAMS ((void));
4static void write_opcodes PARAMS ((void));
5static void write_template PARAMS ((void));
6
7long Opcodes[512];
8static int curop=0;
9
10int
11main (argc, argv)
12 int argc;
13 char *argv[];
14{
15 if ((argc > 1) && (strcmp (argv[1], "-h") == 0))
16 write_header();
17 else if ((argc > 1) && (strcmp (argv[1], "-t") == 0))
18 write_template ();
19 else
20 write_opcodes();
21 return 0;
22}
23
24
25static void
26write_header ()
27{
28 struct mn10300_opcode *opcode;
29
30 for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++)
d2523010 31 printf("void OP_%X PARAMS ((unsigned long, unsigned long));\t\t/* %s */\n",
05ccbdfd
JL
32 opcode->opcode, opcode->name);
33}
34
35
36/* write_template creates a file all required functions, ready */
37/* to be filled out */
38
39static void
40write_template ()
41{
42 struct mn10300_opcode *opcode;
43 int i,j;
44
45 printf ("#include \"mn10300_sim.h\"\n");
46 printf ("#include \"simops.h\"\n");
47
48 for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++)
49 {
fc038f56 50 printf("/* %s */\nvoid\nOP_%X (insn, extension)\n unsigned long insn, extension;\n{\n", opcode->name, opcode->opcode);
05ccbdfd
JL
51
52 /* count operands */
53 j = 0;
54 for (i = 0; i < 6; i++)
55 {
56 int flags = mn10300_operands[opcode->operands[i]].flags;
57
58 if (flags)
59 j++;
60 }
61 switch (j)
62 {
63 case 0:
64 printf ("printf(\" %s\\n\");\n", opcode->name);
65 break;
66 case 1:
67 printf ("printf(\" %s\\t%%x\\n\", OP[0]);\n", opcode->name);
68 break;
69 case 2:
70 printf ("printf(\" %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",
71 opcode->name);
72 break;
73 case 3:
74 printf ("printf(\" %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",
75 opcode->name);
76 break;
77 default:
78 fprintf (stderr,"Too many operands: %d\n", j);
79 }
80 printf ("}\n\n");
81 }
82}
83
84static void
85write_opcodes ()
86{
87 struct mn10300_opcode *opcode;
88 int i, j;
89 int numops;
90
91 /* write out opcode table */
92 printf ("#include \"mn10300_sim.h\"\n");
93 printf ("#include \"simops.h\"\n\n");
94 printf ("struct simops Simops[] = {\n");
95
96 for (opcode = (struct mn10300_opcode *)mn10300_opcodes; opcode->name; opcode++)
97 {
b5f831ac
JL
98 int size;
99
100 if (opcode->format == FMT_S0)
101 size = 1;
102 else if (opcode->format == FMT_S1
103 || opcode->format == FMT_D0)
104 size = 2;
105 else if (opcode->format == FMT_S2
106 || opcode->format == FMT_D1)
107 size = 3;
108 else if (opcode->format == FMT_S4)
109 size = 5;
110 else if (opcode->format == FMT_D2)
111 size = 4;
112 else if (opcode->format == FMT_D4)
113 size = 6;
114 else
115 size = 7;
116
191c9d73
JL
117 printf (" { 0x%x,0x%x,OP_%X,%d,%d,",
118 opcode->opcode, opcode->mask, opcode->opcode,
119 size, opcode->format);
05ccbdfd
JL
120
121 Opcodes[curop++] = opcode->opcode;
122
123 /* count operands */
124 j = 0;
125 for (i = 0; i < 6; i++)
126 {
127 int flags = mn10300_operands[opcode->operands[i]].flags;
128
129 if (flags)
130 j++;
131 }
132 printf ("%d,{",j);
133
134 j = 0;
135 numops = 0;
136 for (i = 0; i < 6; i++)
137 {
138 int flags = mn10300_operands[opcode->operands[i]].flags;
139 int shift = mn10300_operands[opcode->operands[i]].shift;
140
141 if (flags)
142 {
143 if (j)
144 printf (", ");
145 printf ("%d,%d,%d", shift,
146 mn10300_operands[opcode->operands[i]].bits,flags);
147 j = 1;
148 numops++;
149 }
150 }
151
152 switch (numops)
153 {
154 case 0:
155 printf ("0,0,0");
156 case 1:
157 printf (",0,0,0");
158 }
159
160 printf ("}},\n");
161 }
191c9d73 162 printf ("{ 0,0,NULL,0,0,0,{0,0,0,0,0,0}},\n};\n");
05ccbdfd 163}
This page took 0.06536 seconds and 4 git commands to generate.