LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Attrs.cpp
Go to the documentation of this file.
1//===-- Attrs.cpp -----------------------------------------------*- 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
11
13#include "llzk/Util/Constants.h"
15
16#include <mlir/IR/BuiltinAttributes.h>
17
18using namespace mlir;
19
20namespace llzk {
21
22using namespace component;
23
24FailureOr<StructType> getTypeFromLlzkMainAttr(ModuleOp op, Attribute attr) {
25 assert(op); // pre-condition
26 assert(attr); // pre-condition
27
28 // If the attribute is present, it must be a TypeAttr of concrete StructType.
29 if (TypeAttr ta = llvm::dyn_cast<TypeAttr>(attr)) {
30 if (auto st = llvm::dyn_cast<StructType>(ta.getValue())) {
31 if (isConcreteType(st)) {
32 return success(st);
33 }
34 }
35 }
36 return op->emitError().append(
37 '"', MAIN_ATTR_NAME, "\" on module must be a concrete '", StructType::name,
38 "' attribute. Found: ", attr
39 );
40}
41
42} // namespace llzk
static constexpr ::llvm::StringLiteral name
Definition Types.h.inc:38
bool isConcreteType(Type type, bool allowStructParams)
FailureOr< StructType > getTypeFromLlzkMainAttr(ModuleOp op, Attribute attr)
Definition Attrs.cpp:24
constexpr char MAIN_ATTR_NAME[]
Name of the attribute on the top-level ModuleOp that specifies the type of the main struct.
Definition Constants.h:37