LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
JSON.h
Go to the documentation of this file.
1//===-- JSON.h - llzk-witgen JSON conversion helpers ------------*- 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//===----------------------------------------------------------------------===//
9
10#pragma once
11
12#include "ValueModel.h"
13#include "WitnessSelection.h"
14
15#include <llvm/Support/Error.h>
16#include <llvm/Support/JSON.h>
17
18namespace llzk::witgen {
19
21enum class SerializationMode : std::uint8_t {
24};
25
28 std::string path;
29 std::string message;
30};
31
33llvm::Expected<WitnessVal> parseJSONValue(
34 const llvm::json::Value *json, mlir::Type type, const llzk::Field &field,
35 mlir::Operation *origin
36);
37
39llvm::Expected<llvm::json::Value> serializeJSONValue(
40 const WitnessVal &value, mlir::Type type, mlir::SymbolTableCollection &tables,
41 mlir::Operation *origin, SerializationMode mode = SerializationMode::PublicOutputsOnly
42);
43
45llvm::Expected<llvm::json::Object> buildInputsJSONObject(
46 llvm::ArrayRef<InputBinding> bindings, llvm::ArrayRef<WitnessVal> values,
47 mlir::SymbolTableCollection &tables, mlir::Operation *origin
48);
49
51llvm::Expected<WitnessVal> extractValueAtPath(
52 const WitnessVal &root, mlir::Type rootType, llvm::ArrayRef<std::string> path,
53 mlir::SymbolTableCollection &tables, mlir::Operation *origin
54);
55
57void diffJSON(
58 const llvm::json::Value &expected, const llvm::json::Value &actual,
59 llvm::SmallVectorImpl<JSONMismatch> &out, llvm::StringRef path = "$"
60);
61
63void printJSONMismatches(llvm::raw_ostream &os, llvm::ArrayRef<JSONMismatch> mismatches);
64
65} // namespace llzk::witgen
Information about the prime finite field used for the interval analysis.
Definition Field.h:36
llvm::Expected< llvm::json::Object > buildInputsJSONObject(ArrayRef< InputBinding > bindings, ArrayRef< WitnessVal > values, SymbolTableCollection &tables, Operation *origin)
Serialize named input values into a JSON object.
Definition JSON.cpp:401
llvm::Expected< llvm::json::Value > serializeJSONValue(const WitnessVal &value, Type type, SymbolTableCollection &tables, Operation *origin, SerializationMode mode)
Serialize a supported LLZK runtime value into JSON.
Definition JSON.cpp:300
llvm::Expected< WitnessVal > extractValueAtPath(const WitnessVal &root, Type rootType, ArrayRef< std::string > path, SymbolTableCollection &tables, Operation *origin)
Extract one nested runtime leaf by path.
Definition JSON.cpp:422
void diffJSON(const llvm::json::Value &expected, const llvm::json::Value &actual, llvm::SmallVectorImpl< JSONMismatch > &out, llvm::StringRef path)
Compare two JSON values structurally and append any mismatches to out.
Definition JSON.cpp:473
SerializationMode
Select how struct values are filtered during JSON serialization.
Definition JSON.h:21
llvm::Expected< WitnessVal > parseJSONValue(const llvm::json::Value *json, Type type, const Field &field, Operation *origin)
Parse a supported LLZK input type from JSON.
Definition JSON.cpp:263
void printJSONMismatches(llvm::raw_ostream &os, llvm::ArrayRef< JSONMismatch > mismatches)
Render one human-readable mismatch report.
Definition JSON.cpp:504
std::variant< std::monostate, bool, int64_t, llvm::DynamicAPInt, ArrayValueRef, PodValueRef, StructValueRef > WitnessVal
Runtime value representation used by the tool-local interpreter.
Definition ValueModel.h:51
One structured JSON mismatch between expected and actual witgen output.
Definition JSON.h:27
std::string message
Definition JSON.h:29