[Mlir-commits] [mlir] [mlir][python] Expose AsmState python side. (PR #66819)

Maksim Levental llvmlistbot at llvm.org
Tue Sep 19 14:49:27 PDT 2023


================
@@ -748,6 +748,31 @@ class PyRegion {
   MlirRegion region;
 };
 
+/// Wrapper around an MlirAsmState.
+class PyAsmState {
+ public:
+  PyAsmState(MlirValue value, bool useLocalScope) {
+    flags = mlirOpPrintingFlagsCreate();
+    // The OpPrintingFlags are not exposed Python side, create locally and
+    // associate lifetime with the state.
+    if (useLocalScope)
+      mlirOpPrintingFlagsUseLocalScope(flags);
+    state = mlirAsmStateCreateForValue(value, flags);
+  }
+  ~PyAsmState() {
+    mlirOpPrintingFlagsDestroy(flags);
+  }
+  // Delete copy constructors.
+  PyAsmState(PyAsmState &other) = delete;
+  PyAsmState(const PyAsmState &other) = delete;
----------------
makslevental wrote:

just for my own edification about "best practices" - is the de facto reason for this so that there's no references hanging around to something e.g., the `MlirAsmState state`?

https://github.com/llvm/llvm-project/pull/66819


More information about the Mlir-commits mailing list