MLIR  17.0.0git
Go to the documentation of this file.
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 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 //===----------------------------------------------------------------------===//
18 #include "mlir-c/Support.h"
19 #include "mlir/CAPI/Wrap.h"
21 #include "mlir/Support/TypeID.h"
22 #include "llvm/ADT/StringRef.h"
24 /// Converts a StringRef into its MLIR C API equivalent.
25 inline MlirStringRef wrap(llvm::StringRef ref) {
26  return mlirStringRefCreate(, ref.size());
27 }
29 /// Creates a StringRef out of its MLIR C API equivalent.
30 inline llvm::StringRef unwrap(MlirStringRef ref) {
31  return llvm::StringRef(, ref.length);
32 }
35  if (mlir::succeeded(res))
36  return mlirLogicalResultSuccess();
37  return mlirLogicalResultFailure();
38 }
42 }
47 #endif // MLIR_CAPI_SUPPORT_H
#define DEFINE_C_API_PTR_METHODS(name, cpptype)
Definition: Wrap.h:25
#define DEFINE_C_API_METHODS(name, cpptype)
Definition: Wrap.h:31
This class provides a way to define new TypeIDs at runtime.
Definition: TypeID.h:292
This class provides an efficient unique identifier for a specific C++ type.
Definition: TypeID.h:104
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition: Support.h:80
static MlirLogicalResult mlirLogicalResultFailure(void)
Creates a logical result representing a failure.
Definition: Support.h:136
static MlirLogicalResult mlirLogicalResultSuccess(void)
Creates a logical result representing a success.
Definition: Support.h:130
static bool mlirLogicalResultIsSuccess(MlirLogicalResult res)
Checks if the given logical result represents a success.
Definition: Support.h:120
llvm::StringRef unwrap(MlirStringRef ref)
Creates a StringRef out of its MLIR C API equivalent.
Definition: Support.h:30
MlirStringRef wrap(llvm::StringRef ref)
Converts a StringRef into its MLIR C API equivalent.
Definition: Support.h:25
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
A logical result value, essentially a boolean with named states.
Definition: Support.h:114
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:71
const char * data
Pointer to the first symbol.
Definition: Support.h:72
size_t length
Length of the fragment.
Definition: Support.h:73
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26