diff --git a/include/circt/Dialect/Moore/MooreTypes.h b/include/circt/Dialect/Moore/MooreTypes.h index 979e12c5c8..582b9bef57 100644 --- a/include/circt/Dialect/Moore/MooreTypes.h +++ b/include/circt/Dialect/Moore/MooreTypes.h @@ -241,7 +241,6 @@ struct UnsizedDimStorage; struct RangeDimStorage; struct SizedDimStorage; struct AssocDimStorage; -struct EnumTypeStorage; struct StructTypeStorage; } // namespace detail @@ -396,7 +395,6 @@ class VoidType; class IntType; class PackedIndirectType; class PackedDim; -class EnumType; class PackedStructType; /// A packed SystemVerilog type. @@ -425,7 +423,7 @@ public: static bool classof(Type type) { return llvm::isa(type) || llvm::isa(type) || llvm::isa(type) || llvm::isa(type) || - llvm::isa(type) || llvm::isa(type); + llvm::isa(type); } /// Resolve one level of name or type reference indirection. @@ -994,39 +992,6 @@ protected: friend struct detail::DimStorage; }; -//===----------------------------------------------------------------------===// -// Enumerations -//===----------------------------------------------------------------------===// - -/// An enum type. -class EnumType - : public Type::TypeBase { -public: - static EnumType get(StringAttr name, Location loc, PackedType base = {}); - - /// Get the base type of the enumeration. - PackedType getBase() const; - /// Returns whether the base type was explicitly specified by the user. This - /// allows us to distinguish `enum` from `enum int`. - bool isBaseExplicit() const; - /// Get the name of the surrounding typedef, if this enum is embedded in a - /// typedef. Otherwise this returns a null attribute. - StringAttr getName() const; - /// Get the location in the source text where the enum was declared. This - /// shall be the location of the `enum` keyword or, if the enum is embedded in - /// a typedef, the location of the typedef name. - Location getLoc() const; - - /// Format this enum in SystemVerilog syntax. Useful to present the enum back - /// to the user in diagnostics. - void format(llvm::raw_ostream &os) const; - - static constexpr StringLiteral name = "moore.enum"; - -protected: - using Base::Base; -}; - //===----------------------------------------------------------------------===// // Packed and Unpacked Structs //===----------------------------------------------------------------------===// diff --git a/lib/Conversion/ImportVerilog/Types.cpp b/lib/Conversion/ImportVerilog/Types.cpp index 48194fd400..ec8419795c 100644 --- a/lib/Conversion/ImportVerilog/Types.cpp +++ b/lib/Conversion/ImportVerilog/Types.cpp @@ -148,11 +148,8 @@ struct TypeVisitor { // Handle enums. Type visit(const slang::ast::EnumType &type) { - auto baseType = type.baseType.visit(*this); - if (!baseType) - return {}; - return moore::EnumType::get(StringAttr{}, loc, - cast(baseType)); + // Simply return the underlying type. + return type.baseType.visit(*this); } // Collect the members in a struct or union. diff --git a/lib/Dialect/Moore/MooreTypes.cpp b/lib/Dialect/Moore/MooreTypes.cpp index 239824eaaa..c79ac01675 100644 --- a/lib/Dialect/Moore/MooreTypes.cpp +++ b/lib/Dialect/Moore/MooreTypes.cpp @@ -37,7 +37,7 @@ void MooreDialect::registerTypes() { addTypes(); addTypes< @@ -260,7 +260,6 @@ Domain PackedType::getDomain() const { .Case([&](auto type) { return type.getDomain(); }) .Case( [&](auto type) { return type.getInner().getDomain(); }) - .Case([](auto type) { return type.getBase().getDomain(); }) .Case( [](auto type) { return type.getStruct().domain; }); } @@ -271,8 +270,7 @@ Sign PackedType::getSign() const { .Case( [&](auto type) { return type.getSign(); }) .Case( - [&](auto type) { return type.getInner().getSign(); }) - .Case([](auto type) { return type.getBase().getSign(); }); + [&](auto type) { return type.getInner().getSign(); }); } std::optional PackedType::getBitSize() const { @@ -287,7 +285,6 @@ std::optional PackedType::getBitSize() const { }) .Case( [](auto type) { return type.getInner().getBitSize(); }) - .Case([](auto type) { return type.getBase().getBitSize(); }) .Case( [](auto type) { return type.getStruct().bitSize; }); } @@ -295,8 +292,8 @@ std::optional PackedType::getBitSize() const { void PackedType::format(llvm::raw_ostream &os) const { TypeSwitch(*this) .Case([&](auto) { os << "void"; }) - .Case([&](auto type) { type.format(os); }) + .Case( + [&](auto type) { type.format(os); }) .Case( [&](auto type) { os << type.getName().getValue(); }) .Case( @@ -938,66 +935,6 @@ std::optional UnpackedQueueDim::getBound() const { return bound; } -//===----------------------------------------------------------------------===// -// Enumerations -//===----------------------------------------------------------------------===// - -namespace circt { -namespace moore { -namespace detail { - -struct EnumTypeStorage : TypeStorage { - using KeyTy = std::tuple; - - EnumTypeStorage(KeyTy key) - : name(std::get<0>(key)), loc(std::get<1>(key)), base(std::get<2>(key)), - explicitBase(std::get<3>(key)) {} - bool operator==(const KeyTy &key) const { - return std::get<0>(key) == name && std::get<1>(key) == loc && - std::get<2>(key) == base && std::get<3>(key) == explicitBase; - } - static EnumTypeStorage *construct(TypeStorageAllocator &allocator, - const KeyTy &key) { - return new (allocator.allocate()) EnumTypeStorage(key); - } - - StringAttr name; - Location loc; - PackedType base; - bool explicitBase; -}; - -} // namespace detail -} // namespace moore -} // namespace circt - -EnumType EnumType::get(StringAttr name, Location loc, PackedType base) { - return Base::get(loc.getContext(), name, loc, - base ? base : IntType::getInt(loc.getContext()), !!base); -} - -PackedType EnumType::getBase() const { return getImpl()->base; } - -bool EnumType::isBaseExplicit() const { return getImpl()->explicitBase; } - -StringAttr EnumType::getName() const { return getImpl()->name; } - -Location EnumType::getLoc() const { return getImpl()->loc; } - -void EnumType::format(llvm::raw_ostream &os) const { - os << "enum"; - - // If the enum is part of a typedefm simply print it as `enum `. - if (auto name = getName()) { - os << " " << name.getValue(); - return; - } - - // Otherwise print `enum ` or just `enum`. - if (isBaseExplicit()) - os << " " << getBase(); -} - //===----------------------------------------------------------------------===// // Packed and Unpacked Structs //===----------------------------------------------------------------------===// @@ -1227,31 +1164,6 @@ static OptionalParseResult customTypeParser(DialectAsmParser &parser, if (auto kind = RealType::getKindFromKeyword(mnemonic)) return yieldUnpacked(RealType::get(context, *kind)); - // Enums - if (mnemonic == "enum") { - if (parser.parseLess()) - return failure(); - StringAttr name; - auto result = parser.parseOptionalAttribute(name); - if (result.has_value()) - if (*result || parser.parseComma()) - return failure(); - LocationAttr loc; - PackedType base; - result = parser.parseOptionalAttribute(loc); - if (result.has_value()) { - if (*result) - return failure(); - } else { - if (parseMooreType(parser, {Subset::Packed, false}, base) || - parser.parseComma() || parser.parseAttribute(loc)) - return failure(); - } - if (parser.parseGreater()) - return failure(); - return yieldPacked(EnumType::get(name, loc, base)); - } - // Everything that follows can be packed or unpacked. The packing is inferred // from the last `packed<...>` or `unpacked<...>` that we've seen. The // `yieldImplied` function will call the first lambda to construct a packed @@ -1441,19 +1353,6 @@ static LogicalResult customTypePrinter(Type type, DialectAsmPrinter &printer, .Case( [&](auto type) { return printer << type.getKeyword(), success(); }) - // Enums - .Case([&](auto type) { - printer << "enum<"; - if (type.getName()) - printer << type.getName() << ", "; - if (type.isBaseExplicit()) { - printMooreType(type.getBase(), printer, subset); - printer << ", "; - } - printer << type.getLoc() << ">"; - return success(); - }) - // Type indirections .Case([&](auto type) { printer << "named<" << type.getName() << ", "; diff --git a/test/Conversion/ImportVerilog/types.sv b/test/Conversion/ImportVerilog/types.sv index 35a004647b..b4ad27376d 100644 --- a/test/Conversion/ImportVerilog/types.sv +++ b/test/Conversion/ImportVerilog/types.sv @@ -8,9 +8,9 @@ module Enums; typedef enum shortint { MAGIC } myEnum; - // CHECK-NEXT: %e0 = moore.variable : !moore.enum - // CHECK-SAME: %arg1: !moore.enum - // CHECK-SAME: %arg2: !moore.enum<"Foo", loc("foo.sv":42:9001)> - // CHECK-SAME: %arg3: !moore.enum<"Foo", int, loc("foo.sv":42:9001)> - %arg0: !moore.enum, - %arg1: !moore.enum, - %arg2: !moore.enum<"Foo", loc("foo.sv":42:9001)>, - %arg3: !moore.enum<"Foo", int, loc("foo.sv":42:9001)> -) { return } - // CHECK-LABEL: func @IndirectTypes( func.func @IndirectTypes( // CHECK-SAME: %arg0: !moore.packed> diff --git a/unittests/Dialect/Moore/TypesTest.cpp b/unittests/Dialect/Moore/TypesTest.cpp index c76db2d4b1..56203e0601 100644 --- a/unittests/Dialect/Moore/TypesTest.cpp +++ b/unittests/Dialect/Moore/TypesTest.cpp @@ -340,65 +340,6 @@ TEST(TypesTest, Structs) { ASSERT_EQ(s3.getBitSize(), std::nullopt); } -TEST(TypesTest, Enums) { - MLIRContext context; - context.loadDialect(); - auto loc = UnknownLoc::get(&context); - auto foo = StringAttr::get(&context, "Foo"); - auto intType = IntType::getInt(&context); - auto bitType = IntType::get(&context, IntType::Bit); - auto bit8Type = PackedRangeDim::get(bitType, 8); - auto slogicType = IntType::get(&context, IntType::Logic, Sign::Signed); - auto slogic8Type = PackedRangeDim::get(slogicType, 8); - - auto e0 = EnumType::get({}, loc); - auto e1 = EnumType::get(foo, loc); - auto e2 = EnumType::get({}, loc, bit8Type); - auto e3 = EnumType::get(foo, loc, bit8Type); - auto e4 = EnumType::get({}, loc, slogic8Type); - auto e5 = EnumType::get(foo, loc, slogic8Type); - - // Formatting - ASSERT_EQ(e0.toString(), "enum"); - ASSERT_EQ(e1.toString(), "enum Foo"); - ASSERT_EQ(e2.toString(), "enum bit [7:0]"); - ASSERT_EQ(e3.toString(), "enum Foo"); - ASSERT_EQ(e4.toString(), "enum logic signed [7:0]"); - ASSERT_EQ(e5.toString(), "enum Foo"); - - // Base types - ASSERT_EQ(e0.getBase(), intType); - ASSERT_EQ(e1.getBase(), intType); - ASSERT_EQ(e2.getBase(), bit8Type); - ASSERT_EQ(e3.getBase(), bit8Type); - ASSERT_EQ(e4.getBase(), slogic8Type); - ASSERT_EQ(e5.getBase(), slogic8Type); - - // Sign - ASSERT_EQ(e0.getSign(), Sign::Signed); // implicit int - ASSERT_EQ(e1.getSign(), Sign::Signed); // implicit int - ASSERT_EQ(e2.getSign(), Sign::Unsigned); - ASSERT_EQ(e3.getSign(), Sign::Unsigned); - ASSERT_EQ(e4.getSign(), Sign::Signed); - ASSERT_EQ(e5.getSign(), Sign::Signed); - - // Value domain - ASSERT_EQ(e0.getDomain(), Domain::TwoValued); - ASSERT_EQ(e1.getDomain(), Domain::TwoValued); - ASSERT_EQ(e2.getDomain(), Domain::TwoValued); - ASSERT_EQ(e3.getDomain(), Domain::TwoValued); - ASSERT_EQ(e4.getDomain(), Domain::FourValued); - ASSERT_EQ(e5.getDomain(), Domain::FourValued); - - // Bit size - ASSERT_EQ(e0.getBitSize(), 32u); - ASSERT_EQ(e1.getBitSize(), 32u); - ASSERT_EQ(e2.getBitSize(), 8u); - ASSERT_EQ(e3.getBitSize(), 8u); - ASSERT_EQ(e4.getBitSize(), 8u); - ASSERT_EQ(e5.getBitSize(), 8u); -} - TEST(TypesTest, SimpleBitVectorTypes) { MLIRContext context; context.loadDialect();