1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <stdio.h>
25#include <string.h>
26#include "opcodes.h"
27
28#define STRINGIZE(X) #X
29
30const char * const opcode_names[] = {
31#define OPCODE(IID) STRINGIZE(IID)
32#include "opcodes_def_generated.h.inc"
33 NULL
34#undef OPCODE
35};
36
37
38
39
40
41
42
43
44const char * const opcode_syntax[XX_LAST_OPCODE] = {
45#define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
46 [TAG] = BEH,
47#define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
48 [TAG] = BEH,
49#include "imported/allidefs.def"
50#undef Q6INSN
51#undef EXTINSN
52};
53
54const char * const opcode_rregs[] = {
55#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
56#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)
57#include "op_regs_generated.h.inc"
58 NULL
59#undef REGINFO
60#undef IMMINFO
61};
62
63const char * const opcode_wregs[] = {
64#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
65#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2)
66#include "op_regs_generated.h.inc"
67 NULL
68#undef REGINFO
69#undef IMMINFO
70};
71
72const OpcodeEncoding opcode_encodings[] = {
73#define DEF_ENC32(TAG, ENCSTR) \
74 [TAG] = { .encoding = ENCSTR },
75#define DEF_ENC_SUBINSN(TAG, CLASS, ENCSTR) \
76 [TAG] = { .encoding = ENCSTR, .enc_class = CLASS },
77#define DEF_EXT_ENC(TAG, CLASS, ENCSTR) \
78 [TAG] = { .encoding = ENCSTR, .enc_class = CLASS },
79#include "imported/encode.def"
80#undef DEF_ENC32
81#undef DEF_ENC_SUBINSN
82#undef DEF_EXT_ENC
83};
84
85static const char * const opcode_enc_class_names[XX_LAST_ENC_CLASS] = {
86 "NORMAL",
87 "16BIT",
88 "SUBINSN_A",
89 "SUBINSN_L1",
90 "SUBINSN_L2",
91 "SUBINSN_S1",
92 "SUBINSN_S2",
93 "EXT_noext",
94 "EXT_mmvec",
95};
96
97static const char *get_opcode_enc(int opcode)
98{
99 const char *tmp = opcode_encodings[opcode].encoding;
100 if (tmp == NULL) {
101 tmp = "MISSING ENCODING";
102 }
103 return tmp;
104}
105
106static const char *get_opcode_enc_class(int opcode)
107{
108 return opcode_enc_class_names[opcode_encodings[opcode].enc_class];
109}
110
111static void gen_iset_table(FILE *out)
112{
113 int i;
114
115 fprintf(out, "iset = {\n");
116 for (i = 0; i < XX_LAST_OPCODE; i++) {
117 fprintf(out, "\t\'%s\' : {\n", opcode_names[i]);
118 fprintf(out, "\t\t\'tag\' : \'%s\',\n", opcode_names[i]);
119 fprintf(out, "\t\t\'syntax\' : \'%s\',\n", opcode_syntax[i]);
120 fprintf(out, "\t\t\'rregs\' : \'%s\',\n", opcode_rregs[i]);
121 fprintf(out, "\t\t\'wregs\' : \'%s\',\n", opcode_wregs[i]);
122 fprintf(out, "\t\t\'enc\' : \'%s\',\n", get_opcode_enc(i));
123 fprintf(out, "\t\t\'enc_class\' : \'%s\',\n", get_opcode_enc_class(i));
124 fprintf(out, "\t},\n");
125 }
126 fprintf(out, "};\n\n");
127}
128
129static void gen_tags_list(FILE *out)
130{
131 int i;
132
133 fprintf(out, "tags = [\n");
134 for (i = 0; i < XX_LAST_OPCODE; i++) {
135 fprintf(out, "\t\'%s\',\n", opcode_names[i]);
136 }
137 fprintf(out, "];\n\n");
138}
139
140static void gen_enc_ext_spaces_table(FILE *out)
141{
142 fprintf(out, "enc_ext_spaces = {\n");
143#define DEF_EXT_SPACE(SPACEID, ENCSTR) \
144 fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR);
145#include "imported/encode.def"
146#undef DEF_EXT_SPACE
147 fprintf(out, "};\n\n");
148}
149
150static void gen_subinsn_groupings_table(FILE *out)
151{
152 fprintf(out, "subinsn_groupings = {\n");
153#define DEF_PACKED32(TAG, TYPEA, TYPEB, ENCSTR) \
154 do { \
155 fprintf(out, "\t\'%s\' : {\n", #TAG); \
156 fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \
157 fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \
158 fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \
159 fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \
160 fprintf(out, "\t},\n"); \
161 } while (0);
162#include "imported/encode.def"
163#undef DEF_PACKED32
164 fprintf(out, "};\n\n");
165}
166
167int main(int argc, char *argv[])
168{
169 FILE *outfile;
170
171 if (argc != 2) {
172 fprintf(stderr, "Usage: gen_dectree_import ouptputfile\n");
173 return 1;
174 }
175 outfile = fopen(argv[1], "w");
176 if (outfile == NULL) {
177 fprintf(stderr, "Cannot open %s for writing\n", argv[1]);
178 return 1;
179 }
180
181 gen_iset_table(outfile);
182 gen_tags_list(outfile);
183 gen_enc_ext_spaces_table(outfile);
184 gen_subinsn_groupings_table(outfile);
185
186 fclose(outfile);
187 return 0;
188}
189