2 ## Copyright(c) 2020-2023 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/>.
18 hexagon_ss = ss.source_set()
20 hex_common_py = 'hex_common.py'
21 attribs_def = meson.current_source_dir() / 'attribs_def.h.inc'
22 gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
23 gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h'
24 idef_parser_dir = meson.current_source_dir() / 'idef-parser'
28 # We use a C program to create semantics_generated.pyinc
30 gen_semantics = executable(
33 native: true, build_by_default: false)
35 semantics_generated = custom_target(
36 'semantics_generated.pyinc',
37 output: 'semantics_generated.pyinc',
38 command: [gen_semantics, '@OUTPUT@'],
40 hexagon_ss.add(semantics_generated)
44 # We use Python scripts to generate the following files
45 # shortcode_generated.h.inc
46 # tcg_func_table_generated.c.inc
47 # printinsn_generated.h.inc
48 # op_regs_generated.h.inc
49 # op_attribs_generated.h.inc
50 # opcodes_def_generated.h.inc
52 shortcode_generated = custom_target(
53 'shortcode_generated.h.inc',
54 output: 'shortcode_generated.h.inc',
55 depends: [semantics_generated],
56 depend_files: [hex_common_py, attribs_def],
57 command: [python, files('gen_shortcode.py'), semantics_generated, attribs_def, '@OUTPUT@'],
59 hexagon_ss.add(shortcode_generated)
61 tcg_func_table_generated = custom_target(
62 'tcg_func_table_generated.c.inc',
63 output: 'tcg_func_table_generated.c.inc',
64 depends: [semantics_generated],
65 depend_files: [hex_common_py, attribs_def],
66 command: [python, files('gen_tcg_func_table.py'), semantics_generated, attribs_def, '@OUTPUT@'],
68 hexagon_ss.add(tcg_func_table_generated)
70 printinsn_generated = custom_target(
71 'printinsn_generated.h.inc',
72 output: 'printinsn_generated.h.inc',
73 depends: [semantics_generated],
74 depend_files: [hex_common_py, attribs_def],
75 command: [python, files('gen_printinsn.py'), semantics_generated, attribs_def, '@OUTPUT@'],
77 hexagon_ss.add(printinsn_generated)
79 op_regs_generated = custom_target(
80 'op_regs_generated.h.inc',
81 output: 'op_regs_generated.h.inc',
82 depends: [semantics_generated],
83 depend_files: [hex_common_py, attribs_def],
84 command: [python, files('gen_op_regs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
86 hexagon_ss.add(op_regs_generated)
88 op_attribs_generated = custom_target(
89 'op_attribs_generated.h.inc',
90 output: 'op_attribs_generated.h.inc',
91 depends: [semantics_generated],
92 depend_files: [hex_common_py, attribs_def],
93 command: [python, files('gen_op_attribs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
95 hexagon_ss.add(op_attribs_generated)
97 opcodes_def_generated = custom_target(
98 'opcodes_def_generated.h.inc',
99 output: 'opcodes_def_generated.h.inc',
100 depends: [semantics_generated],
101 depend_files: [hex_common_py, attribs_def],
102 command: [python, files('gen_opcodes_def.py'), semantics_generated, attribs_def, '@OUTPUT@'],
104 hexagon_ss.add(opcodes_def_generated)
108 # We use a C program to create iset.py which is imported into dectree.py
109 # to create the decode tree
111 gen_dectree_import = executable(
112 'gen_dectree_import',
113 'gen_dectree_import.c', opcodes_def_generated, op_regs_generated,
114 native: true, build_by_default: false)
116 iset_py = custom_target(
119 command: [gen_dectree_import, '@OUTPUT@'],
121 hexagon_ss.add(iset_py)
125 # We use the dectree.py script to generate the decode tree header file
127 dectree_generated = custom_target(
128 'dectree_generated.h.inc',
129 output: 'dectree_generated.h.inc',
131 env: {'PYTHONPATH': meson.current_build_dir()},
132 command: [python, files('dectree.py'), '@OUTPUT@'],
134 hexagon_ss.add(dectree_generated)
136 hexagon_ss.add(files(
149 'mmvec/decode_ext_mmvec.c',
150 'mmvec/system_ext_mmvec.c',
155 # We use flex/bison based idef-parser to generate TCG code for a lot
156 # of instructions. idef-parser outputs
157 # idef-generated-emitter.c
158 # idef-generated-emitter.h.inc
159 # idef-generated-enabled-instructions
161 idef_parser_enabled = get_option('hexagon_idef_parser')
162 if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
163 idef_parser_input_generated = custom_target(
164 'idef_parser_input.h.inc',
165 output: 'idef_parser_input.h.inc',
166 depends: [semantics_generated],
167 depend_files: [hex_common_py],
168 command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, attribs_def, '@OUTPUT@'],
171 preprocessed_idef_parser_input_generated = custom_target(
172 'idef_parser_input.preprocessed.h.inc',
173 output: 'idef_parser_input.preprocessed.h.inc',
174 input: idef_parser_input_generated,
175 depend_files: [idef_parser_dir / 'macros.inc'],
176 command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'],
180 find_program('flex'),
181 output: ['@BASENAME@.yy.c', '@BASENAME@.yy.h'],
182 arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@']
186 find_program('bison', version: '>=3.0'),
187 output: ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
188 arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']
191 glib_dep = dependency('glib-2.0', native: true)
193 idef_parser = executable(
195 [flex.process(idef_parser_dir / 'idef-parser.lex'),
196 bison.process(idef_parser_dir / 'idef-parser.y'),
197 idef_parser_dir / 'parser-helpers.c'],
198 include_directories: ['idef-parser', '../../include/'],
199 dependencies: [glib_dep],
203 idef_generated_tcg = custom_target(
204 'idef-generated-tcg',
205 output: ['idef-generated-emitter.c',
206 'idef-generated-emitter.h.inc',
207 'idef-generated-enabled-instructions'],
208 input: preprocessed_idef_parser_input_generated,
209 depend_files: [hex_common_py],
210 command: [idef_parser, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@', '@OUTPUT2@']
213 indent = find_program('indent', required: false)
215 idef_generated_tcg_c = custom_target(
217 input: idef_generated_tcg[0],
218 output: 'idef-generated-emitter.indented.c',
219 command: [indent, '-linux', '@INPUT@', '-o', '@OUTPUT@']
222 idef_generated_tcg_c = custom_target(
224 input: idef_generated_tcg[0],
225 output: 'idef-generated-emitter.indented.c',
226 command: ['cp', '@INPUT@', '@OUTPUT@']
230 idef_generated_list = idef_generated_tcg[2].full_path()
232 hexagon_ss.add(idef_generated_tcg_c)
234 # Setup input and dependencies for the next step, this depends on whether or
235 # not idef-parser is enabled
236 helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
237 helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h, idef_generated_list]
239 # Setup input and dependencies for the next step, this depends on whether or
240 # not idef-parser is enabled
241 helper_dep = [semantics_generated]
242 helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h]
247 # We use Python scripts to generate the following files
248 # helper_protos_generated.h.inc
249 # helper_funcs_generated.c.inc
250 # tcg_funcs_generated.c.inc
252 helper_protos_generated = custom_target(
253 'helper_protos_generated.h.inc',
254 output: 'helper_protos_generated.h.inc',
256 depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
257 command: [python, files('gen_helper_protos.py'), helper_in, '@OUTPUT@'],
259 hexagon_ss.add(helper_protos_generated)
261 helper_funcs_generated = custom_target(
262 'helper_funcs_generated.c.inc',
263 output: 'helper_funcs_generated.c.inc',
265 depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
266 command: [python, files('gen_helper_funcs.py'), helper_in, '@OUTPUT@'],
268 hexagon_ss.add(helper_funcs_generated)
270 tcg_funcs_generated = custom_target(
271 'tcg_funcs_generated.c.inc',
272 output: 'tcg_funcs_generated.c.inc',
274 depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
275 command: [python, files('gen_tcg_funcs.py'), helper_in, '@OUTPUT@'],
277 hexagon_ss.add(tcg_funcs_generated)
279 analyze_funcs_generated = custom_target(
280 'analyze_funcs_generated.c.inc',
281 output: 'analyze_funcs_generated.c.inc',
283 depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
284 command: [python, files('gen_analyze_funcs.py'), helper_in, '@OUTPUT@'],
286 hexagon_ss.add(analyze_funcs_generated)
288 target_arch += {'hexagon': hexagon_ss}