BUILD 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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: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: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/base:int",
  68. "//toolchain/diagnostics:emitter",
  69. "//toolchain/diagnostics:format_providers",
  70. "@llvm-project//llvm:Support",
  71. ],
  72. )
  73. cc_binary(
  74. name = "numeric_literal_benchmark",
  75. testonly = 1,
  76. srcs = ["numeric_literal_benchmark.cpp"],
  77. deps = [
  78. ":numeric_literal",
  79. "//common:check",
  80. "//testing/base:benchmark_main",
  81. "//toolchain/diagnostics:null_diagnostics",
  82. "@google_benchmark//:benchmark",
  83. ],
  84. )
  85. cc_test(
  86. name = "numeric_literal_test",
  87. size = "small",
  88. srcs = ["numeric_literal_test.cpp"],
  89. deps = [
  90. ":numeric_literal",
  91. ":test_helpers",
  92. "//common:check",
  93. "//common:ostream",
  94. "//testing/base:gtest_main",
  95. "//toolchain/diagnostics:emitter",
  96. "@googletest//:gtest",
  97. "@llvm-project//llvm:Support",
  98. ],
  99. )
  100. cc_fuzz_test(
  101. name = "numeric_literal_fuzzer",
  102. size = "small",
  103. srcs = ["numeric_literal_fuzzer.cpp"],
  104. corpus = glob(["fuzzer_corpus/numeric_literal/*"]),
  105. deps = [
  106. ":numeric_literal",
  107. "//testing/fuzzing:libfuzzer_header",
  108. "//toolchain/diagnostics:emitter",
  109. "//toolchain/diagnostics:null_diagnostics",
  110. "@llvm-project//llvm:Support",
  111. ],
  112. )
  113. cc_library(
  114. name = "string_literal",
  115. srcs = ["string_literal.cpp"],
  116. hdrs = ["string_literal.h"],
  117. deps = [
  118. ":character_set",
  119. ":helpers",
  120. ":token_info",
  121. "//common:check",
  122. "//toolchain/diagnostics:emitter",
  123. "@llvm-project//llvm:Support",
  124. ],
  125. )
  126. cc_binary(
  127. name = "string_literal_benchmark",
  128. testonly = 1,
  129. srcs = ["string_literal_benchmark.cpp"],
  130. deps = [
  131. ":string_literal",
  132. "//testing/base:benchmark_main",
  133. "//toolchain/diagnostics:null_diagnostics",
  134. "@google_benchmark//:benchmark",
  135. ],
  136. )
  137. cc_test(
  138. name = "string_literal_test",
  139. size = "small",
  140. srcs = ["string_literal_test.cpp"],
  141. deps = [
  142. ":string_literal",
  143. ":test_helpers",
  144. "//common:check",
  145. "//common:ostream",
  146. "//testing/base:gtest_main",
  147. "//toolchain/diagnostics:emitter",
  148. "@googletest//:gtest",
  149. "@llvm-project//llvm:Support",
  150. ],
  151. )
  152. cc_fuzz_test(
  153. name = "string_literal_fuzzer",
  154. size = "small",
  155. srcs = ["string_literal_fuzzer.cpp"],
  156. corpus = glob(["fuzzer_corpus/string_literal/*"]),
  157. deps = [
  158. ":string_literal",
  159. "//common:check",
  160. "//testing/fuzzing:libfuzzer_header",
  161. "//toolchain/diagnostics:emitter",
  162. "//toolchain/diagnostics:null_diagnostics",
  163. "@llvm-project//llvm:Support",
  164. ],
  165. )
  166. cc_library(
  167. name = "lex",
  168. srcs = ["lex.cpp"],
  169. hdrs = ["lex.h"],
  170. deps = [
  171. ":character_set",
  172. ":dump",
  173. ":helpers",
  174. ":numeric_literal",
  175. ":string_literal",
  176. ":token_index",
  177. ":token_info",
  178. ":token_kind",
  179. ":tokenized_buffer",
  180. "//common:check",
  181. "//common:vlog",
  182. "//toolchain/base:kind_switch",
  183. "//toolchain/base:shared_value_stores",
  184. "//toolchain/diagnostics:emitter",
  185. "//toolchain/diagnostics:format_providers",
  186. "//toolchain/source:source_buffer",
  187. "@llvm-project//llvm:Support",
  188. ],
  189. )
  190. cc_library(
  191. name = "dump",
  192. srcs = ["dump.cpp"],
  193. hdrs = ["dump.h"],
  194. deps = [
  195. ":tokenized_buffer",
  196. "//common:ostream",
  197. "//common:raw_string_ostream",
  198. ],
  199. # Always link dump methods.
  200. alwayslink = 1,
  201. )
  202. cc_library(
  203. name = "token_index",
  204. hdrs = ["token_index.h"],
  205. deps = [
  206. ":token_kind",
  207. "//toolchain/base:index_base",
  208. ],
  209. )
  210. cc_library(
  211. name = "token_info",
  212. hdrs = ["token_info.h"],
  213. deps = [
  214. ":token_index",
  215. ":token_kind",
  216. "//common:check",
  217. "//toolchain/base:int",
  218. "//toolchain/base:value_ids",
  219. ],
  220. )
  221. cc_library(
  222. name = "tokenized_buffer",
  223. srcs = ["tokenized_buffer.cpp"],
  224. hdrs = ["tokenized_buffer.h"],
  225. deps = [
  226. ":character_set",
  227. ":helpers",
  228. ":numeric_literal",
  229. ":string_literal",
  230. ":token_index",
  231. ":token_info",
  232. ":token_kind",
  233. "//common:check",
  234. "//common:ostream",
  235. "//common:string_helpers",
  236. "//toolchain/base:index_base",
  237. "//toolchain/base:mem_usage",
  238. "//toolchain/base:shared_value_stores",
  239. "//toolchain/diagnostics:emitter",
  240. "//toolchain/source:source_buffer",
  241. "@llvm-project//llvm:Support",
  242. ],
  243. )
  244. cc_library(
  245. name = "tokenized_buffer_test_helpers",
  246. testonly = 1,
  247. hdrs = ["tokenized_buffer_test_helpers.h"],
  248. deps = [
  249. ":lex",
  250. ":tokenized_buffer",
  251. "//common:check",
  252. "//toolchain/base:shared_value_stores",
  253. "@googletest//:gtest",
  254. "@llvm-project//llvm:Support",
  255. ],
  256. )
  257. cc_test(
  258. name = "tokenized_buffer_test",
  259. size = "small",
  260. srcs = ["tokenized_buffer_test.cpp"],
  261. deps = [
  262. ":lex",
  263. ":token_kind",
  264. ":tokenized_buffer",
  265. ":tokenized_buffer_test_helpers",
  266. "//common:raw_string_ostream",
  267. "//testing/base:gtest_main",
  268. "//toolchain/base:shared_value_stores",
  269. "//toolchain/diagnostics:emitter",
  270. "//toolchain/diagnostics:mocks",
  271. "//toolchain/testing:compile_helper",
  272. "//toolchain/testing:yaml_test_helpers",
  273. "@googletest//:gtest",
  274. "@llvm-project//llvm:Support",
  275. ],
  276. )
  277. cc_fuzz_test(
  278. name = "tokenized_buffer_fuzzer",
  279. size = "small",
  280. srcs = ["tokenized_buffer_fuzzer.cpp"],
  281. corpus = glob(["fuzzer_corpus/tokenized_buffer/*"]),
  282. deps = [
  283. ":lex",
  284. "//common:check",
  285. "//testing/fuzzing:libfuzzer_header",
  286. "//toolchain/base:shared_value_stores",
  287. "//toolchain/diagnostics:emitter",
  288. "//toolchain/diagnostics:null_diagnostics",
  289. "@llvm-project//llvm:Support",
  290. ],
  291. )
  292. cc_binary(
  293. name = "tokenized_buffer_benchmark",
  294. testonly = 1,
  295. srcs = ["tokenized_buffer_benchmark.cpp"],
  296. deps = [
  297. ":lex",
  298. ":token_kind",
  299. ":tokenized_buffer",
  300. "//common:check",
  301. "//common:raw_string_ostream",
  302. "//testing/base:benchmark_main",
  303. "//testing/base:source_gen_lib",
  304. "//toolchain/base:shared_value_stores",
  305. "//toolchain/diagnostics:emitter",
  306. "//toolchain/diagnostics:null_diagnostics",
  307. "@abseil-cpp//absl/random",
  308. "@google_benchmark//:benchmark",
  309. "@llvm-project//llvm:Support",
  310. ],
  311. )