inst_kind.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "toolchain/sem_ir/inst_kind.h"
  5. #include "toolchain/sem_ir/typed_insts.h"
  6. namespace Carbon::SemIR {
  7. CARBON_DEFINE_ENUM_CLASS_NAMES(InstKind) {
  8. #define CARBON_SEM_IR_INST_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
  9. #include "toolchain/sem_ir/inst_kind.def"
  10. };
  11. auto InstKind::definition_info(InstKind inst_kind) -> const DefinitionInfo& {
  12. static constexpr InstKind::DefinitionInfo DefinitionInfos[] = {
  13. #define CARBON_SEM_IR_INST_KIND(Name) SemIR::Name::Kind.info_,
  14. #include "toolchain/sem_ir/inst_kind.def"
  15. };
  16. return DefinitionInfos[inst_kind.AsInt()];
  17. }
  18. auto InstKind::has_type() const -> bool {
  19. static constexpr bool Table[] = {
  20. #define CARBON_SEM_IR_INST_KIND(Name) Internal::HasTypeIdMember<SemIR::Name>,
  21. #include "toolchain/sem_ir/inst_kind.def"
  22. };
  23. return Table[AsInt()];
  24. }
  25. auto InstKind::IsAllowedNodeKind(Parse::NodeKind node_kind) const -> bool {
  26. const auto& def = definition_info(*this);
  27. if (def.internal_allow_all_node_kinds) {
  28. return true;
  29. }
  30. return llvm::is_contained(def.internal_allowed_node_kinds, node_kind);
  31. }
  32. } // namespace Carbon::SemIR