check.h 2.9 KB

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