24
24
25
25
#include < cstdint>
26
26
27
+ #include " llvm/ADT/Twine.h"
27
28
#include " mlir-c/Bindings/Python/Interop.h"
28
29
#include " mlir-c/Diagnostics.h"
29
30
#include " mlir-c/IR.h"
30
- #include " llvm/ADT/Twine.h"
31
31
32
32
// Raw CAPI type casters need to be declared before use, so always include them
33
33
// first.
@@ -233,8 +233,7 @@ struct type_caster<MlirOperation> {
233
233
}
234
234
static handle from_cpp (MlirOperation v, rv_policy,
235
235
cleanup_list *cleanup) noexcept {
236
- if (v.ptr == nullptr )
237
- return nanobind::none ();
236
+ if (v.ptr == nullptr ) return nanobind::none ();
238
237
nanobind::object capsule =
239
238
nanobind::steal<nanobind::object>(mlirPythonOperationToCapsule (v));
240
239
return nanobind::module_::import_ (MAKE_MLIR_PYTHON_QUALNAME (" ir" ))
@@ -255,8 +254,7 @@ struct type_caster<MlirValue> {
255
254
}
256
255
static handle from_cpp (MlirValue v, rv_policy,
257
256
cleanup_list *cleanup) noexcept {
258
- if (v.ptr == nullptr )
259
- return nanobind::none ();
257
+ if (v.ptr == nullptr ) return nanobind::none ();
260
258
nanobind::object capsule =
261
259
nanobind::steal<nanobind::object>(mlirPythonValueToCapsule (v));
262
260
return nanobind::module_::import_ (MAKE_MLIR_PYTHON_QUALNAME (" ir" ))
@@ -289,8 +287,7 @@ struct type_caster<MlirTypeID> {
289
287
}
290
288
static handle from_cpp (MlirTypeID v, rv_policy,
291
289
cleanup_list *cleanup) noexcept {
292
- if (v.ptr == nullptr )
293
- return nanobind::none ();
290
+ if (v.ptr == nullptr ) return nanobind::none ();
294
291
nanobind::object capsule =
295
292
nanobind::steal<nanobind::object>(mlirPythonTypeIDToCapsule (v));
296
293
return nanobind::module_::import_ (MAKE_MLIR_PYTHON_QUALNAME (" ir" ))
@@ -321,8 +318,8 @@ struct type_caster<MlirType> {
321
318
}
322
319
};
323
320
324
- } // namespace detail
325
- } // namespace nanobind
321
+ } // namespace detail
322
+ } // namespace nanobind
326
323
327
324
namespace mlir {
328
325
namespace python {
@@ -340,7 +337,7 @@ namespace nanobind_adaptors {
340
337
// / (plus a fair amount of extra curricular poking)
341
338
// / TODO: If this proves useful, see about including it in nanobind.
342
339
class pure_subclass {
343
- public:
340
+ public:
344
341
pure_subclass (nanobind::handle scope, const char *derivedClassName,
345
342
const nanobind::object &superClass) {
346
343
nanobind::object pyType =
@@ -382,7 +379,7 @@ class pure_subclass {
382
379
" function pointer" );
383
380
nanobind::object cf = nanobind::cpp_function (
384
381
std::forward<Func>(f),
385
- nanobind::name (name), // nanobind::scope(thisClass),
382
+ nanobind::name (name), // nanobind::scope(thisClass),
386
383
extra...);
387
384
thisClass.attr (name) = cf;
388
385
return *this ;
@@ -396,7 +393,7 @@ class pure_subclass {
396
393
" function pointer" );
397
394
nanobind::object cf = nanobind::cpp_function (
398
395
std::forward<Func>(f),
399
- nanobind::name (name), // nanobind::scope(thisClass),
396
+ nanobind::name (name), // nanobind::scope(thisClass),
400
397
extra...);
401
398
thisClass.attr (name) =
402
399
nanobind::borrow<nanobind::object>(PyClassMethod_New (cf.ptr ()));
@@ -405,15 +402,15 @@ class pure_subclass {
405
402
406
403
nanobind::object get_class () const { return thisClass; }
407
404
408
- protected:
405
+ protected:
409
406
nanobind::object superClass;
410
407
nanobind::object thisClass;
411
408
};
412
409
413
410
// / Creates a custom subclass of mlir.ir.Attribute, implementing a casting
414
411
// / constructor and type checking methods.
415
412
class mlir_attribute_subclass : public pure_subclass {
416
- public:
413
+ public:
417
414
using IsAFunctionTy = bool (*)(MlirAttribute);
418
415
using GetTypeIDFunctionTy = MlirTypeID (*)();
419
416
@@ -445,7 +442,7 @@ class mlir_attribute_subclass : public pure_subclass {
445
442
// have no additional members, we can just return the instance thus created
446
443
// without amending it.
447
444
std::string captureTypeName (
448
- typeClassName); // As string in case if typeClassName is not static.
445
+ typeClassName); // As string in case if typeClassName is not static.
449
446
nanobind::object newCf = nanobind::cpp_function (
450
447
[superCls, isaFunction, captureTypeName](
451
448
nanobind::object cls, nanobind::object otherAttribute) {
@@ -491,7 +488,7 @@ class mlir_attribute_subclass : public pure_subclass {
491
488
// / Creates a custom subclass of mlir.ir.Type, implementing a casting
492
489
// / constructor and type checking methods.
493
490
class mlir_type_subclass : public pure_subclass {
494
- public:
491
+ public:
495
492
using IsAFunctionTy = bool (*)(MlirType);
496
493
using GetTypeIDFunctionTy = MlirTypeID (*)();
497
494
@@ -523,7 +520,7 @@ class mlir_type_subclass : public pure_subclass {
523
520
// have no additional members, we can just return the instance thus created
524
521
// without amending it.
525
522
std::string captureTypeName (
526
- typeClassName); // As string in case if typeClassName is not static.
523
+ typeClassName); // As string in case if typeClassName is not static.
527
524
nanobind::object newCf = nanobind::cpp_function (
528
525
[superCls, isaFunction, captureTypeName](nanobind::object cls,
529
526
nanobind::object otherType) {
@@ -573,7 +570,7 @@ class mlir_type_subclass : public pure_subclass {
573
570
// / Creates a custom subclass of mlir.ir.Value, implementing a casting
574
571
// / constructor and type checking methods.
575
572
class mlir_value_subclass : public pure_subclass {
576
- public:
573
+ public:
577
574
using IsAFunctionTy = bool (*)(MlirValue);
578
575
579
576
// / Subclasses by looking up the super-class dynamically.
@@ -601,7 +598,7 @@ class mlir_value_subclass : public pure_subclass {
601
598
// have no additional members, we can just return the instance thus created
602
599
// without amending it.
603
600
std::string captureValueName (
604
- valueClassName); // As string in case if valueClassName is not static.
601
+ valueClassName); // As string in case if valueClassName is not static.
605
602
nanobind::object newCf = nanobind::cpp_function (
606
603
[superCls, isaFunction, captureValueName](nanobind::object cls,
607
604
nanobind::object otherValue) {
@@ -629,12 +626,12 @@ class mlir_value_subclass : public pure_subclass {
629
626
}
630
627
};
631
628
632
- } // namespace nanobind_adaptors
629
+ } // namespace nanobind_adaptors
633
630
634
631
// / RAII scope intercepting all diagnostics into a string. The message must be
635
632
// / checked before this goes out of scope.
636
633
class CollectDiagnosticsToStringScope {
637
- public:
634
+ public:
638
635
explicit CollectDiagnosticsToStringScope (MlirContext ctx) : context(ctx) {
639
636
handlerID = mlirContextAttachDiagnosticHandler (ctx, &handler, &errorMessage,
640
637
/* deleteUserData=*/ nullptr );
@@ -646,7 +643,7 @@ class CollectDiagnosticsToStringScope {
646
643
647
644
[[nodiscard]] std::string takeMessage () { return std::move (errorMessage); }
648
645
649
- private:
646
+ private:
650
647
static MlirLogicalResult handler (MlirDiagnostic diag, void *data) {
651
648
auto printer = +[](MlirStringRef message, void *data) {
652
649
*static_cast <std::string *>(data) +=
@@ -665,7 +662,7 @@ class CollectDiagnosticsToStringScope {
665
662
std::string errorMessage = " " ;
666
663
};
667
664
668
- } // namespace python
669
- } // namespace mlir
665
+ } // namespace python
666
+ } // namespace mlir
670
667
671
- #endif // MLIR_BINDINGS_PYTHON_NANOBINDADAPTORS_H
668
+ #endif // MLIR_BINDINGS_PYTHON_NANOBINDADAPTORS_H
0 commit comments