BUILD 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. # TODO(https://github.com/carbon-language/carbon-lang/issues/266):
  5. # Migrate bison/flex usage to a more hermetic bazel build.
  6. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
  7. load("//bazel/testing:golden_test.bzl", "golden_test")
  8. cc_binary(
  9. name = "executable_semantics",
  10. srcs = ["main.cpp"],
  11. deps = [":syntax"],
  12. )
  13. cc_library(
  14. name = "syntax",
  15. srcs = [
  16. "syntax.tab.cpp",
  17. "syntax.yy.cpp",
  18. "syntax_helpers.cpp",
  19. "syntax_helpers.h",
  20. ],
  21. hdrs = ["syntax.tab.h"],
  22. # Disable warnings for generated code.
  23. copts = [
  24. "-Wno-unneeded-internal-declaration",
  25. "-Wno-unused-function",
  26. "-Wno-writable-strings",
  27. ],
  28. deps = [
  29. "//executable_semantics/ast:declaration",
  30. "//executable_semantics/ast:expression",
  31. "//executable_semantics/ast:expression_or_field_list",
  32. "//executable_semantics/interpreter",
  33. ],
  34. )
  35. genrule(
  36. name = "syntax_bison_srcs",
  37. srcs = ["syntax.ypp"],
  38. outs = [
  39. "syntax.tab.cpp",
  40. "syntax.tab.h",
  41. ],
  42. cmd = "bison " +
  43. "--output=$(location syntax.tab.cpp) " +
  44. "--defines=$(location syntax.tab.h) " +
  45. "$(location syntax.ypp)",
  46. )
  47. genrule(
  48. name = "syntax_flex_srcs",
  49. srcs = ["syntax.lpp"],
  50. outs = ["syntax.yy.cpp"],
  51. cmd = "flex " +
  52. "--outfile=$(location syntax.yy.cpp) " +
  53. "$(location syntax.lpp)",
  54. )
  55. EXAMPLES = [
  56. "block1",
  57. "break1",
  58. "choice1",
  59. "continue1",
  60. "fun_recur",
  61. "fun1",
  62. "fun2",
  63. "fun3",
  64. "fun4",
  65. "fun5",
  66. "fun6_fail_type",
  67. "funptr1",
  68. "if1",
  69. "if2",
  70. "if3",
  71. "match_int_default",
  72. "match_int",
  73. "match_type",
  74. "next",
  75. "pattern_init",
  76. "record1",
  77. "struct1",
  78. "struct2",
  79. "struct3",
  80. "tuple_assign",
  81. "tuple_match",
  82. "tuple1",
  83. "tuple2",
  84. "undef1",
  85. "undef2",
  86. "while1",
  87. "zero",
  88. ]
  89. [genrule(
  90. name = "%s_out" % e,
  91. srcs = ["testdata/%s.6c" % e],
  92. outs = ["testdata/%s.out" % e],
  93. # Suppress command errors.
  94. cmd = "$(location executable_semantics) $< > $@ 2>&1 || true",
  95. tools = [":executable_semantics"],
  96. ) for e in EXAMPLES]
  97. [golden_test(
  98. name = "%s_test" % e,
  99. golden = "testdata/%s.golden" % e,
  100. subject = "testdata/%s.out" % e,
  101. ) for e in EXAMPLES]