BUILD 7.5 KB

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