github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/mlir/tblgen.bzl (about) 1 """BUILD extensions for MLIR table generation.""" 2 3 def gentbl(name, tblgen, td_file, tbl_outs, td_srcs = []): 4 """gentbl() generates tabular code from a table definition file. 5 6 Args: 7 name: The name of the build rule for use in dependencies. 8 tblgen: The binary used to produce the output. 9 td_file: The primary table definitions file. 10 tbl_outs: A list of tuples (opts, out), where each opts is a string of 11 options passed to tblgen, and the out is the corresponding output file 12 produced. 13 td_srcs: A list of table definition files included transitively. 14 """ 15 srcs = [] 16 srcs += td_srcs 17 if td_file not in td_srcs: 18 srcs += [td_file] 19 20 # Add google_mlir/include directory as include so derived op td files can 21 # import relative to that. 22 td_includes = "-I external/local_config_mlir/include -I external/org_tensorflow " 23 td_includes += "-I $$(dirname $(location %s)) " % td_file 24 for (opts, out) in tbl_outs: 25 rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" ")) 26 native.genrule( 27 name = "%s_%s_genrule" % (name, rule_suffix), 28 srcs = srcs, 29 outs = [out], 30 tools = [tblgen], 31 message = "Generating code from table: %s" % td_file, 32 cmd = (("$(location %s) %s %s $(location %s) -o $@") % ( 33 tblgen, 34 td_includes, 35 opts, 36 td_file, 37 )), 38 ) 39 40 native.cc_library( 41 name = name, 42 textual_hdrs = [f for (_, f) in tbl_outs], 43 )