53 auto portTypes =
module.getPortTypesAttr();
54 if (!portTypes || llvm::any_of(portTypes.getValue(), [](Attribute attr) {
55 return !isa<TypeAttr>(attr);
57 return module.emitOpError("requires valid port types");
59 auto numPorts = portTypes.size();
62 auto portDirections =
module.getPortDirectionsAttr();
64 return module.emitOpError("requires valid port direction");
67 auto bitWidth = portDirections.size();
68 if (
static_cast<size_t>(bitWidth) != numPorts)
69 return module.emitOpError("requires ") << numPorts << " port directions";
72 auto portNames =
module.getPortNamesAttr();
74 return module.emitOpError("requires valid port names");
75 if (portNames.size() != numPorts)
76 return module.emitOpError("requires ") << numPorts << " port names";
77 if (llvm::any_of(portNames.getValue(),
78 [](Attribute attr) { return !isa<StringAttr>(attr); }))
79 return module.emitOpError("port names should all be string attributes");
82 auto portAnnotations =
module.getPortAnnotationsAttr();
84 return module.emitOpError("requires valid port annotations");
86 if (!portAnnotations.empty() && portAnnotations.size() != numPorts)
87 return module.emitOpError("requires ") << numPorts << " port annotations";
89 for (
auto annos : portAnnotations.getValue()) {
90 auto arrayAttr = dyn_cast<ArrayAttr>(annos);
92 return module.emitOpError(
93 "requires port annotations be array attributes");
94 if (llvm::any_of(arrayAttr.getValue(),
95 [](Attribute attr) { return !isa<DictionaryAttr>(attr); }))
96 return module.emitOpError(
97 "annotations must be dictionaries or subannotations");
101 auto portSymbols =
module.getPortSymbolsAttr();
103 return module.emitOpError("requires valid port symbols");
104 if (!portSymbols.empty() && portSymbols.size() != numPorts)
105 return module.emitOpError("requires ") << numPorts << " port symbols";
106 if (llvm::any_of(portSymbols.getValue(), [](Attribute attr) {
107 return !attr || !isa<hw::InnerSymAttr>(attr);
109 return module.emitOpError("port symbols should all be InnerSym attributes");
112 auto portLocs =
module.getPortLocationsAttr();
114 return module.emitOpError("requires valid port locations");
115 if (portLocs.size() != numPorts)
116 return module.emitOpError("requires ") << numPorts << " port locations";
117 if (llvm::any_of(portLocs.getValue(), [](Attribute attr) {
118 return !attr || !isa<LocationAttr>(attr);
120 return module.emitOpError("port symbols should all be location attributes");
134 auto domains =
module.getDomainInfoAttr();
137 return module.emitOpError("requires valid port domain associations");
139 if (!domains.empty() && domains.size() != numPorts)
140 return module.emitOpError("requires ")
141 << numPorts << " port domain associations, but has "
146 for (
auto [index, port] : llvm::enumerate(module.getPorts())) {
147 auto type = cast<TypeAttr>(portTypes[index]).getValue();
155 auto domain = domains[index];
156 auto arrayAttr = dyn_cast<ArrayAttr>(domain);
158 return module.emitOpError()
159 << "domain associations for port '" << module.getPortName(index)
160 << "' must be an 'ArrayAttr'";
163 if (isa<DomainType>(type)) {
164 if (!arrayAttr.empty())
165 return module.emitOpError()
166 << "domain type port '" << module.getPortName(index)
167 << "' must have empty domain associations";
172 for (
auto attr : arrayAttr) {
173 auto association = dyn_cast<IntegerAttr>(attr);
175 return module.emitOpError()
176 << "domain associations for port '" << module.getPortName(index)
177 << "' must be an 'ArrayAttr<IntegerAttr>'";
178 auto associationIdx = association.getValue().getZExtValue();
179 if (associationIdx >= numPorts)
180 return module.emitOpError()
181 << "has domain association " << associationIdx << " for port '"
182 << module.getPortName(index) << "', but the module only has "
183 << numPorts << " ports";
185 return module.emitOpError()
186 << "has port '" << module.getPortName(index)
187 << "' which has a domain association with non-domain port '"
188 << module.getPortName(associationIdx) << "'";
193 if (module->getNumRegions() != 1)
194 return module.emitOpError("requires one region");
static std::unique_ptr< Context > context