LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Dialect.cpp
Go to the documentation of this file.
1//===-- Dialect.cpp - Dialect method implementations ------------*- 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
12#include "llzk/Config/Config.h"
20
21#include <mlir/Bytecode/BytecodeImplementation.h>
22#include <mlir/IR/DialectImplementation.h>
23#include <mlir/Support/LLVM.h>
24
25#include <llvm/ADT/TypeSwitch.h>
26
27// TableGen'd implementation files
29
30// Need a complete declaration of storage classes for below
31#define GET_ATTRDEF_CLASSES
33
34using namespace mlir;
35using namespace llzk;
36
37//===------------------------------------------------------------------===//
38// LLZKDialect
39//===------------------------------------------------------------------===//
40
41namespace {
42
43LogicalResult verifyLlzkMainAttr(Operation *op, Attribute attr) {
44 ModuleOp moduleOp = llvm::dyn_cast<ModuleOp>(op);
45 if (!moduleOp) {
46 return op->emitError().append(
47 '"', MAIN_ATTR_NAME, "\" attribute can only be specified on '",
48 ModuleOp::getOperationName(), '\''
49 );
50 }
51
52 FailureOr<component::StructType> mainStructTypeOpt = getTypeFromLlzkMainAttr(moduleOp, attr);
53 if (succeeded(mainStructTypeOpt)) {
54 if (component::StructType st = mainStructTypeOpt.value()) {
55 SymbolTableCollection symbolTables;
56 return st.getDefinition(symbolTables, op);
57 }
58 }
59 return failure();
60}
61
62} // namespace
63
64LogicalResult LLZKDialect::verifyOperationAttribute(Operation *op, NamedAttribute attr) {
65 if (attr.getName() == MAIN_ATTR_NAME) {
66 return verifyLlzkMainAttr(op, attr.getValue());
67 }
68 return success();
69}
70
71auto LLZKDialect::initialize() -> void {
72 // clang-format off
73 // Suppress false positive from `clang-tidy`
74 // NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
75 addAttributes<
76 #define GET_ATTRDEF_LIST
78 >();
79
80 addOperations<
81 #define GET_OP_LIST
83 >();
84 // clang-format on
85 addInterfaces<LLZKDialectBytecodeInterface<LLZKDialect>>();
86}
::llvm::LogicalResult verifyOperationAttribute(::mlir::Operation *op, ::mlir::NamedAttribute attribute) override
Provides a hook for verifying dialect attributes attached to the given op.
Definition Dialect.cpp:64
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