xref: /openbmc/qemu/target/hexagon/meson.build (revision dd84028f)
1##
2##  Copyright(c) 2020-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3##
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.
8##
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.
13##
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/>.
16##
17
18hexagon_ss = ss.source_set()
19
20hex_common_py = 'hex_common.py'
21attribs_def = meson.current_source_dir() / 'attribs_def.h.inc'
22gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h'
23gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h'
24idef_parser_dir = meson.current_source_dir() / 'idef-parser'
25
26#
27#  Step 1
28#  We use a C program to create semantics_generated.pyinc
29#
30gen_semantics = executable(
31    'gen_semantics',
32    'gen_semantics.c',
33    native: true, build_by_default: false)
34
35semantics_generated = custom_target(
36    'semantics_generated.pyinc',
37    output: 'semantics_generated.pyinc',
38    command: [gen_semantics, '@OUTPUT@'],
39)
40hexagon_ss.add(semantics_generated)
41
42#
43# Step 2
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
51#
52shortcode_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@'],
58)
59hexagon_ss.add(shortcode_generated)
60
61tcg_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@'],
67)
68hexagon_ss.add(tcg_func_table_generated)
69
70printinsn_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@'],
76)
77hexagon_ss.add(printinsn_generated)
78
79op_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@'],
85)
86hexagon_ss.add(op_regs_generated)
87
88op_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@'],
94)
95hexagon_ss.add(op_attribs_generated)
96
97opcodes_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@'],
103)
104hexagon_ss.add(opcodes_def_generated)
105
106#
107# Step 3
108# We use a C program to create iset.py which is imported into dectree.py
109# to create the decode tree
110#
111gen_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)
115
116iset_py = custom_target(
117    'iset.py',
118    output: 'iset.py',
119    command: [gen_dectree_import, '@OUTPUT@'],
120)
121hexagon_ss.add(iset_py)
122
123#
124# Step 4
125# We use the dectree.py script to generate the decode tree header file
126#
127dectree_generated = custom_target(
128    'dectree_generated.h.inc',
129    output: 'dectree_generated.h.inc',
130    depends: [iset_py],
131    env: {'PYTHONPATH': meson.current_build_dir()},
132    command: [python, files('dectree.py'), '@OUTPUT@'],
133)
134hexagon_ss.add(dectree_generated)
135
136hexagon_ss.add(files(
137    'cpu.c',
138    'translate.c',
139    'op_helper.c',
140    'gdbstub.c',
141    'genptr.c',
142    'reg_fields.c',
143    'decode.c',
144    'iclass.c',
145    'opcodes.c',
146    'printinsn.c',
147    'arch.c',
148    'fma_emu.c',
149    'mmvec/decode_ext_mmvec.c',
150    'mmvec/system_ext_mmvec.c',
151))
152
153#
154# Step 4.5
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
160#
161idef_parser_enabled = get_option('hexagon_idef_parser')
162if 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@'],
169    )
170
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@'],
177    )
178
179    flex = generator(
180        find_program('flex'),
181        output: ['@BASENAME@.yy.c', '@BASENAME@.yy.h'],
182        arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@']
183    )
184
185    bison = generator(
186        find_program('bison', version: '>=3.0'),
187        output: ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
188        arguments: ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']
189    )
190
191    glib_dep = dependency('glib-2.0', native: true)
192
193    idef_parser = executable(
194        'idef-parser',
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],
200        native: true
201    )
202
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@']
211    )
212
213    indent = find_program('indent', required: false)
214    if indent.found()
215        idef_generated_tcg_c = custom_target(
216            'indent',
217            input: idef_generated_tcg[0],
218            output: 'idef-generated-emitter.indented.c',
219            command: [indent, '-linux', '@INPUT@', '-o', '@OUTPUT@']
220        )
221    else
222        idef_generated_tcg_c = custom_target(
223            'copy',
224            input: idef_generated_tcg[0],
225            output: 'idef-generated-emitter.indented.c',
226            command: ['cp', '@INPUT@', '@OUTPUT@']
227        )
228    endif
229
230    idef_generated_list = idef_generated_tcg[2].full_path()
231
232    hexagon_ss.add(idef_generated_tcg_c)
233
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]
238else
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]
243endif
244
245#
246# Step 5
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
251#
252helper_protos_generated = custom_target(
253    'helper_protos_generated.h.inc',
254    output: 'helper_protos_generated.h.inc',
255    depends: helper_dep,
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@'],
258)
259hexagon_ss.add(helper_protos_generated)
260
261helper_funcs_generated = custom_target(
262    'helper_funcs_generated.c.inc',
263    output: 'helper_funcs_generated.c.inc',
264    depends: helper_dep,
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@'],
267)
268hexagon_ss.add(helper_funcs_generated)
269
270tcg_funcs_generated = custom_target(
271    'tcg_funcs_generated.c.inc',
272    output: 'tcg_funcs_generated.c.inc',
273    depends: helper_dep,
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@'],
276)
277hexagon_ss.add(tcg_funcs_generated)
278
279analyze_funcs_generated = custom_target(
280    'analyze_funcs_generated.c.inc',
281    output: 'analyze_funcs_generated.c.inc',
282    depends: helper_dep,
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@'],
285)
286hexagon_ss.add(analyze_funcs_generated)
287
288target_arch += {'hexagon': hexagon_ss}
289