LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches

#include <Builders.h>

Inheritance diagram for llzk::ModuleLikeBuilder< Derived >:
[legend]
Collaboration diagram for llzk::ModuleLikeBuilder< Derived >:
[legend]

Public Member Functions

 ModuleLikeBuilder (mlir::MLIRContext *ctx)
mlir::Region & getBodyRegion ()
mlir::FailureOr< component::StructDefOpgetStruct (std::string_view structName) const
mlir::FailureOr< function::FuncDefOpgetComputeFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOpgetComputeFn (component::StructDefOp op) const
mlir::FailureOr< function::FuncDefOpgetConstrainFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOpgetConstrainFn (component::StructDefOp op) const
mlir::FailureOr< function::FuncDefOpgetProductFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOpgetProductFn (component::StructDefOp op) const
mlir::FailureOr< function::FuncDefOpgetFreeFunc (std::string_view funcName) const
Derived & insertEmptyStruct (std::string_view structName, mlir::Location loc)
Derived & insertEmptyStruct (std::string_view structName)
Derived & insertComputeOnlyStruct (std::string_view structName, mlir::Location structLoc, mlir::Location computeLoc)
Derived & insertComputeOnlyStruct (std::string_view structName)
Derived & insertConstrainOnlyStruct (std::string_view structName, mlir::Location structLoc, mlir::Location constrainLoc)
Derived & insertConstrainOnlyStruct (std::string_view structName)
Derived & insertFullStruct (std::string_view structName, mlir::Location structLoc, mlir::Location computeLoc, mlir::Location constrainLoc)
Derived & insertFullStruct (std::string_view structName)
 Inserts a struct with both compute and constrain functions.
Derived & insertProductStruct (std::string_view structName, mlir::Location structLoc, mlir::Location productLoc)
Derived & insertProductStruct (std::string_view structName)
Derived & insertComputeFn (component::StructDefOp op, mlir::Location loc)
Derived & insertComputeFn (std::string_view structName, mlir::Location loc)
Derived & insertComputeFn (std::string_view structName)
Derived & insertConstrainFn (component::StructDefOp op, mlir::Location loc)
Derived & insertConstrainFn (std::string_view structName, mlir::Location loc)
Derived & insertConstrainFn (std::string_view structName)
Derived & insertProductFn (component::StructDefOp op, mlir::Location loc)
Derived & insertProductFn (std::string_view structName, mlir::Location loc)
Derived & insertProductFn (std::string_view structName)
Derived & insertComputeCall (component::StructDefOp caller, component::StructDefOp callee, mlir::Location callLoc)
 Only requirement for compute is the call itself.
Derived & insertComputeCall (std::string_view caller, std::string_view callee, mlir::Location callLoc)
Derived & insertComputeCall (std::string_view caller, std::string_view callee)
Derived & insertConstrainCall (component::StructDefOp caller, component::StructDefOp callee, mlir::Location callLoc, mlir::Location memberDefLoc)
 To call a constraint function, you must:
Derived & insertConstrainCall (std::string_view caller, std::string_view callee, mlir::Location callLoc, mlir::Location memberDefLoc)
Derived & insertConstrainCall (std::string_view caller, std::string_view callee)
Derived & insertFreeFunc (std::string_view funcName, ::mlir::FunctionType type, mlir::Location loc)
Derived & insertFreeFunc (std::string_view funcName, ::mlir::FunctionType type)
Derived & insertFreeCall (function::FuncDefOp caller, std::string_view callee, mlir::Location callLoc)
Derived & insertFreeCall (function::FuncDefOp caller, std::string_view callee)
Public Member Functions inherited from llzk::BaseBuilder
 BaseBuilder (mlir::MLIRContext *ctx)
mlir::Location getUnknownLoc ()

Static Public Member Functions

static function::FuncDefOp buildComputeFn (component::StructDefOp op, mlir::Location loc)
 compute returns the type of the struct that defines it.
static function::FuncDefOp buildConstrainFn (component::StructDefOp op, mlir::Location loc)
 constrain accepts the struct type as the first argument.
static function::FuncDefOp buildProductFn (component::StructDefOp op, mlir::Location loc)
 product returns the type of the struct that defines it.

Protected Member Functions

