Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Bindings/Python/IRCore.cpp
Show First 20 Lines • Show All 1,839 Lines • ▼ Show 20 Lines | PyNamedAttribute dunderGetItemIndexed(intptr_t index) { | ||||
if (index < 0 || index >= dunderLen()) { | if (index < 0 || index >= dunderLen()) { | ||||
throw SetPyError(PyExc_IndexError, | throw SetPyError(PyExc_IndexError, | ||||
"attempt to access out of bounds attribute"); | "attempt to access out of bounds attribute"); | ||||
} | } | ||||
MlirNamedAttribute namedAttr = | MlirNamedAttribute namedAttr = | ||||
mlirOperationGetAttribute(operation->get(), index); | mlirOperationGetAttribute(operation->get(), index); | ||||
return PyNamedAttribute( | return PyNamedAttribute( | ||||
namedAttr.attribute, | namedAttr.attribute, | ||||
std::string(mlirIdentifierStr(namedAttr.name).data)); | std::string(mlirIdentifierStr(namedAttr.name).data, | ||||
mlirIdentifierStr(namedAttr.name).length)); | |||||
} | } | ||||
void dunderSetItem(const std::string &name, PyAttribute attr) { | void dunderSetItem(const std::string &name, PyAttribute attr) { | ||||
mlirOperationSetAttributeByName(operation->get(), toMlirStringRef(name), | mlirOperationSetAttributeByName(operation->get(), toMlirStringRef(name), | ||||
attr); | attr); | ||||
} | } | ||||
void dunderDelItem(const std::string &name) { | void dunderDelItem(const std::string &name) { | ||||
▲ Show 20 Lines • Show All 739 Lines • ▼ Show 20 Lines | void mlir::python::populateIRCore(py::module &m) { | ||||
// Mapping of PyNamedAttribute | // Mapping of PyNamedAttribute | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
py::class_<PyNamedAttribute>(m, "NamedAttribute", py::module_local()) | py::class_<PyNamedAttribute>(m, "NamedAttribute", py::module_local()) | ||||
.def("__repr__", | .def("__repr__", | ||||
[](PyNamedAttribute &self) { | [](PyNamedAttribute &self) { | ||||
PyPrintAccumulator printAccum; | PyPrintAccumulator printAccum; | ||||
printAccum.parts.append("NamedAttribute("); | printAccum.parts.append("NamedAttribute("); | ||||
printAccum.parts.append( | printAccum.parts.append( | ||||
mlirIdentifierStr(self.namedAttr.name).data); | py::str(mlirIdentifierStr(self.namedAttr.name).data, | ||||
mlirIdentifierStr(self.namedAttr.name).length)); | |||||
printAccum.parts.append("="); | printAccum.parts.append("="); | ||||
mlirAttributePrint(self.namedAttr.attribute, | mlirAttributePrint(self.namedAttr.attribute, | ||||
printAccum.getCallback(), | printAccum.getCallback(), | ||||
printAccum.getUserData()); | printAccum.getUserData()); | ||||
printAccum.parts.append(")"); | printAccum.parts.append(")"); | ||||
return printAccum.join(); | return printAccum.join(); | ||||
}) | }) | ||||
.def_property_readonly( | .def_property_readonly( | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |