//===- Class.h - Helper classes for C++ code emission -----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines several classes for C++ code emission. They are only // expected to be used by MLIR TableGen backends. // // We emit the declarations and definitions into separate files: *.h.inc and // *.cpp.inc. The former is to be included in the dialect *.h and the latter for // dialect *.cpp. This way provides a cleaner interface. // // In order to do this split, we need to track method signature and // implementation logic separately. Signature information is used for both // declaration and definition, while implementation logic is only for // definition. So we have the following classes for C++ code emission. // //===----------------------------------------------------------------------===// #ifndef MLIR_TABLEGEN_CLASS_H_ #define MLIR_TABLEGEN_CLASS_H_ #include "mlir/Support/IndentedOstream.h" #include "mlir/Support/LLVM.h" #include "mlir/TableGen/CodeGenHelpers.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Twine.h" #include <set> #include <string> namespace mlir { namespace tblgen { class FmtObjectBase; /// This class contains a single method parameter for a C++ function. class MethodParameter { … }; /// This class contains a list of method parameters for constructor, class /// methods, and method signatures. class MethodParameters { … }; /// This class contains the signature of a C++ method, including the return /// type. method name, and method parameters. class MethodSignature { … }; /// This class contains the body of a C++ method. class MethodBody { … }; /// A class declaration is a class element that appears as part of its /// declaration. class ClassDeclaration { … }; /// Base class for class declarations. template <ClassDeclaration::Kind DeclKind> class ClassDeclarationBase : public ClassDeclaration { … }; /// Class for holding an op's method for C++ code emission class Method : public ClassDeclarationBase<ClassDeclaration::Method> { … }; /// This enum describes C++ inheritance visibility. enum class Visibility { … }; /// Write "public", "protected", or "private". llvm::raw_ostream &operator<<(llvm::raw_ostream &os, mlir::tblgen::Visibility visibility); // Class for holding an op's constructor method for C++ code emission. class Constructor : public Method { … }; } // namespace tblgen } // namespace mlir /// The OR of two method properties should return method properties. Ensure that /// this function is visible to `Class`. inline constexpr mlir::tblgen::Method::Properties operator|(mlir::tblgen::Method::Properties lhs, mlir::tblgen::Method::Properties rhs) { … } inline constexpr mlir::tblgen::Method::Properties & operator|=(mlir::tblgen::Method::Properties &lhs, mlir::tblgen::Method::Properties rhs) { … } namespace mlir { namespace tblgen { template <typename ParamT> void Method::addTemplateParam(ParamT param) { … } template <typename ContainerT> void Method::addTemplateParams(ContainerT &&container) { … } /// This class describes a C++ parent class declaration. class ParentClass { … }; /// This class describes a using-declaration for a class. E.g. /// /// using Op::Op; /// using Adaptor = OpAdaptor; /// class UsingDeclaration : public ClassDeclarationBase<ClassDeclaration::UsingDeclaration> { … }; /// This class describes a class field. class Field : public ClassDeclarationBase<ClassDeclaration::Field> { … }; /// A declaration for the visibility of subsequent declarations. class VisibilityDeclaration : public ClassDeclarationBase<ClassDeclaration::VisibilityDeclaration> { … }; /// Unstructured extra class declarations and definitions, from TableGen /// definitions. The default visibility of extra class declarations is up to the /// owning class. class ExtraClassDeclaration : public ClassDeclarationBase<ClassDeclaration::ExtraClassDeclaration> { … }; /// A class used to emit C++ classes from Tablegen. Contains a list of public /// methods and a list of private fields to be emitted. class Class { … }; } // namespace tblgen } // namespace mlir #endif // MLIR_TABLEGEN_CLASS_H_