53 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_10#define MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_11 12#include "mlir/TableGen/Class.h"13 14namespace mlir {15namespace tblgen {16 17/// Class for holding an op for C++ code emission. The class is specialized to18/// add Op-specific declarations to the class.19class OpClass : public Class {20public:21 /// Create an operation class with extra class declarations, whose default22 /// 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 class27 ///28 OpClass(StringRef name, std::string extraClassDeclaration,29 std::string extraClassDefinition);30 31 /// Add an op trait.32 void addTrait(Twine trait) { parent.addTemplateParam(trait.str()); }33 34 /// The operation class is finalized by calling `Class::finalize` to delcare35 /// all pending private and public methods (ops don't have custom constructors36 /// or fields). Then, the extra class declarations are appended to the end of37 /// the class declaration.38 void finalize() override;39 40private: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.46 ParentClass &parent;47};48 49} // namespace tblgen50} // namespace mlir51 52#endif // MLIR_TOOLS_MLIRTBLGEN_OPCLASS_H_53