LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
CommonCAPIGen.h File Reference
#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>
Include dependency graph for CommonCAPIGen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ClangLexerContext
 RAII wrapper for Clang lexer infrastructure. More...
struct  MethodParameter
 Structure to represent a parameter in a parsed method signature from an extraClassDeclaration More...
struct  ExtraMethod
 Structure to represent a parsed method signature from an extraClassDeclaration More...
struct  Generator
 Base class for C API generators. More...
struct  HeaderGenerator
 Generator for common C header file elements. More...
struct  ImplementationGenerator
 Generator for common C implementation file elements. More...
struct  TestGenerator
 Generator for common test implementation file elements. More...

Namespaces

namespace  clang

Functions

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< ExtraMethodparseExtraMethods (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.

Variables

constexpr bool WARN_SKIPPED_METHODS = false
llvm::cl::OptionCategory OpGenCat
llvm::cl::opt< std::string > DialectName
llvm::cl::opt< std::string > FunctionPrefix
llvm::cl::opt< bool > GenIsA
llvm::cl::opt< bool > GenOpBuild
llvm::cl::opt< bool > GenOpOperandGetters
llvm::cl::opt< bool > GenOpOperandSetters
llvm::cl::opt< bool > GenOpAttributeGetters
llvm::cl::opt< bool > GenOpAttributeSetters
llvm::cl::opt< bool > GenOpRegionGetters
llvm::cl::opt< bool > GenOpResultGetters
llvm::cl::opt< bool > GenTypeOrAttrGet
llvm::cl::opt< bool > GenTypeOrAttrParamGetters
llvm::cl::opt< bool > GenExtraClassMethods

Function Documentation

◆ extractArrayRefElementType()

mlir::StringRef extractArrayRefElementType ( mlir::StringRef cppType)
inline

Extract element type from ArrayRef<...>

Definition at line 197 of file CommonCAPIGen.h.

◆ isAPIntType()

bool isAPIntType ( mlir::StringRef cppType)
inline

Check if a C++ type is APInt.

Parameters
cppTypeThe 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
cppTypeThe 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
methodNameThe 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
tokenTextThe 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
typeThe 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
cppTypeThe 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
cppTypeThe 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
cppTypeThe C++ type to check
typeNameThe 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
extraDeclThe 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
strThe 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
cppTypeThe 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.

Variable Documentation

◆ 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

Definition at line 27 of file CommonCAPIGen.h.