| # This file defines a template for running llvm-tblgen. |
| # |
| # Parameters: |
| # |
| # args (required) |
| # [list of strings] Flags to pass to llvm-tblgen. |
| # |
| # output_name (optional) |
| # Basename of the generated output file. |
| # Defaults to target name with ".inc" appended. |
| # |
| # td_file (roptional) |
| # The .td file to pass to llvm-tblgen. |
| # Defaults to target name with ".td" appended. |
| # |
| # visibility (optional) |
| # GN's regular visibility attribute, see `gn help visibility`. |
| # |
| # Example use: |
| # |
| # tablegen("attributes_compat_func_gen") { |
| # visibility = [ ":IR" ] |
| # args = [ "-gen-attrs" ] |
| # td_file = "AttributesCompatFunc.td" |
| # } |
| |
| template("tablegen") { |
| assert(defined(invoker.args), "must set 'args' in $target_name") |
| |
| config_name = "${target_name}_config" |
| config(config_name) { |
| visibility = [ ":$target_name" ] |
| include_dirs = [ target_gen_dir ] |
| } |
| |
| action(target_name) { |
| forward_variables_from(invoker, [ "visibility" ]) |
| |
| if (defined(invoker.tblgen_target)) { |
| tblgen_target = invoker.tblgen_target |
| } else { |
| # FIXME: In cross builds, this should depend on the host binary. |
| tblgen_target = "//llvm/utils/TableGen:llvm-tblgen" |
| } |
| tblgen_executable = get_label_info(tblgen_target, "root_out_dir") + |
| "/bin/" + get_label_info(tblgen_target, "name") |
| deps = [ |
| tblgen_target, |
| ] |
| if (defined(invoker.td_file)) { |
| td_file = invoker.td_file |
| } else { |
| td_file = "$target_name.td" |
| } |
| sources = [ |
| td_file, |
| ] |
| script = "//llvm/utils/gn/build/run_tablegen.py" |
| if (defined(invoker.output_name)) { |
| gen_output = "$target_gen_dir/" + invoker.output_name |
| } else { |
| gen_output = "$target_gen_dir/$target_name.inc" |
| } |
| depfile = "$gen_output.d" |
| td_file = rebase_path(td_file, root_build_dir) |
| |
| args = [ |
| rebase_path(tblgen_executable, root_build_dir), |
| "-I", |
| rebase_path("//llvm/include", root_build_dir), |
| |
| # FIXME: Rather than duplicating this -I flag in both the CMake and |
| # the gn build, let tablegen add input dir to include search path |
| # instead? |
| "-I", |
| get_path_info(td_file, "dir"), |
| "-d", |
| rebase_path(depfile, root_build_dir), |
| "-o", |
| rebase_path(gen_output, root_build_dir), |
| td_file, |
| ] + invoker.args |
| outputs = [ |
| gen_output, |
| ] |
| |
| # Let targets depending on this find the generated file. |
| public_configs = [ ":$config_name" ] |
| } |
| } |