[bazel] NFC: Change tbl_outs to dicts. (#137788)
There were some `gentbl_cc_library` targets left to convert. Allow `gentbl_filegroup` rule to take a dict as well and change all targets. Move lld/BUILD.bazel from //llvm:tblgen.bzl to //mlir:tblgen.bzl, delete the former. This makes the BUILD files shorter and more readable.
This commit is contained in:
@@ -43,7 +43,7 @@ cc_binary(
|
||||
|
||||
gentbl_cc_library(
|
||||
name = "diagnostic_defs_gen",
|
||||
tbl_outs = [out for c in [
|
||||
tbl_outs = dict([out for c in [
|
||||
"AST",
|
||||
"Analysis",
|
||||
"Comment",
|
||||
@@ -59,47 +59,47 @@ gentbl_cc_library(
|
||||
"Serialization",
|
||||
] for out in [
|
||||
(
|
||||
"include/clang/Basic/Diagnostic%sKinds.inc" % c,
|
||||
[
|
||||
"-gen-clang-diags-defs",
|
||||
"-clang-component=%s" % c,
|
||||
],
|
||||
"include/clang/Basic/Diagnostic%sKinds.inc" % c,
|
||||
),
|
||||
(
|
||||
"include/clang/Basic/Diagnostic%sEnums.inc" % c,
|
||||
[
|
||||
"-gen-clang-diags-enums",
|
||||
"-clang-component=%s" % c,
|
||||
],
|
||||
"include/clang/Basic/Diagnostic%sEnums.inc" % c,
|
||||
),
|
||||
(
|
||||
"include/clang/Basic/Diagnostic%sCompatIDs.inc" % c,
|
||||
[
|
||||
"-gen-clang-diags-compat-ids",
|
||||
"-clang-component=%s" % c,
|
||||
],
|
||||
"include/clang/Basic/Diagnostic%sCompatIDs.inc" % c,
|
||||
),
|
||||
(
|
||||
"include/clang/Basic/Diagnostic%sInterface.inc" % c,
|
||||
[
|
||||
"-gen-clang-diags-iface",
|
||||
"-clang-component=%s" % c,
|
||||
],
|
||||
"include/clang/Basic/Diagnostic%sInterface.inc" % c,
|
||||
),
|
||||
]] + [
|
||||
(
|
||||
["-gen-clang-diag-groups"],
|
||||
"include/clang/Basic/DiagnosticGroups.inc",
|
||||
["-gen-clang-diag-groups"],
|
||||
),
|
||||
(
|
||||
["-gen-clang-diags-index-name"],
|
||||
"include/clang/Basic/DiagnosticIndexName.inc",
|
||||
["-gen-clang-diags-index-name"],
|
||||
),
|
||||
(
|
||||
["-gen-clang-diags-compat-ids"],
|
||||
"include/clang/Basic/DiagnosticAllCompatIDs.inc",
|
||||
["-gen-clang-diags-compat-ids"],
|
||||
),
|
||||
],
|
||||
]),
|
||||
tblgen = ":clang-tblgen",
|
||||
td_file = "include/clang/Basic/Diagnostic.td",
|
||||
deps = [":BasicTdFiles"],
|
||||
|
||||
@@ -8,7 +8,7 @@ load(
|
||||
)
|
||||
load("//llvm:binary_alias.bzl", "binary_alias")
|
||||
load("//llvm:driver.bzl", "llvm_driver_cc_binary")
|
||||
load("//llvm:tblgen.bzl", "gentbl")
|
||||
load("//mlir:tblgen.bzl", "gentbl_cc_library")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
@@ -59,19 +59,14 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl(
|
||||
gentbl_cc_library(
|
||||
name = "elf_options_inc_gen",
|
||||
# See https://github.com/bazelbuild/bazel/issues/13803
|
||||
strip_include_prefix = "ELF",
|
||||
tbl_outs = [(
|
||||
"-gen-opt-parser-defs",
|
||||
"ELF/Options.inc",
|
||||
)],
|
||||
tbl_outs = {"ELF/Options.inc": ["-gen-opt-parser-defs"]},
|
||||
tblgen = "//llvm:llvm-tblgen",
|
||||
td_file = "ELF/Options.td",
|
||||
td_srcs = [
|
||||
"//llvm:include/llvm/Option/OptParser.td",
|
||||
],
|
||||
deps = ["//llvm:OptParserTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -116,19 +111,14 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl(
|
||||
gentbl_cc_library(
|
||||
name = "coff_options_inc_gen",
|
||||
# See https://github.com/bazelbuild/bazel/issues/13803
|
||||
strip_include_prefix = "COFF",
|
||||
tbl_outs = [(
|
||||
"-gen-opt-parser-defs",
|
||||
"COFF/Options.inc",
|
||||
)],
|
||||
tbl_outs = {"COFF/Options.inc": ["-gen-opt-parser-defs"]},
|
||||
tblgen = "//llvm:llvm-tblgen",
|
||||
td_file = "COFF/Options.td",
|
||||
td_srcs = [
|
||||
"//llvm:include/llvm/Option/OptParser.td",
|
||||
],
|
||||
deps = ["//llvm:OptParserTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -172,17 +162,12 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl(
|
||||
gentbl_cc_library(
|
||||
name = "mingw_options_inc_gen",
|
||||
tbl_outs = [(
|
||||
"-gen-opt-parser-defs",
|
||||
"MinGW/Options.inc",
|
||||
)],
|
||||
tbl_outs = {"MinGW/Options.inc": ["-gen-opt-parser-defs"]},
|
||||
tblgen = "//llvm:llvm-tblgen",
|
||||
td_file = "MinGW/Options.td",
|
||||
td_srcs = [
|
||||
"//llvm:include/llvm/Option/OptParser.td",
|
||||
],
|
||||
deps = ["//llvm:OptParserTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -200,19 +185,14 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl(
|
||||
gentbl_cc_library(
|
||||
name = "macho_options_inc_gen",
|
||||
# See https://github.com/bazelbuild/bazel/issues/13803
|
||||
strip_include_prefix = "MachO",
|
||||
tbl_outs = [(
|
||||
"-gen-opt-parser-defs",
|
||||
"MachO/Options.inc",
|
||||
)],
|
||||
tbl_outs = {"MachO/Options.inc": ["-gen-opt-parser-defs"]},
|
||||
tblgen = "//llvm:llvm-tblgen",
|
||||
td_file = "MachO/Options.td",
|
||||
td_srcs = [
|
||||
"//llvm:include/llvm/Option/OptParser.td",
|
||||
],
|
||||
deps = ["//llvm:OptParserTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -246,19 +226,14 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
gentbl(
|
||||
gentbl_cc_library(
|
||||
name = "wasm_options_inc_gen",
|
||||
# See https://github.com/bazelbuild/bazel/issues/13803
|
||||
strip_include_prefix = "wasm",
|
||||
tbl_outs = [(
|
||||
"-gen-opt-parser-defs",
|
||||
"wasm/Options.inc",
|
||||
)],
|
||||
tbl_outs = {"wasm/Options.inc": ["-gen-opt-parser-defs"]},
|
||||
tblgen = "//llvm:llvm-tblgen",
|
||||
td_file = "wasm/Options.td",
|
||||
td_srcs = [
|
||||
"//llvm:include/llvm/Option/OptParser.td",
|
||||
],
|
||||
deps = ["//llvm:OptParserTdFiles"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,81 +0,0 @@
|
||||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
"""This file contains BUILD extensions for generating source code from LLVM's
|
||||
table definition files using the TableGen tool.
|
||||
|
||||
See http://llvm.org/cmds/tblgen.html for more information on the TableGen
|
||||
tool.
|
||||
TODO(chandlerc): Currently this expresses include-based dependencies as
|
||||
"sources", and has no transitive understanding due to these files not being
|
||||
correctly understood by the build system.
|
||||
"""
|
||||
|
||||
def gentbl(
|
||||
name,
|
||||
tblgen,
|
||||
td_file,
|
||||
td_srcs,
|
||||
tbl_outs,
|
||||
library = True,
|
||||
tblgen_args = "",
|
||||
**kwargs):
|
||||
"""gentbl() generates tabular code from a table definition file.
|
||||
|
||||
Args:
|
||||
name: The name of the build rule for use in dependencies.
|
||||
tblgen: The binary used to produce the output.
|
||||
td_file: The primary table definitions file.
|
||||
td_srcs: A list of table definition files included transitively.
|
||||
tbl_outs: A list of tuples (opts, out), where each opts is a string of
|
||||
options passed to tblgen, and the out is the corresponding output file
|
||||
produced.
|
||||
library: Whether to bundle the generated files into a library.
|
||||
tblgen_args: Extra arguments string to pass to the tblgen binary.
|
||||
**kwargs: Keyword arguments to pass to subsidiary cc_library() rule.
|
||||
"""
|
||||
llvm_project_execroot_path = Label("//llvm:tblgen.bzl").workspace_root
|
||||
|
||||
if td_file not in td_srcs:
|
||||
td_srcs += [td_file]
|
||||
for (opts, out) in tbl_outs:
|
||||
rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" "))
|
||||
native.genrule(
|
||||
name = "%s_%s_genrule" % (name, rule_suffix),
|
||||
srcs = td_srcs,
|
||||
outs = [out],
|
||||
tools = [tblgen],
|
||||
message = "Generating code from table: %s" % td_file,
|
||||
cmd = (("$(location %s) -I %s/llvm/include " +
|
||||
"-I %s/clang/include " +
|
||||
"-I $$(dirname $(location %s)) " +
|
||||
"%s $(location %s) %s -o $@") % (
|
||||
tblgen,
|
||||
llvm_project_execroot_path,
|
||||
llvm_project_execroot_path,
|
||||
td_file,
|
||||
opts,
|
||||
td_file,
|
||||
tblgen_args,
|
||||
)),
|
||||
)
|
||||
|
||||
# For now, all generated files can be assumed to comprise public interfaces.
|
||||
# If this is not true, you should specify library = False
|
||||
# and list the generated '.inc' files in "srcs".
|
||||
if library:
|
||||
native.cc_library(
|
||||
name = name,
|
||||
# FIXME: This should be `textual_hdrs` instead of `hdrs`, but
|
||||
# unfortunately that doesn't work with `strip_include_prefix`:
|
||||
# https://github.com/bazelbuild/bazel/issues/12424
|
||||
#
|
||||
# Once that issue is fixed and released, we can switch this to
|
||||
# `textual_hdrs` and remove the feature disabling the various Bazel
|
||||
# features (both current and under-development) that motivated the
|
||||
# distinction between these two.
|
||||
hdrs = [f for (_, f) in tbl_outs],
|
||||
features = ["-parse_headers", "-header_modules"],
|
||||
**kwargs
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -321,9 +321,9 @@ def gentbl_filegroup(
|
||||
name: The name of the generated filegroup rule for use in dependencies.
|
||||
tblgen: The binary used to produce the output.
|
||||
td_file: The primary table definitions file.
|
||||
tbl_outs: A list of tuples ([opts], out), where each 'opts' is a list of
|
||||
options passed to tblgen, each option being a string, and 'out' is the
|
||||
corresponding output file produced.
|
||||
tbl_outs: Either a dict {out: [opts]} or a list of tuples ([opts], out),
|
||||
where each 'opts' is a list of options passed to tblgen, each option
|
||||
being a string, and 'out' is the corresponding output file produced.
|
||||
td_srcs: See gentbl_rule.td_srcs
|
||||
includes: See gentbl_rule.includes
|
||||
deps: See gentbl_rule.deps
|
||||
@@ -333,6 +333,8 @@ def gentbl_filegroup(
|
||||
**kwargs: Extra keyword arguments to pass to all generated rules.
|
||||
"""
|
||||
|
||||
if type(tbl_outs) == type({}):
|
||||
tbl_outs = [(v, k) for k, v in tbl_outs.items()]
|
||||
for (opts, out) in tbl_outs:
|
||||
first_opt = opts[0] if opts else ""
|
||||
rule_suffix = "_{}_{}".format(
|
||||
@@ -409,8 +411,6 @@ def gentbl_cc_library(
|
||||
**kwargs: Extra keyword arguments to pass to all generated rules.
|
||||
"""
|
||||
|
||||
if type(tbl_outs) == type({}):
|
||||
tbl_outs = [(v, k) for k, v in tbl_outs.items()]
|
||||
filegroup_name = name + "_filegroup"
|
||||
gentbl_filegroup(
|
||||
name = filegroup_name,
|
||||
@@ -510,22 +510,16 @@ def gentbl_sharded_ops(
|
||||
name = cc_lib_name,
|
||||
strip_include_prefix = strip_include_prefix,
|
||||
includes = includes,
|
||||
tbl_outs = [
|
||||
(
|
||||
[
|
||||
"-gen-op-defs",
|
||||
"-op-shard-count=" + str(shard_count),
|
||||
],
|
||||
src_out,
|
||||
),
|
||||
(
|
||||
[
|
||||
"-gen-op-decls",
|
||||
"-op-shard-count=" + str(shard_count),
|
||||
],
|
||||
hdr_out,
|
||||
),
|
||||
],
|
||||
tbl_outs = {
|
||||
src_out: [
|
||||
"-gen-op-defs",
|
||||
"-op-shard-count=" + str(shard_count),
|
||||
],
|
||||
hdr_out: [
|
||||
"-gen-op-decls",
|
||||
"-op-shard-count=" + str(shard_count),
|
||||
],
|
||||
},
|
||||
tblgen = tblgen,
|
||||
td_file = td_file,
|
||||
test = test,
|
||||
|
||||
Reference in New Issue
Block a user