1 //===- OpClass.h - Implementation of an Op Class --------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_
10 #define MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_
12 #include "mlir/TableGen/Class.h"
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
{
21 /// Create an operation class with extra class declarations, whose default
22 /// visibility is public. Also declares at the top of the class:
24 /// - inheritance of constructors from `Op`
25 /// - inheritance of `print`
26 /// - a type alias for the associated adaptor class
28 OpClass(StringRef name
, std::string extraClassDeclaration
,
29 std::string extraClassDefinition
);
32 void addTrait(Twine trait
) { parent
.addTemplateParam(trait
.str()); }
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
;
41 /// Hand-written extra class declarations.
42 std::string extraClassDeclaration
;
43 /// Hand-written extra class definitions.
44 std::string extraClassDefinition
;
45 /// The parent class, which also contains the traits to be inherited.
52 #endif // MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_