12#include "mlir-c/Bindings/Python/Interop.h"
14#include "mlir/Bindings/Python/NanobindAdaptors.h"
15#include "mlir/CAPI/IR.h"
16#include "mlir/CAPI/Support.h"
18#include "llvm/ADT/SmallVector.h"
21#include <nanobind/nanobind.h>
22#include <nanobind/stl/string.h>
25using namespace mlir::python::nanobind_adaptors;
28 m.doc() =
"SV Python Native Extension";
33 [](nb::object cls, std::string name, nb::object expressionObj,
34 nb::object emitAsCommentObj, MlirContext ctxt) {
36 bool emitAsComment =
false;
37 if (!emitAsCommentObj.is_none())
38 emitAsComment = nb::cast<bool>(emitAsCommentObj);
42 MlirStringRef expression = {
nullptr, 0};
43 if (!expressionObj.is_none()) {
44 expr = nb::cast<std::string>(expressionObj);
45 expression = mlirStringRefCreateFromCString(expr.c_str());
48 ctxt, mlirStringRefCreateFromCString(name.c_str()), expression,
51 "Create a SystemVerilog attribute", nb::arg(), nb::arg(
"name"),
52 nb::arg(
"expression") = nb::none(),
53 nb::arg(
"emit_as_comment") = nb::none(), nb::arg(
"ctxt") = nb::none())
54 .def_property_readonly(
"name",
55 [](MlirAttribute self) {
58 return std::string(name.data, name.length);
60 .def_property_readonly(
"expression",
61 [](MlirAttribute self) -> nb::object {
64 if (name.data ==
nullptr)
66 return nb::str(name.data, name.length);
68 .def_property_readonly(
"emit_as_comment", [](MlirAttribute self) {
MLIR_CAPI_EXPORTED MlirAttribute svSVAttributeAttrGet(MlirContext, MlirStringRef name, MlirStringRef expression, bool emitAsComment)
MLIR_CAPI_EXPORTED MlirStringRef svSVAttributeAttrGetExpression(MlirAttribute)
MLIR_CAPI_EXPORTED bool svSVAttributeAttrGetEmitAsComment(MlirAttribute)
MLIR_CAPI_EXPORTED bool svAttrIsASVAttributeAttr(MlirAttribute)
MLIR_CAPI_EXPORTED MlirStringRef svSVAttributeAttrGetName(MlirAttribute)
void populateDialectSVSubmodule(nanobind::module_ &m)