1 | //===- OpClass.h - Implementation of an Op Class --------------------------===// |
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 | #ifndef MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_ |
10 | #define MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_ |
11 | |
12 | #include "mlir/TableGen/Class.h" |
13 | |
14 | namespace mlir { |
15 | namespace tblgen { |
16 | |
17 | /// Class for holding an op for C++ code emission. The class is specialized to |
18 | /// add Op-specific declarations to the class. |
19 | class OpClass : public Class { |
20 | public: |
21 | /// Create an operation class with extra class declarations, whose default |
22 | /// visibility is public. Also declares at the top of the class: |
23 | /// |
24 | /// - inheritance of constructors from `Op` |
25 | /// - inheritance of `print` |
26 | /// - a type alias for the associated adaptor class |
27 | /// |
28 | OpClass(StringRef name, std::string , |
29 | std::string ); |
30 | |
31 | /// Add an op trait. |
32 | void addTrait(Twine trait) { parent.addTemplateParam(param: trait.str()); } |
33 | |
34 | /// The operation class is finalized by calling `Class::finalize` to delcare |
35 | /// all pending private and public methods (ops don't have custom constructors |
36 | /// or fields). Then, the extra class declarations are appended to the end of |
37 | /// the class declaration. |
38 | void finalize() override; |
39 | |
40 | private: |
41 | /// Hand-written extra class declarations. |
42 | std::string ; |
43 | /// Hand-written extra class definitions. |
44 | std::string ; |
45 | /// The parent class, which also contains the traits to be inherited. |
46 | ParentClass &parent; |
47 | }; |
48 | |
49 | } // namespace tblgen |
50 | } // namespace mlir |
51 | |
52 | #endif // MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_ |
53 | |