void ensureNoSuchFreeFunc (std::string_view funcName)
 Ensure that a global function with the given funcName has not been added, reporting a fatal error otherwise.
void ensureFreeFnExists (std::string_view funcName)
 Ensure that a global function with the given funcName has been added, reporting a fatal error otherwise.
void ensureNoSuchStruct (std::string_view structName)
 Ensure that a struct with the given structName has not been added, reporting a fatal error otherwise.
void ensureStructExists (std::string_view structName)
 Ensure that a struct with the given structName exists, reporting a fatal error otherwise.
void ensureNoSuchComputeFn (std::string_view structName)
 Ensure that the given struct does not have a compute function, reporting a fatal error otherwise.
void ensureComputeFnExists (std::string_view structName)
 Ensure that the given struct has a compute function, reporting a fatal error otherwise.
void ensureNoSuchConstrainFn (std::string_view structName)
 Ensure that the given struct does not have a constrain function, reporting a fatal error otherwise.
void ensureConstrainFnExists (std::string_view structName)
 Ensure that the given struct has a constrain function, reporting a fatal error otherwise.
void ensureNoSuchProductFn (std::string_view structName)
 Ensure that the given struct does not have a product function, reporting a fatal error otherwise.
void ensureProductFnExists (std::string_view structName)
 Ensure that the given struct has a product function, reporting a fatal error otherwise.

Protected Attributes

std::unordered_map< std::string_view, function::FuncDefOpfreeFuncMap
std::unordered_map< std::string_view, component::StructDefOpstructMap
std::unordered_map< std::string_view, function::FuncDefOpcomputeFnMap
std::unordered_map< std::string_view, function::FuncDefOpconstrainFnMap
std::unordered_map< std::string_view, function::FuncDefOpproductFnMap
Protected Attributes inherited from llzk::BaseBuilder
mlir::MLIRContext * context

Detailed Description

template<typename Derived>
class llzk::ModuleLikeBuilder< Derived >

Definition at line 45 of file Builders.h.

Constructor & Destructor Documentation

◆ ModuleLikeBuilder()

template<typename Derived>
llzk::ModuleLikeBuilder< Derived >::ModuleLikeBuilder ( mlir::MLIRContext * ctx)
inline

Definition at line 109 of file Builders.h.

Member Function Documentation

◆ buildComputeFn()

template<typename Derived>
FuncDefOp llzk::ModuleLikeBuilder< Derived >::buildComputeFn ( component::StructDefOp op,
mlir::Location loc )
static

compute returns the type of the struct that defines it.

Since this is for testing, we accept no arguments.

Definition at line 124 of file Builders.cpp.

◆ buildConstrainFn()

template<typename Derived>
FuncDefOp llzk::ModuleLikeBuilder< Derived >::buildConstrainFn ( component::StructDefOp op,
mlir::Location loc )
static

constrain accepts the struct type as the first argument.

Definition at line 150 of file Builders.cpp.

◆ buildProductFn()

template<typename Derived>
FuncDefOp llzk::ModuleLikeBuilder< Derived >::buildProductFn ( component::StructDefOp op,
mlir::Location loc )
static

product returns the type of the struct that defines it.

Since this is for testing, we accept no arguments.

Definition at line 176 of file Builders.cpp.

◆ ensureComputeFnExists()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureComputeFnExists ( std::string_view structName)
protected

Ensure that the given struct has a compute function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 76 of file Builders.cpp.

◆ ensureConstrainFnExists()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureConstrainFnExists ( std::string_view structName)
protected

Ensure that the given struct has a constrain function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 90 of file Builders.cpp.

◆ ensureFreeFnExists()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureFreeFnExists ( std::string_view funcName)
protected

Ensure that a global function with the given funcName has been added, reporting a fatal error otherwise.

Parameters
funcName

Definition at line 48 of file Builders.cpp.

◆ ensureNoSuchComputeFn()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureNoSuchComputeFn ( std::string_view structName)
protected

Ensure that the given struct does not have a compute function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 69 of file Builders.cpp.

◆ ensureNoSuchConstrainFn()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureNoSuchConstrainFn ( std::string_view structName)
protected

Ensure that the given struct does not have a constrain function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 83 of file Builders.cpp.

