1 //===- TestInterfaces.cpp - Test interface generation and application -----===//
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 "TestTypes.h"
10 #include "mlir/Pass/Pass.h"
11 
12 using namespace mlir;
13 using namespace mlir::test;
14 
15 namespace {
16 /// This test checks various aspects of Type interface generation and
17 /// application.
18 struct TestTypeInterfaces
19     : public PassWrapper<TestTypeInterfaces, OperationPass<ModuleOp>> {
20   void runOnOperation() override {
21     getOperation().walk([](Operation *op) {
22       for (Type type : op->getResultTypes()) {
23         if (auto testInterface = type.dyn_cast<TestTypeInterface>()) {
24           testInterface.printTypeA(op->getLoc());
25           testInterface.printTypeB(op->getLoc());
26           testInterface.printTypeC(op->getLoc());
27           testInterface.printTypeD(op->getLoc());
28           // Just check that we can assign the result to a variable of interface
29           // type.
30           TestTypeInterface result = testInterface.printTypeRet(op->getLoc());
31           (void)result;
32         }
33         if (auto testType = type.dyn_cast<TestType>())
34           testType.printTypeE(op->getLoc());
35       }
36     });
37   }
38 };
39 } // end anonymous namespace
40 
41 namespace mlir {
42 namespace test {
43 void registerTestInterfaces() {
44   PassRegistration<TestTypeInterfaces> pass("test-type-interfaces",
45                                             "Test type interface support.");
46 }
47 } // namespace test
48 } // namespace mlir
49