Files
carbon-lang/toolchain/sem_ir/inst_kind.cpp
T
Jon Ross-Perkins 27d0d26739 Replace value_kind with has_type, make FormatInstLhs name-dependent (#5501)
InstValueKind is really just wrapping HasTypeIdMember. Rather than
exposing this as an enum, expose it as a bool since it better reflects
what's going on.

In eval.cpp, AddImportedConstant should never be called on an untyped
instruction.

In FormatInstLhs, we can also depend on whether InstNamer has assigned a
name in order to decide whether to print an instruction. This should
avoid some divergence with CollectNamesInBlock.

We also discussed restoring InstValueKind::Untyped, but that's mainly
motivated by the formatter, and the InstNamer approach gives a more
localized implementation.
2025-05-19 23:26:32 +00:00

33 lines
1.0 KiB
C++

// 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_kind.h"
#include "toolchain/sem_ir/typed_insts.h"
namespace Carbon::SemIR {
CARBON_DEFINE_ENUM_CLASS_NAMES(InstKind) = {
#define CARBON_SEM_IR_INST_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
#include "toolchain/sem_ir/inst_kind.def"
};
auto InstKind::definition_info(InstKind inst_kind) -> const DefinitionInfo& {
static constexpr InstKind::DefinitionInfo DefinitionInfos[] = {
#define CARBON_SEM_IR_INST_KIND(Name) SemIR::Name::Kind.info_,
#include "toolchain/sem_ir/inst_kind.def"
};
return DefinitionInfos[inst_kind.AsInt()];
}
auto InstKind::has_type() const -> bool {
static constexpr bool Table[] = {
#define CARBON_SEM_IR_INST_KIND(Name) Internal::HasTypeIdMember<SemIR::Name>,
#include "toolchain/sem_ir/inst_kind.def"
};
return Table[AsInt()];
}
} // namespace Carbon::SemIR