LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
CommonCAPIGen.cpp File Reference
#include "CommonCAPIGen.h"
#include "CAPIGenRegistration.h"
#include <llvm/ADT/StringMap.h>
#include <clang/Basic/FileManager.h>
#include <clang/Basic/LangOptions.h>
#include <clang/Basic/SourceManager.h>
#include <clang/Lex/Lexer.h>
#include <optional>
Include dependency graph for CommonCAPIGen.cpp:

Go to the source code of this file.

Classes

struct  ClangLexerContext::Impl

Enumerations

enum class  AccessLevel : std::uint8_t { Public , Private , Protected }
 Access level tracking for C++ class declarations. More...

Functions

llvm::cl::opt< std::string > & getDialectName ()
 Return the DialectName option, registering it on first access.
llvm::cl::opt< std::string > & getFunctionPrefix ()
 Return the FunctionPrefix option, registering it on first access.
llvm::cl::opt< bool > & getGenIsA ()
 Return the GenIsA option, registering it on first access.
llvm::cl::opt< bool > & getGenOpBuild ()
 Return the GenOpBuild option, registering it on first access.
llvm::cl::opt< bool > & getGenOpOperandGetters ()
 Return the GenOpOperandGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenOpOperandSetters ()
 Return the GenOpOperandSetters option, registering it on first access.
llvm::cl::opt< bool > & getGenOpAttributeGetters ()
 Return the GenOpAttributeGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenOpAttributeSetters ()
 Return the GenOpAttributeSetters option, registering it on first access.
llvm::cl::opt< bool > & getGenOpRegionGetters ()
 Return the GenOpRegionGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenOpResultGetters ()
 Return the GenOpResultGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenTypeOrAttrGet ()
 Return the GenTypeOrAttrGet option, registering it on first access.
llvm::cl::opt< bool > & getGenTypeOrAttrParamGetters ()
 Return the GenTypeOrAttrParamGetters option, registering it on first access.
llvm::cl::opt< bool > & getGenExtraClassMethods ()
 Return the GenExtraClassMethods option, registering it on first access.
SmallVector< ExtraMethod > parseExtraMethods (StringRef extraDecl)
 Parse method declarations from extraClassDeclaration using Clang's Lexer.
bool matchesMLIRClass (StringRef cppType, StringRef typeName)
 Check if a C++ type matches an MLIR type pattern.
std::optional< std::string > tryCppTypeToCapiType (StringRef cppType)
 Convert C++ type to MLIR C API type.
std::string mapCppTypeToCapiType (StringRef cppType)
std::optional< std::string > mapCapiTypeToBasicCppType (StringRef capiType)

Enumeration Type Documentation

◆ AccessLevel

enum class AccessLevel : std::uint8_t
strong

Access level tracking for C++ class declarations.

Enumerator
Public 
Private 
Protected 

Definition at line 309 of file CommonCAPIGen.cpp.

Function Documentation

◆ getDialectName()

llvm::cl::opt< std::string > & getDialectName ( )

Return the DialectName option, registering it on first access.

Definition at line 37 of file CommonCAPIGen.cpp.

◆ getFunctionPrefix()

llvm::cl::opt< std::string > & getFunctionPrefix ( )

Return the FunctionPrefix option, registering it on first access.

Definition at line 49 of file CommonCAPIGen.cpp.

◆ getGenExtraClassMethods()

llvm::cl::opt< bool > & getGenExtraClassMethods ( )

Return the GenExtraClassMethods option, registering it on first access.

Definition at line 142 of file CommonCAPIGen.cpp.

◆ getGenIsA()

llvm::cl::opt< bool > & getGenIsA ( )

Return the GenIsA option, registering it on first access.

Definition at line 61 of file CommonCAPIGen.cpp.

◆ getGenOpAttributeGetters()

llvm::cl::opt< bool > & getGenOpAttributeGetters ( )

Return the GenOpAttributeGetters option, registering it on first access.

Definition at line 93 of file CommonCAPIGen.cpp.

◆ getGenOpAttributeSetters()

llvm::cl::opt< bool > & getGenOpAttributeSetters ( )

Return the GenOpAttributeSetters option, registering it on first access.

Definition at line 101 of file CommonCAPIGen.cpp.

◆ getGenOpBuild()

llvm::cl::opt< bool > & getGenOpBuild ( )

Return the GenOpBuild option, registering it on first access.

Definition at line 69 of file CommonCAPIGen.cpp.

◆ getGenOpOperandGetters()

llvm::cl::opt< bool > & getGenOpOperandGetters ( )

Return the GenOpOperandGetters option, registering it on first access.

Definition at line 77 of file CommonCAPIGen.cpp.

◆ getGenOpOperandSetters()

llvm::cl::opt< bool > & getGenOpOperandSetters ( )

Return the GenOpOperandSetters option, registering it on first access.

Definition at line 85 of file CommonCAPIGen.cpp.

◆ getGenOpRegionGetters()

llvm::cl::opt< bool > & getGenOpRegionGetters ( )

Return the GenOpRegionGetters option, registering it on first access.

Definition at line 109 of file CommonCAPIGen.cpp.

◆ getGenOpResultGetters()

llvm::cl::opt< bool > & getGenOpResultGetters ( )

Return the GenOpResultGetters option, registering it on first access.

Definition at line 117 of file CommonCAPIGen.cpp.

◆ getGenTypeOrAttrGet()

llvm::cl::opt< bool > & getGenTypeOrAttrGet ( )

Return the GenTypeOrAttrGet option, registering it on first access.

Definition at line 125 of file CommonCAPIGen.cpp.

◆ getGenTypeOrAttrParamGetters()

llvm::cl::opt< bool > & getGenTypeOrAttrParamGetters ( )

Return the GenTypeOrAttrParamGetters option, registering it on first access.

Definition at line 133 of file CommonCAPIGen.cpp.

◆ mapCapiTypeToBasicCppType()

std::optional< std::string > mapCapiTypeToBasicCppType ( StringRef capiType)

Definition at line 866 of file CommonCAPIGen.cpp.

◆ mapCppTypeToCapiType()

std::string mapCppTypeToCapiType ( StringRef cppType)

Definition at line 853 of file CommonCAPIGen.cpp.

◆ matchesMLIRClass()

bool matchesMLIRClass ( StringRef cppType,
StringRef typeName )

Check if a C++ type matches an MLIR type pattern.

Definition at line 720 of file CommonCAPIGen.cpp.

◆ parseExtraMethods()

SmallVector< ExtraMethod > parseExtraMethods ( StringRef extraDecl)

Parse method declarations from extraClassDeclaration using Clang's Lexer.

This function parses C++ method declarations to extract method signatures. It identifies methods by looking for the pattern: <return_type> <identifier> '(' [params] ')' [const] ';'

The parsing process:

  1. Tokenizes the input using Clang's lexer
  2. Tracks access level (public/private/protected) to filter methods
  3. For each potential method declaration:
    • Extracts the return type
    • Parses parameters (if any)
    • Checks for const qualifier
    • Extracts documentation comments
  4. Returns a list of successfully parsed methods, excluding:
    • Static methods
    • Private/protected methods
    • Overloaded methods (duplicate names)

Definition at line 616 of file CommonCAPIGen.cpp.

◆ tryCppTypeToCapiType()

std::optional< std::string > tryCppTypeToCapiType ( StringRef cppType)

Convert C++ type to MLIR C API type.

Definition at line 736 of file CommonCAPIGen.cpp.