[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
================
@@ -3425,19 +3425,35 @@ void mlir::python::populateIRCore(py::module &m) {
kValueDunderStrDocstring)
.def(
"get_name",
- [](PyValue &self, bool useLocalScope) {
+ [](PyValue &self, std::optional<bool> useLocalScope,
+ std::optional<std::reference_wrapper<PyAsmState>> state) {
PyPrintAccumulator printAccum;
- MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
- if (useLocalScope)
- mlirOpPrintingFlagsUseLocalScope(flags);
- MlirAsmState state = mlirAsmStateCreateForValue(self.get(), flags);
- mlirValuePrintAsOperand(self.get(), state, printAccum.getCallback(),
+ MlirOpPrintingFlags flags;
+ MlirAsmState valueState;
+ // Use state if provided, else create a new state.
+ if (state) {
+ valueState = state.value().get().get();
+ // Don't allow setting using local scope and state at same time.
+ if (useLocalScope)
----------------
makslevental wrote:
won't this be truthy even if user passes in a `False` (since the `std::optional` will actually contain a `bool` value instead of `nullopt`)? Maybe `std::optional` delegates to the truthiness of the contained value when there is one...
https://github.com/llvm/llvm-project/pull/66819
More information about the Mlir-commits
mailing list