CIRCT 20.0.0git
Loading...
Searching...
No Matches
RTGModule.cpp
Go to the documentation of this file.
1//===- RTGModule.cpp - RTG API nanobind module ----------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CIRCTModules.h"
10
11#include "circt-c/Dialect/RTG.h"
12
13#include "mlir/Bindings/Python/NanobindAdaptors.h"
14
15#include <nanobind/nanobind.h>
16
17namespace nb = nanobind;
18
19using namespace circt;
20using namespace mlir::python::nanobind_adaptors;
21
22/// Populate the rtg python module.
24 m.doc() = "RTG dialect Python native extension";
25
26 mlir_type_subclass(m, "SequenceType", rtgTypeIsASequence)
27 .def_classmethod(
28 "get",
29 [](nb::object cls, MlirContext ctxt) {
30 return cls(rtgSequenceTypeGet(ctxt));
31 },
32 nb::arg("self"), nb::arg("ctxt") = nullptr);
33
34 mlir_type_subclass(m, "LabelType", rtgTypeIsALabel)
35 .def_classmethod(
36 "get",
37 [](nb::object cls, MlirContext ctxt) {
38 return cls(rtgLabelTypeGet(ctxt));
39 },
40 nb::arg("self"), nb::arg("ctxt") = nullptr);
41
42 mlir_type_subclass(m, "SetType", rtgTypeIsASet)
43 .def_classmethod(
44 "get",
45 [](nb::object cls, MlirType elementType) {
46 return cls(rtgSetTypeGet(elementType));
47 },
48 nb::arg("self"), nb::arg("element_type"));
49
50 mlir_type_subclass(m, "BagType", rtgTypeIsABag)
51 .def_classmethod(
52 "get",
53 [](nb::object cls, MlirType elementType) {
54 return cls(rtgBagTypeGet(elementType));
55 },
56 nb::arg("self"), nb::arg("element_type"));
57
58 mlir_type_subclass(m, "DictType", rtgTypeIsADict)
59 .def_classmethod(
60 "get",
61 [](nb::object cls, MlirContext ctxt,
62 const std::vector<std::pair<MlirAttribute, MlirType>> &entries) {
63 std::vector<MlirAttribute> names;
64 std::vector<MlirType> types;
65 for (auto entry : entries) {
66 names.push_back(entry.first);
67 types.push_back(entry.second);
68 }
69 return cls(
70 rtgDictTypeGet(ctxt, types.size(), names.data(), types.data()));
71 },
72 nb::arg("self"), nb::arg("ctxt") = nullptr,
73 nb::arg("entries") =
74 std::vector<std::pair<MlirAttribute, MlirType>>());
75}
MlirType elementType
Definition CHIRRTL.cpp:29
MLIR_CAPI_EXPORTED MlirType rtgLabelTypeGet(MlirContext ctxt)
Creates an RTG mode type in the context.
Definition RTG.cpp:44
MLIR_CAPI_EXPORTED bool rtgTypeIsABag(MlirType type)
If the type is an RTG bag.
Definition RTG.cpp:61
MLIR_CAPI_EXPORTED MlirType rtgSetTypeGet(MlirType elementType)
Creates an RTG set type in the context.
Definition RTG.cpp:53
MLIR_CAPI_EXPORTED bool rtgTypeIsASet(MlirType type)
If the type is an RTG set.
Definition RTG.cpp:51
MLIR_CAPI_EXPORTED bool rtgTypeIsADict(MlirType type)
If the type is an RTG dict.
Definition RTG.cpp:71
MLIR_CAPI_EXPORTED MlirType rtgSequenceTypeGet(MlirContext ctxt)
Creates an RTG sequence type in the context.
Definition RTG.cpp:35
MLIR_CAPI_EXPORTED MlirType rtgDictTypeGet(MlirContext ctxt, intptr_t numEntries, MlirAttribute const *entryNames, MlirType const *entryTypes)
Creates an RTG dict type in the context.
Definition RTG.cpp:73
MLIR_CAPI_EXPORTED MlirType rtgBagTypeGet(MlirType elementType)
Creates an RTG bag type in the context.
Definition RTG.cpp:63
MLIR_CAPI_EXPORTED bool rtgTypeIsASequence(MlirType type)
If the type is an RTG sequence.
Definition RTG.cpp:31
MLIR_CAPI_EXPORTED bool rtgTypeIsALabel(MlirType type)
If the type is an RTG label.
Definition RTG.cpp:42
void populateDialectRTGSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.