SplitUnorganized:
PUBLIC
PROC [d: Design, take: Set
--of CellInstance--]
RETURNS [from, to: CellType] ~ {
from ← NARROW[d.cct[i].Image[take].TheElt.VA];
IF NOT d.arrayElt.MappingEmpty[AV[from], rightToLeft] THEN ERROR nyet;
{takename: SteppyName ~ VSn[from.fullName[i].Image[take].First[].Val];
fix: OneToOne ~ BiRels.CreateRopeCat[Rope.Cat["-", takename.UnparseSteppyName], suffix];
to ← CreateCellType[d, unorganized, fix.Image[d.CTNames[from]]];
[] ← d.crossedCellTypes.AddA[from];
[] ← d.crossedCellTypes.AddA[to];
{allcis: Set ~ from.Subcells[];
keep: Set ~ allcis.Difference[take].CreateHashCopy[];
tw: Set ~ d.iwConns.Image[take];
kw: Set ~ d.iwConns.Image[keep];
twRoots: Set ~ d.toRoot.Image[tw].CreateHashCopy[];
kwRoots: Set ~ d.toRoot.Image[kw].CreateHashCopy[];
twForest: Set ~ d.toRoot.Image[twRoots, rightToLeft].CreateHashCopy[];
kwForest: Set ~ d.toRoot.Image[kwRoots, rightToLeft].CreateHashCopy[];
dwForest: Set ~ from.CTParts[w].Difference[kwForest].CreateHashCopy[];
bw: Set ~ tw.Intersection[kw];
bwRoots: Set ~ d.toRoot.Image[bw].CreateHashCopy[];
bwForest: Set ~ d.toRoot.Image[bwRoots, rightToLeft].CreateHashCopy[];
npbwForest: Set ~ bwForest .Difference[from.asu.publics] .CreateHashCopy[];
[] ← FullySfwdlyExportWires[from, npbwForest];
IF NOT npbwForest.Subset[from.asu.publics] THEN ERROR;
{tp: Set ~ from.asu.exports.Image[twForest, rightToLeft];
kp: Set ~ from.asu.exports.Image[kwForest, rightToLeft];
tpRoots: Set ~ d.toRoot.Image[tp].CreateHashCopy[];
kpRoots: Set ~ d.toRoot.Image[kp].CreateHashCopy[];
tpForest: Set ~ d.toRoot.Image[tpRoots, rightToLeft].CreateHashCopy[];
kpForest: Set ~ d.toRoot.Image[kpRoots, rightToLeft].CreateHashCopy[];
dpForest: Set ~ from.CTParts[p].Difference[kpForest].CreateHashCopy[];
portWas: OneToOne ~ CopyPWStructure[from, to, p, tpForest, nilSet];
wireWas: OneToOne ~ CopyPWStructure[from, to, w, twForest, nilSet];
ciWas: OneToOne ~ CopyInstStructure[from, to, take, nilSet, wireWas, [], ALL[0]];
FixInst:
PROC [ociv: Sets.Value]
RETURNS [
BOOL] ~ {
oci: CellInstance ~ NARROW[ociv.VA];
cct: CellType ~ d.CiCct[oci];
nci: CellInstance ~ Instantiate[to, cct, FALSE, IF d.physd THEN VXfm[d.ciXfm.ApplyA[oci].Val] ELSE [], oci.offset, cct.INames[oci]];
ConnectPWs[d, portWas.Compose[oci.conns], nci];
RETURN [FALSE]};
ConnectPWs[d, portWas.Compose[from.asu.exports.Compose[wireWas.Invert]], to];
IF d.ciType.ScanMapping[AV[from], FixInst, rightToLeft].found THEN ERROR;
DeletePorts[from, dpForest, TRUE, FALSE];
DeleteWires[from, dwForest, TRUE];
DeleteInsts[d, take, TRUE];
RETURN}}}};