xref: /llvm-project/mlir/tools/mlir-tblgen/OpClass.h (revision 47b0a9b9311ffdaab511c240de89b5da75b1252b)
1ca6bd9cdSMogball //===- OpClass.h - Implementation of an Op Class --------------------------===//
2ca6bd9cdSMogball //
3ca6bd9cdSMogball // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ca6bd9cdSMogball // See https://llvm.org/LICENSE.txt for license information.
5ca6bd9cdSMogball // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ca6bd9cdSMogball //
7ca6bd9cdSMogball //===----------------------------------------------------------------------===//
8ca6bd9cdSMogball 
9ca6bd9cdSMogball #ifndef MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_
10ca6bd9cdSMogball #define MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_
11ca6bd9cdSMogball 
12ca6bd9cdSMogball #include "mlir/TableGen/Class.h"
13ca6bd9cdSMogball 
14ca6bd9cdSMogball namespace mlir {
15ca6bd9cdSMogball namespace tblgen {
16ca6bd9cdSMogball 
17ca6bd9cdSMogball /// Class for holding an op for C++ code emission. The class is specialized to
18ca6bd9cdSMogball /// add Op-specific declarations to the class.
19ca6bd9cdSMogball class OpClass : public Class {
20ca6bd9cdSMogball public:
21ca6bd9cdSMogball   /// Create an operation class with extra class declarations, whose default
22ca6bd9cdSMogball   /// visibility is public. Also declares at the top of the class:
23ca6bd9cdSMogball   ///
24ca6bd9cdSMogball   /// - inheritance of constructors from `Op`
25ca6bd9cdSMogball   /// - inheritance of `print`
26ca6bd9cdSMogball   /// - a type alias for the associated adaptor class
27ca6bd9cdSMogball   ///
28*47b0a9b9SAmanda Tang   OpClass(StringRef name, std::string extraClassDeclaration,
29b0774e5fSMogball           std::string extraClassDefinition);
30ca6bd9cdSMogball 
31ca6bd9cdSMogball   /// Add an op trait.
addTrait(Twine trait)32ca6bd9cdSMogball   void addTrait(Twine trait) { parent.addTemplateParam(trait.str()); }
33ca6bd9cdSMogball 
34ca6bd9cdSMogball   /// The operation class is finalized by calling `Class::finalize` to delcare
35ca6bd9cdSMogball   /// all pending private and public methods (ops don't have custom constructors
36ca6bd9cdSMogball   /// or fields). Then, the extra class declarations are appended to the end of
37ca6bd9cdSMogball   /// the class declaration.
38ca6bd9cdSMogball   void finalize() override;
39ca6bd9cdSMogball 
40ca6bd9cdSMogball private:
41ca6bd9cdSMogball   /// Hand-written extra class declarations.
42*47b0a9b9SAmanda Tang   std::string extraClassDeclaration;
43b0774e5fSMogball   /// Hand-written extra class definitions.
44b0774e5fSMogball   std::string extraClassDefinition;
45ca6bd9cdSMogball   /// The parent class, which also contains the traits to be inherited.
46ca6bd9cdSMogball   ParentClass &parent;
47ca6bd9cdSMogball };
48ca6bd9cdSMogball 
49be0a7e9fSMehdi Amini } // namespace tblgen
50be0a7e9fSMehdi Amini } // namespace mlir
51ca6bd9cdSMogball 
52ca6bd9cdSMogball #endif // MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_
53