LLZK 0.1.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Ops.td
Go to the documentation of this file.
1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
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#ifndef LLZK_CAST_OPS
11#define LLZK_CAST_OPS
12
13include "llzk/Dialect/Shared/Types.td"
14include "llzk/Dialect/Cast/IR/Dialect.td"
15include "llzk/Dialect/Felt/IR/Types.td"
16include "llzk/Dialect/Function/IR/OpTraits.td"
17
18include "mlir/IR/OpBase.td"
19include "mlir/Interfaces/SideEffectInterfaces.td"
20include "mlir/IR/SymbolInterfaces.td"
21
22def LLZK_IntToFeltOp : Op<CastDialect, "tofelt", [Pure]> {
23 let summary = "convert an integer into a field element";
24 let description = [{
25 This operation converts a supported integer type value into a field element value.
26
27 Example:
28
29 ```llzk
30 %0 = bool.cmp lt(%a, %b)
31 %1 = cast.tofelt %0 : i1
32 ```
33 }];
34
35 let arguments = (ins AnyLLZKIntType:$value);
36 let results = (outs LLZK_FeltType:$result);
37 let assemblyFormat = [{ $value `:` type($value) attr-dict }];
38}
39
40def LLZK_FeltToIndexOp : Op<CastDialect, "toindex", [Pure, NotFieldNative]> {
41 let summary = "convert a field element into an index";
42 let description = [{
43 This operation converts a field element value into an index value to allow use
44 as an array index or loop bound.
45
46 Example:
47 ```llzk
48 %0 = cast.toindex %a
49 %1 = array.read %b[%0]
50 ```
51 }];
52
53 let arguments = (ins LLZK_FeltType:$value);
54 let results = (outs Index:$result);
55 let assemblyFormat = [{ $value attr-dict }];
56}
57
58#endif // LLZK_CAST_OPS