LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
CommonCAPIGen.cpp File Reference
#include "CommonCAPIGen.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 { Public , Private , Protected }
 Access level tracking for C++ class declarations. More...

Functions

llvm::cl::OptionCategory OpGenCat ("Options for -gen-op-capi-header, -gen-op-capi-impl, and -gen-op-capi-tests")
llvm::cl::opt< std::string > DialectName ("dialect", llvm::cl::desc("The dialect name to use for this group of ops. " "Must match across header, implementation, and test generation."), llvm::cl::cat(OpGenCat))
llvm::cl::opt< std::string > FunctionPrefix ("prefix", llvm::cl::desc("The prefix to use for generated C API function names. " "Default is 'mlir'. Must match across header, implementation, and test generation."), llvm::cl::init("mlir"), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenIsA ("gen-isa", llvm::cl::desc("Generate IsA checks"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpBuild ("gen-op-build", llvm::cl::desc("Generate operation build(..) functions"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpOperandGetters ("gen-operand-getters", llvm::cl::desc("Generate operand getters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpOperandSetters ("gen-operand-setters", llvm::cl::desc("Generate operand setters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpAttributeGetters ("gen-attribute-getters", llvm::cl::desc("Generate attribute getters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpAttributeSetters ("gen-attribute-setters", llvm::cl::desc("Generate attribute setters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpRegionGetters ("gen-region-getters", llvm::cl::desc("Generate region getters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenOpResultGetters ("gen-result-getters", llvm::cl::desc("Generate result getters for operations"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenTypeOrAttrGet ("gen-type-attr-get", llvm::cl::desc("Generate get functions for types and attributes"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenTypeOrAttrParamGetters ("gen-parameter-getters", llvm::cl::desc("Generate parameter getters for types and attributes"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
llvm::cl::opt< bool > GenExtraClassMethods ("gen-extra-class-methods", llvm::cl::desc("Generate C API wrappers for methods in `extraClassDeclaration`"), llvm::cl::init(true), llvm::cl::cat(OpGenCat))
SmallVector< ExtraMethodparseExtraMethods (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)

Enumeration Type Documentation

◆ AccessLevel

enum class AccessLevel
strong

Access level tracking for C++ class declarations.

Enumerator
Public 
Private 
Protected 

Definition at line 243 of file CommonCAPIGen.cpp.

Function Documentation

◆ DialectName()

llvm::cl::opt< std::string > DialectName ( "dialect" ,
llvm::cl::desc("The dialect name to use for this group of ops. " "Must match across header, implementation, and test generation.") ,
llvm::cl::cat(OpGenCat)  )

◆ FunctionPrefix()

llvm::cl::opt< std::string > FunctionPrefix ( "prefix" ,
llvm::cl::desc("The prefix to use for generated C API function names. " "Default is 'mlir'. Must match across header, implementation, and test generation.") ,
llvm::cl::init("mlir") ,
llvm::cl::cat(OpGenCat)  )

◆ GenExtraClassMethods()

llvm::cl::opt< bool > GenExtraClassMethods ( "gen-extra-class-methods" ,
llvm::cl::desc("Generate C API wrappers for methods in `extraClassDeclaration`") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenIsA()

llvm::cl::opt< bool > GenIsA ( "gen-isa" ,
llvm::cl::desc("Generate IsA checks") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpAttributeGetters()

llvm::cl::opt< bool > GenOpAttributeGetters ( "gen-attribute-getters" ,
llvm::cl::desc("Generate attribute getters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpAttributeSetters()

llvm::cl::opt< bool > GenOpAttributeSetters ( "gen-attribute-setters" ,
llvm::cl::desc("Generate attribute setters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpBuild()

llvm::cl::opt< bool > GenOpBuild ( "gen-op-build" ,
llvm::cl::desc("Generate operation build(..) functions") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpOperandGetters()

llvm::cl::opt< bool > GenOpOperandGetters ( "gen-operand-getters" ,
llvm::cl::desc("Generate operand getters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpOperandSetters()

llvm::cl::opt< bool > GenOpOperandSetters ( "gen-operand-setters" ,
llvm::cl::desc("Generate operand setters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpRegionGetters()

llvm::cl::opt< bool > GenOpRegionGetters ( "gen-region-getters" ,
llvm::cl::desc("Generate region getters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenOpResultGetters()

llvm::cl::opt< bool > GenOpResultGetters ( "gen-result-getters" ,
llvm::cl::desc("Generate result getters for operations") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenTypeOrAttrGet()

llvm::cl::opt< bool > GenTypeOrAttrGet ( "gen-type-attr-get" ,
llvm::cl::desc("Generate get functions for types and attributes") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ GenTypeOrAttrParamGetters()

llvm::cl::opt< bool > GenTypeOrAttrParamGetters ( "gen-parameter-getters" ,
llvm::cl::desc("Generate parameter getters for types and attributes") ,
llvm::cl::init(true) ,
llvm::cl::cat(OpGenCat)  )

◆ mapCppTypeToCapiType()

std::string mapCppTypeToCapiType ( StringRef cppType)

Definition at line 788 of file CommonCAPIGen.cpp.

◆ matchesMLIRClass()

bool matchesMLIRClass ( StringRef cppType,
StringRef typeName )

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

Definition at line 654 of file CommonCAPIGen.cpp.

◆ OpGenCat()

llvm::cl::OptionCategory OpGenCat ( "Options for -gen-op-capi- header,
-gen-op-capi- impl,
and -gen-op-capi-tests"  )

◆ 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 550 of file CommonCAPIGen.cpp.

◆ tryCppTypeToCapiType()

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

Convert C++ type to MLIR C API type.

Definition at line 670 of file CommonCAPIGen.cpp.