BUILD 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
  5. load("//bazel/sh_run:rules.bzl", "glob_sh_run")
  6. load("//testing/file_test:rules.bzl", "file_test")
  7. load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")
  8. package(default_visibility = ["//visibility:public"])
  9. cc_library(
  10. name = "token_kind",
  11. srcs = ["token_kind.cpp"],
  12. hdrs = ["token_kind.h"],
  13. textual_hdrs = ["token_kind.def"],
  14. deps = [
  15. "//common:check",
  16. "//common:enum_base",
  17. "@llvm-project//llvm:Support",
  18. ],
  19. )
  20. cc_test(
  21. name = "token_kind_test",
  22. size = "small",
  23. srcs = ["token_kind_test.cpp"],
  24. deps = [
  25. ":token_kind",
  26. "//testing/base:gtest_main",
  27. "@com_google_googletest//:gtest",
  28. "@llvm-project//llvm:Support",
  29. ],
  30. )
  31. cc_library(
  32. name = "character_set",
  33. hdrs = ["character_set.h"],
  34. deps = ["@llvm-project//llvm:Support"],
  35. )
  36. cc_library(
  37. name = "helpers",
  38. srcs = ["helpers.cpp"],
  39. hdrs = ["helpers.h"],
  40. deps = [
  41. "//toolchain/diagnostics:diagnostic_emitter",
  42. "@llvm-project//llvm:Support",
  43. ],
  44. )
  45. cc_library(
  46. name = "test_helpers",
  47. testonly = 1,
  48. hdrs = ["test_helpers.h"],
  49. deps = [
  50. "//common:check",
  51. "//common:string_helpers",
  52. "//toolchain/diagnostics:diagnostic_emitter",
  53. "@com_google_googletest//:gtest",
  54. "@llvm-project//llvm:Support",
  55. ],
  56. )
  57. cc_library(
  58. name = "numeric_literal",
  59. srcs = ["numeric_literal.cpp"],
  60. hdrs = ["numeric_literal.h"],
  61. deps = [
  62. ":character_set",
  63. ":helpers",
  64. "//common:check",
  65. "//toolchain/diagnostics:diagnostic_emitter",
  66. "@llvm-project//llvm:Support",
  67. ],
  68. )
  69. cc_binary(
  70. name = "numeric_literal_benchmark",
  71. testonly = 1,
  72. srcs = ["numeric_literal_benchmark.cpp"],
  73. deps = [
  74. ":numeric_literal",
  75. "//common:check",
  76. "//toolchain/diagnostics:null_diagnostics",
  77. "@com_github_google_benchmark//:benchmark_main",
  78. ],
  79. )
  80. cc_test(
  81. name = "numeric_literal_test",
  82. size = "small",
  83. srcs = ["numeric_literal_test.cpp"],
  84. deps = [
  85. ":numeric_literal",
  86. ":test_helpers",
  87. "//common:check",
  88. "//common:ostream",
  89. "//testing/base:gtest_main",
  90. "//toolchain/diagnostics:diagnostic_emitter",
  91. "@com_google_googletest//:gtest",
  92. "@llvm-project//llvm:Support",
  93. ],
  94. )
  95. cc_fuzz_test(
  96. name = "numeric_literal_fuzzer",
  97. size = "small",
  98. srcs = ["numeric_literal_fuzzer.cpp"],
  99. corpus = glob(["fuzzer_corpus/numeric_literal/*"]),
  100. deps = [
  101. ":numeric_literal",
  102. "//toolchain/diagnostics:diagnostic_emitter",
  103. "//toolchain/diagnostics:null_diagnostics",
  104. "@llvm-project//llvm:Support",
  105. ],
  106. )
  107. cc_library(
  108. name = "string_literal",
  109. srcs = ["string_literal.cpp"],
  110. hdrs = ["string_literal.h"],
  111. deps = [
  112. ":character_set",
  113. ":helpers",
  114. "//common:check",
  115. "//toolchain/diagnostics:diagnostic_emitter",
  116. "@llvm-project//llvm:Support",
  117. ],
  118. )
  119. cc_binary(
  120. name = "string_literal_benchmark",
  121. testonly = 1,
  122. srcs = ["string_literal_benchmark.cpp"],
  123. deps = [
  124. ":string_literal",
  125. "//toolchain/diagnostics:null_diagnostics",
  126. "@com_github_google_benchmark//:benchmark_main",
  127. ],
  128. )
  129. cc_test(
  130. name = "string_literal_test",
  131. size = "small",
  132. srcs = ["string_literal_test.cpp"],
  133. deps = [
  134. ":string_literal",
  135. ":test_helpers",
  136. "//common:check",
  137. "//common:ostream",
  138. "//testing/base:gtest_main",
  139. "//toolchain/diagnostics:diagnostic_emitter",
  140. "@com_google_googletest//:gtest",
  141. "@llvm-project//llvm:Support",
  142. ],
  143. )
  144. cc_fuzz_test(
  145. name = "string_literal_fuzzer",
  146. size = "small",
  147. srcs = ["string_literal_fuzzer.cpp"],
  148. corpus = glob(["fuzzer_corpus/string_literal/*"]),
  149. deps = [
  150. ":string_literal",
  151. "//common:check",
  152. "//toolchain/diagnostics:diagnostic_emitter",
  153. "//toolchain/diagnostics:null_diagnostics",
  154. "@llvm-project//llvm:Support",
  155. ],
  156. )
  157. cc_library(
  158. name = "tokenized_buffer",
  159. srcs = ["tokenized_buffer.cpp"],
  160. hdrs = ["tokenized_buffer.h"],
  161. deps = [
  162. ":character_set",
  163. ":helpers",
  164. ":numeric_literal",
  165. ":string_literal",
  166. ":token_kind",
  167. "//common:check",
  168. "//common:ostream",
  169. "//common:string_helpers",
  170. "//toolchain/base:index_base",
  171. "//toolchain/diagnostics:diagnostic_emitter",
  172. "//toolchain/source:source_buffer",
  173. "@llvm-project//llvm:Support",
  174. ],
  175. )
  176. cc_library(
  177. name = "tokenized_buffer_test_helpers",
  178. testonly = 1,
  179. hdrs = ["tokenized_buffer_test_helpers.h"],
  180. deps = [
  181. ":tokenized_buffer",
  182. "//common:check",
  183. "@com_google_googletest//:gtest",
  184. "@llvm-project//llvm:Support",
  185. ],
  186. )
  187. cc_test(
  188. name = "tokenized_buffer_test",
  189. size = "small",
  190. srcs = ["tokenized_buffer_test.cpp"],
  191. deps = [
  192. ":tokenized_buffer",
  193. ":tokenized_buffer_test_helpers",
  194. "//testing/base:gtest_main",
  195. "//testing/base:test_raw_ostream",
  196. "//toolchain/base:yaml_test_helpers",
  197. "//toolchain/diagnostics:diagnostic_emitter",
  198. "//toolchain/diagnostics:mocks",
  199. "@com_google_googletest//:gtest",
  200. "@llvm-project//llvm:Support",
  201. ],
  202. )
  203. cc_fuzz_test(
  204. name = "tokenized_buffer_fuzzer",
  205. size = "small",
  206. srcs = ["tokenized_buffer_fuzzer.cpp"],
  207. corpus = glob(["fuzzer_corpus/tokenized_buffer/*"]),
  208. deps = [
  209. ":tokenized_buffer",
  210. "//common:check",
  211. "//toolchain/diagnostics:diagnostic_emitter",
  212. "//toolchain/diagnostics:null_diagnostics",
  213. "@llvm-project//llvm:Support",
  214. ],
  215. )
  216. cc_binary(
  217. name = "tokenized_buffer_benchmark",
  218. testonly = 1,
  219. srcs = ["tokenized_buffer_benchmark.cpp"],
  220. deps = [
  221. ":token_kind",
  222. ":tokenized_buffer",
  223. "//common:check",
  224. "//toolchain/diagnostics:diagnostic_emitter",
  225. "//toolchain/diagnostics:null_diagnostics",
  226. "@com_github_google_benchmark//:benchmark_main",
  227. "@com_google_absl//absl/random",
  228. "@llvm-project//llvm:Support",
  229. ],
  230. )
  231. file_test(
  232. name = "lex_file_test",
  233. srcs = ["lex_file_test.cpp"],
  234. tests = glob(["testdata/**/*.carbon"]),
  235. deps = [
  236. "//toolchain/driver:driver_file_test_base",
  237. "@com_googlesource_code_re2//:re2",
  238. "@llvm-project//llvm:Support",
  239. ],
  240. )
  241. glob_sh_run(
  242. args = [
  243. "$(location //toolchain/driver:carbon)",
  244. "compile",
  245. "--phase=lex",
  246. "--dump-tokens",
  247. ],
  248. data = ["//toolchain/driver:carbon"],
  249. file_exts = ["carbon"],
  250. )
  251. glob_sh_run(
  252. args = [
  253. "$(location //toolchain/driver:carbon)",
  254. "-v",
  255. "compile",
  256. "--phase=lex",
  257. ],
  258. data = ["//toolchain/driver:carbon"],
  259. file_exts = ["carbon"],
  260. run_ext = "verbose",
  261. )