1 | //===- DialectHandle.cpp - C Interface for MLIR Dialect Operations -------===// |
---|---|
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 "mlir/CAPI/Registration.h" |
10 | |
11 | static inline const MlirDialectRegistrationHooks * |
12 | unwrap(MlirDialectHandle handle) { |
13 | return (const MlirDialectRegistrationHooks *)handle.ptr; |
14 | } |
15 | |
16 | MlirStringRef mlirDialectHandleGetNamespace(MlirDialectHandle handle) { |
17 | return unwrap(handle)->getNamespaceHook(); |
18 | } |
19 | |
20 | void mlirDialectHandleInsertDialect(MlirDialectHandle handle, |
21 | MlirDialectRegistry registry) { |
22 | unwrap(handle)->insertHook(registry); |
23 | } |
24 | |
25 | void mlirDialectHandleRegisterDialect(MlirDialectHandle handle, |
26 | MlirContext ctx) { |
27 | mlir::DialectRegistry registry; |
28 | mlirDialectHandleInsertDialect(handle, registry: wrap(cpp: ®istry)); |
29 | unwrap(c: ctx)->appendDialectRegistry(registry); |
30 | } |
31 | |
32 | MlirDialect mlirDialectHandleLoadDialect(MlirDialectHandle handle, |
33 | MlirContext ctx) { |
34 | return unwrap(handle)->loadHook(ctx); |
35 | } |
36 |