| 1 | //===- Dialect.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 | #include "mlir/Tools/PDLL/ODS/Dialect.h" |
| 10 | #include "mlir/Tools/PDLL/ODS/Constraint.h" |
| 11 | #include "mlir/Tools/PDLL/ODS/Operation.h" |
| 12 | #include "llvm/Support/raw_ostream.h" |
| 13 | |
| 14 | using namespace mlir; |
| 15 | using namespace mlir::pdll::ods; |
| 16 | |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | // Dialect |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
| 21 | Dialect::Dialect(StringRef name) : name(name.str()) {} |
| 22 | Dialect::~Dialect() = default; |
| 23 | |
| 24 | std::pair<Operation *, bool> |
| 25 | Dialect::insertOperation(StringRef name, StringRef summary, StringRef desc, |
| 26 | StringRef nativeClassName, |
| 27 | bool supportsResultTypeInferrence, llvm::SMLoc loc) { |
| 28 | std::unique_ptr<Operation> &operation = operations[name]; |
| 29 | if (operation) |
| 30 | return std::make_pair(x: &*operation, /*wasInserted*/ y: false); |
| 31 | |
| 32 | operation.reset(p: new Operation(name, summary, desc, nativeClassName, |
| 33 | supportsResultTypeInferrence, loc)); |
| 34 | return std::make_pair(x: &*operation, /*wasInserted*/ y: true); |
| 35 | } |
| 36 | |
| 37 | Operation *Dialect::lookupOperation(StringRef name) const { |
| 38 | auto it = operations.find(Key: name); |
| 39 | return it != operations.end() ? it->second.get() : nullptr; |
| 40 | } |
| 41 | |