LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
StreamHelper.h
Go to the documentation of this file.
1
//===-- StreamHelper.h ------------------------------------------*- 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
//===----------------------------------------------------------------------===//
9
10
#pragma once
11
12
#include <llvm/Support/raw_ostream.h>
13
14
namespace
llzk
{
15
17
class
filtered_raw_ostream
:
public
llvm::raw_ostream {
18
llvm::raw_ostream &underlyingStream;
19
std::function<bool(
char
)> filterFunc;
20
21
void
write_impl(
const
char
*ptr,
size_t
size)
override
{
22
for
(
size_t
i = 0; i < size; ++i) {
23
if
(!filterFunc(ptr[i])) {
24
underlyingStream << ptr[i];
25
}
26
}
27
}
28
29
uint64_t current_pos()
const override
{
return
underlyingStream.tell(); }
30
31
public
:
32
filtered_raw_ostream
(llvm::raw_ostream &os, std::function<
bool
(
char
)> filter)
33
: underlyingStream(os), filterFunc(std::move(filter)) {}
34
35
// Moved to a separate file to avoid a weak vtable error.
36
~filtered_raw_ostream
()
override
;
37
};
38
41
template
<
typename
Func,
typename
... Args>
42
inline
std::string
buildStringViaCallback
(Func &&appendFn, Args &&...args) {
43
std::string output;
44
llvm::raw_string_ostream oss(output);
45
std::invoke(std::forward<Func>(appendFn), oss, std::forward<Args>(args)...);
46
return
output;
47
}
48
51
template
<
typename
T,
typename
... Args>
52
inline
std::string
buildStringViaPrint
(
const
T &base, Args &&...args) {
53
return
buildStringViaCallback
([&](llvm::raw_ostream &ss,
const
T &b) {
54
b.print(ss, std::forward<Args>(args)...);
55
}, base);
56
}
57
60
template
<
typename
... Args>
inline
std::string
buildStringViaInsertionOp
(Args &&...args) {
61
std::string output;
62
llvm::raw_string_ostream oss(output);
63
(oss << ... << std::forward<Args>(args));
64
return
output;
65
}
66
67
}
// namespace llzk
llzk::filtered_raw_ostream::~filtered_raw_ostream
~filtered_raw_ostream() override
Definition
StreamHelper.cpp:15
llzk::filtered_raw_ostream::filtered_raw_ostream
filtered_raw_ostream(llvm::raw_ostream &os, std::function< bool(char)> filter)
Definition
StreamHelper.h:32
llzk
Definition
AnalysisPassEnums.cpp:19
llzk::buildStringViaPrint
std::string buildStringViaPrint(const T &base, Args &&...args)
Generate a string by calling base.print(llvm::raw_ostream &) on a stream backed by the returned strin...
Definition
StreamHelper.h:52
llzk::buildStringViaInsertionOp
std::string buildStringViaInsertionOp(Args &&...args)
Generate a string by using the insertion operator (<<) to append all args to a stream backed by the r...
Definition
StreamHelper.h:60
llzk::buildStringViaCallback
std::string buildStringViaCallback(Func &&appendFn, Args &&...args)
Generate a string by calling the given appendFn with an llvm::raw_ostream & as the first argument fol...
Definition
StreamHelper.h:42
include
llzk
Util
StreamHelper.h
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.