◆ ensureNoSuchFreeFunc()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureNoSuchFreeFunc ( std::string_view funcName)
protected

Ensure that a global function with the given funcName has not been added, reporting a fatal error otherwise.

Parameters
funcName

Definition at line 41 of file Builders.cpp.

◆ ensureNoSuchProductFn()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureNoSuchProductFn ( std::string_view structName)
protected

Ensure that the given struct does not have a product function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 97 of file Builders.cpp.

◆ ensureNoSuchStruct()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureNoSuchStruct ( std::string_view structName)
protected

Ensure that a struct with the given structName has not been added, reporting a fatal error otherwise.

Parameters
structName

Definition at line 55 of file Builders.cpp.

◆ ensureProductFnExists()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureProductFnExists ( std::string_view structName)
protected

Ensure that the given struct has a product function, reporting a fatal error otherwise.

Parameters
structName

Definition at line 104 of file Builders.cpp.

◆ ensureStructExists()

template<typename Derived>
void llzk::ModuleLikeBuilder< Derived >::ensureStructExists ( std::string_view structName)
protected

Ensure that a struct with the given structName exists, reporting a fatal error otherwise.

Parameters
structName

Definition at line 62 of file Builders.cpp.

◆ getBodyRegion()

template<typename Derived>
mlir::Region & llzk::ModuleLikeBuilder< Derived >::getBodyRegion ( )
inline

Definition at line 113 of file Builders.h.

