CIRCT 22.0.0git
Loading...
Searching...
No Matches
ArcModule.cpp
Go to the documentation of this file.
1//===- ArcModule.cpp - Arc 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/Arc.h"
12#include "mlir-c/IR.h"
13#include "mlir/Bindings/Python/NanobindAdaptors.h"
14
15#include <nanobind/nanobind.h>
16namespace nb = nanobind;
17
18using namespace mlir::python::nanobind_adaptors;
19
21 m.doc() = "Arc dialect Python native extension";
22
23 mlir_type_subclass(m, "StateType", arcTypeIsAState)
24 .def_classmethod(
25 "get",
26 [](nb::object cls, MlirType innerType) {
27 return cls(arcStateTypeGet(innerType));
28 },
29 nb::arg("cls"), nb::arg("inner_type"))
30 .def_property_readonly(
31 "type", [](MlirType self) { return arcStateTypeGetType(self); })
32 .def_property_readonly(
33 "bit_width",
34 [](MlirType self) { return arcStateTypeGetBitWidth(self); })
35 .def_property_readonly("byte_width", [](MlirType self) {
36 return arcStateTypeGetByteWidth(self);
37 });
38
39 mlir_type_subclass(m, "MemoryType", arcTypeIsAMemory)
40 .def_classmethod(
41 "get",
42 [](nb::object cls, unsigned numWords, MlirType wordType,
43 MlirType addressType) {
44 return cls(arcMemoryTypeGet(numWords, wordType, addressType));
45 },
46 nb::arg("cls"), nb::arg("num_words"), nb::arg("word_type"),
47 nb::arg("address_type"))
48 .def_property_readonly(
49 "num_words",
50 [](MlirType self) { return arcMemoryTypeGetNumWords(self); })
51 .def_property_readonly(
52 "word_type",
53 [](MlirType self) { return arcMemoryTypeGetWordType(self); })
54 .def_property_readonly(
55 "address_type",
56 [](MlirType self) { return arcMemoryTypeGetAddressType(self); })
57 .def_property_readonly(
58 "stride", [](MlirType self) { return arcMemoryTypeGetStride(self); });
59
60 mlir_type_subclass(m, "StorageType", arcTypeIsAStorage)
61 .def_classmethod(
62 "get",
63 [](nb::object cls, MlirContext ctx, nb::object size) {
64 if (size.is_none())
65 return cls(arcStorageTypeGet(ctx));
66 return cls(
67 arcStorageTypeGetWithSize(ctx, nb::cast<unsigned>(size)));
68 },
69 nb::arg("cls"), nb::arg("context") = nb::none(),
70 nb::arg("size") = nb::none())
71 .def_property_readonly(
72 "size", [](MlirType self) { return arcStorageTypeGetSize(self); });
73
74 mlir_type_subclass(m, "SimModelInstanceType", arcTypeIsASimModelInstance)
75 .def_classmethod(
76 "get",
77 [](nb::object cls, MlirAttribute model) {
78 return cls(arcSimModelInstanceTypeGet(model));
79 },
80 nb::arg("cls"), nb::arg("model"))
81 .def_property_readonly("model", [](MlirType self) {
83 });
84}
MLIR_CAPI_EXPORTED MlirType arcMemoryTypeGet(unsigned numWords, MlirType wordType, MlirType addressType)
Definition Arc.cpp:51
MLIR_CAPI_EXPORTED bool arcTypeIsASimModelInstance(MlirType type)
Definition Arc.cpp:91
MLIR_CAPI_EXPORTED MlirType arcStateTypeGetType(MlirType type)
Definition Arc.cpp:35
MLIR_CAPI_EXPORTED unsigned arcMemoryTypeGetNumWords(MlirType type)
Definition Arc.cpp:59
MLIR_CAPI_EXPORTED unsigned arcStateTypeGetBitWidth(MlirType type)
Definition Arc.cpp:39
MLIR_CAPI_EXPORTED MlirType arcMemoryTypeGetAddressType(MlirType type)
Definition Arc.cpp:67
MLIR_CAPI_EXPORTED MlirType arcMemoryTypeGetWordType(MlirType type)
Definition Arc.cpp:63
MLIR_CAPI_EXPORTED bool arcTypeIsAState(MlirType type)
Definition Arc.cpp:27
MLIR_CAPI_EXPORTED MlirType arcStorageTypeGet(MlirContext ctx)
Definition Arc.cpp:79
MLIR_CAPI_EXPORTED MlirType arcSimModelInstanceTypeGet(MlirAttribute model)
Definition Arc.cpp:95
MLIR_CAPI_EXPORTED unsigned arcStorageTypeGetSize(MlirType type)
Definition Arc.cpp:87
MLIR_CAPI_EXPORTED unsigned arcStateTypeGetByteWidth(MlirType type)
Definition Arc.cpp:43
MLIR_CAPI_EXPORTED MlirType arcStorageTypeGetWithSize(MlirContext ctx, unsigned size)
Definition Arc.cpp:83
MLIR_CAPI_EXPORTED bool arcTypeIsAMemory(MlirType type)
Definition Arc.cpp:47
MLIR_CAPI_EXPORTED bool arcTypeIsAStorage(MlirType type)
Definition Arc.cpp:75
MLIR_CAPI_EXPORTED MlirType arcStateTypeGet(MlirType innerType)
Definition Arc.cpp:31
MLIR_CAPI_EXPORTED MlirAttribute arcSimModelInstanceTypeGetModel(MlirType type)
Definition Arc.cpp:100
MLIR_CAPI_EXPORTED unsigned arcMemoryTypeGetStride(MlirType type)
Definition Arc.cpp:71
void populateDialectArcSubmodule(nanobind::module_ &m)