BUILD 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 = [
  12. ":syntax",
  13. "@llvm-project//llvm:Support",
  14. ],
  15. )
  16. cc_library(
  17. name = "tracing_flag",
  18. srcs = ["tracing_flag.cpp"],
  19. hdrs = ["tracing_flag.h"],
  20. visibility = ["//visibility:public"],
  21. )
  22. cc_library(
  23. name = "syntax",
  24. srcs = [
  25. "syntax.tab.cpp",
  26. "syntax.yy.cpp",
  27. "syntax_helpers.cpp",
  28. "syntax_helpers.h",
  29. ],
  30. hdrs = ["syntax.tab.h"],
  31. # Disable warnings for generated code.
  32. copts = [
  33. "-Wno-unneeded-internal-declaration",
  34. "-Wno-unused-function",
  35. "-Wno-writable-strings",
  36. ],
  37. deps = [
  38. ":tracing_flag",
  39. "//executable_semantics/ast:declaration",
  40. "//executable_semantics/ast:expression",
  41. "//executable_semantics/ast:field_list",
  42. "//executable_semantics/interpreter",
  43. ],
  44. )
  45. genrule(
  46. name = "syntax_bison_srcs",
  47. srcs = ["syntax.ypp"],
  48. outs = [
  49. "syntax.tab.cpp",
  50. "syntax.tab.h",
  51. ],
  52. cmd = "M4=$(M4) $(BISON) " +
  53. "--output=$(location syntax.tab.cpp) " +
  54. "--defines=$(location syntax.tab.h) " +
  55. "$(location syntax.ypp)",
  56. toolchains = [
  57. "@rules_bison//bison:current_bison_toolchain",
  58. "@rules_m4//m4:current_m4_toolchain",
  59. ],
  60. )
  61. genrule(
  62. name = "syntax_flex_srcs",
  63. srcs = ["syntax.lpp"],
  64. outs = ["syntax.yy.cpp"],
  65. cmd = "M4=$(M4) $(FLEX) " +
  66. "--outfile=$(location syntax.yy.cpp) " +
  67. "$(location syntax.lpp)",
  68. toolchains = [
  69. "@rules_flex//flex:current_flex_toolchain",
  70. "@rules_m4//m4:current_m4_toolchain",
  71. ],
  72. )
  73. EXAMPLES = [
  74. "block1",
  75. "break1",
  76. "choice1",
  77. "continue1",
  78. "fun_recur",
  79. "fun1",
  80. "fun2",
  81. "fun3",
  82. "fun4",
  83. "fun5",
  84. "fun6_fail_type",
  85. "funptr1",
  86. "if1",
  87. "if2",
  88. "if3",
  89. "match_int_default",
  90. "match_int",
  91. "match_type",
  92. "next",
  93. "pattern_init",
  94. "pattern_variable_fail",
  95. "record1",
  96. "struct1",
  97. "struct2",
  98. "struct3",
  99. "tuple_assign",
  100. "tuple_match",
  101. "tuple1",
  102. "tuple2",
  103. "undef1",
  104. "undef2",
  105. "while1",
  106. "zero",
  107. ]
  108. [genrule(
  109. name = "%s_out" % e,
  110. srcs = ["testdata/%s.6c" % e],
  111. outs = ["testdata/%s.out" % e],
  112. # Suppress command errors.
  113. cmd = "$(location executable_semantics) $< > $@ 2>&1 || echo EXIT CODE: $$? >> $@",
  114. tools = [":executable_semantics"],
  115. ) for e in EXAMPLES]
  116. [golden_test(
  117. name = "%s_test" % e,
  118. golden = "testdata/%s.golden" % e,
  119. subject = "testdata/%s.out" % e,
  120. ) for e in EXAMPLES]