isaspec: Stop depending on glue headers and out-of-folder C files

The way the isaspec decoder used to work was that it would generate a
header and a C file, each with ISA-specific stuff in it. Then that would
get built together with a stand-alone decode.c file which lives in the
isaspec folder, not the driver's folder.  In order for decode.c to find
the ISA-specific headers, it would also generate a glue header which had
to be named isaspec-isa.h.  This effectively meant that you can't have
multiple isaspec definitions in the same folder.

To solve this, we make do it the other way around and make the generated
header and C files include the stand-alone files.  This is a bit awkward
because it means including a C file from another C file but it's better
for the build system.

Acked-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20525>
This commit is contained in:
Jason Ekstrand
2023-01-04 13:47:54 -06:00
committed by Marge Bot
parent 4953a8db25
commit e8945a8ce6
5 changed files with 17 additions and 50 deletions

View File

@@ -21,6 +21,10 @@
* SOFTWARE.
*/
/* This file should not be built directly. Instead, it is included in the C
* file generated by isaspec/decode.py and built along with it.
*/
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -37,7 +41,6 @@
#include "util/u_debug.h"
#include "util/u_math.h"
#include "decode.h"
#include "isa.h"
/**

View File

@@ -21,10 +21,10 @@
* SOFTWARE.
*/
#ifndef _DECODE_H_
#define _DECODE_H_
/* This file should not be included directly. Instead, it is included as part
* of the header file generated by isaspec/decode.py
*/
#include <isaspec-isa.h>
#include <stdbool.h>
#include <stdint.h>
@@ -145,5 +145,3 @@ struct isa_bitset {
unsigned num_cases;
const struct isa_case *cases[];
};
#endif /* _DECODE_H_ */

View File

@@ -50,7 +50,7 @@ template = """\
* IN THE SOFTWARE.
*/
#include "decode.h"
#include "${header}"
/*
* enum tables, these don't have any link back to other tables so just
@@ -192,6 +192,8 @@ const struct isa_bitset *${root.get_c_name()}[] = {
};
%endfor
#include "decode.c"
"""
header = """\
@@ -258,37 +260,7 @@ uint64_t_to_bitmask(uint64_t val)
return mask;
}
#endif /* _${guard}_ */
"""
glue = """\
/* Copyright (C) 2020 Google, Inc.
*
* 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.
*/
#ifndef _${guard}_
#define _${guard}_
#include "${isa}"
#include "decode.h"
#endif /* _${guard}_ */
@@ -302,20 +274,14 @@ def main():
parser.add_argument('--xml', required=True, help='isaspec XML file.')
parser.add_argument('--out-c', required=True, help='Output C file.')
parser.add_argument('--out-h', required=True, help='Output H file.')
parser.add_argument('--out-glue-h',
required=True,
help='Output glue H file.')
args = parser.parse_args()
isa = ISA(args.xml)
try:
with open(args.out_glue_h, 'w') as f:
f.write(Template(glue).render(guard=guard(args.out_glue_h),
isa=os.path.basename(args.out_h)))
with open(args.out_c, 'w') as f:
f.write(Template(template).render(isa=isa))
out_h_basename = os.path.basename(args.out_h)
f.write(Template(template).render(isa=isa, header=out_h_basename))
with open(args.out_h, 'w') as f:
f.write(Template(header).render(isa=isa, guard=guard(args.out_h)))

View File

@@ -19,7 +19,7 @@
# SOFTWARE.
prog_isaspec_decode = find_program('decode.py')
idep_isaspec_decode = declare_dependency(sources : files('decode.c'), include_directories : include_directories('.'))
idep_isaspec_decode = declare_dependency(include_directories : include_directories('.'))
prog_isaspec_encode = find_program('encode.py')

View File

@@ -34,10 +34,10 @@ isa_depend_files = [
ir3_isa = custom_target(
'ir3-isa',
input: ['ir3.xml'],
output: ['isaspec-isa.h', 'ir3-isa.c', 'ir3-isa.h'],
output: ['ir3-isa.c', 'ir3-isa.h'],
command: [
prog_isaspec_decode, '--xml', '@INPUT@', '--out-glue-h', '@OUTPUT0@',
'--out-c', '@OUTPUT1@', '--out-h', '@OUTPUT2@',
prog_isaspec_decode, '--xml', '@INPUT@',
'--out-c', '@OUTPUT0@', '--out-h', '@OUTPUT1@',
],
depend_files: isa_depend_files,
)