| 1 | //===- TestDynDialect.cpp -------------------------------------------------===// |
|---|---|
| 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 | // This file defines a fake 'test_dyn' dynamic dialect that is used to test the |
| 10 | // registration of dynamic dialects. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "mlir/IR/ExtensibleDialect.h" |
| 15 | |
| 16 | using namespace mlir; |
| 17 | |
| 18 | namespace test { |
| 19 | void registerTestDynDialect(DialectRegistry ®istry) { |
| 20 | registry.insertDynamic( |
| 21 | name: "test_dyn", ctor: [](MLIRContext *ctx, DynamicDialect *testDyn) { |
| 22 | auto opVerifier = [](Operation *op) -> LogicalResult { |
| 23 | if (op->getNumOperands() == 0 && op->getNumResults() == 1 && |
| 24 | op->getNumRegions() == 0) |
| 25 | return success(); |
| 26 | return op->emitError( |
| 27 | message: "expected a single result, no operands and no regions"); |
| 28 | }; |
| 29 | |
| 30 | auto opRegionVerifier = [](Operation *op) { return success(); }; |
| 31 | |
| 32 | testDyn->registerDynamicOp(type: DynamicOpDefinition::get( |
| 33 | name: "one_result", dialect: testDyn, verifyFn: opVerifier, verifyRegionFn: opRegionVerifier)); |
| 34 | }); |
| 35 | } |
| 36 | } // namespace test |
| 37 |
