CIRCT  20.0.0git
RTGModule.cpp
Go to the documentation of this file.
1 //===- RTGModule.cpp - RTG API pybind 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/PybindAdaptors.h"
14 
15 #include <pybind11/pybind11.h>
16 #include <pybind11/pytypes.h>
17 #include <pybind11/stl.h>
18 namespace py = pybind11;
19 
20 using namespace circt;
21 using namespace mlir::python::adaptors;
22 
23 /// Populate the rtg python module.
25  m.doc() = "RTG dialect Python native extension";
26 
27  mlir_type_subclass(m, "SequenceType", rtgTypeIsASequence)
28  .def_classmethod(
29  "get",
30  [](py::object cls, MlirContext ctxt) {
31  return cls(rtgSequenceTypeGet(ctxt));
32  },
33  py::arg("self"), py::arg("ctxt") = nullptr);
34 
35  mlir_type_subclass(m, "LabelType", rtgTypeIsALabel)
36  .def_classmethod(
37  "get",
38  [](py::object cls, MlirContext ctxt) {
39  return cls(rtgLabelTypeGet(ctxt));
40  },
41  py::arg("self"), py::arg("ctxt") = nullptr);
42 
43  mlir_type_subclass(m, "SetType", rtgTypeIsASet)
44  .def_classmethod(
45  "get",
46  [](py::object cls, MlirType elementType) {
47  return cls(rtgSetTypeGet(elementType));
48  },
49  py::arg("self"), py::arg("element_type"));
50 
51  mlir_type_subclass(m, "BagType", rtgTypeIsABag)
52  .def_classmethod(
53  "get",
54  [](py::object cls, MlirType elementType) {
55  return cls(rtgBagTypeGet(elementType));
56  },
57  py::arg("self"), py::arg("element_type"));
58 
59  mlir_type_subclass(m, "DictType", rtgTypeIsADict)
60  .def_classmethod(
61  "get",
62  [](py::object cls, MlirContext ctxt,
63  const std::vector<std::pair<MlirAttribute, MlirType>> &entries) {
64  std::vector<MlirAttribute> names;
65  std::vector<MlirType> types;
66  for (auto entry : entries) {
67  names.push_back(entry.first);
68  types.push_back(entry.second);
69  }
70  return cls(
71  rtgDictTypeGet(ctxt, types.size(), names.data(), types.data()));
72  },
73  py::arg("self"), py::arg("ctxt") = nullptr,
74  py::arg("entries") =
75  std::vector<std::pair<MlirAttribute, MlirType>>());
76 }
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(pybind11::module &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21