[clang-tidy][NFC]remove deps of clang in clang tidy test (#116588)
[llvm-project.git] / mlir / test / CAPI / irdl.c
blobb35345b664b14c1fd88b4faf93d6807ddf7c4203
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 //===----------------------------------------------------------------------===//
10 /* RUN: mlir-capi-irdl-test 2>&1 | FileCheck %s
13 #include "mlir-c/Dialect/IRDL.h"
14 #include "mlir-c/IR.h"
16 const char irdlDialect[] = "\
17 irdl.dialect @foo {\
18 irdl.operation @op {\
19 %i32 = irdl.is i32\
20 irdl.results(%i32)\
23 irdl.dialect @bar {\
24 irdl.operation @op {\
25 %i32 = irdl.is i32\
26 irdl.operands(%i32)\
28 }";
30 // CHECK: module {
31 // CHECK-NEXT: %[[RES:.*]] = "foo.op"() : () -> i32
32 // CHECK-NEXT: "bar.op"(%[[RES]]) : (i32) -> ()
33 // CHECK-NEXT: }
34 const char newDialectUsage[] = "\
35 module {\
36 %res = \"foo.op\"() : () -> i32\
37 \"bar.op\"(%res) : (i32) -> ()\
38 }";
40 int main(void) {
41 MlirContext ctx = mlirContextCreate();
42 mlirDialectHandleLoadDialect(mlirGetDialectHandle__irdl__(), ctx);
44 MlirModule dialectDecl =
45 mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(irdlDialect));
47 mlirLoadIRDLDialects(dialectDecl);
48 mlirModuleDestroy(dialectDecl);
50 MlirModule usingModule = mlirModuleCreateParse(
51 ctx, mlirStringRefCreateFromCString(newDialectUsage));
53 mlirOperationDump(mlirModuleGetOperation(usingModule));
55 mlirModuleDestroy(usingModule);
56 mlirContextDestroy(ctx);
57 return 0;