LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
AttributeHelper.h
Go to the documentation of this file.
1//===-- AttributeHelper.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
13
14#include <mlir/IR/DialectImplementation.h>
15
16#include <llvm/ADT/APInt.h>
17
18template <> struct mlir::FieldParser<llvm::APInt> {
19 static mlir::FailureOr<llvm::APInt> parse(mlir::AsmParser &parser) {
20 auto loc = parser.getCurrentLocation();
21 llvm::APInt val;
22 auto result = parser.parseOptionalInteger(val);
23 if (!result.has_value() || *result) {
24 return parser.emitError(loc, "expected integer value");
25 } else {
26 return val;
27 }
28 }
29};
30
31namespace llzk {
32
33inline llvm::APInt toAPInt(int64_t i) { return llvm::APInt(64, i); }
34inline int64_t fromAPInt(llvm::APInt i) { return i.getZExtValue(); }
35
36inline bool isNullOrEmpty(mlir::ArrayAttr a) { return !a || a.empty(); }
37inline bool isNullOrEmpty(mlir::DenseArrayAttr a) { return !a || a.empty(); }
38inline bool isNullOrEmpty(mlir::DictionaryAttr a) { return !a || a.empty(); }
39
40inline void appendWithoutType(mlir::raw_ostream &os, mlir::Attribute a) { a.print(os, true); }
41inline std::string stringWithoutType(mlir::Attribute a) {
43}
44
46 mlir::AsmPrinter &printer, mlir::ArrayRef<mlir::Attribute> attrs,
47 const mlir::StringRef &separator
48);
49
50} // namespace llzk
llvm::APInt toAPInt(int64_t i)
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)
std::string stringWithoutType(mlir::Attribute a)
bool isNullOrEmpty(mlir::ArrayAttr a)
void appendWithoutType(mlir::raw_ostream &os, mlir::Attribute a)
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...
int64_t fromAPInt(llvm::APInt i)
static mlir::FailureOr< llvm::APInt > parse(mlir::AsmParser &parser)