1# Modified `llvm/utils/TableGen/tablegen.gni` file to suit clspv build 2# structure. 3 4import("//build_overrides/clspv.gni") 5 6# This file defines a template for running llvm-tblgen. 7# 8# Parameters: 9# 10# args (required) 11# [list of strings] Flags to pass to llvm-tblgen. 12# 13# output_name (optional) 14# Basename of the generated output file. 15# Defaults to target name with ".inc" appended. 16# 17# td_file (optional) 18# The .td file to pass to llvm-tblgen. 19# Defaults to target name with ".td" appended. 20# 21# visibility (optional) 22# GN's regular visibility attribute, see `gn help visibility`. 23# 24# Example use: 25# 26# tablegen("attributes_compat_func_gen") { 27# visibility = [ ":IR" ] 28# args = [ "-gen-attrs" ] 29# td_file = "AttributesCompatFunc.td" 30# } 31 32import("../compiled_action.gni") 33 34template("tablegen") { 35 assert(defined(invoker.args), "must set 'args' in $target_name") 36 37 config_name = "${target_name}_config" 38 config(config_name) { 39 visibility = [ ":$target_name" ] 40 include_dirs = [ target_gen_dir ] 41 } 42 43 compiled_action(target_name) { 44 forward_variables_from(invoker, [ "visibility" ]) 45 46 if (defined(invoker.tblgen_target)) { 47 tool = invoker.tblgen_target 48 } else { 49 tool = "../tools:clspv-tool-llvm-tblgen" 50 } 51 if (defined(invoker.td_file)) { 52 td_file = invoker.td_file 53 } else { 54 td_file = "$target_name.td" 55 } 56 inputs = [ td_file ] 57 if (defined(invoker.output_name)) { 58 gen_output = "$root_gen_dir/" + invoker.output_name 59 } else if (defined(invoker.output_path)) { 60 gen_output = "$root_gen_dir/" + invoker.output_path + "/$target_name.inc" 61 } else { 62 gen_output = "$target_gen_dir/$target_name.inc" 63 } 64 depfile = "$gen_output.d" 65 td_file = rebase_path(td_file, root_build_dir) 66 67 args = [ 68 "--write-if-changed", 69 70 "-I", 71 rebase_path("//$clspv_llvm_dir/llvm/include", root_build_dir), 72 73 # FIXME: Rather than duplicating this -I flag in both the CMake and 74 # the gn build, let tablegen add input dir to include search path 75 # instead? 76 "-I", 77 get_path_info(td_file, "dir"), 78 "-d", 79 rebase_path(depfile, root_build_dir), 80 "-o", 81 rebase_path(gen_output, root_build_dir), 82 td_file, 83 ] + invoker.args 84 outputs = [ gen_output ] 85 86 # Let targets depending on this find the generated file. 87 public_configs = [ ":$config_name" ] 88 } 89} 90