CIRCT  19.0.0git
ParsingUtils.cpp
Go to the documentation of this file.
1 //===- ParsingUtils.cpp - CIRCT parsing common functions ------------------===//
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 
11 using namespace circt;
12 
14  OpAsmParser &parser,
15  llvm::SmallVector<OpAsmParser::Argument> &inputArguments,
16  llvm::SmallVector<OpAsmParser::UnresolvedOperand> &inputOperands,
17  llvm::SmallVector<Type> &inputTypes, ArrayAttr &inputNames) {
18  llvm::SmallVector<Attribute> names;
19  if (failed(parser.parseCommaSeparatedList(
20  OpAsmParser::Delimiter::Paren, [&]() -> ParseResult {
21  OpAsmParser::UnresolvedOperand inputOperand;
22  Type type;
23  auto &arg = inputArguments.emplace_back();
24  if (parser.parseArgument(arg) || parser.parseColonType(type) ||
25  parser.parseEqual() || parser.parseOperand(inputOperand))
26  return failure();
27 
28  inputOperands.push_back(inputOperand);
29  inputTypes.push_back(type);
30  arg.type = type;
31  names.push_back(StringAttr::get(
32  parser.getContext(),
33  /*drop leading %*/ arg.ssaName.name.drop_front()));
34  return success();
35  })))
36  return failure();
37 
38  inputNames = ArrayAttr::get(parser.getContext(), names);
39  return success();
40 }
41 
42 void circt::parsing_util::printInitializerList(OpAsmPrinter &p, ValueRange ins,
43  ArrayRef<BlockArgument> args) {
44  p << "(";
45  llvm::interleaveComma(llvm::zip(ins, args), p, [&](auto it) {
46  auto [in, arg] = it;
47  p << arg << " : " << in.getType() << " = " << in;
48  });
49  p << ")";
50 }
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
ParseResult parseInitializerList(mlir::OpAsmParser &parser, llvm::SmallVector< mlir::OpAsmParser::Argument > &inputArguments, llvm::SmallVector< mlir::OpAsmParser::UnresolvedOperand > &inputOperands, llvm::SmallVector< Type > &inputTypes, ArrayAttr &inputNames)
Parses an initializer.
void printInitializerList(OpAsmPrinter &p, ValueRange ins, ArrayRef< BlockArgument > args)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21