[llvm] [LLVM][TableGen][DecoderEmitter] Add wrapper class for `bit_value_t` (PR #146248)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 13:52:45 PDT 2025
================
@@ -252,84 +246,97 @@ class DecoderEmitter {
StringRef PredicateNamespace;
};
-} // end anonymous namespace
-
// The set (BIT_TRUE, BIT_FALSE, BIT_UNSET) represents a ternary logic system
// for a bit value.
//
// BIT_UNFILTERED is used as the init value for a filter position. It is used
// only for filter processings.
-typedef enum : uint8_t {
- BIT_FALSE, // '0'
- BIT_TRUE, // '1'
- BIT_UNSET, // '?'
- BIT_UNFILTERED // unfiltered
-} bit_value_t;
-
-static bool ValueSet(bit_value_t V) {
- return (V == BIT_TRUE || V == BIT_FALSE);
-}
-
-static bool ValueNotSet(bit_value_t V) { return (V == BIT_UNSET); }
-
-static int Value(bit_value_t V) {
- return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1);
-}
+struct BitValue {
+ enum bit_value_t : uint8_t {
+ BIT_FALSE, // '0'
+ BIT_TRUE, // '1'
+ BIT_UNSET, // '?', printed as '_'
+ BIT_UNFILTERED // unfiltered, printed as '.'
+ };
-static bit_value_t bitFromBits(const BitsInit &bits, unsigned index) {
- if (const BitInit *bit = dyn_cast<BitInit>(bits.getBit(index)))
- return bit->getValue() ? BIT_TRUE : BIT_FALSE;
+ BitValue(bit_value_t V) : V(V) {}
+ explicit BitValue(const Init *Init) {
+ if (const auto *Bit = dyn_cast<BitInit>(Init))
+ V = Bit->getValue() ? BIT_TRUE : BIT_FALSE;
+ else
+ V = BIT_UNSET;
+ }
+ BitValue(const BitsInit &Bits, unsigned Idx) : BitValue(Bits.getBit(Idx)) {}
- // The bit is uninitialized.
- return BIT_UNSET;
-}
+ bool isSet() const { return V == BIT_TRUE || V == BIT_FALSE; }
+ bool isUnset() const { return V == BIT_UNSET; }
+ std::optional<uint64_t> getValue() const {
+ if (isSet())
+ return static_cast<uint64_t>(V);
+ return std::nullopt;
+ }
+ bit_value_t getRawValue() const { return V; }
----------------
topperc wrote:
Remove getRawValue
https://github.com/llvm/llvm-project/pull/146248
More information about the llvm-commits
mailing list