2 * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * This program generates the encodings file that is processed by
20 * the dectree.py script to produce the decoding tree. We use the C
21 * preprocessor to manipulate the files imported from the Hexagon
22 * architecture library.
28 #define STRINGIZE(X) #X
30 const char * const opcode_names
[] = {
31 #define OPCODE(IID) STRINGIZE(IID)
32 #include "opcodes_def_generated.h.inc"
38 * Process the instruction definitions
39 * Scalar core instructions have the following form
40 * Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(),
41 * "Add 32-bit registers",
44 const char * const opcode_syntax
[XX_LAST_OPCODE
] = {
45 #define Q6INSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
47 #define EXTINSN(TAG, BEH, ATTRIBS, DESCR, SEM) \
49 #include "imported/allidefs.def"
54 const char * const opcode_rregs
[] = {
55 #define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS,
56 #define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */
57 #include "op_regs_generated.h.inc"
63 const char * const opcode_wregs
[] = {
64 #define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS,
65 #define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */
66 #include "op_regs_generated.h.inc"
72 const 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"
81 #undef DEF_ENC_SUBINSN
85 static const char * const opcode_enc_class_names
[XX_LAST_ENC_CLASS
] = {
97 static const char *get_opcode_enc(int opcode
)
99 const char *tmp
= opcode_encodings
[opcode
].encoding
;
101 tmp
= "MISSING ENCODING";
106 static const char *get_opcode_enc_class(int opcode
)
108 return opcode_enc_class_names
[opcode_encodings
[opcode
].enc_class
];
111 static void gen_iset_table(FILE *out
)
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");
126 fprintf(out
, "};\n\n");
129 static void gen_tags_list(FILE *out
)
133 fprintf(out
, "tags = [\n");
134 for (i
= 0; i
< XX_LAST_OPCODE
; i
++) {
135 fprintf(out
, "\t\'%s\',\n", opcode_names
[i
]);
137 fprintf(out
, "];\n\n");
140 static void gen_enc_ext_spaces_table(FILE *out
)
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"
147 fprintf(out
, "};\n\n");
150 static void gen_subinsn_groupings_table(FILE *out
)
152 fprintf(out
, "subinsn_groupings = {\n");
153 #define DEF_PACKED32(TAG, TYPEA, TYPEB, ENCSTR) \
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"); \
162 #include "imported/encode.def"
164 fprintf(out
, "};\n\n");
167 int main(int argc
, char *argv
[])
172 fprintf(stderr
, "Usage: gen_dectree_import ouptputfile\n");
175 outfile
= fopen(argv
[1], "w");
176 if (outfile
== NULL
) {
177 fprintf(stderr
, "Cannot open %s for writing\n", argv
[1]);
181 gen_iset_table(outfile
);
182 gen_tags_list(outfile
);
183 gen_enc_ext_spaces_table(outfile
);
184 gen_subinsn_groupings_table(outfile
);