16#include <mlir/IR/Diagnostics.h>
17#include <mlir/IR/DialectImplementation.h>
18#include <mlir/IR/OpImplementation.h>
20#include <llvm/ADT/StringExtras.h>
21#include <llvm/ADT/TypeSwitch.h>
26#define GET_ATTRDEF_CLASSES
31bool isValidAtomChar(
char ch) {
32 return llvm::isAlnum(ch) || ch ==
'_' || ch ==
'.' || ch ==
'$' || ch ==
'-' || ch ==
'!';
36verifySymbol(function_ref<InFlightDiagnostic()> emitError, StringRef text,
bool keyword) {
38 return emitError() <<
"symbol text must not be empty";
41 if (!text.starts_with(
':')) {
42 return emitError() <<
"keyword must start with ':'";
44 text = text.drop_front();
45 }
else if (text.starts_with(
':')) {
46 return emitError() <<
"symbol must not start with ':'";
49 return emitError() <<
"keyword must contain characters after ':'";
51 for (
char ch : text) {
52 if (!isValidAtomChar(ch)) {
53 return emitError() <<
"invalid SMT-LIB symbol character '" << ch <<
'\'';
61LogicalResult KeywordAttr::verify(function_ref<InFlightDiagnostic()> emitError, StringRef value) {
62 return verifySymbol(emitError, value,
true);
65Attribute KeywordAttr::parse(AsmParser &parser, Type) {
66 SMLoc loc = parser.getCurrentLocation();
68 if (parser.parseLess() || parser.parseColon() || parser.parseKeyword(&value) ||
69 parser.parseGreater()) {
72 return parser.getChecked<KeywordAttr>(loc, parser.getContext(), (
":" + value).str());
75void KeywordAttr::print(AsmPrinter &printer)
const { printer <<
'<' << getValue() <<
'>'; }
77LogicalResult SymbolAttr::verify(function_ref<InFlightDiagnostic()> emitError, StringRef value) {
78 return verifySymbol(emitError, value,
false);
81Attribute SymbolAttr::parse(AsmParser &parser, Type) {
82 SMLoc loc = parser.getCurrentLocation();
84 if (parser.parseLess() || parser.parseKeyword(&value) || parser.parseGreater()) {
87 return parser.getChecked<SymbolAttr>(loc, parser.getContext(), value.str());
90void SymbolAttr::print(AsmPrinter &printer)
const { printer <<
'<' << getValue() <<
'>'; }
93 return KeywordAttr::get(context, value);
97 return SymbolAttr::get(context, value);
101 function_ref<InFlightDiagnostic()> emitError, StringRef value
103 return verifySymbol(emitError, value,
true);
109 #define GET_ATTRDEF_LIST
void registerAttributes()
mlir::Attribute getSymbolAttr(mlir::MLIRContext *context, llvm::StringRef value)
Creates a symbol attribute without exposing generated attribute storage to operation implementation f...
mlir::Attribute getKeywordAttr(mlir::MLIRContext *context, llvm::StringRef value)
Creates a keyword attribute without exposing generated attribute storage to operation implementation ...
mlir::LogicalResult verifyKeyword(llvm::function_ref< mlir::InFlightDiagnostic()> emitError, llvm::StringRef value)
Verifies that value is a valid SMT-LIB keyword and reports failures through emitError.