check.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #ifndef CARBON_TOOLCHAIN_CHECK_CHECK_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CHECK_H_
  6. #include "clang/Frontend/CompilerInvocation.h"
  7. #include "common/ostream.h"
  8. #include "toolchain/base/shared_value_stores.h"
  9. #include "toolchain/base/timings.h"
  10. #include "toolchain/check/diagnostic_emitter.h"
  11. #include "toolchain/diagnostics/emitter.h"
  12. #include "toolchain/parse/tree_and_subtrees.h"
  13. #include "toolchain/sem_ir/file.h"
  14. #include "toolchain/sem_ir/ids.h"
  15. namespace Carbon::Check {
  16. // Checking information that's tracked per file. All members are caller-owned.
  17. // Other than `timings`, members must be non-null.
  18. struct Unit {
  19. Diagnostics::Consumer* consumer;
  20. SharedValueStores* value_stores;
  21. // The `timings` may be null if nothing is to be recorded.
  22. Timings* timings;
  23. // The unit's SemIR, provided as empty and filled in by CheckParseTrees.
  24. SemIR::File* sem_ir;
  25. llvm::LLVMContext* llvm_context;
  26. // The total number of files.
  27. int total_ir_count;
  28. };
  29. struct CheckParseTreesOptions {
  30. // Options must be set individually, not through initialization.
  31. explicit CheckParseTreesOptions() = default;
  32. // Whether to import the prelude.
  33. bool prelude_import = false;
  34. // If set, enables verbose output.
  35. llvm::raw_ostream* vlog_stream = nullptr;
  36. // Whether fuzzing is being run. Used to disable features we don't want to
  37. // fuzz.
  38. bool fuzzing = false;
  39. // Whether to include each unit in dumps. This is required when dumping
  40. // (either of `dump_stream` or `raw_dump_stream`), and must have entries based
  41. // on CheckIRId.
  42. const FixedSizeValueStore<SemIR::CheckIRId, bool>* include_in_dumps = nullptr;
  43. // If set, SemIR will be dumped to this.
  44. llvm::raw_ostream* dump_stream = nullptr;
  45. // If set, C++ AST will be dumped to this.
  46. llvm::raw_ostream* dump_cpp_ast_stream = nullptr;
  47. // When dumping textual SemIR (or printing it to for verbose output), whether
  48. // to use ranges.
  49. enum class DumpSemIRRanges : int8_t {
  50. IfPresent,
  51. Only,
  52. Ignore,
  53. };
  54. DumpSemIRRanges dump_sem_ir_ranges = DumpSemIRRanges::IfPresent;
  55. // If set, raw SemIR will be dumped to this.
  56. llvm::raw_ostream* raw_dump_stream = nullptr;
  57. // When dumping raw SemIR, whether to include builtins.
  58. bool dump_raw_sem_ir_builtins = false;
  59. // If not empty, a raw SemIR dump should be written to this path in the event
  60. // of a crash.
  61. llvm::StringRef sem_ir_crash_dump;
  62. };
  63. // Checks a group of parse trees. This will use imports to decide the order of
  64. // checking.
  65. //
  66. // `units` will only contain units which should be checked, and is not indexed
  67. // by `CheckIRId`.
  68. auto CheckParseTrees(
  69. llvm::MutableArrayRef<Unit> units,
  70. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  71. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  72. const CheckParseTreesOptions& options,
  73. std::shared_ptr<clang::CompilerInvocation> clang_invocation) -> void;
  74. } // namespace Carbon::Check
  75. #endif // CARBON_TOOLCHAIN_CHECK_CHECK_H_