blob: 6d9a59abf111fb6446eecba5ccd05108851b6f2c [file] [log] [blame]
//===- Support.h - C API Helpers Implementation -----------------*- C++ -*-===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// This file contains definitions for converting MLIR C++ objects into helper
// C structures for the purpose of C API. This file should not be included from
// C++ code other than C API implementation nor from C code.
#include "mlir-c/Support.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/StringRef.h"
/// Converts a StringRef into its MLIR C API equivalent.
inline MlirStringRef wrap(llvm::StringRef ref) {
return mlirStringRefCreate(, ref.size());
/// Creates a StringRef out of its MLIR C API equivalent.
inline llvm::StringRef unwrap(MlirStringRef ref) {
return llvm::StringRef(, ref.length);
inline MlirLogicalResult wrap(mlir::LogicalResult res) {
if (mlir::succeeded(res))
return mlirLogicalResultSuccess();
return mlirLogicalResultFailure();
inline mlir::LogicalResult unwrap(MlirLogicalResult res) {
return mlir::success(mlirLogicalResultIsSuccess(res));