◆ getComputeFn() [1/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getComputeFn ( component::StructDefOp op) const
inline

Definition at line 128 of file Builders.h.

◆ getComputeFn() [2/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getComputeFn ( std::string_view structName) const
inline

Definition at line 122 of file Builders.h.

◆ getConstrainFn() [1/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getConstrainFn ( component::StructDefOp op) const
inline

Definition at line 138 of file Builders.h.

◆ getConstrainFn() [2/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getConstrainFn ( std::string_view structName) const
inline

Definition at line 132 of file Builders.h.

◆ getFreeFunc()

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getFreeFunc ( std::string_view funcName) const
inline

Definition at line 152 of file Builders.h.

◆ getProductFn() [1/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getProductFn ( component::StructDefOp op) const
inline

Definition at line 148 of file Builders.h.

◆ getProductFn() [2/2]

template<typename Derived>
mlir::FailureOr< function::FuncDefOp > llzk::ModuleLikeBuilder< Derived >::getProductFn ( std::string_view structName) const
inline

Definition at line 142 of file Builders.h.

◆ getStruct()

template<typename Derived>
mlir::FailureOr< component::StructDefOp > llzk::ModuleLikeBuilder< Derived >::getStruct ( std::string_view structName) const
inline

Definition at line 115 of file Builders.h.

◆ insertComputeCall() [1/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeCall ( component::StructDefOp caller,
component::StructDefOp callee,
mlir::Location callLoc )

Only requirement for compute is the call itself.

It should also initialize the internal member, but we can ignore those ops for the sake of testing.

◆ insertComputeCall() [2/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeCall ( std::string_view caller,
std::string_view callee )
inline

Definition at line 263 of file Builders.h.

◆ insertComputeCall() [3/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeCall ( std::string_view caller,
std::string_view callee,
mlir::Location callLoc )

◆ insertComputeFn() [1/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeFn ( component::StructDefOp op,
mlir::Location loc )

◆ insertComputeFn() [2/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeFn ( std::string_view structName)
inline

Definition at line 228 of file Builders.h.

◆ insertComputeFn() [3/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeFn ( std::string_view structName,
mlir::Location loc )

◆ insertComputeOnlyStruct() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeOnlyStruct ( std::string_view structName)
inline

Definition at line 174 of file Builders.h.

◆ insertComputeOnlyStruct() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertComputeOnlyStruct ( std::string_view structName,
mlir::Location structLoc,
mlir::Location computeLoc )
inline

Definition at line 166 of file Builders.h.

◆ insertConstrainCall() [1/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainCall ( component::StructDefOp caller,
component::StructDefOp callee,
mlir::Location callLoc,
mlir::Location memberDefLoc )

To call a constraint function, you must:

  1. Add the callee as an internal member of the caller,
  2. Read the callee in the caller's constraint function,
  3. Call the callee's constraint function.

◆ insertConstrainCall() [2/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainCall ( std::string_view caller,
std::string_view callee )
inline

Definition at line 281 of file Builders.h.

◆ insertConstrainCall() [3/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainCall ( std::string_view caller,
std::string_view callee,
mlir::Location callLoc,
mlir::Location memberDefLoc )

◆ insertConstrainFn() [1/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainFn ( component::StructDefOp op,
mlir::Location loc )

◆ insertConstrainFn() [2/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainFn ( std::string_view structName)
inline

Definition at line 238 of file Builders.h.

◆ insertConstrainFn() [3/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainFn ( std::string_view structName,
mlir::Location loc )

◆ insertConstrainOnlyStruct() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainOnlyStruct ( std::string_view structName)
inline

Definition at line 187 of file Builders.h.

◆ insertConstrainOnlyStruct() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertConstrainOnlyStruct ( std::string_view structName,
mlir::Location structLoc,
mlir::Location constrainLoc )
inline

Definition at line 179 of file Builders.h.

◆ insertEmptyStruct() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertEmptyStruct ( std::string_view structName)
inline

Definition at line 162 of file Builders.h.

◆ insertEmptyStruct() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertEmptyStruct ( std::string_view structName,
mlir::Location loc )

◆ insertFreeCall() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFreeCall ( function::FuncDefOp caller,
std::string_view callee )
inline

Definition at line 292 of file Builders.h.

◆ insertFreeCall() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFreeCall ( function::FuncDefOp caller,
std::string_view callee,
mlir::Location callLoc )

◆ insertFreeFunc() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFreeFunc ( std::string_view funcName,
::mlir::FunctionType type )
inline

Definition at line 286 of file Builders.h.

◆ insertFreeFunc() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFreeFunc ( std::string_view funcName,
::mlir::FunctionType type,
mlir::Location loc )

◆ insertFullStruct() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFullStruct ( std::string_view structName)
inline

Inserts a struct with both compute and constrain functions.

Definition at line 203 of file Builders.h.

◆ insertFullStruct() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertFullStruct ( std::string_view structName,
mlir::Location structLoc,
mlir::Location computeLoc,
mlir::Location constrainLoc )
inline

Definition at line 192 of file Builders.h.

◆ insertProductFn() [1/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertProductFn ( component::StructDefOp op,
mlir::Location loc )

◆ insertProductFn() [2/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertProductFn ( std::string_view structName)
inline

Definition at line 249 of file Builders.h.

◆ insertProductFn() [3/3]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertProductFn ( std::string_view structName,
mlir::Location loc )

◆ insertProductStruct() [1/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertProductStruct ( std::string_view structName)
inline

Definition at line 216 of file Builders.h.

◆ insertProductStruct() [2/2]

template<typename Derived>
Derived & llzk::ModuleLikeBuilder< Derived >::insertProductStruct ( std::string_view structName,
mlir::Location structLoc,
mlir::Location productLoc )
inline

Definition at line 208 of file Builders.h.

Member Data Documentation

◆ computeFnMap

template<typename Derived>
std::unordered_map<std::string_view, function::FuncDefOp> llzk::ModuleLikeBuilder< Derived >::computeFnMap
protected

Definition at line 52 of file Builders.h.

◆ constrainFnMap

template<typename Derived>
std::unordered_map<std::string_view, function::FuncDefOp> llzk::ModuleLikeBuilder< Derived >::constrainFnMap
protected

Definition at line 54 of file Builders.h.

◆ freeFuncMap

template<typename Derived>
std::unordered_map<std::string_view, function::FuncDefOp> llzk::ModuleLikeBuilder< Derived >::freeFuncMap
protected

Definition at line 48 of file Builders.h.

◆ productFnMap

template<typename Derived>
std::unordered_map<std::string_view, function::FuncDefOp> llzk::ModuleLikeBuilder< Derived >::productFnMap
protected

Definition at line 56 of file Builders.h.

◆ structMap

template<typename Derived>
std::unordered_map<std::string_view, component::StructDefOp> llzk::ModuleLikeBuilder< Derived >::structMap
protected

Definition at line 50 of file Builders.h.


The documentation for this class was generated from the following files: