xref: /llvm-project/mlir/test/python/lib/PythonTestCAPI.cpp (revision 69cc3cfb21b7b962ae77c2438bfb2d1e21f5f77e)
1 //===- PythonTestCAPI.cpp - C API for the PythonTest dialect --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PythonTestCAPI.h"
10 #include "PythonTestDialect.h"
11 #include "mlir-c/BuiltinTypes.h"
12 #include "mlir/CAPI/Registration.h"
13 #include "mlir/CAPI/Wrap.h"
14 
15 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest, python_test,
16                                       python_test::PythonTestDialect)
17 
18 bool mlirAttributeIsAPythonTestTestAttribute(MlirAttribute attr) {
19   return unwrap(attr).isa<python_test::TestAttrAttr>();
20 }
21 
22 MlirAttribute mlirPythonTestTestAttributeGet(MlirContext context) {
23   return wrap(python_test::TestAttrAttr::get(unwrap(context)));
24 }
25 
26 bool mlirTypeIsAPythonTestTestType(MlirType type) {
27   return unwrap(type).isa<python_test::TestTypeType>();
28 }
29 
30 MlirType mlirPythonTestTestTypeGet(MlirContext context) {
31   return wrap(python_test::TestTypeType::get(unwrap(context)));
32 }
33 
34 bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value) {
35   return mlirTypeIsATensor(wrap(unwrap(value).getType()));
36 }
37