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