LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
llzk-opt.cpp
Go to the documentation of this file.
1//===-- llzk-opt.cpp - LLZK opt tool ----------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
14//===----------------------------------------------------------------------===//
15
17#include "llzk/Config/Config.h"
25#include "r1cs/Dialect/IR/Dialect.h"
26#include "r1cs/InitAllDialects.h"
27
28#include <mlir/IR/DialectRegistry.h>
29#include <mlir/Pass/PassManager.h>
30#include <mlir/Pass/PassRegistry.h>
31#include <mlir/Tools/mlir-opt/MlirOptMain.h>
32
33#include <llvm/ADT/StringRef.h>
34#include <llvm/Support/CommandLine.h>
35#include <llvm/Support/PrettyStackTrace.h>
36#include <llvm/Support/Signals.h>
37
38#include "tools/config.h"
39
40static llvm::cl::list<std::string> IncludeDirs(
41 "I", llvm::cl::desc("Directory of include files"), llvm::cl::value_desc("directory"),
42 llvm::cl::Prefix
43);
44
45static llvm::cl::opt<bool>
46 PrintAllOps("print-llzk-ops", llvm::cl::desc("Print a list of all ops registered in LLZK"));
47
48int main(int argc, char **argv) {
49 llvm::sys::PrintStackTraceOnErrorSignal(llvm::StringRef());
50 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
51 " and include the crash backtrace, relevant LLZK files,"
52 " and associated run script(s).\n");
53 llvm::cl::AddExtraVersionPrinter([](llvm::raw_ostream &os) {
54 os << "\nLLZK (" LLZK_URL "):\n LLZK version " LLZK_VERSION_STRING "\n";
55 });
56
57 // MLIR initialization
58 mlir::DialectRegistry registry;
60 r1cs::registerAllDialects(registry);
61
69
70 // Register and parse command line options.
71 std::string inputFilename, outputFilename;
72 std::tie(inputFilename, outputFilename) =
73 registerAndParseCLIOptions(argc, argv, "llzk-opt", registry);
74
75 if (PrintAllOps) {
76 mlir::MLIRContext context;
77 context.appendDialectRegistry(registry);
78 context.loadAllAvailableDialects();
79 llvm::outs() << "All ops registered in LLZK IR: {\n";
80 for (const auto &opName : context.getRegisteredOperations()) {
81 llvm::outs().indent(2) << opName.getStringRef() << '\n';
82 }
83 llvm::outs() << "}\n";
84 return EXIT_SUCCESS;
85 }
86
87 // Set the include directories from CL option
88 if (mlir::failed(llzk::GlobalSourceMgr::get().setup(IncludeDirs))) {
89 return EXIT_FAILURE;
90 }
91
92 // Run 'mlir-opt'
93 auto result = mlir::MlirOptMain(argc, argv, inputFilename, outputFilename, registry);
94 return mlir::asMainReturnCode(result);
95}
#define LLZK_VERSION_STRING
Definition Config.h:12
#define LLZK_URL
Definition Config.h:17
static GlobalSourceMgr & get()
#define BUG_REPORT_URL
Definition config.h:14
int main(int argc, char **argv)
Definition llzk-opt.cpp:48
This file defines llzk::registerAllDialects.
void registerTransformationPasses()
void registerTransformationPasses()
void registerTransformationPassPipelines()
void registerValidationPasses()
void registerAllDialects(mlir::DialectRegistry &registry)
void registerAnalysisPasses()