1//===- SPIRVParsingUtilities.cpp - MLIR SPIR-V Dialect Parsing Utils-------===//
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// Implements common SPIR-V dialect parsing functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVParsingUtils.h"
14
15#include "llvm/ADT/StringExtras.h"
16
17using namespace mlir::spirv::AttrNames;
18
19namespace mlir::spirv {
20
21ParseResult parseVariableDecorations(OpAsmParser &parser,
22 OperationState &state) {
23 auto builtInName = llvm::convertToSnakeFromCamelCase(
24 stringifyDecoration(spirv::Decoration::BuiltIn));
25 if (succeeded(result: parser.parseOptionalKeyword(keyword: "bind"))) {
26 Attribute set, binding;
27 // Parse optional descriptor binding
28 auto descriptorSetName = llvm::convertToSnakeFromCamelCase(
29 stringifyDecoration(spirv::Decoration::DescriptorSet));
30 auto bindingName = llvm::convertToSnakeFromCamelCase(
31 stringifyDecoration(spirv::Decoration::Binding));
32 Type i32Type = parser.getBuilder().getIntegerType(32);
33 if (parser.parseLParen() ||
34 parser.parseAttribute(set, i32Type, descriptorSetName,
35 state.attributes) ||
36 parser.parseComma() ||
37 parser.parseAttribute(binding, i32Type, bindingName,
38 state.attributes) ||
39 parser.parseRParen()) {
40 return failure();
41 }
42 } else if (succeeded(parser.parseOptionalKeyword(builtInName))) {
43 StringAttr builtIn;
44 if (parser.parseLParen() ||
45 parser.parseAttribute(builtIn, builtInName, state.attributes) ||
46 parser.parseRParen()) {
47 return failure();
48 }
49 }
50
51 // Parse other attributes
52 if (parser.parseOptionalAttrDict(result&: state.attributes))
53 return failure();
54
55 return success();
56}
57
58} // namespace mlir::spirv
59

source code of mlir/lib/Dialect/SPIRV/IR/SPIRVParsingUtils.cpp