3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-13 04:28:18 +00:00

Split extract -attr into extract -cell_attr and -wire_attr

This commit is contained in:
Clifford Wolf 2013-03-08 08:19:24 +01:00
parent bf3a3b9589
commit ef4f1c55b6

View file

@ -34,11 +34,11 @@ namespace
class SubCircuitSolver : public SubCircuit::Solver class SubCircuitSolver : public SubCircuit::Solver
{ {
public: public:
std::set<RTLIL::IdString> attr_compare; std::set<RTLIL::IdString> cell_attr, wire_attr;
bool compareAttributes(const std::map<RTLIL::IdString, RTLIL::Const> &needleAttr, const std::map<RTLIL::IdString, RTLIL::Const> &haystackAttr) bool compareAttributes(const std::set<RTLIL::IdString> &attr, const std::map<RTLIL::IdString, RTLIL::Const> &needleAttr, const std::map<RTLIL::IdString, RTLIL::Const> &haystackAttr)
{ {
for (auto &it : attr_compare) { for (auto &it : attr) {
size_t nc = needleAttr.count(it), hc = haystackAttr.count(it); size_t nc = needleAttr.count(it), hc = haystackAttr.count(it);
if (nc != hc || (nc > 0 && needleAttr.at(it) != haystackAttr.at(it))) if (nc != hc || (nc > 0 && needleAttr.at(it) != haystackAttr.at(it)))
return false; return false;
@ -49,33 +49,33 @@ namespace
virtual bool userCompareNodes(const std::string &, const std::string &, void *needleUserData, virtual bool userCompareNodes(const std::string &, const std::string &, void *needleUserData,
const std::string &, const std::string &, void *haystackUserData, const std::map<std::string, std::string> &portMapping) const std::string &, const std::string &, void *haystackUserData, const std::map<std::string, std::string> &portMapping)
{ {
if (attr_compare.size() == 0)
return true;
RTLIL::Cell *needleCell = (RTLIL::Cell*) needleUserData; RTLIL::Cell *needleCell = (RTLIL::Cell*) needleUserData;
RTLIL::Cell *haystackCell = (RTLIL::Cell*) haystackUserData; RTLIL::Cell *haystackCell = (RTLIL::Cell*) haystackUserData;
if (!compareAttributes(needleCell->attributes, haystackCell->attributes)) if (cell_attr.size() > 0 && !compareAttributes(cell_attr, needleCell->attributes, haystackCell->attributes))
return false; return false;
RTLIL::Wire *lastNeedleWire = NULL; if (wire_attr.size() > 0)
RTLIL::Wire *lastHaystackWire = NULL;
std::map<RTLIL::IdString, RTLIL::Const> emptyAttr;
for (auto &conn : needleCell->connections)
{ {
RTLIL::SigSpec needleSig = conn.second; RTLIL::Wire *lastNeedleWire = NULL;
RTLIL::SigSpec haystackSig = haystackCell->connections.at(portMapping.at(conn.first)); RTLIL::Wire *lastHaystackWire = NULL;
std::map<RTLIL::IdString, RTLIL::Const> emptyAttr;
needleSig.expand(); for (auto &conn : needleCell->connections)
haystackSig.expand(); {
RTLIL::SigSpec needleSig = conn.second;
RTLIL::SigSpec haystackSig = haystackCell->connections.at(portMapping.at(conn.first));
for (int i = 0; i < std::min(needleSig.width, haystackSig.width); i++) { needleSig.expand();
RTLIL::Wire *needleWire = needleSig.chunks.at(i).wire, *haystackWire = haystackSig.chunks.at(i).wire; haystackSig.expand();
if (needleWire != lastNeedleWire || haystackWire != lastHaystackWire)
if (!compareAttributes(needleWire ? needleWire->attributes : emptyAttr, haystackWire ? haystackWire->attributes : emptyAttr)) for (int i = 0; i < std::min(needleSig.width, haystackSig.width); i++) {
return false; RTLIL::Wire *needleWire = needleSig.chunks.at(i).wire, *haystackWire = haystackSig.chunks.at(i).wire;
lastNeedleWire = needleWire, lastHaystackWire = haystackWire; if (needleWire != lastNeedleWire || haystackWire != lastHaystackWire)
if (!compareAttributes(wire_attr, needleWire ? needleWire->attributes : emptyAttr, haystackWire ? haystackWire->attributes : emptyAttr))
return false;
lastNeedleWire = needleWire, lastHaystackWire = haystackWire;
}
} }
} }
@ -340,8 +340,11 @@ struct ExtractPass : public Pass {
log(" Register a valid permutation of swapable ports for a needle\n"); log(" Register a valid permutation of swapable ports for a needle\n");
log(" cell type. This option can be used multiple times.\n"); log(" cell type. This option can be used multiple times.\n");
log("\n"); log("\n");
log(" -attr <attribute_name>\n"); log(" -cell_attr <attribute_name>\n");
log(" Attributes with the given name must match (cells and wires).\n"); log(" Attributes on cells with the given name must match.\n");
log("\n");
log(" -wire_attr <attribute_name>\n");
log(" Attributes on wires with the given name must match.\n");
log("\n"); log("\n");
log("This pass does not operate on modules with uprocessed processes in it.\n"); log("This pass does not operate on modules with uprocessed processes in it.\n");
log("(I.e. the 'proc' pass should be used first to convert processes to netlists.)\n"); log("(I.e. the 'proc' pass should be used first to convert processes to netlists.)\n");
@ -477,8 +480,12 @@ struct ExtractPass : public Pass {
solver.addSwappablePortsPermutation(type, map); solver.addSwappablePortsPermutation(type, map);
continue; continue;
} }
if (args[argidx] == "-attr" && argidx+1 < args.size()) { if (args[argidx] == "-cell_attr" && argidx+1 < args.size()) {
solver.attr_compare.insert(RTLIL::escape_id(args[++argidx])); solver.cell_attr.insert(RTLIL::escape_id(args[++argidx]));
continue;
}
if (args[argidx] == "-wire_attr" && argidx+1 < args.size()) {
solver.wire_attr.insert(RTLIL::escape_id(args[++argidx]));
continue; continue;
} }
break; break;