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         }
29         if (auto testType = type.dyn_cast<TestType>())
30           testType.printTypeE(op->getLoc());
31       }
32     });
33   }
34 };
35 } // end anonymous namespace
36 
37 namespace mlir {
38 namespace test {
39 void registerTestInterfaces() {
40   PassRegistration<TestTypeInterfaces> pass("test-type-interfaces",
41                                             "Test type interface support.");
42 }
43 } // namespace test
44 } // namespace mlir
45