llvm-project
58 строк · 1.5 Кб
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[] = "\17irdl.dialect @foo {\
18irdl.operation @op {\
19%i32 = irdl.is i32\
20irdl.results(%i32)\
21}\
22}\
23irdl.dialect @bar {\
24irdl.operation @op {\
25%i32 = irdl.is i32\
26irdl.operands(%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[] = "\35module {\
36%res = \"foo.op\"() : () -> i32\
37\"bar.op\"(%res) : (i32) -> ()\
38}";39
40int main(void) {41MlirContext ctx = mlirContextCreate();42mlirDialectHandleLoadDialect(mlirGetDialectHandle__irdl__(), ctx);43
44MlirModule dialectDecl =45mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(irdlDialect));46
47mlirLoadIRDLDialects(dialectDecl);48mlirModuleDestroy(dialectDecl);49
50MlirModule usingModule = mlirModuleCreateParse(51ctx, mlirStringRefCreateFromCString(newDialectUsage));52
53mlirOperationDump(mlirModuleGetOperation(usingModule));54
55mlirModuleDestroy(usingModule);56mlirContextDestroy(ctx);57return 0;58}
59