BUILD 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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("//bazel/cc_rules: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. srcs = 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_index",
  175. ":token_kind",
  176. ":tokenized_buffer",
  177. "//common:check",
  178. "//common:vlog",
  179. "//toolchain/base:kind_switch",
  180. "//toolchain/base:shared_value_stores",
  181. "//toolchain/diagnostics:diagnostic_emitter",
  182. "//toolchain/source:source_buffer",
  183. "@llvm-project//llvm:Support",
  184. ],
  185. )
  186. cc_library(
  187. name = "dump",
  188. srcs = ["dump.cpp"],
  189. hdrs = ["dump.h"],
  190. deps = [
  191. ":tokenized_buffer",
  192. "//common:ostream",
  193. "//common:raw_string_ostream",
  194. ],
  195. # Always link dump methods.
  196. alwayslink = 1,
  197. )
  198. cc_library(
  199. name = "token_index",
  200. hdrs = ["token_index.h"],
  201. deps = [
  202. ":token_kind",
  203. "//toolchain/base:index_base",
  204. ],
  205. )
  206. cc_library(
  207. name = "token_info",
  208. hdrs = ["token_info.h"],
  209. deps = [
  210. ":token_index",
  211. ":token_kind",
  212. "//common:check",
  213. "//toolchain/base:int",
  214. "//toolchain/base:value_ids",
  215. ],
  216. )
  217. cc_library(
  218. name = "tokenized_buffer",
  219. srcs = ["tokenized_buffer.cpp"],
  220. hdrs = ["tokenized_buffer.h"],
  221. deps = [
  222. ":character_set",
  223. ":helpers",
  224. ":numeric_literal",
  225. ":string_literal",
  226. ":token_index",
  227. ":token_info",
  228. ":token_kind",
  229. "//common:check",
  230. "//common:ostream",
  231. "//common:string_helpers",
  232. "//toolchain/base:index_base",
  233. "//toolchain/base:mem_usage",
  234. "//toolchain/base:shared_value_stores",
  235. "//toolchain/diagnostics:diagnostic_emitter",
  236. "//toolchain/source:source_buffer",
  237. "@llvm-project//llvm:Support",
  238. ],
  239. )
  240. cc_library(
  241. name = "tokenized_buffer_test_helpers",
  242. testonly = 1,
  243. hdrs = ["tokenized_buffer_test_helpers.h"],
  244. deps = [
  245. ":lex",
  246. ":tokenized_buffer",
  247. "//common:check",
  248. "//toolchain/base:shared_value_stores",
  249. "@googletest//:gtest",
  250. "@llvm-project//llvm:Support",
  251. ],
  252. )
  253. cc_test(
  254. name = "tokenized_buffer_test",
  255. size = "small",
  256. srcs = ["tokenized_buffer_test.cpp"],
  257. deps = [
  258. ":lex",
  259. ":token_kind",
  260. ":tokenized_buffer",
  261. ":tokenized_buffer_test_helpers",
  262. "//common:raw_string_ostream",
  263. "//testing/base:gtest_main",
  264. "//toolchain/base:shared_value_stores",
  265. "//toolchain/diagnostics:diagnostic_emitter",
  266. "//toolchain/diagnostics:mocks",
  267. "//toolchain/testing:compile_helper",
  268. "//toolchain/testing:yaml_test_helpers",
  269. "@googletest//:gtest",
  270. "@llvm-project//llvm:Support",
  271. ],
  272. )
  273. cc_fuzz_test(
  274. name = "tokenized_buffer_fuzzer",
  275. size = "small",
  276. srcs = ["tokenized_buffer_fuzzer.cpp"],
  277. corpus = glob(["fuzzer_corpus/tokenized_buffer/*"]),
  278. deps = [
  279. ":lex",
  280. "//common:check",
  281. "//testing/fuzzing:libfuzzer_header",
  282. "//toolchain/base:shared_value_stores",
  283. "//toolchain/diagnostics:diagnostic_emitter",
  284. "//toolchain/diagnostics:null_diagnostics",
  285. "@llvm-project//llvm:Support",
  286. ],
  287. )
  288. cc_binary(
  289. name = "tokenized_buffer_benchmark",
  290. testonly = 1,
  291. srcs = ["tokenized_buffer_benchmark.cpp"],
  292. deps = [
  293. ":lex",
  294. ":token_kind",
  295. ":tokenized_buffer",
  296. "//common:check",
  297. "//common:raw_string_ostream",
  298. "//testing/base:benchmark_main",
  299. "//testing/base:source_gen_lib",
  300. "//toolchain/base:shared_value_stores",
  301. "//toolchain/diagnostics:diagnostic_emitter",
  302. "//toolchain/diagnostics:null_diagnostics",
  303. "@abseil-cpp//absl/random",
  304. "@google_benchmark//:benchmark",
  305. "@llvm-project//llvm:Support",
  306. ],
  307. )