1//===- irdl.c - Test for the C bindings for IRDL registration -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10/* RUN: mlir-capi-irdl-test 2>&1 | FileCheck %s
11 */
12
13#include "mlir-c/Dialect/IRDL.h"
14#include "mlir-c/IR.h"
15
16const char irdlDialect[] = "\
17 irdl.dialect @foo {\
18 irdl.operation @op {\
19 %i32 = irdl.is i32\
20 irdl.results(baz: %i32)\
21 }\
22 }\
23 irdl.dialect @bar {\
24 irdl.operation @op {\
25 %i32 = irdl.is i32\
26 irdl.operands(baz: %i32)\
27 }\
28 }";
29
30// CHECK: module {
31// CHECK-NEXT: %[[RES:.*]] = "foo.op"() : () -> i32
32// CHECK-NEXT: "bar.op"(%[[RES]]) : (i32) -> ()
33// CHECK-NEXT: }
34const char newDialectUsage[] = "\
35 module {\
36 %res = \"foo.op\"() : () -> i32\
37 \"bar.op\"(%res) : (i32) -> ()\
38 }";
39
40int main(void) {
41 MlirContext ctx = mlirContextCreate();
42 mlirDialectHandleLoadDialect(mlirGetDialectHandle__irdl__(), ctx);
43
44 MlirModule dialectDecl =
45 mlirModuleCreateParse(context: ctx, module: mlirStringRefCreateFromCString(str: irdlDialect));
46
47 mlirLoadIRDLDialects(module: dialectDecl);
48 mlirModuleDestroy(module: dialectDecl);
49
50 MlirModule usingModule = mlirModuleCreateParse(
51 context: ctx, module: mlirStringRefCreateFromCString(str: newDialectUsage));
52
53 mlirOperationDump(op: mlirModuleGetOperation(module: usingModule));
54
55 mlirModuleDestroy(module: usingModule);
56 mlirContextDestroy(context: ctx);
57 return 0;
58}
59

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of mlir/test/CAPI/irdl.c