Skip to content

Commit

Permalink
Combine extinst-name and extinst-output-base into one arg. (#3200)
Browse files Browse the repository at this point in the history
* Combine the extinst-name and extinst-output-base into one arg.

Some build systems such as Android blueprints require that the inputs
and outputs of generator scripts are all provided as arguments.  These
two arguments to generate_language_headers.py are combined to form the
output path in the script.  This change simply lets the user provide the
whole output path as an argument.

* Fix typo in build_defs.bzl and update Android.mk
  • Loading branch information
vonture authored Feb 25, 2020
1 parent 8910ea5 commit fb6e3e4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
3 changes: 1 addition & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ $(1)/$(2).h : \
$(LOCAL_PATH)/utils/generate_language_headers.py \
$(3)
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \
--extinst-name=$(2) \
--extinst-grammar=$(3) \
--extinst-output-base=$(1)/$(2)
--extinst-output-path=$(1)/$(2).h
@echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar"
$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
: $(1)/$(2).h
Expand Down
10 changes: 4 additions & 6 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,19 @@ template("spvtools_language_header") {
script = "utils/generate_language_headers.py"

name = invoker.name
extinst_output_base = "${target_gen_dir}/${name}"
extinst_output_path = "${target_gen_dir}/${name}.h"

args = [
"--extinst-name",
"${name}",
"--extinst-grammar",
rebase_path(invoker.grammar_file, root_build_dir),
"--extinst-output-base",
rebase_path(extinst_output_base, root_build_dir),
"--extinst-output-path",
rebase_path(extinst_output_path, root_build_dir),
]
inputs = [
invoker.grammar_file,
]
outputs = [
"${extinst_output_base}.h",
"${extinst_output_path}",
]
}
}
Expand Down
8 changes: 4 additions & 4 deletions build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ def generate_vendor_tables(extension, operand_kind_prefix = ""):
def generate_extinst_lang_headers(name, grammar = None):
if not grammar:
fail("Must specify grammar", "grammar")
fmtargs = [name]
outs = [name + ".h"]
fmtargs = outs
native.genrule(
name = "gen_extinst_lang_headers_" + name,
srcs = [grammar],
outs = [name + ".h"],
outs = outs,
cmd = (
"$(location :generate_language_headers) " +
"--extinst-name={0} " +
"--extinst-grammar=$< " +
"--extinst-output-base=$(@D)/{0}"
"--extinst-output-path=$(location {0})"
).format(*fmtargs),
tools = [":generate_language_headers"],
visibility = ["//visibility:private"],
Expand Down
6 changes: 2 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ macro(spvtools_vendor_tables VENDOR_TABLE SHORT_NAME OPERAND_KIND_PREFIX)
endmacro(spvtools_vendor_tables)

macro(spvtools_extinst_lang_headers NAME GRAMMAR_FILE)
set(OUTBASE ${spirv-tools_BINARY_DIR}/${NAME})
set(OUT_H ${OUTBASE}.h)
set(OUT_H ${spirv-tools_BINARY_DIR}/${NAME}.h)
add_custom_command(OUTPUT ${OUT_H}
COMMAND ${PYTHON_EXECUTABLE} ${LANG_HEADER_PROCESSING_SCRIPT}
--extinst-name=${NAME}
--extinst-grammar=${GRAMMAR_FILE}
--extinst-output-base=${OUTBASE}
--extinst-output-path=${OUT_H}
DEPENDS ${LANG_HEADER_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
COMMENT "Generate language specific header for ${NAME}.")
add_custom_target(spirv-tools-header-${NAME} DEPENDS ${OUT_H})
Expand Down
14 changes: 6 additions & 8 deletions utils/generate_language_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,25 @@ def main():
import argparse
parser = argparse.ArgumentParser(description='Generate language headers from a JSON grammar')

parser.add_argument('--extinst-name',
type=str, required=True,
help='The name to use in tokens')
parser.add_argument('--extinst-grammar', metavar='<path>',
type=str, required=True,
help='input JSON grammar file for extended instruction set')
parser.add_argument('--extinst-output-base', metavar='<path>',
parser.add_argument('--extinst-output-path', metavar='<path>',
type=str, required=True,
help='Basename of the language-specific output file.')
help='Path of the language-specific output file.')
args = parser.parse_args()

with open(args.extinst_grammar) as json_file:
grammar_json = json.loads(json_file.read())
grammar = ExtInstGrammar(name = args.extinst_name,
grammar_name = os.path.splitext(os.path.basename(args.extinst_output_path))[0]
grammar = ExtInstGrammar(name = grammar_name,
copyright = grammar_json['copyright'],
instructions = grammar_json['instructions'],
operand_kinds = grammar_json['operand_kinds'],
version = grammar_json['version'],
revision = grammar_json['revision'])
make_path_to_file(args.extinst_output_base)
with open(args.extinst_output_base + '.h', 'w') as f:
make_path_to_file(args.extinst_output_path)
with open(args.extinst_output_path, 'w') as f:
f.write(CGenerator().generate(grammar))


Expand Down

0 comments on commit fb6e3e4

Please sign in to comment.