xref: /openbmc/qemu/target/hexagon/meson.build (revision 824cac68)
1##
2##  Copyright(c) 2020-2021 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'),
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        c_args: ['-Wextra'],
201        native: true
202    )
203
204    idef_generated_tcg = custom_target(
205        'idef-generated-tcg',
206        output: ['idef-generated-emitter.c',
207                 'idef-generated-emitter.h.inc',
208                 'idef-generated-enabled-instructions'],
209        input: preprocessed_idef_parser_input_generated,
210        depend_files: [hex_common_py],
211        command: [idef_parser, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@', '@OUTPUT2@']
212    )
213
214    indent = find_program('indent', required: false)
215    if indent.found()
216        idef_generated_tcg_c = custom_target(
217            'indent',
218            input: idef_generated_tcg[0],
219            output: 'idef-generated-emitter.indented.c',
220            command: [indent, '-linux', '@INPUT@', '-o', '@OUTPUT@']
221        )
222    else
223        idef_generated_tcg_c = custom_target(
224            'copy',
225            input: idef_generated_tcg[0],
226            output: 'idef-generated-emitter.indented.c',
227            command: ['cp', '@INPUT@', '@OUTPUT@']
228        )
229    endif
230
231    idef_generated_list = idef_generated_tcg[2].full_path()
232
233    hexagon_ss.add(idef_generated_tcg_c)
234
235    # Setup input and dependencies for the next step, this depends on whether or
236    # not idef-parser is enabled
237    helper_dep = [semantics_generated, idef_generated_tcg_c, idef_generated_tcg]
238    helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h, idef_generated_list]
239else
240    # Setup input and dependencies for the next step, this depends on whether or
241    # not idef-parser is enabled
242    helper_dep = [semantics_generated]
243    helper_in = [semantics_generated, attribs_def, gen_tcg_h, gen_tcg_hvx_h]
244endif
245
246#
247# Step 5
248# We use Python scripts to generate the following files
249#     helper_protos_generated.h.inc
250#     helper_funcs_generated.c.inc
251#     tcg_funcs_generated.c.inc
252#
253helper_protos_generated = custom_target(
254    'helper_protos_generated.h.inc',
255    output: 'helper_protos_generated.h.inc',
256    depends: helper_dep,
257    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
258    command: [python, files('gen_helper_protos.py'), helper_in, '@OUTPUT@'],
259)
260hexagon_ss.add(helper_protos_generated)
261
262helper_funcs_generated = custom_target(
263    'helper_funcs_generated.c.inc',
264    output: 'helper_funcs_generated.c.inc',
265    depends: helper_dep,
266    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
267    command: [python, files('gen_helper_funcs.py'), helper_in, '@OUTPUT@'],
268)
269hexagon_ss.add(helper_funcs_generated)
270
271tcg_funcs_generated = custom_target(
272    'tcg_funcs_generated.c.inc',
273    output: 'tcg_funcs_generated.c.inc',
274    depends: helper_dep,
275    depend_files: [hex_common_py, attribs_def, gen_tcg_h, gen_tcg_hvx_h],
276    command: [python, files('gen_tcg_funcs.py'), helper_in, '@OUTPUT@'],
277)
278hexagon_ss.add(tcg_funcs_generated)
279
280target_arch += {'hexagon': hexagon_ss}
281