check.h 2.7 KB

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