xref: /llvm-project/mlir/test/python/lib/PythonTestCAPI.cpp (revision 9315645834ea81cf9550364a4950f289e9706a26)
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 
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest,python_test,python_test::PythonTestDialect)15 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest, python_test,
16                                       python_test::PythonTestDialect)
17 
18 bool mlirAttributeIsAPythonTestTestAttribute(MlirAttribute attr) {
19   return llvm::isa<python_test::TestAttrAttr>(unwrap(attr));
20 }
21 
mlirPythonTestTestAttributeGet(MlirContext context)22 MlirAttribute mlirPythonTestTestAttributeGet(MlirContext context) {
23   return wrap(python_test::TestAttrAttr::get(unwrap(context)));
24 }
25 
mlirPythonTestTestAttributeGetTypeID(void)26 MlirTypeID mlirPythonTestTestAttributeGetTypeID(void) {
27   return wrap(python_test::TestAttrAttr::getTypeID());
28 }
29 
mlirTypeIsAPythonTestTestType(MlirType type)30 bool mlirTypeIsAPythonTestTestType(MlirType type) {
31   return llvm::isa<python_test::TestTypeType>(unwrap(type));
32 }
33 
mlirPythonTestTestTypeGet(MlirContext context)34 MlirType mlirPythonTestTestTypeGet(MlirContext context) {
35   return wrap(python_test::TestTypeType::get(unwrap(context)));
36 }
37 
mlirPythonTestTestTypeGetTypeID(void)38 MlirTypeID mlirPythonTestTestTypeGetTypeID(void) {
39   return wrap(python_test::TestTypeType::getTypeID());
40 }
41 
mlirTypeIsAPythonTestTestTensorValue(MlirValue value)42 bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value) {
43   return mlirTypeIsATensor(wrap(unwrap(value).getType()));
44 }
45