check.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/diagnostic_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. // The total number of files.
  26. int total_ir_count;
  27. // Storage for the unit's Clang AST. The unique_ptr should start empty, and
  28. // can be assigned as part of checking.
  29. std::unique_ptr<clang::ASTUnit>* clang_ast_unit;
  30. };
  31. struct CheckParseTreesOptions {
  32. // Options must be set individually, not through initialization.
  33. explicit CheckParseTreesOptions() = default;
  34. // Whether to import the prelude.
  35. bool prelude_import = false;
  36. // If set, enables verbose output.
  37. llvm::raw_ostream* vlog_stream = nullptr;
  38. // Whether fuzzing is being run. Used to disable features we don't want to
  39. // fuzz.
  40. bool fuzzing = false;
  41. // Whether to include each unit in dumps. This is required when dumping
  42. // (either of `dump_stream` or `raw_dump_stream`), and must have entries based
  43. // on CheckIRId.
  44. const FixedSizeValueStore<SemIR::CheckIRId, bool>* include_in_dumps = nullptr;
  45. // If set, SemIR will be dumped to this.
  46. llvm::raw_ostream* dump_stream = nullptr;
  47. // If set, C++ AST will be dumped to this.
  48. llvm::raw_ostream* dump_cpp_ast_stream = nullptr;
  49. // When dumping textual SemIR (or printing it to for verbose output), whether
  50. // to use ranges.
  51. enum class DumpSemIRRanges : int8_t {
  52. IfPresent,
  53. Only,
  54. Ignore,
  55. };
  56. DumpSemIRRanges dump_sem_ir_ranges = DumpSemIRRanges::IfPresent;
  57. // If set, raw SemIR will be dumped to this.
  58. llvm::raw_ostream* raw_dump_stream = nullptr;
  59. // When dumping raw SemIR, whether to include builtins.
  60. bool dump_raw_sem_ir_builtins = false;
  61. };
  62. // Checks a group of parse trees. This will use imports to decide the order of
  63. // checking.
  64. //
  65. // `units` will only contain units which should be checked, and is not indexed
  66. // by `CheckIRId`.
  67. auto CheckParseTrees(
  68. llvm::MutableArrayRef<Unit> units,
  69. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  70. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  71. const CheckParseTreesOptions& options,
  72. std::shared_ptr<clang::CompilerInvocation> clang_invocation) -> void;
  73. } // namespace Carbon::Check
  74. #endif // CARBON_TOOLCHAIN_CHECK_CHECK_H_