1//===- Support.h - C API Helpers Implementation -----------------*- C++ -*-===//
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// This file contains definitions for converting MLIR C++ objects into helper
10// C structures for the purpose of C API. This file should not be included from
11// C++ code other than C API implementation nor from C code.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_CAPI_SUPPORT_H
16#define MLIR_CAPI_SUPPORT_H
17
18#include "mlir-c/Support.h"
19#include "mlir/CAPI/Wrap.h"
20#include "mlir/Support/LogicalResult.h"
21#include "mlir/Support/TypeID.h"
22#include "llvm/ADT/StringRef.h"
23
24namespace llvm {
25class ThreadPoolInterface;
26} // namespace llvm
27
28/// Converts a StringRef into its MLIR C API equivalent.
29inline MlirStringRef wrap(llvm::StringRef ref) {
30 return mlirStringRefCreate(str: ref.data(), length: ref.size());
31}
32
33/// Creates a StringRef out of its MLIR C API equivalent.
34inline llvm::StringRef unwrap(MlirStringRef ref) {
35 return llvm::StringRef(ref.data, ref.length);
36}
37
38inline MlirLogicalResult wrap(mlir::LogicalResult res) {
39 if (mlir::succeeded(result: res))
40 return mlirLogicalResultSuccess();
41 return mlirLogicalResultFailure();
42}
43
44inline mlir::LogicalResult unwrap(MlirLogicalResult res) {
45 return mlir::success(isSuccess: mlirLogicalResultIsSuccess(res));
46}
47
48DEFINE_C_API_PTR_METHODS(MlirLlvmThreadPool, llvm::ThreadPoolInterface)
49DEFINE_C_API_METHODS(MlirTypeID, mlir::TypeID)
50DEFINE_C_API_PTR_METHODS(MlirTypeIDAllocator, mlir::TypeIDAllocator)
51
52#endif // MLIR_CAPI_SUPPORT_H
53

source code of mlir/include/mlir/CAPI/Support.h