@@ -64,7 +64,7 @@ static nanobind::object mlirApiObjectToCapsule(nanobind::handle apiObject) {
64
64
// / Casts object <-> MlirAffineMap.
65
65
template <>
66
66
struct type_caster <MlirAffineMap> {
67
- NB_TYPE_CASTER (MlirAffineMap, const_name(" MlirAffineMap" ));
67
+ NB_TYPE_CASTER (MlirAffineMap, const_name(" MlirAffineMap" ))
68
68
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
69
69
nanobind::object capsule = mlirApiObjectToCapsule (src);
70
70
value = mlirPythonCapsuleToAffineMap (capsule.ptr ());
@@ -87,7 +87,7 @@ struct type_caster<MlirAffineMap> {
87
87
// / Casts object <-> MlirAttribute.
88
88
template <>
89
89
struct type_caster <MlirAttribute> {
90
- NB_TYPE_CASTER (MlirAttribute, const_name(" MlirAttribute" ));
90
+ NB_TYPE_CASTER (MlirAttribute, const_name(" MlirAttribute" ))
91
91
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
92
92
nanobind::object capsule = mlirApiObjectToCapsule (src);
93
93
value = mlirPythonCapsuleToAttribute (capsule.ptr ());
@@ -108,7 +108,7 @@ struct type_caster<MlirAttribute> {
108
108
// / Casts object -> MlirBlock.
109
109
template <>
110
110
struct type_caster <MlirBlock> {
111
- NB_TYPE_CASTER (MlirBlock, const_name(" MlirBlock" ));
111
+ NB_TYPE_CASTER (MlirBlock, const_name(" MlirBlock" ))
112
112
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
113
113
nanobind::object capsule = mlirApiObjectToCapsule (src);
114
114
value = mlirPythonCapsuleToBlock (capsule.ptr ());
@@ -119,7 +119,7 @@ struct type_caster<MlirBlock> {
119
119
// / Casts object -> MlirContext.
120
120
template <>
121
121
struct type_caster <MlirContext> {
122
- NB_TYPE_CASTER (MlirContext, const_name(" MlirContext" ));
122
+ NB_TYPE_CASTER (MlirContext, const_name(" MlirContext" ))
123
123
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
124
124
if (src.is_none ()) {
125
125
// Gets the current thread-bound context.
@@ -139,7 +139,7 @@ struct type_caster<MlirContext> {
139
139
// / Casts object <-> MlirDialectRegistry.
140
140
template <>
141
141
struct type_caster <MlirDialectRegistry> {
142
- NB_TYPE_CASTER (MlirDialectRegistry, const_name(" MlirDialectRegistry" ));
142
+ NB_TYPE_CASTER (MlirDialectRegistry, const_name(" MlirDialectRegistry" ))
143
143
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
144
144
nanobind::object capsule = mlirApiObjectToCapsule (src);
145
145
value = mlirPythonCapsuleToDialectRegistry (capsule.ptr ());
@@ -159,7 +159,7 @@ struct type_caster<MlirDialectRegistry> {
159
159
// / Casts object <-> MlirLocation.
160
160
template <>
161
161
struct type_caster <MlirLocation> {
162
- NB_TYPE_CASTER (MlirLocation, const_name(" MlirLocation" ));
162
+ NB_TYPE_CASTER (MlirLocation, const_name(" MlirLocation" ))
163
163
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
164
164
if (src.is_none ()) {
165
165
// Gets the current thread-bound context.
@@ -185,7 +185,7 @@ struct type_caster<MlirLocation> {
185
185
// / Casts object <-> MlirModule.
186
186
template <>
187
187
struct type_caster <MlirModule> {
188
- NB_TYPE_CASTER (MlirModule, const_name(" MlirModule" ));
188
+ NB_TYPE_CASTER (MlirModule, const_name(" MlirModule" ))
189
189
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
190
190
nanobind::object capsule = mlirApiObjectToCapsule (src);
191
191
value = mlirPythonCapsuleToModule (capsule.ptr ());
@@ -206,7 +206,7 @@ struct type_caster<MlirModule> {
206
206
template <>
207
207
struct type_caster <MlirFrozenRewritePatternSet> {
208
208
NB_TYPE_CASTER (MlirFrozenRewritePatternSet,
209
- const_name (" MlirFrozenRewritePatternSet" ));
209
+ const_name (" MlirFrozenRewritePatternSet" ))
210
210
bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) {
211
211
nanobind::object capsule = mlirApiObjectToCapsule (src);
212
212
value = mlirPythonCapsuleToFrozenRewritePatternSet (capsule.ptr ());
@@ -225,7 +225,7 @@ struct type_caster<MlirFrozenRewritePatternSet> {
225
225
// / Casts object <-> MlirOperation.
226
226
template <>
227
227
struct type_caster <MlirOperation> {
228
- NB_TYPE_CASTER (MlirOperation, const_name(" MlirOperation" ));
228
+ NB_TYPE_CASTER (MlirOperation, const_name(" MlirOperation" ))
229
229
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
230
230
nanobind::object capsule = mlirApiObjectToCapsule (src);
231
231
value = mlirPythonCapsuleToOperation (capsule.ptr ());
@@ -247,7 +247,7 @@ struct type_caster<MlirOperation> {
247
247
// / Casts object <-> MlirValue.
248
248
template <>
249
249
struct type_caster <MlirValue> {
250
- NB_TYPE_CASTER (MlirValue, const_name(" MlirValue" ));
250
+ NB_TYPE_CASTER (MlirValue, const_name(" MlirValue" ))
251
251
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
252
252
nanobind::object capsule = mlirApiObjectToCapsule (src);
253
253
value = mlirPythonCapsuleToValue (capsule.ptr ());
@@ -270,7 +270,7 @@ struct type_caster<MlirValue> {
270
270
// / Casts object -> MlirPassManager.
271
271
template <>
272
272
struct type_caster <MlirPassManager> {
273
- NB_TYPE_CASTER (MlirPassManager, const_name(" MlirPassManager" ));
273
+ NB_TYPE_CASTER (MlirPassManager, const_name(" MlirPassManager" ))
274
274
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
275
275
nanobind::object capsule = mlirApiObjectToCapsule (src);
276
276
value = mlirPythonCapsuleToPassManager (capsule.ptr ());
@@ -281,7 +281,7 @@ struct type_caster<MlirPassManager> {
281
281
// / Casts object <-> MlirTypeID.
282
282
template <>
283
283
struct type_caster <MlirTypeID> {
284
- NB_TYPE_CASTER (MlirTypeID, const_name(" MlirTypeID" ));
284
+ NB_TYPE_CASTER (MlirTypeID, const_name(" MlirTypeID" ))
285
285
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
286
286
nanobind::object capsule = mlirApiObjectToCapsule (src);
287
287
value = mlirPythonCapsuleToTypeID (capsule.ptr ());
@@ -303,7 +303,7 @@ struct type_caster<MlirTypeID> {
303
303
// / Casts object <-> MlirType.
304
304
template <>
305
305
struct type_caster <MlirType> {
306
- NB_TYPE_CASTER (MlirType, const_name(" MlirType" ));
306
+ NB_TYPE_CASTER (MlirType, const_name(" MlirType" ))
307
307
bool from_python (handle src, uint8_t flags, cleanup_list *cleanup) {
308
308
nanobind::object capsule = mlirApiObjectToCapsule (src);
309
309
value = mlirPythonCapsuleToType (capsule.ptr ());
@@ -631,40 +631,6 @@ class mlir_value_subclass : public pure_subclass {
631
631
632
632
} // namespace nanobind_adaptors
633
633
634
- // / RAII scope intercepting all diagnostics into a string. The message must be
635
- // / checked before this goes out of scope.
636
- class CollectDiagnosticsToStringScope {
637
- public:
638
- explicit CollectDiagnosticsToStringScope (MlirContext ctx) : context(ctx) {
639
- handlerID = mlirContextAttachDiagnosticHandler (ctx, &handler, &errorMessage,
640
- /* deleteUserData=*/ nullptr );
641
- }
642
- ~CollectDiagnosticsToStringScope () {
643
- assert (errorMessage.empty () && " unchecked error message" );
644
- mlirContextDetachDiagnosticHandler (context, handlerID);
645
- }
646
-
647
- [[nodiscard]] std::string takeMessage () { return std::move (errorMessage); }
648
-
649
- private:
650
- static MlirLogicalResult handler (MlirDiagnostic diag, void *data) {
651
- auto printer = +[](MlirStringRef message, void *data) {
652
- *static_cast <std::string *>(data) +=
653
- llvm::StringRef (message.data , message.length );
654
- };
655
- MlirLocation loc = mlirDiagnosticGetLocation (diag);
656
- *static_cast <std::string *>(data) += " at " ;
657
- mlirLocationPrint (loc, printer, data);
658
- *static_cast <std::string *>(data) += " : " ;
659
- mlirDiagnosticPrint (diag, printer, data);
660
- return mlirLogicalResultSuccess ();
661
- }
662
-
663
- MlirContext context;
664
- MlirDiagnosticHandlerID handlerID;
665
- std::string errorMessage = " " ;
666
- };
667
-
668
634
} // namespace python
669
635
} // namespace mlir
670
636
0 commit comments