Created
August 18, 2023 22:57
-
-
Save j2kun/cca9d6302c78f80b2a0a9ec7507fdef8 to your computer and use it in GitHub Desktop.
PolyTypes generated files after adding a type parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |
|* *| | |
|* TypeDef Definitions *| | |
|* *| | |
|* Automatically generated file, do not edit! *| | |
|* *| | |
\*===----------------------------------------------------------------------===*/ | |
#ifdef GET_TYPEDEF_LIST | |
#undef GET_TYPEDEF_LIST | |
::mlir::tutorial::poly::PolynomialType | |
#endif // GET_TYPEDEF_LIST | |
#ifdef GET_TYPEDEF_CLASSES | |
#undef GET_TYPEDEF_CLASSES | |
static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) { | |
return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser) | |
.Case(::mlir::tutorial::poly::PolynomialType::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) { | |
value = ::mlir::tutorial::poly::PolynomialType::parse(parser); | |
return ::mlir::success(!!value); | |
}) | |
.Default([&](llvm::StringRef keyword, llvm::SMLoc) { | |
*mnemonic = keyword; | |
return std::nullopt; | |
}); | |
} | |
static ::mlir::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) { | |
return ::llvm::TypeSwitch<::mlir::Type, ::mlir::LogicalResult>(def) .Case<::mlir::tutorial::poly::PolynomialType>([&](auto t) { | |
printer << ::mlir::tutorial::poly::PolynomialType::getMnemonic(); | |
t.print(printer); | |
return ::mlir::success(); | |
}) | |
.Default([](auto) { return ::mlir::failure(); }); | |
} | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
namespace detail { | |
struct PolynomialTypeStorage : public ::mlir::TypeStorage { | |
using KeyTy = std::tuple<int>; | |
PolynomialTypeStorage(int degreeBound) : degreeBound(degreeBound) {} | |
KeyTy getAsKey() const { | |
return KeyTy(degreeBound); | |
} | |
bool operator==(const KeyTy &tblgenKey) const { | |
return (degreeBound == std::get<0>(tblgenKey)); | |
} | |
static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) { | |
return ::llvm::hash_combine(std::get<0>(tblgenKey)); | |
} | |
static PolynomialTypeStorage *construct(::mlir::TypeStorageAllocator &allocator, const KeyTy &tblgenKey) { | |
auto degreeBound = std::get<0>(tblgenKey); | |
return new (allocator.allocate<PolynomialTypeStorage>()) PolynomialTypeStorage(degreeBound); | |
} | |
int degreeBound; | |
}; | |
} // namespace detail | |
PolynomialType PolynomialType::get(::mlir::MLIRContext *context, int degreeBound) { | |
return Base::get(context, degreeBound); | |
} | |
::mlir::Type PolynomialType::parse(::mlir::AsmParser &odsParser) { | |
::mlir::Builder odsBuilder(odsParser.getContext()); | |
::llvm::SMLoc odsLoc = odsParser.getCurrentLocation(); | |
(void) odsLoc; | |
::mlir::FailureOr<int> _result_degreeBound; | |
// Parse literal '<' | |
if (odsParser.parseLess()) return {}; | |
// Parse variable 'degreeBound' | |
_result_degreeBound = ::mlir::FieldParser<int>::parse(odsParser); | |
if (::mlir::failed(_result_degreeBound)) { | |
odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Poly parameter 'degreeBound' which is to be a `int`"); | |
return {}; | |
} | |
// Parse literal '>' | |
if (odsParser.parseGreater()) return {}; | |
assert(::mlir::succeeded(_result_degreeBound)); | |
return PolynomialType::get(odsParser.getContext(), | |
int((*_result_degreeBound))); | |
} | |
void PolynomialType::print(::mlir::AsmPrinter &odsPrinter) const { | |
::mlir::Builder odsBuilder(getContext()); | |
odsPrinter << "<"; | |
odsPrinter.printStrippedAttrOrType(getDegreeBound()); | |
odsPrinter << ">"; | |
} | |
int PolynomialType::getDegreeBound() const { | |
return getImpl()->degreeBound; | |
} | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tutorial::poly::PolynomialType) | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
/// Parse a type registered to this dialect. | |
::mlir::Type PolyDialect::parseType(::mlir::DialectAsmParser &parser) const { | |
::llvm::SMLoc typeLoc = parser.getCurrentLocation(); | |
::llvm::StringRef mnemonic; | |
::mlir::Type genType; | |
auto parseResult = generatedTypeParser(parser, &mnemonic, genType); | |
if (parseResult.has_value()) | |
return genType; | |
parser.emitError(typeLoc) << "unknown type `" | |
<< mnemonic << "` in dialect `" << getNamespace() << "`"; | |
return {}; | |
} | |
/// Print a type registered to this dialect. | |
void PolyDialect::printType(::mlir::Type type, | |
::mlir::DialectAsmPrinter &printer) const { | |
if (::mlir::succeeded(generatedTypePrinter(type, printer))) | |
return; | |
} | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
#endif // GET_TYPEDEF_CLASSES | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ | |
|* *| | |
|* TypeDef Declarations *| | |
|* *| | |
|* Automatically generated file, do not edit! *| | |
|* *| | |
\*===----------------------------------------------------------------------===*/ | |
#ifdef GET_TYPEDEF_CLASSES | |
#undef GET_TYPEDEF_CLASSES | |
namespace mlir { | |
class AsmParser; | |
class AsmPrinter; | |
} // namespace mlir | |
namespace mlir { | |
namespace tutorial { | |
namespace poly { | |
class PolynomialType; | |
namespace detail { | |
struct PolynomialTypeStorage; | |
} // namespace detail | |
class PolynomialType : public ::mlir::Type::TypeBase<PolynomialType, ::mlir::Type, detail::PolynomialTypeStorage> { | |
public: | |
using Base::Base; | |
static PolynomialType get(::mlir::MLIRContext *context, int degreeBound); | |
static constexpr ::llvm::StringLiteral getMnemonic() { | |
return {"poly"}; | |
} | |
static ::mlir::Type parse(::mlir::AsmParser &odsParser); | |
void print(::mlir::AsmPrinter &odsPrinter) const; | |
int getDegreeBound() const; | |
}; | |
} // namespace poly | |
} // namespace tutorial | |
} // namespace mlir | |
MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::tutorial::poly::PolynomialType) | |
#endif // GET_TYPEDEF_CLASSES | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment