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
33 mlir_type_subclass(m, "MemoryType", arcTypeIsAMemory)
34 .def_classmethod(
35 "get",
36 [](nb::object cls, unsigned numWords, MlirType wordType,
37 MlirType addressType) {
38 return cls(arcMemoryTypeGet(numWords, wordType, addressType));
39 },
40 nb::arg("cls"), nb::arg("num_words"), nb::arg("word_type"),
41 nb::arg("address_type"));
42
43 mlir_type_subclass(m, "StorageType", arcTypeIsAStorage)
44 .def_classmethod(
45 "get",
46 [](nb::object cls, MlirContext ctx, nb::object size) {
47 if (size.is_none())
48 return cls(arcStorageTypeGet(ctx));
49 return cls(
50 arcStorageTypeGetWithSize(ctx, nb::cast<unsigned>(size)));
51 },
52 nb::arg("cls"), nb::arg("context") = nb::none(),
53 nb::arg("size") = nb::none());
54
55 mlir_type_subclass(m, "SimModelInstanceType", arcTypeIsASimModelInstance)
56 .def_classmethod(
57 "get",
58 [](nb::object cls, MlirAttribute model) {
59 return cls(arcSimModelInstanceTypeGet(model));
60 },
61 nb::arg("cls"), nb::arg("model"));
62}
MLIR_CAPI_EXPORTED MlirType arcMemoryTypeGet(unsigned numWords, MlirType wordType, MlirType addressType)
Definition Arc.cpp:43
MLIR_CAPI_EXPORTED bool arcTypeIsASimModelInstance(MlirType type)
Definition Arc.cpp:63
MLIR_CAPI_EXPORTED MlirType arcStateTypeGetType(MlirType type)
Definition Arc.cpp:35
MLIR_CAPI_EXPORTED bool arcTypeIsAState(MlirType type)
Definition Arc.cpp:27
MLIR_CAPI_EXPORTED MlirType arcStorageTypeGet(MlirContext ctx)
Definition Arc.cpp:55
MLIR_CAPI_EXPORTED MlirType arcSimModelInstanceTypeGet(MlirAttribute model)
Definition Arc.cpp:67
MLIR_CAPI_EXPORTED MlirType arcStorageTypeGetWithSize(MlirContext ctx, unsigned size)
Definition Arc.cpp:59
MLIR_CAPI_EXPORTED bool arcTypeIsAMemory(MlirType type)
Definition Arc.cpp:39
MLIR_CAPI_EXPORTED bool arcTypeIsAStorage(MlirType type)
Definition Arc.cpp:51
MLIR_CAPI_EXPORTED MlirType arcStateTypeGet(MlirType innerType)
Definition Arc.cpp:31
void populateDialectArcSubmodule(nanobind::module_ &m)