1 //===- Type.cpp - Type class ----------------------------------------------===// 2 // 3 // Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Type wrapper to simplify using TableGen Record defining a MLIR Type. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/TableGen/Type.h" 14 #include "llvm/TableGen/Record.h" 15 16 using namespace mlir; 17 using namespace mlir::tblgen; 18 19 TypeConstraint::TypeConstraint(const llvm::Record *record) 20 : Constraint(Constraint::CK_Type, record) { 21 assert(def->isSubClassOf("TypeConstraint") && 22 "must be subclass of TableGen 'TypeConstraint' class"); 23 } 24 25 TypeConstraint::TypeConstraint(const llvm::DefInit *init) 26 : TypeConstraint(init->getDef()) {} 27 28 bool TypeConstraint::isVariadic() const { 29 return def->isSubClassOf("Variadic"); 30 } 31 32 Type::Type(const llvm::Record *record) : TypeConstraint(record) {} 33 34 StringRef Type::getTypeDescription() const { 35 return def->getValueAsString("typeDescription"); 36 } 37 38 Dialect Type::getDialect() const { 39 return Dialect(def->getValueAsDef("dialect")); 40 } 41