inst.cpp 990 B

1234567891011121314151617181920212223242526272829303132333435
  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.h"
  5. namespace Carbon::SemIR {
  6. auto Inst::Print(llvm::raw_ostream& out) const -> void {
  7. out << "{kind: " << kind_;
  8. auto print_args = [&](auto info) {
  9. using Info = decltype(info);
  10. if constexpr (Info::NumArgs > 0) {
  11. out << ", arg0: " << FromRaw<typename Info::template ArgType<0>>(arg0_);
  12. }
  13. if constexpr (Info::NumArgs > 1) {
  14. out << ", arg1: " << FromRaw<typename Info::template ArgType<1>>(arg1_);
  15. }
  16. };
  17. switch (kind_) {
  18. #define CARBON_SEM_IR_INST_KIND(Name) \
  19. case Name::Kind: \
  20. print_args(InstLikeTypeInfo<Name>()); \
  21. break;
  22. #include "toolchain/sem_ir/inst_kind.def"
  23. }
  24. if (type_id_.is_valid()) {
  25. out << ", type: " << type_id_;
  26. }
  27. out << "}";
  28. }
  29. } // namespace Carbon::SemIR