inst_kind.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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::ir_name() const -> llvm::StringLiteral {
  12. return definition().ir_name();
  13. }
  14. auto InstKind::value_kind() const -> InstValueKind {
  15. static constexpr InstValueKind Table[] = {
  16. #define CARBON_SEM_IR_INST_KIND(Name) \
  17. HasTypeId<SemIR::Name> ? InstValueKind::Typed : InstValueKind::None,
  18. #include "toolchain/sem_ir/inst_kind.def"
  19. };
  20. return Table[AsInt()];
  21. }
  22. auto InstKind::terminator_kind() const -> TerminatorKind {
  23. return definition().terminator_kind();
  24. }
  25. auto InstKind::definition() const -> const Definition& {
  26. static constexpr const Definition* Table[] = {
  27. #define CARBON_SEM_IR_INST_KIND(Name) &SemIR::Name::Kind,
  28. #include "toolchain/sem_ir/inst_kind.def"
  29. };
  30. return *Table[AsInt()];
  31. }
  32. } // namespace Carbon::SemIR