My Project
GenInfo.h
Go to the documentation of this file.
1 //===- GenInfo.h - Generator info -------------------------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 #ifndef MLIR_TABLEGEN_GENINFO_H_
10 #define MLIR_TABLEGEN_GENINFO_H_
11 
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 #include <functional>
15 
16 namespace llvm {
17 class RecordKeeper;
18 } // end namespace llvm
19 
20 namespace mlir {
21 
23 using GenFunction = std::function<bool(const llvm::RecordKeeper &recordKeeper,
24  raw_ostream &os)>;
25 
28 class GenInfo {
29 public:
32  GenInfo(StringRef arg, StringRef description, GenFunction generator)
33  : arg(arg), description(description), generator(generator) {}
34 
36  bool invoke(const llvm::RecordKeeper &recordKeeper, raw_ostream &os) const {
37  assert(generator && "Cannot call generator with null generator");
38  return generator(recordKeeper, os);
39  }
40 
43  StringRef getGenArgument() const { return arg; }
44 
46  StringRef getGenDescription() const { return description; }
47 
48 private:
49  // The argument with which to invoke the generator via mlir-tblgen.
50  StringRef arg;
51 
52  // Description of the generator.
53  StringRef description;
54 
55  // Generator function.
56  GenFunction generator;
57 };
58 
67  GenRegistration(StringRef arg, StringRef description, GenFunction function);
68 };
69 
70 } // end namespace mlir
71 
72 #endif // MLIR_TABLEGEN_GENINFO_H_
Definition: InferTypeOpInterface.cpp:20
std::function< bool(const llvm::RecordKeeper &recordKeeper, raw_ostream &os)> GenFunction
Generator function to invoke.
Definition: GenInfo.h:24
StringRef getGenArgument() const
Definition: GenInfo.h:43
Definition: PassRegistry.cpp:413
StringRef getGenDescription() const
Returns a description for the generator.
Definition: GenInfo.h:46
GenInfo(StringRef arg, StringRef description, GenFunction generator)
Definition: GenInfo.h:32
Definition: GenInfo.h:66
Definition: GenInfo.h:28
bool invoke(const llvm::RecordKeeper &recordKeeper, raw_ostream &os) const
Invokes the generator and returns whether the generator failed.
Definition: GenInfo.h:36