check.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // Storage for the unit's Clang AST. The unique_ptr should start empty, and
  26. // can be assigned as part of checking.
  27. std::unique_ptr<clang::ASTUnit>* cpp_ast;
  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. // When dumping textual SemIR (or printing it to for verbose output), whether
  46. // to use ranges.
  47. enum class DumpSemIRRanges : int8_t {
  48. IfPresent,
  49. Only,
  50. Ignore,
  51. };
  52. DumpSemIRRanges dump_sem_ir_ranges = DumpSemIRRanges::IfPresent;
  53. // If set, raw SemIR will be dumped to this.
  54. llvm::raw_ostream* raw_dump_stream = nullptr;
  55. // When dumping raw SemIR, whether to include builtins.
  56. bool dump_raw_sem_ir_builtins = false;
  57. };
  58. // Checks a group of parse trees. This will use imports to decide the order of
  59. // checking.
  60. //
  61. // `units` will only contain units which should be checked, and is not indexed
  62. // by `CheckIRId`.
  63. auto CheckParseTrees(
  64. llvm::MutableArrayRef<Unit> units,
  65. const Parse::GetTreeAndSubtreesStore& tree_and_subtrees_getters,
  66. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  67. const CheckParseTreesOptions& options,
  68. std::shared_ptr<clang::CompilerInvocation> clang_invocation) -> void;
  69. } // namespace Carbon::Check
  70. #endif // CARBON_TOOLCHAIN_CHECK_CHECK_H_