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
Dialect(StringRef name)21 Dialect::Dialect(StringRef name) : name(name.str()) {}
22 Dialect::~Dialect() = default;
23
24 std::pair<Operation *, bool>
insertOperation(StringRef name,StringRef summary,StringRef desc,StringRef nativeClassName,bool supportsResultTypeInferrence,llvm::SMLoc loc)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(&*operation, /*wasInserted*/ false);
31
32 operation.reset(new Operation(name, summary, desc, nativeClassName,
33 supportsResultTypeInferrence, loc));
34 return std::make_pair(&*operation, /*wasInserted*/ true);
35 }
36
lookupOperation(StringRef name) const37 Operation *Dialect::lookupOperation(StringRef name) const {
38 auto it = operations.find(name);
39 return it != operations.end() ? it->second.get() : nullptr;
40 }
41