semantics_node_kind.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_NODE_KIND_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_NODE_KIND_H_
  6. #include <cstdint>
  7. #include "common/enum_base.h"
  8. namespace Carbon {
  9. CARBON_DEFINE_RAW_ENUM_CLASS(SemanticsNodeKind, uint8_t) {
  10. #define CARBON_SEMANTICS_NODE_KIND(Name) CARBON_RAW_ENUM_ENUMERATOR(Name)
  11. #include "toolchain/semantics/semantics_node_kind.def"
  12. };
  13. // Whether a node is a terminator or part of the terminator sequence. The nodes
  14. // in a block appear in the order NotTerminator, then TerminatorSequence, then
  15. // Terminator, which is also the numerical order of these values.
  16. enum class SemanticsTerminatorKind {
  17. // This node is not a terminator.
  18. NotTerminator,
  19. // This node is not itself a terminator, but forms part of a terminator
  20. // sequence.
  21. TerminatorSequence,
  22. // This node is a terminator.
  23. Terminator,
  24. };
  25. class SemanticsNodeKind : public CARBON_ENUM_BASE(SemanticsNodeKind) {
  26. public:
  27. #define CARBON_SEMANTICS_NODE_KIND(Name) CARBON_ENUM_CONSTANT_DECLARATION(Name)
  28. #include "toolchain/semantics/semantics_node_kind.def"
  29. using EnumBase::Create;
  30. // Returns whether this node kind is a code block terminator, such as an
  31. // unconditional branch instruction, or part of the termination sequence,
  32. // such as a conditional branch instruction. The termination sequence of a
  33. // code block appears after all other instructions, and ends with a
  34. // terminator instruction.
  35. [[nodiscard]] auto terminator_kind() const -> SemanticsTerminatorKind;
  36. };
  37. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  38. CARBON_ENUM_CONSTANT_DEFINITION(SemanticsNodeKind, Name)
  39. #include "toolchain/semantics/semantics_node_kind.def"
  40. // We expect the node kind to fit compactly into 8 bits.
  41. static_assert(sizeof(SemanticsNodeKind) == 1, "Kind objects include padding!");
  42. } // namespace Carbon
  43. #endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_NODE_KIND_H_