CIRCT  20.0.0git
RTGTypes.cpp
Go to the documentation of this file.
1 //===- RTGTypes.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 
11 #include "mlir/IR/Builders.h"
12 #include "mlir/IR/DialectImplementation.h"
13 #include "llvm/ADT/StringSet.h"
14 #include "llvm/ADT/TypeSwitch.h"
15 
16 using namespace circt;
17 using namespace rtg;
18 
19 #define GET_TYPEDEF_CLASSES
20 #include "circt/Dialect/RTG/IR/RTGTypes.cpp.inc"
21 
22 //===----------------------------------------------------------------------===//
23 // DictType
24 //===----------------------------------------------------------------------===/
25 
26 LogicalResult DictType::verify(function_ref<InFlightDiagnostic()> emitError,
27  ArrayRef<DictEntry> entries) {
28  StringAttr last;
29  for (auto entry : entries) {
30  if (entry.name.empty())
31  return emitError() << "empty strings not allowed as entry names";
32 
33  if (last && entry.name.getValue() <= last.getValue())
34  return emitError() << "dictionary must be sorted by names and contain no "
35  "duplicates, first violation at entry '"
36  << entry.name.getValue() << "'";
37 
38  last = entry.name;
39  }
40 
41  return success();
42 }
43 
44 Type DictType::parse(AsmParser &p) {
45  SmallVector<DictEntry> entries;
46  auto loc = p.getCurrentLocation();
47 
48  auto parseResult = p.parseCommaSeparatedList(
49  mlir::AsmParser::Delimiter::LessGreater, [&]() -> ParseResult {
50  std::string name;
51  Type type;
52  loc = p.getCurrentLocation();
53 
54  if (p.parseKeywordOrString(&name) || p.parseColon() ||
55  p.parseType(type))
56  return failure();
57 
58  DictEntry entry;
59  entry.name = StringAttr::get(p.getContext(), name);
60  entry.type = type;
61  entries.emplace_back(entry);
62  return success();
63  });
64 
65  if (failed(parseResult))
66  return Type();
67 
68  auto emitError = [&]() { return p.emitError(loc); };
69 
70  // Call 'getChecked' here such that we do not have to repeat the verification
71  // checks in the parser here, but still get the errors reported at meaningful
72  // locations.
73  return getChecked(emitError, p.getContext(), entries);
74 }
75 
76 void DictType::print(AsmPrinter &p) const {
77  p << '<';
78  llvm::interleaveComma(getEntries(), p, [&](auto entry) {
79  p.printKeywordOrString(entry.name.getValue());
80  p << ": " << entry.type;
81  });
82  p << ">";
83 }
84 
85 bool DictType::entryTypesMatch(TypeRange types) const {
86  return llvm::equal(getEntries(), types,
87  [](const DictEntry &entry, const Type &type) {
88  return entry.type == type;
89  });
90 }
91 
92 void circt::rtg::RTGDialect::registerTypes() {
93  addTypes<
94 #define GET_TYPEDEF_LIST
95 #include "circt/Dialect/RTG/IR/RTGTypes.cpp.inc"
96  >();
97 }
static LogicalResult verify(Value clock, bool eventExists, mlir::Location loc)
Definition: SVOps.cpp:2467
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: rtg.py:1