load("@heir//lib/Dialect:dialect.bzl", "add_heir_dialect_library")
load("@llvm-project//mlir:tblgen.bzl", "td_library")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(
    default_applicable_licenses = ["@heir//:license"],
    default_visibility = ["//visibility:public"],
)

cc_library(
    name = "Dialect",
    srcs = [
        "TfheRustDialect.cpp",
    ],
    hdrs = [
        "TfheRustDialect.h",
        "TfheRustOps.h",
        "TfheRustTypes.h",
    ],
    deps = [
        ":Patterns",
        ":dialect_inc_gen",
        ":ops_inc_gen",
        ":types_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
    ],
)

cc_library(
    name = "Patterns",
    srcs = ["TfheRustPatterns.cpp"],
    hdrs = [
        "TfheRustDialect.h",
        "TfheRustOps.h",
        "TfheRustPatterns.h",
        "TfheRustTypes.h",
    ],
    deps = [
        ":dialect_inc_gen",
        ":ops_inc_gen",
        ":types_inc_gen",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:Support",
    ],
)

td_library(
    name = "td_files",
    srcs = [
        "TfheRustDialect.td",
        "TfheRustOps.td",
        "TfheRustTypes.td",
    ],
    deps = [
        "@llvm-project//mlir:ArithOpsTdFiles",
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

add_heir_dialect_library(
    name = "dialect_inc_gen",
    dialect = "TfheRust",
    dialect_doc_name = "tfhe_rust",
    kind = "dialect",
    td_file = "TfheRustDialect.td",
    deps = [
        ":td_files",
    ],
)

add_heir_dialect_library(
    name = "types_inc_gen",
    dialect = "TfheRust",
    dialect_doc_name = "tfhe_rust",
    kind = "type",
    td_file = "TfheRustTypes.td",
    deps = [
        ":td_files",
    ],
)

add_heir_dialect_library(
    name = "ops_inc_gen",
    dialect = "TfheRust",
    dialect_doc_name = "tfhe_rust",
    kind = "op",
    td_file = "TfheRustOps.td",
    deps = [
        ":td_files",
    ],
)
