LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
OpCAPIParamHelper.cpp
Go to the documentation of this file.
1//===- OpCAPIParamHelper.cpp ----------------------------------------------===//
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#include "OpCAPIParamHelper.h"
11
12#include <mlir/TableGen/Operator.h>
13
14#include <llvm/Support/FormatVariadic.h>
15
16#include "CommonCAPIGen.h"
17
18std::string GenStringFromOpPieces::gen(const mlir::tblgen::Operator &op) {
19 std::string params;
20 llvm::raw_string_ostream oss(params);
21 genHeader(oss);
22 if (!op.allResultTypesKnown()) {
23 // If result types are not inferred, call handler for each result
24 for (auto [i, result] : llvm::enumerate(op.getResults())) {
25 llvm::StringRef name = result.name;
26 genResult(oss, result, name.empty() ? llvm::formatv("result{0}", i).str() : name.str());
27 }
28 } else {
29 // Otherewise, call inferred result handler
31 }
32 for (const mlir::tblgen::NamedTypeConstraint &operand : op.getOperands()) {
33 genOperand(oss, operand);
34 }
35 {
36 auto attrs = op.getAttributes();
37 if (!attrs.empty()) {
38 genAttributesPrefix(oss, op);
39 for (const mlir::tblgen::NamedAttribute &namedAttr : attrs) {
40 genAttribute(oss, namedAttr);
41 }
42 genAttributesSuffix(oss, op);
43 }
44 }
45 {
46 auto regions = op.getRegions();
47 if (!regions.empty()) {
48 genRegionsPrefix(oss, op);
49 for (const mlir::tblgen::NamedRegion &region : regions) {
50 genRegion(oss, region);
51 }
52 genRegionsSuffix(oss, op);
53 }
54 }
55 return params;
56}
virtual void genRegionsSuffix(llvm::raw_ostream &os, const mlir::tblgen::Operator &op)
Generate region section suffix code to os. Default does nothing.
virtual void genOperand(llvm::raw_ostream &os, const mlir::tblgen::NamedTypeConstraint &operand)=0
Generate code for operand to os.
std::string gen(const mlir::tblgen::Operator &op)
Generate string from the operation pieces.
virtual void genAttributesSuffix(llvm::raw_ostream &os, const mlir::tblgen::Operator &op)
Generate attribute section suffix code to os. Default does nothing.
virtual void genResultInferred(llvm::raw_ostream &os)
Generate code to os when result type is inferred. Default does nothing.
virtual void genHeader(llvm::raw_ostream &os)
Generate header code to os. Default does nothing.
virtual void genRegion(llvm::raw_ostream &os, const mlir::tblgen::NamedRegion &region)=0
Generate code for region to os.
virtual void genAttributesPrefix(llvm::raw_ostream &os, const mlir::tblgen::Operator &op)
Generate attribute section prefix code to os. Default does nothing.
virtual void genResult(llvm::raw_ostream &os, const mlir::tblgen::NamedTypeConstraint &result, const std::string &resultName)=0
Generate code for result to os.
virtual void genAttribute(llvm::raw_ostream &os, const mlir::tblgen::NamedAttribute &attr)=0
Generate code for attr to os.
virtual void genRegionsPrefix(llvm::raw_ostream &os, const mlir::tblgen::Operator &op)
Generate region section prefix code to os. Default does nothing.