// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "toolchain/sem_ir/inst.h" namespace Carbon::SemIR { auto Inst::Print(llvm::raw_ostream& out) const -> void { out << "{kind: " << kind(); auto print_args = [&](auto info) { using Info = decltype(info); if constexpr (Info::NumArgs > 0) { out << ", arg0: " << FromRaw>(arg0_); } if constexpr (Info::NumArgs > 1) { out << ", arg1: " << FromRaw>(arg1_); } }; switch (kind()) { #define CARBON_SEM_IR_INST_KIND(Name) \ case Name::Kind: \ print_args(Internal::InstLikeTypeInfo()); \ break; #include "toolchain/sem_ir/inst_kind.def" } if (type_id_.has_value()) { out << ", type: " << type_id_; } out << "}"; } // Returns the IdKind of an instruction's argument, or None if there is no // argument with that index. template static constexpr auto IdKindFor() -> IdKind { using Info = Internal::InstLikeTypeInfo; if constexpr (ArgIndex < Info::NumArgs) { return IdKind::For>; } else { return IdKind::None; } } const std::pair Inst::ArgKindTable[] = { #define CARBON_SEM_IR_INST_KIND(Name) \ {IdKindFor(), IdKindFor()}, #include "toolchain/sem_ir/inst_kind.def" }; } // namespace Carbon::SemIR