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 
14 namespace {
15 /// This test checks various aspects of Type interface generation and
16 /// application.
17 struct TestTypeInterfaces
18     : public PassWrapper<TestTypeInterfaces, OperationPass<ModuleOp>> {
19   void runOnOperation() override {
20     getOperation().walk([](Operation *op) {
21       for (Type type : op->getResultTypes()) {
22         if (auto testInterface = type.dyn_cast<TestTypeInterface>()) {
23           testInterface.printTypeA(op->getLoc());
24           testInterface.printTypeB(op->getLoc());
25           testInterface.printTypeC(op->getLoc());
26           testInterface.printTypeD(op->getLoc());
27         }
28         if (auto testType = type.dyn_cast<TestType>())
29           testType.printTypeE(op->getLoc());
30       }
31     });
32   }
33 };
34 } // end anonymous namespace
35 
36 namespace mlir {
37 void registerTestInterfaces() {
38   PassRegistration<TestTypeInterfaces> pass("test-type-interfaces",
39                                             "Test type interface support.");
40 }
41 } // namespace mlir
42