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 16 const 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: } 34 const char newDialectUsage[] = "\ 35 module {\ 36 %res = \"foo.op\"() : () -> i32\ 37 \"bar.op\"(%res) : (i32) -> ()\ 38 }"; 39 40 int main(void) { 41 MlirContext ctx = mlirContextCreate(); 42 mlirDialectHandleLoadDialect(mlirGetDialectHandle__irdl__(), ctx); 43 44 MlirModule dialectDecl = 45 mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(irdlDialect)); 46 47 mlirLoadIRDLDialects(dialectDecl); 48 mlirModuleDestroy(dialectDecl); 49 50 MlirModule usingModule = mlirModuleCreateParse( 51 ctx, mlirStringRefCreateFromCString(newDialectUsage)); 52 53 mlirOperationDump(mlirModuleGetOperation(usingModule)); 54 55 mlirModuleDestroy(usingModule); 56 mlirContextDestroy(ctx); 57 return 0; 58 } 59