semantics_ir.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_SEMANTICS_SEMANTICS_IR_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_
  6. #include "llvm/ADT/ArrayRef.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "toolchain/parser/parse_tree.h"
  9. #include "toolchain/semantics/node_store.h"
  10. namespace Carbon::Testing {
  11. class SemanticsIRForTest;
  12. } // namespace Carbon::Testing
  13. namespace Carbon {
  14. // Provides semantic analysis on a ParseTree.
  15. class SemanticsIR {
  16. public:
  17. // File-level declarations.
  18. auto root_block() const -> llvm::ArrayRef<Semantics::NodeRef> {
  19. return root_block_;
  20. }
  21. // Prints the full IR.
  22. auto Print(llvm::raw_ostream& out) const -> void;
  23. auto PrintBlock(llvm::raw_ostream& out, int indent,
  24. llvm::ArrayRef<Semantics::NodeRef> node_refs) const -> void;
  25. // Prints the node information.
  26. auto Print(llvm::raw_ostream& out, int indent,
  27. Semantics::NodeRef node_ref) const -> void;
  28. private:
  29. friend class SemanticsIRFactory;
  30. friend class Testing::SemanticsIRForTest;
  31. explicit SemanticsIR(const ParseTree& parse_tree)
  32. : parse_tree_(&parse_tree) {}
  33. Semantics::NodeStore nodes_;
  34. llvm::SmallVector<Semantics::NodeRef, 0> root_block_;
  35. const ParseTree* parse_tree_;
  36. };
  37. } // namespace Carbon
  38. #endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_H_