pan/va: Generate header containing enums
We already collect enums in the ISA description XML. Export them for use in the compiler backend, particularly the packing code. Usually we'd use Mako for templating. In this case, the script is so trivial a template engine didn't seem worth it. (The obvious version with Mako was about 10 lines longer than just prints and f-strings used here.) Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Suggested-by: Icecream95 <ixn@disroot.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15223>
This commit is contained in:
parent
7ad98ae96e
commit
619566dea1
|
@ -138,7 +138,7 @@ libpanfrost_bifrost = static_library(
|
|||
'panfrost_bifrost',
|
||||
[libpanfrost_bifrost_files, bi_opcodes_c, bi_printer_c, bi_packer_c, bifrost_nir_algebraic_c, valhall_c],
|
||||
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_panfrost_hw, inc_valhall],
|
||||
dependencies: [idep_nir, idep_bi_opcodes_h, idep_bi_builder_h],
|
||||
dependencies: [idep_nir, idep_bi_opcodes_h, idep_bi_builder_h, idep_valhall_enums_h],
|
||||
link_with: [libpanfrost_util, libpanfrost_bifrost_disasm, libpanfrost_valhall_disasm],
|
||||
c_args : [no_override_init_args],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
|
|
|
@ -28,6 +28,20 @@ valhall_c = custom_target(
|
|||
depend_files : files('valhall.py'),
|
||||
)
|
||||
|
||||
valhall_enums_h = custom_target(
|
||||
'valhall_enums.h',
|
||||
input : ['valhall_enums.h.py', 'ISA.xml'],
|
||||
output : 'valhall_enums.h',
|
||||
command : [prog_python, '@INPUT@'],
|
||||
capture : true,
|
||||
depend_files : files('valhall.py'),
|
||||
)
|
||||
|
||||
idep_valhall_enums_h = declare_dependency(
|
||||
sources : [valhall_enums_h],
|
||||
include_directories : include_directories('.'),
|
||||
)
|
||||
|
||||
valhall_disasm_c = custom_target(
|
||||
'valhall_disasm_c',
|
||||
input : ['disasm.py', 'ISA.xml'],
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#encoding=utf-8
|
||||
|
||||
# Copyright (C) 2021 Collabora, Ltd.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the next
|
||||
# paragraph) shall be included in all copies or substantial portions of the
|
||||
# Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
from valhall import safe_name, enums
|
||||
|
||||
for enum in sorted(enums):
|
||||
print(f"enum va_{safe_name(enum)} {{")
|
||||
|
||||
for i, value in enumerate(enums[enum].values):
|
||||
if value.value != 'reserved':
|
||||
key = safe_name(f"va_{enum}_{value.value}")
|
||||
print(f" {key.upper()} = {i},")
|
||||
|
||||
print("};\n")
|
Loading…
Reference in New Issue