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