LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
llzk-translate.cpp
Go to the documentation of this file.
1//===-- llzk-translate.cpp - LLZK translate tool ----------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
14//===----------------------------------------------------------------------===//
15
16#include "r1cs/Target/TranslateRegistration.h"
17#include "smt/Target/TranslateRegistration.h"
18#include "tools/config.h"
19#include "zklean/Target/TranslateRegistration.h"
20
21#include "llzk/Config/Config.h"
25
26#include <mlir/Dialect/Func/Extensions/InlinerExtension.h>
27#include <mlir/Dialect/Func/IR/FuncOps.h>
28#include <mlir/Dialect/SCF/IR/SCF.h>
29#include <mlir/IR/DialectRegistry.h>
30#include <mlir/InitAllTranslations.h>
31#include <mlir/Pass/PassManager.h>
32#include <mlir/Pass/PassRegistry.h>
33#include <mlir/Tools/mlir-translate/MlirTranslateMain.h>
34#include <mlir/Tools/mlir-translate/Translation.h>
35#include <mlir/Transforms/Passes.h>
36
37#include <llvm/ADT/StringRef.h>
38#include <llvm/Support/CommandLine.h>
39#include <llvm/Support/PrettyStackTrace.h>
40#include <llvm/Support/Signals.h>
41
42#if LLZK_WITH_PCL
43#include "pcl/Target/TranslateRegistration.h"
44#endif // LLZK_WITH_PCL
45
46using namespace llzk;
47using namespace mlir;
48
50static LogicalResult generateLayout(Operation *op, llvm::raw_ostream &output, bool monomorphize) {
51 auto module = dyn_cast<ModuleOp>(op);
52 if (!module) {
53 return op->emitOpError("expected builtin.module as top level operation");
54 }
55 if (monomorphize) {
56 PassManager pm(module.getContext());
58 if (failed(pm.run(module))) {
59 return failure();
60 }
61 }
62 auto result = buildLLZKLayout(module);
63 if (failed(result)) {
64 return failure();
65 }
66 printLLZKLayout(*result, output);
67 return success();
68}
69
70int main(int argc, char **argv) {
71 llvm::sys::PrintStackTraceOnErrorSignal(llvm::StringRef());
72 llvm::setBugReportMsg(
73 "PLEASE submit a bug report to " BUG_REPORT_URL
74 " and include the crash backtrace, relevant LLZK files,"
75 " and associated run script(s).\n"
76 );
77 llvm::cl::AddExtraVersionPrinter([](llvm::raw_ostream &os) {
78 os << "\nLLZK (" LLZK_URL "):\n LLZK version " LLZK_VERSION_STRING "\n";
79 });
80
81 // Register all MLIR translations
82 registerAllTranslations();
83 TranslateFromMLIRRegistration layout(
84 "llzk-layout", "export the logical LLZK signal layout",
85 [](Operation *op, llvm::raw_ostream &output) { return generateLayout(op, output, false); },
86 [](DialectRegistry &registry) { registerDialects(registry); }
87 );
88 TranslateFromMLIRRegistration generateLayoutPipeline(
89 "llzk-generate-layout", "monomorphize LLZK and export the logical signal layout",
90 [](Operation *op, llvm::raw_ostream &output) { return generateLayout(op, output, true); },
91 [](DialectRegistry &registry) { registerDialects(registry); }
92 );
93 r1cs::registerR1CSTranslation();
94 llzk::smt::registerSmtTranslation();
95 zklean::registerZKLeanTranslation();
96#if LLZK_WITH_PCL
97 pcl::registerPclTranslation();
98#endif
99
100 // Run 'mlir-translate'
101 return failed(mlirTranslateMain(argc, argv, "LLZK Translation tool"));
102}
#define LLZK_VERSION_STRING
LLZK version string configured by CMake for this build.
Definition Config.h:13
#define LLZK_URL
Project homepage URL configured by CMake.
Definition Config.h:22
#define BUG_REPORT_URL
Definition config.h:15
int main(int argc, char **argv)
Declares dialect and pass registration functions for core LLZK dialects.
std::unique_ptr<::mlir::Pass > createTemplateMonomorphizationPass()
void printLLZKLayout(const LLZKLayout &layout, llvm::raw_ostream &output)
Print the logical signal section of the .llzk-layout format.
void registerDialects(mlir::DialectRegistry &registry)
Register core LLZK dialects, the MLIR arith, scf, and smt dialects, and verification extensions in re...
mlir::FailureOr< LLZKLayout > buildLLZKLayout(mlir::ModuleOp module)
Enumerate the signal leaves of llzk.main and its constrain arguments.