BUILD 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: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 = "M4=$(M4) $(BISON) " +
  43. "--output=$(location syntax.tab.cpp) " +
  44. "--defines=$(location syntax.tab.h) " +
  45. "$(location syntax.ypp)",
  46. toolchains = [
  47. "@rules_bison//bison:current_bison_toolchain",
  48. "@rules_m4//m4:current_m4_toolchain",
  49. ],
  50. )
  51. genrule(
  52. name = "syntax_flex_srcs",
  53. srcs = ["syntax.lpp"],
  54. outs = ["syntax.yy.cpp"],
  55. cmd = "M4=$(M4) $(FLEX) " +
  56. "--outfile=$(location syntax.yy.cpp) " +
  57. "$(location syntax.lpp)",
  58. toolchains = [
  59. "@rules_flex//flex:current_flex_toolchain",
  60. "@rules_m4//m4:current_m4_toolchain",
  61. ],
  62. )
  63. EXAMPLES = [
  64. "block1",
  65. "break1",
  66. "choice1",
  67. "continue1",
  68. "fun_recur",
  69. "fun1",
  70. "fun2",
  71. "fun3",
  72. "fun4",
  73. "fun5",
  74. "fun6_fail_type",
  75. "funptr1",
  76. "if1",
  77. # (Temporarily disabled pending
  78. # https://github.com/carbon-language/carbon-lang/issues/311)
  79. # "if2",
  80. "if3",
  81. "match_int_default",
  82. "match_int",
  83. "match_type",
  84. "next",
  85. "pattern_init",
  86. "record1",
  87. "struct1",
  88. "struct2",
  89. "struct3",
  90. "tuple_assign",
  91. "tuple_match",
  92. "tuple1",
  93. "tuple2",
  94. "undef1",
  95. "undef2",
  96. "while1",
  97. "zero",
  98. ]
  99. [genrule(
  100. name = "%s_out" % e,
  101. srcs = ["testdata/%s.6c" % e],
  102. outs = ["testdata/%s.out" % e],
  103. # Suppress command errors.
  104. cmd = "$(location executable_semantics) $< > $@ 2>&1 || echo EXIT CODE: $$? >> $@",
  105. tools = [":executable_semantics"],
  106. ) for e in EXAMPLES]
  107. [golden_test(
  108. name = "%s_test" % e,
  109. golden = "testdata/%s.golden" % e,
  110. subject = "testdata/%s.out" % e,
  111. ) for e in EXAMPLES]