LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
AttrCAPIGen.cpp
Go to the documentation of this file.
1//===- AttrCAPIGen.cpp - C API generator for attributes -------------------===//
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// AttrCAPIGen uses the description of attributes to generate C API for the attrs.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CAPIGenRegistration.h"
16#include "CommonCAPIGen.h"
17
18#include <mlir/TableGen/AttrOrTypeDef.h>
19#include <mlir/TableGen/GenInfo.h>
20
21#include <llvm/Support/CommandLine.h>
22#include <llvm/Support/FormatVariadic.h>
23#include <llvm/TableGen/Record.h>
24#include <llvm/TableGen/TableGenBackend.h>
25
26using namespace mlir;
27using namespace mlir::tblgen;
28
30static bool emitAttrCAPIHeader(const llvm::RecordKeeper &records, raw_ostream &os) {
31 emitSourceFileHeader("Attr C API Declarations", os, records);
32
33 AttrOrTypeHeaderGenerator generator("Attribute", os);
34 generator.genPrologue();
35
36 for (const auto *def : records.getAllDerivedDefinitions("AttrDef")) {
37 const AttrOrTypeDef attr(def);
38 generator.genCompleteRecord(attr);
39 }
40
41 generator.genEpilogue();
42 return false;
43}
44
46static bool emitAttrCAPIImpl(const llvm::RecordKeeper &records, raw_ostream &os) {
47 emitSourceFileHeader("Attr C API Implementations", os, records);
48
49 AttrOrTypeImplementationGenerator generator("Attribute", os);
50 generator.genPrologue();
51
52 for (const auto *def : records.getAllDerivedDefinitions("AttrDef")) {
53 const AttrOrTypeDef attr(def);
54 generator.genCompleteRecord(attr);
55 }
56
57 return false;
58}
59
61 static mlir::GenRegistration genAttrCAPIHeader(
62 "gen-attr-capi-header", "Generate attribute C API header declarations", &emitAttrCAPIHeader
63 );
64
65 static mlir::GenRegistration genAttrCAPIImpl(
66 "gen-attr-capi-impl", "Generate attribute C API implementations", &emitAttrCAPIImpl
67 );
68}
void registerAttrCAPIGenerators()
Register the attribute C API generators before command-line parsing.
Generator for attribute/type C header files.
Generator for attribute/type C implementation files.