LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
llzk::TemplateBuilder Class Reference

Builds out a LLZK-compliant template and provides utilities for populating that template. More...

#include <Builders.h>

Inheritance diagram for llzk::TemplateBuilder:
[legend]
Collaboration diagram for llzk::TemplateBuilder:
[legend]

Public Member Functions

 TemplateBuilder (polymorphic::TemplateOp t)
mlir::Region & getBodyRegion ()
 Provide the template body for ModuleLikeBuilder's CRTP dispatch.
polymorphic::TemplateOp & getTemplate ()
 Get the associated template of this builder.
mlir::FailureOr< polymorphic::TemplateParamOp > getParam (std::string_view name)
mlir::FailureOr< polymorphic::TemplateExprOp > getExpr (std::string_view name)
TemplateBuilder & insertParam (std::string_view name, mlir::Location loc, mlir::TypeAttr type={})
TemplateBuilder & insertParam (std::string_view name)
TemplateBuilder & insertExpr (std::string_view name, mlir::Location loc)
TemplateBuilder & insertExpr (std::string_view name)
Public Member Functions inherited from llzk::ModuleLikeBuilder< TemplateBuilder >
mlir::Region & getBodyRegion ()
mlir::FailureOr< component::StructDefOp > getStruct (std::string_view structName) const
mlir::FailureOr< function::FuncDefOp > getComputeFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOp > getConstrainFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOp > getProductFn (std::string_view structName) const
mlir::FailureOr< function::FuncDefOp > getFreeFunc (std::string_view funcName) const
TemplateBuilder & insertEmptyStruct (std::string_view structName, mlir::Location loc)
TemplateBuilder & insertComputeOnlyStruct (std::string_view structName, mlir::Location structLoc, mlir::Location computeLoc)
TemplateBuilder & insertConstrainOnlyStruct (std::string_view structName, mlir::Location structLoc, mlir::Location constrainLoc)
TemplateBuilder & insertFullStruct (std::string_view structName, mlir::Location structLoc, mlir::Location computeLoc, mlir::Location constrainLoc)
TemplateBuilder & insertProductStruct (std::string_view structName, mlir::Location structLoc, mlir::Location productLoc)
TemplateBuilder & insertComputeFn (component::StructDefOp op, mlir::Location loc)
TemplateBuilder & insertConstrainFn (component::StructDefOp op, mlir::Location loc)
TemplateBuilder & insertProductFn (component::StructDefOp op, mlir::Location loc)
TemplateBuilder & insertComputeCall (component::StructDefOp caller, component::StructDefOp callee, mlir::Location callLoc)
 Only requirement for compute is the call itself.
TemplateBuilder & insertConstrainCall (component::StructDefOp caller, component::StructDefOp callee, mlir::Location callLoc, mlir::Location memberDefLoc)
 To call a constraint function, you must:
TemplateBuilder & insertFreeFunc (std::string_view funcName, ::mlir::FunctionType type, mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &)> fnBody=nullptr)
TemplateBuilder & insertFreeCall (function::FuncDefOp caller, std::string_view callee, mlir::Location callLoc)
Public Member Functions inherited from llzk::BaseBuilder
 BaseBuilder (mlir::MLIRContext *ctx)
mlir::Location getUnknownLoc ()

Additional Inherited Members

Static Public Member Functions inherited from llzk::ModuleLikeBuilder< TemplateBuilder >
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 inherited from llzk::ModuleLikeBuilder< TemplateBuilder >
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 inherited from llzk::ModuleLikeBuilder< TemplateBuilder >
std::unordered_map< std::string_view, function::FuncDefOp > freeFuncMap
std::unordered_map< std::string_view, component::StructDefOp > structMap
std::unordered_map< std::string_view, function::FuncDefOp > computeFnMap
std::unordered_map< std::string_view, function::FuncDefOp > constrainFnMap
std::unordered_map< std::string_view, function::FuncDefOp > productFnMap
Protected Attributes inherited from llzk::BaseBuilder
mlir::MLIRContext * context

Detailed Description

Builds out a LLZK-compliant template and provides utilities for populating that template.

This class is designed to be used by front-ends looking to generate LLZK IR programmatically and is also a useful unit testing facility.

Definition at line 309 of file Builders.h.

Constructor & Destructor Documentation

◆ TemplateBuilder()

llzk::TemplateBuilder::TemplateBuilder ( polymorphic::TemplateOp t)
inline

Definition at line 313 of file Builders.h.

Member Function Documentation

◆ getBodyRegion()

mlir::Region & llzk::TemplateBuilder::getBodyRegion ( )
inline

Provide the template body for ModuleLikeBuilder's CRTP dispatch.

Definition at line 319 of file Builders.h.

◆ getExpr()

mlir::FailureOr< polymorphic::TemplateExprOp > llzk::TemplateBuilder::getExpr ( std::string_view name)
inline

Definition at line 332 of file Builders.h.

◆ getParam()

mlir::FailureOr< polymorphic::TemplateParamOp > llzk::TemplateBuilder::getParam ( std::string_view name)
inline

Definition at line 324 of file Builders.h.

◆ getTemplate()

polymorphic::TemplateOp & llzk::TemplateBuilder::getTemplate ( )
inline

Get the associated template of this builder.

Definition at line 322 of file Builders.h.

◆ insertExpr() [1/2]

TemplateBuilder & llzk::TemplateBuilder::insertExpr ( std::string_view name)
inline

Definition at line 387 of file Builders.h.

◆ insertExpr() [2/2]

TemplateBuilder & llzk::TemplateBuilder::insertExpr ( std::string_view name,
mlir::Location loc )
inline

Definition at line 366 of file Builders.h.

◆ insertParam() [1/2]

TemplateBuilder & llzk::TemplateBuilder::insertParam ( std::string_view name)
inline

Definition at line 362 of file Builders.h.

◆ insertParam() [2/2]

TemplateBuilder & llzk::TemplateBuilder::insertParam ( std::string_view name,
mlir::Location loc,
mlir::TypeAttr type = {} )
inline

Definition at line 341 of file Builders.h.


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