LLZK 0.1.0
Veridise's ZK Language IR
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"
16
17include "mlir/IR/OpBase.td"
18include "mlir/Interfaces/SideEffectInterfaces.td"
19include "mlir/IR/SymbolInterfaces.td"
20
21def LLZK_IntToFeltOp : Op<CastDialect, "tofelt", [Pure]> {
22 let summary = "convert an integer into a field element";
23 let description = [{
24 This operation converts a supported integer type value into a field element value.
25
26 Example:
27
28 ```llzk
29 %0 = bool.cmp lt(%a, %b)
30 %1 = cast.tofelt %0 : i1
31 ```
32 }];
33
34 let arguments = (ins AnyLLZKIntType:$value);
35 let results = (outs LLZK_FeltType:$result);
36 let assemblyFormat = [{ $value `:` type($value) attr-dict }];
37}
38
39def LLZK_FeltToIndexOp : Op<CastDialect, "toindex", [Pure]> {
40 let summary = "convert a field element into an index";
41 let description = [{
42 This operation converts a field element value into an index value to allow
43 use as an array index or loop bound. In struct @constrain functions, the
44 argument to this op is not allowed to be derived from a Signal struct.
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 let hasVerifier = 1;
58}
59
60#endif // LLZK_CAST_OPS