inst_kind.cpp 1.9 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. #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. static constexpr const llvm::StringLiteral Table[] = {
  13. #define CARBON_SEM_IR_INST_KIND(Name) SemIR::Name::Kind.ir_name(),
  14. #include "toolchain/sem_ir/inst_kind.def"
  15. };
  16. return Table[AsInt()];
  17. }
  18. auto InstKind::value_kind() const -> InstValueKind {
  19. static constexpr InstValueKind Table[] = {
  20. #define CARBON_SEM_IR_INST_KIND(Name) \
  21. Internal::HasTypeIdMember<SemIR::Name> ? InstValueKind::Typed \
  22. : InstValueKind::None,
  23. #include "toolchain/sem_ir/inst_kind.def"
  24. };
  25. return Table[AsInt()];
  26. }
  27. auto InstKind::constant_kind() const -> InstConstantKind {
  28. static constexpr InstConstantKind Table[] = {
  29. #define CARBON_SEM_IR_INST_KIND_CONSTANT_NEVER(...) InstConstantKind::Never,
  30. #define CARBON_SEM_IR_INST_KIND_CONSTANT_SYMBOLIC_ONLY(...) \
  31. InstConstantKind::SymbolicOnly,
  32. #define CARBON_SEM_IR_INST_KIND_CONSTANT_CONDITIONAL(...) \
  33. InstConstantKind::Conditional,
  34. #define CARBON_SEM_IR_INST_KIND_CONSTANT_ALWAYS(...) InstConstantKind::Always,
  35. #define CARBON_SEM_IR_INST_KIND(Name)
  36. #include "toolchain/sem_ir/inst_kind.def"
  37. };
  38. return Table[AsInt()];
  39. }
  40. auto InstKind::terminator_kind() const -> TerminatorKind {
  41. static constexpr const TerminatorKind Table[] = {
  42. #define CARBON_SEM_IR_INST_KIND(Name) SemIR::Name::Kind.terminator_kind(),
  43. #include "toolchain/sem_ir/inst_kind.def"
  44. };
  45. return Table[AsInt()];
  46. }
  47. } // namespace Carbon::SemIR