CIRCT 24.0.0git
Loading...
Searching...
No Matches
FieldInfo.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
10#include "mlir/IR/OpImplementation.h"
11#include "llvm/ADT/DenseSet.h"
12
13using namespace circt;
14
16 AsmParser &p, SmallVectorImpl<FieldInfo> &fields,
17 SmallVectorImpl<std::pair<llvm::SMLoc, StringAttr>> &duplicates) {
18 llvm::SmallDenseSet<StringAttr> nameSet;
19 return p.parseCommaSeparatedList(
20 mlir::AsmParser::Delimiter::LessGreater, [&]() -> ParseResult {
21 std::string name;
22 Type type;
23
24 auto fieldLoc = p.getCurrentLocation();
25 if (p.parseKeywordOrString(&name) || p.parseColon() ||
26 p.parseType(type))
27 return failure();
28
29 auto nameAttr = StringAttr::get(p.getContext(), name);
30 if (!nameSet.insert(nameAttr).second)
31 duplicates.push_back({fieldLoc, nameAttr});
32
33 fields.push_back(FieldInfo{nameAttr, type});
34 return success();
35 });
36}
37
38void circt::printFieldList(AsmPrinter &p, ArrayRef<FieldInfo> fields) {
39 p << '<';
40 llvm::interleaveComma(fields, p, [&](const FieldInfo &field) {
41 p.printKeywordOrString(field.name.getValue());
42 p << ": " << field.type;
43 });
44 p << ">";
45}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ParseResult parseFieldList(AsmParser &p, SmallVectorImpl< FieldInfo > &fields, SmallVectorImpl< std::pair< llvm::SMLoc, StringAttr > > &duplicates)
Parse a list of named fields within <>, e.g.
Definition FieldInfo.cpp:15
void printFieldList(AsmPrinter &p, ArrayRef< FieldInfo > fields)
Print a list of fields within <>, e.g. <foo: i7, bar: i8>.
Definition FieldInfo.cpp:38
A named and typed field of an aggregate type.
Definition FieldInfo.h:27
mlir::Type type
Definition FieldInfo.h:29
mlir::StringAttr name
Definition FieldInfo.h:28