#include <mlir/TableGen/Dialect.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/StringSwitch.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/FormatVariadic.h>
#include <memory>
#include <string>
Go to the source code of this file.
|
| template<typename S> |
| void | warnSkipped (const S &methodName, const std::string &message) |
| | Print warning about skipping a function.
|
| template<typename S> |
| void | warnSkippedNoConversion (const S &methodName, const std::string &cppType) |
| | Print warning about skipping a function due to no conversion of C++ type to C API type.
|
| std::string | toPascalCase (mlir::StringRef str) |
| | Convert names separated by underscore or colon to PascalCase.
|
| bool | isIntegerType (mlir::StringRef type) |
| | Check if a C++ type is a known integer type.
|
| bool | isPrimitiveType (mlir::StringRef cppType) |
| | Check if a C++ type is a known primitive type.
|
| bool | isCppModifierKeyword (mlir::StringRef tokenText) |
| | Check if a token text represents a C++ modifier/specifier keyword.
|
| bool | isCppLanguageConstruct (mlir::StringRef methodName) |
| | Check if a method name represents a C++ control flow keyword or language construct.
|
| bool | isAPIntType (mlir::StringRef cppType) |
| | Check if a C++ type is APInt.
|
| bool | isArrayRefType (mlir::StringRef cppType) |
| | Check if a C++ type is an ArrayRef type.
|
| mlir::StringRef | extractArrayRefElementType (mlir::StringRef cppType) |
| | Extract element type from ArrayRef<...>
|
| llvm::SmallVector< ExtraMethod > | parseExtraMethods (mlir::StringRef extraDecl) |
| | Parse method declarations from an extraClassDeclaration using Clang's Lexer.
|
| bool | matchesMLIRClass (mlir::StringRef cppType, mlir::StringRef typeName) |
| | Check if a C++ type matches an MLIR type pattern.
|
| std::optional< std::string > | tryCppTypeToCapiType (mlir::StringRef cppType) |
| | Convert C++ type to MLIR C API type.
|
| std::string | mapCppTypeToCapiType (mlir::StringRef cppType) |
| | Map C++ type to corresponding C API type.
|
◆ extractArrayRefElementType()
| mlir::StringRef extractArrayRefElementType |
( |
mlir::StringRef | cppType | ) |
|
|
inline |
◆ isAPIntType()
| bool isAPIntType |
( |
mlir::StringRef | cppType | ) |
|
|
inline |
Check if a C++ type is APInt.
- Parameters
-
| cppType | The C++ type string to check |
- Returns
- true if the type is APInt, llvm::APInt, or ::llvm::APInt
Definition at line 181 of file CommonCAPIGen.h.
◆ isArrayRefType()
| bool isArrayRefType |
( |
mlir::StringRef | cppType | ) |
|
|
inline |
Check if a C++ type is an ArrayRef type.
- Parameters
-
| cppType | The C++ type string to check |
- Returns
- true if the type is ArrayRef, llvm::ArrayRef, or ::llvm::ArrayRef
Definition at line 190 of file CommonCAPIGen.h.
◆ isCppLanguageConstruct()
| bool isCppLanguageConstruct |
( |
mlir::StringRef | methodName | ) |
|
|
inline |
Check if a method name represents a C++ control flow keyword or language construct.
- Parameters
-
| methodName | The method name to check |
- Returns
- true if the name is a C++ language construct (if, for, while, etc.)
Definition at line 162 of file CommonCAPIGen.h.
◆ isCppModifierKeyword()
| bool isCppModifierKeyword |
( |
mlir::StringRef | tokenText | ) |
|
|
inline |
Check if a token text represents a C++ modifier/specifier keyword.
- Parameters
-
| tokenText | The token to check |
- Returns
- true if the token is a C++ modifier (inline, static, virtual, etc.)
Definition at line 145 of file CommonCAPIGen.h.
◆ isIntegerType()
| bool isIntegerType |
( |
mlir::StringRef | type | ) |
|
|
inline |
Check if a C++ type is a known integer type.
- Parameters
-
| type | The type string to check |
- Returns
- true if the type is an integer type (size_t, unsigned, int*, uint*, etc.)
Definition at line 100 of file CommonCAPIGen.h.
◆ isPrimitiveType()
| bool isPrimitiveType |
( |
mlir::StringRef | cppType | ) |
|
|
inline |
Check if a C++ type is a known primitive type.
- Parameters
-
| cppType | The C++ type string to check |
- Returns
- true if the type is a primitive (bool, void, int, etc.)
- Note
- This function must be called on the CPP type because after converting to CAPI type, some things like APInt become primitive which can lead to missing wrap/unwrap functions.
Definition at line 136 of file CommonCAPIGen.h.
◆ mapCppTypeToCapiType()
| std::string mapCppTypeToCapiType |
( |
mlir::StringRef | cppType | ) |
|
Map C++ type to corresponding C API type.
- Parameters
-
| cppType | The C++ type to map |
- Returns
- The corresponding C API type string
- Note
- This function should not be called directly for ArrayRef types. Use extractArrayRefElementType() first and then use this on the result.
◆ matchesMLIRClass()
| bool matchesMLIRClass |
( |
mlir::StringRef | cppType, |
|
|
mlir::StringRef | typeName ) |
Check if a C++ type matches an MLIR type pattern.
- Parameters
-
| cppType | The C++ type to check |
| typeName | The MLIR type name to match against |
- Returns
- true if the C++ type matches the MLIR type
◆ parseExtraMethods()
| llvm::SmallVector< ExtraMethod > parseExtraMethods |
( |
mlir::StringRef | extraDecl | ) |
|
Parse method declarations from an extraClassDeclaration using Clang's Lexer.
- Parameters
-
| extraDecl | The C++ code from an extraClassDeclaration |
- Returns
- Vector of parsed method signatures
This function parses C++ method declarations to extract signatures that can be wrapped in C API functions. It identifies methods by looking for the pattern: [modifiers] <return_type> <identifier> '(' [params] ')' [const] ';'
Example input:
unsigned getWidth() const;
bool isSignless() const;
Example output:
- ExtraMethod { returnType="unsigned", methodName="getWidth", documentation="Get the width of this type", isConst=true, hasParameters=false, parameters={} }
- ExtraMethod { returnType="bool", methodName="isSignless", documentation="", isConst=true, hasParameters=false, parameters={} }
◆ toPascalCase()
| std::string toPascalCase |
( |
mlir::StringRef | str | ) |
|
|
inline |
Convert names separated by underscore or colon to PascalCase.
- Parameters
-
| str | The input string to convert (may contain underscores or colons) |
- Returns
- The converted PascalCase string
Examples: "no_inline" -> "NoInline" "::llzk::boolean::Type" -> "LlzkBooleanType"
Definition at line 75 of file CommonCAPIGen.h.
◆ tryCppTypeToCapiType()
| std::optional< std::string > tryCppTypeToCapiType |
( |
mlir::StringRef | cppType | ) |
|
Convert C++ type to MLIR C API type.
- Parameters
-
| cppType | The C++ type to convert |
- Returns
- The corresponding MLIR C API type if convertible, std::nullopt otherwise
◆ warnSkipped()
template<typename S>
| void warnSkipped |
( |
const S & | methodName, |
|
|
const std::string & | message ) |
|
inline |
Print warning about skipping a function.
Definition at line 30 of file CommonCAPIGen.h.
◆ warnSkippedNoConversion()
template<typename S>
| void warnSkippedNoConversion |
( |
const S & | methodName, |
|
|
const std::string & | cppType ) |
|
inline |
Print warning about skipping a function due to no conversion of C++ type to C API type.
Definition at line 38 of file CommonCAPIGen.h.
◆ DialectName
| llvm::cl::opt<std::string> DialectName |
|
extern |
◆ FunctionPrefix
| llvm::cl::opt<std::string> FunctionPrefix |
|
extern |
◆ GenExtraClassMethods
| llvm::cl::opt<bool> GenExtraClassMethods |
|
extern |
◆ GenIsA
| llvm::cl::opt<bool> GenIsA |
|
extern |
◆ GenOpAttributeGetters
| llvm::cl::opt<bool> GenOpAttributeGetters |
|
extern |
◆ GenOpAttributeSetters
| llvm::cl::opt<bool> GenOpAttributeSetters |
|
extern |
◆ GenOpBuild
| llvm::cl::opt<bool> GenOpBuild |
|
extern |
◆ GenOpOperandGetters
| llvm::cl::opt<bool> GenOpOperandGetters |
|
extern |
◆ GenOpOperandSetters
| llvm::cl::opt<bool> GenOpOperandSetters |
|
extern |
◆ GenOpRegionGetters
| llvm::cl::opt<bool> GenOpRegionGetters |
|
extern |
◆ GenOpResultGetters
| llvm::cl::opt<bool> GenOpResultGetters |
|
extern |
◆ GenTypeOrAttrGet
| llvm::cl::opt<bool> GenTypeOrAttrGet |
|
extern |
◆ GenTypeOrAttrParamGetters
| llvm::cl::opt<bool> GenTypeOrAttrParamGetters |
|
extern |
◆ OpGenCat
| llvm::cl::OptionCategory OpGenCat |
|
extern |
◆ WARN_SKIPPED_METHODS
| bool WARN_SKIPPED_METHODS = false |
|
constexpr |