CIRCT  20.0.0git
ParsingUtils.h
Go to the documentation of this file.
1 //===- ParsingUtils.h - CIRCT parsing common functions ----------*- C++ -*-===//
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 // Utilities to help with parsing.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_SUPPORT_PARSINGUTILS_H
14 #define CIRCT_SUPPORT_PARSINGUTILS_H
15 
16 #include "circt/Support/LLVM.h"
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "mlir/IR/OpImplementation.h"
19 
20 namespace circt {
21 namespace parsing_util {
22 
23 /// Get a name from an SSA value string, if said value name is not a
24 /// number.
25 static inline StringAttr getNameFromSSA(MLIRContext *context, StringRef name) {
26  if (!name.empty()) {
27  // Ignore numeric names like %42
28  assert(name.size() > 1 && name[0] == '%' && "Unknown MLIR name");
29  if (isdigit(name[1]))
30  name = StringRef();
31  else
32  name = name.drop_front();
33  }
34  return StringAttr::get(context, name);
35 }
36 
37 //===----------------------------------------------------------------------===//
38 // Initializer lists
39 //===----------------------------------------------------------------------===//
40 
41 /// Parses an initializer.
42 /// An initializer list is a list of operands, types and names on the format:
43 /// (%arg = %input : type, ...)
45  mlir::OpAsmParser &parser,
46  llvm::SmallVector<mlir::OpAsmParser::Argument> &inputArguments,
47  llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand> &inputOperands,
48  llvm::SmallVector<Type> &inputTypes, ArrayAttr &inputNames);
49 
50 // Prints an initializer list.
51 void printInitializerList(OpAsmPrinter &p, ValueRange ins,
52  ArrayRef<BlockArgument> args);
53 
54 } // namespace parsing_util
55 } // namespace circt
56 
57 #endif // CIRCT_SUPPORT_PARSINGUTILS_H
assert(baseType &&"element must be base type")
#define isdigit(x)
Definition: FIRLexer.cpp:26
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
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)
static StringAttr getNameFromSSA(MLIRContext *context, StringRef name)
Get a name from an SSA value string, if said value name is not a number.
Definition: ParsingUtils.h:25
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21