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> Dialect::insertOperation(StringRef name, 25 StringRef summary, 26 StringRef desc, 27 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, loc)); 33 return std::make_pair(&*operation, /*wasInserted*/ true); 34 } 35 36 Operation *Dialect::lookupOperation(StringRef name) const { 37 auto it = operations.find(name); 38 return it != operations.end() ? it->second.get() : nullptr; 39 } 40