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