void migrate_block(Block* target, Migration* migration) { ca_assert(target != migration->oldBlock); if (target == migration->newBlock) return; // Store a cache of lookups that we've made in this call. TermMap cache; for (BlockIterator it(target); it; ++it) { Term* term = *it; // Iterate through each "dependency", which includes the function & inputs. for (int i=0; i < term->numDependencies(); i++) { Term* ref = term->dependency(i); Term* newRef = NULL; if (cache.contains(ref)) { newRef = cache[ref]; } else { // Lookup and save result in cache newRef = migrate_term_pointer(ref, migration); cache[ref] = newRef; } // Possibly rebind if (newRef != ref) term->setDependency(i, newRef); } } }
void update_all_code_references(Branch* target, Branch* oldBranch, Branch* newBranch) { ca_assert(target != oldBranch); ca_assert(target != newBranch); // Store a cache of lookups that we've made in this call. TermMap cache; for (BranchIterator it(target); it.unfinished(); it.advance()) { Term* term = *it; // Iterate through each "dependency", which includes the function & inputs. for (int i=0; i < term->numDependencies(); i++) { Term* ref = term->dependency(i); Term* newRef = NULL; if (cache.contains(ref)) { newRef = cache[ref]; } else { // Lookup and save result in cache newRef = translate_term_across_branches(ref, oldBranch, newBranch); cache[ref] = newRef; } // Possibly rebind if (newRef != ref) term->setDependency(i, newRef); } } }