aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Tools/PDLL/ODS/Dialect.cpp
blob: 5e4ea5063b78d7a58cf9da645eed73a9217bf3a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//===- Dialect.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir/Tools/PDLL/ODS/Dialect.h"
#include "mlir/Tools/PDLL/ODS/Operation.h"

using namespace mlir;
using namespace mlir::pdll::ods;

//===----------------------------------------------------------------------===//
// Dialect
//===----------------------------------------------------------------------===//

Dialect::Dialect(StringRef name) : name(name.str()) {}
Dialect::~Dialect() = default;

std::pair<Operation *, bool>
Dialect::insertOperation(StringRef name, StringRef summary, StringRef desc,
                         StringRef nativeClassName,
                         bool supportsResultTypeInferrence, llvm::SMLoc loc) {
  std::unique_ptr<Operation> &operation = operations[name];
  if (operation)
    return std::make_pair(&*operation, /*wasInserted*/ false);

  operation.reset(new Operation(name, summary, desc, nativeClassName,
                                supportsResultTypeInferrence, loc));
  return std::make_pair(&*operation, /*wasInserted*/ true);
}

Operation *Dialect::lookupOperation(StringRef name) const {
  auto it = operations.find(name);
  return it != operations.end() ? it->second.get() : nullptr;
}