diff --git a/mlir/include/mlir-c/AffineExpr.h b/mlir/include/mlir-c/AffineExpr.h --- a/mlir/include/mlir-c/AffineExpr.h +++ b/mlir/include/mlir-c/AffineExpr.h @@ -17,8 +17,30 @@ extern "C" { #endif +/*============================================================================*/ +/** Opaque type declarations. + * + * Types are exposed to C bindings as structs containing opaque pointers. They + * are not supposed to be inspected from C. This allows the underlying + * representation to change without affecting the API users. The use of structs + * instead of typedefs enables some type safety as structs are not implicitly + * convertible to each other. + * + * Instances of these types may or may not own the underlying object. The + * ownership semantics is defined by how an instance of the type was obtained. + */ +/*============================================================================*/ + +#define DEFINE_C_API_STRUCT(name, storage) \ + struct name { \ + storage *ptr; \ + }; \ + typedef struct name name + DEFINE_C_API_STRUCT(MlirAffineExpr, const void); +#undef DEFINE_C_API_STRUCT + /** Gets the context that owns the affine expression. */ MlirContext mlirAffineExprGetContext(MlirAffineExpr affineExpr); diff --git a/mlir/include/mlir-c/AffineMap.h b/mlir/include/mlir-c/AffineMap.h --- a/mlir/include/mlir-c/AffineMap.h +++ b/mlir/include/mlir-c/AffineMap.h @@ -16,8 +16,30 @@ extern "C" { #endif +/*============================================================================*/ +/** Opaque type declarations. + * + * Types are exposed to C bindings as structs containing opaque pointers. They + * are not supposed to be inspected from C. This allows the underlying + * representation to change without affecting the API users. The use of structs + * instead of typedefs enables some type safety as structs are not implicitly + * convertible to each other. + * + * Instances of these types may or may not own the underlying object. The + * ownership semantics is defined by how an instance of the type was obtained. + */ +/*============================================================================*/ + +#define DEFINE_C_API_STRUCT(name, storage) \ + struct name { \ + storage *ptr; \ + }; \ + typedef struct name name + DEFINE_C_API_STRUCT(MlirAffineMap, const void); +#undef DEFINE_C_API_STRUCT + /** Gets the context that the given affine map was created with*/ MlirContext mlirAffineMapGetContext(MlirAffineMap affineMap); diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -61,6 +61,8 @@ DEFINE_C_API_STRUCT(MlirType, const void); DEFINE_C_API_STRUCT(MlirValue, const void); +#undef DEFINE_C_API_STRUCT + /** Named MLIR attribute. * * A named attribute is essentially a (name, attribute) pair where the name is