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 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   StringRef getArgument() const final { return "test-type-interfaces"; }
21   StringRef getDescription() const final {
22     return "Test type interface support.";
23   }
24   void runOnOperation() override {
25     getOperation().walk([](Operation *op) {
26       for (Type type : op->getResultTypes()) {
27         if (auto testInterface = type.dyn_cast<TestTypeInterface>()) {
28           testInterface.printTypeA(op->getLoc());
29           testInterface.printTypeB(op->getLoc());
30           testInterface.printTypeC(op->getLoc());
31           testInterface.printTypeD(op->getLoc());
32           // Just check that we can assign the result to a variable of interface
33           // type.
34           TestTypeInterface result = testInterface.printTypeRet(op->getLoc());
35           (void)result;
36         }
37         if (auto testType = type.dyn_cast<TestType>())
38           testType.printTypeE(op->getLoc());
39       }
40     });
41   }
42 };
43 } // end anonymous namespace
44 
45 namespace mlir {
46 namespace test {
47 void registerTestInterfaces() { PassRegistration<TestTypeInterfaces>(); }
48 } // namespace test
49 } // namespace mlir
50