Use TableGen to define new types

This commit is contained in:
Yan Da
2022-04-08 16:32:46 +08:00
parent 6002340456
commit 13aead4808
6 changed files with 74 additions and 138 deletions

View File

@@ -23,49 +23,3 @@ void TritonDialect::initialize() {
// We can also add interface here.
}
//===----------------------------------------------------------------------===//
// Type Parsing
//===----------------------------------------------------------------------===//
// pointer-type ::= `!triton.ptr<` element-type ` >`
static Type parsePointerType(TritonDialect const &dialect,
DialectAsmParser &parser) {
if (parser.parseLess())
return Type();
Type pointeeType;
if (parser.parseType(pointeeType))
return Type();
if (parser.parseGreater())
return Type();
return PointerType::get(pointeeType);
}
// trtion-type ::= pointer-type
Type TritonDialect::parseType(DialectAsmParser &parser) const {
StringRef keyword;
if (parser.parseKeyword(&keyword))
return Type();
if (keyword == "ptr")
return parsePointerType(*this, parser);
parser.emitError(parser.getNameLoc(), "unknown Triton type: ") << keyword;
return Type();
}
//===----------------------------------------------------------------------===//
// Type Printing
//===----------------------------------------------------------------------===//
static void print(PointerType type, DialectAsmPrinter &os) {
os << "ptr<" << type.getPointeeType() << ">";
}
void TritonDialect::printType(Type type, DialectAsmPrinter &os) const {
TypeSwitch<Type>(type)
.Case<PointerType>( [&](auto type) { print(type, os); })
.Default([](Type) { llvm_unreachable("unhandled Triton type"); });
}