1 //===------------ ParserUtils.h - Parse text to SPIR-V ops ----------------===// 2 // 3 // Part of the LLVM 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 // This file defines utilities used for parsing types and ops for SPIR-V 10 // dialect. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef MLIR_DIALECT_SPIRV_PARSERUTILS_H_ 14 #define MLIR_DIALECT_SPIRV_PARSERUTILS_H_ 15 16 #include "mlir/Dialect/SPIRV/SPIRVOps.h" 17 #include "mlir/IR/OpDefinition.h" 18 #include "mlir/IR/OpImplementation.h" 19 20 namespace mlir { 21 /// Parses the next keyword in `parser` as an enumerant of the given 22 /// `EnumClass`. 23 template <typename EnumClass, typename ParserType> 24 static ParseResult 25 parseEnumKeywordAttr(EnumClass &value, ParserType &parser, 26 StringRef attrName = spirv::attributeName<EnumClass>()) { 27 StringRef keyword; 28 SmallVector<NamedAttribute, 1> attr; 29 auto loc = parser.getCurrentLocation(); 30 if (parser.parseKeyword(&keyword)) 31 return failure(); 32 if (Optional<EnumClass> attr = spirv::symbolizeEnum<EnumClass>(keyword)) { 33 value = attr.getValue(); 34 return success(); 35 } 36 return parser.emitError(loc, "invalid ") 37 << attrName << " attribute specification: " << keyword; 38 } 39 } // namespace mlir 40 41 #endif // MLIR_DIALECT_SPIRV_PARSERUTILS_H_ 42