Use TableGen to define new types
This commit is contained in:
@@ -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"); });
|
||||
}
|
||||
|
Reference in New Issue
Block a user