Compiler projects using llvm
load("//:pch.bzl", "pch")


cc_library(
    name = "support",
    srcs = glob(["lib/*.cc"]) + select({
        "@bazel_tools//src/conditions:windows": [
            "lib/win/getopt.c",
            "lib/win/getopt.h",
            "lib/win/unistd.h",
        ],
        "//conditions:default": [],
    }),
    hdrs = [
        "include/ast_parse.h",
        "include/cool_tree.h",
        "include/cool_tree.handcode.h",
        "include/copyright.h",
        "include/stringtab.h",
        "include/stringtab.handcode.h",
        "include/symtab.h",
        "include/tree.h",
        "include/utils.h",
    ],
    includes = ["include"],
    copts = ["-Os", "-Wno-register"],
    deps = [],
)

pch(
    name = "support_pch",
    includes = [
        "ast_parse.h",
        "cool_tree.h",
        "cool_tree.handcode.h",
        "copyright.h",
        "stringtab.h",
        "stringtab.handcode.h",
        "symtab.h",
        "tree.h",
        "utils.h",
    ],
    deps = [":support"],
)


cc_library(
    name = "runtime",
    srcs = glob(["rt/*.c"]),
    hdrs = glob(["rt/*.h"]),
    copts = ["-Os",  "-DNDEBUG"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "codegen",
    srcs = ["src/cgen.cc"],
    hdrs = ["include/cgen.h"],
    deps = [
        ":support_pch",
        ":support",
        "//llvm:ir_headers_pch",
        "//llvm:support_pch",
        "//llvm:Core",
        "//llvm:Support",
    ],
)

cc_binary(
    name = "cgen",
    deps = [":codegen"],
    visibility = ["//visibility:public"],
)