53 lines · cpp
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-exception6//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#include "mlir/IR/Diagnostics.h"15#include "mlir/IR/Location.h"16 17MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PythonTest, python_test,18 python_test::PythonTestDialect)19 20bool mlirAttributeIsAPythonTestTestAttribute(MlirAttribute attr) {21 return llvm::isa<python_test::TestAttrAttr>(unwrap(attr));22}23 24MlirAttribute mlirPythonTestTestAttributeGet(MlirContext context) {25 return wrap(python_test::TestAttrAttr::get(unwrap(context)));26}27 28MlirTypeID mlirPythonTestTestAttributeGetTypeID(void) {29 return wrap(python_test::TestAttrAttr::getTypeID());30}31 32bool mlirTypeIsAPythonTestTestType(MlirType type) {33 return llvm::isa<python_test::TestTypeType>(unwrap(type));34}35 36MlirType mlirPythonTestTestTypeGet(MlirContext context) {37 return wrap(python_test::TestTypeType::get(unwrap(context)));38}39 40MlirTypeID mlirPythonTestTestTypeGetTypeID(void) {41 return wrap(python_test::TestTypeType::getTypeID());42}43 44bool mlirTypeIsAPythonTestTestTensorValue(MlirValue value) {45 return mlirTypeIsATensor(wrap(unwrap(value).getType()));46}47 48void mlirPythonTestEmitDiagnosticWithNote(MlirContext ctx) {49 auto diag =50 mlir::emitError(unwrap(mlirLocationUnknownGet(ctx)), "created error");51 diag.attachNote() << "attached note";52}53