BUILD 7.9 KB

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