},
py::arg("name"), py::arg("childLoc") = py::none(),
py::arg("context") = py::none(), kContextGetNameLocationDocString)
+ .def_static(
+ "from_attr",
+ [](PyAttribute &attribute, DefaultingPyMlirContext context) {
+ return PyLocation(context->getRef(),
+ mlirLocationFromAttribute(attribute));
+ },
+ py::arg("attribute"), py::arg("context") = py::none(),
+ "Gets a Location from a LocationAttr")
.def_property_readonly(
"context",
[](PyLocation &self) { return self.getContext().getObject(); },
"Context that owns the Location")
+ .def_property_readonly(
+ "attr",
+ [](PyLocation &self) {
+ return PyAttribute(self.getContext(),
+ mlirLocationGetAttribute(self));
+ },
+ "Get the underlying LocationAttr")
.def(
"emit_error",
[](PyLocation &self, std::string message) {
run(testUnknown)
+# CHECK-LABEL: TEST: testLocationAttr
+def testLocationAttr():
+ with Context() as ctxt:
+ loc = Location.unknown()
+ attr = loc.get_attr()
+ clone = Location.from_attr(attr)
+ gc.collect()
+ # CHECK: loc: loc(unknown)
+ print("loc:", str(loc))
+ # CHECK: clone: loc(unknown)
+ print("clone:", str(clone))
+ assert loc == clone
+
+run(testLocationAttr)
+
# CHECK-LABEL: TEST: testFileLineCol
def testFileLineCol():
with Context() as ctx: