parent
77ce9cec1e
commit
97838325cd
|
|
@ -827,10 +827,18 @@ std::unordered_map<const AstSenTree*, AstSenTree*>
|
||||||
cloneMapWithNewTriggerReferences(const std::unordered_map<const AstSenTree*, AstSenTree*>& map,
|
cloneMapWithNewTriggerReferences(const std::unordered_map<const AstSenTree*, AstSenTree*>& map,
|
||||||
AstVarScope* vscp) {
|
AstVarScope* vscp) {
|
||||||
AstTopScope* const topScopep = v3Global.rootp()->topScopep();
|
AstTopScope* const topScopep = v3Global.rootp()->topScopep();
|
||||||
// Copy map
|
// Label global SenTrees by the order they are in the Ast
|
||||||
std::unordered_map<const AstSenTree*, AstSenTree*> newMap{map};
|
const VNUser1InUse user1InUse;
|
||||||
|
int n = 0;
|
||||||
|
for (AstNode* nodep = topScopep->senTreesp(); nodep; nodep = nodep->nextp()) nodep->user1(++n);
|
||||||
|
// Sort map by key order for determinism
|
||||||
|
using Pair = std::pair<const AstSenTree*, AstSenTree*>;
|
||||||
|
std::vector<Pair> pairs{map.begin(), map.end()};
|
||||||
|
std::sort(pairs.begin(), pairs.end(), [](const Pair& a, const Pair& b) { //
|
||||||
|
return a.first->user1() < b.first->user1();
|
||||||
|
});
|
||||||
// Replace references in each mapped value with a reference to the given vscp
|
// Replace references in each mapped value with a reference to the given vscp
|
||||||
for (auto& pair : newMap) {
|
for (Pair& pair : pairs) {
|
||||||
pair.second = pair.second->cloneTree(false);
|
pair.second = pair.second->cloneTree(false);
|
||||||
pair.second->foreach([&](AstVarRef* refp) {
|
pair.second->foreach([&](AstVarRef* refp) {
|
||||||
UASSERT_OBJ(refp->access() == VAccess::READ, refp, "Should be read ref");
|
UASSERT_OBJ(refp->access() == VAccess::READ, refp, "Should be read ref");
|
||||||
|
|
@ -839,7 +847,8 @@ cloneMapWithNewTriggerReferences(const std::unordered_map<const AstSenTree*, Ast
|
||||||
});
|
});
|
||||||
topScopep->addSenTreesp(pair.second);
|
topScopep->addSenTreesp(pair.second);
|
||||||
}
|
}
|
||||||
return newMap;
|
// Convert back to map
|
||||||
|
return std::unordered_map<const AstSenTree*, AstSenTree*>{pairs.begin(), pairs.end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue