1 //===- Dialect.cpp - Dialect wrapper 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 // Dialect wrapper to simplify using TableGen Record defining a MLIR dialect. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/TableGen/Dialect.h" 14 #include "llvm/TableGen/Record.h" 15 16 namespace mlir { 17 namespace tblgen { 18 19 StringRef tblgen::Dialect::getName() const { 20 return def->getValueAsString("name"); 21 } 22 23 StringRef tblgen::Dialect::getCppNamespace() const { 24 return def->getValueAsString("cppNamespace"); 25 } 26 27 static StringRef getAsStringOrEmpty(const llvm::Record &record, 28 StringRef fieldName) { 29 if (auto valueInit = record.getValueInit(fieldName)) { 30 if (llvm::isa<llvm::CodeInit>(valueInit) || 31 llvm::isa<llvm::StringInit>(valueInit)) 32 return record.getValueAsString(fieldName); 33 } 34 return ""; 35 } 36 37 StringRef tblgen::Dialect::getSummary() const { 38 return getAsStringOrEmpty(*def, "summary"); 39 } 40 41 StringRef tblgen::Dialect::getDescription() const { 42 return getAsStringOrEmpty(*def, "description"); 43 } 44 45 bool Dialect::operator==(const Dialect &other) const { 46 return def == other.def; 47 } 48 49 bool Dialect::operator<(const Dialect &other) const { 50 return getName() < other.getName(); 51 } 52 53 } // end namespace tblgen 54 } // end namespace mlir 55