LLZK 2.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
AttributeHelper.cpp
Go to the documentation of this file.
1//===-- AttributeHelper.cpp -------------------------------------*- 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
11
13
14using namespace mlir;
15
16namespace llzk {
17
18// Adapted from AsmPrinter::printStrippedAttrOrType(), but without printing type.
19void printAttrs(AsmPrinter &printer, ArrayRef<Attribute> attrs, const StringRef &separator) {
20 llvm::interleave(attrs, printer.getStream(), [&printer](Attribute a) {
21 if (auto intAttr = mlir::dyn_cast_if_present<IntegerAttr>(a)) {
22 if (isDynamic(intAttr)) {
23 printer.getStream() << "?";
24 return;
25 }
26 }
27 if (succeeded(printer.printAlias(a))) {
28 return;
29 }
30 raw_ostream &os = printer.getStream();
31 uint64_t posPrior = os.tell();
32 printer.printAttributeWithoutType(a);
33 // Fallback to printing with prefix if the above failed to write anything to the output stream.
34 if (posPrior == os.tell()) {
35 printer << a;
36 }
37 }, separator);
38}
39
40} // namespace llzk
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)