[
design: Design,
fromAncestorCT, toAncestorCT: CellType,
eltConnections: ConstOneToOne--port of toAncestorCT é port of fromAncestorCT--,
doomedFromPorts: ConstSet--of port of fromAncestorCT--,
eltTPToWire: UWFunction--port of toAncestorCT b prototypical wire--,
subTail: ROPE--to append to name of from array--,
pairs: VarOneToOne--instance of from or ancestor é instance of to or ancestor--
SplitArray:
PROC [fromArrayCT: CellType] ~ {
fa: Array ~ fromArrayCT.asArray;
faName: ROPE ~ NARROW[Asserting.FnVal[nameReln, fromArrayCT.otherPublic]];
taName: ROPE ~ faName.Cat[subTail];
toArrayCT: CellType ~ CreateArray[design, taName, NIL, toAncestorCT, fa.size2, fa.basePeriod, fromArrayCT.inheritNames, NIL, NIL];
ta: Array ~ toArrayCT.asArray;
arrayConnectionsV: VarOneToOne--port of toArrayCT é port of fromArrayCT-- ~ BiRels.CreateHashOTO[];
arrayTPToWireV: VarFunction--port of ta b wire-- ~ BiRels.CreateHashFn[];
doomedArrayPortsV: VarSet--of port of fa-- ~ Sets.CreateHashSet[];
NotDoomed:
PROC [fep: Port]
RETURNS [
BOOL]
~ {RETURN [NOT doomedFromPorts.HasMemA[fep]]};
HasNew:
PROC [fep: Port]
RETURNS [
BOOL]
~ {RETURN [eltConnections.ApplyA[fep, rightToLeft].found]};
toNewComp: SubComponenting ~ CreateSubComponents[fa, HasNew];
inSameNewComp: BiRel--between svs of fa-- ~ toNewComp[TRUE].Compose[toNewComp[TRUE].Invert];
nonDoomedSVs: Set--of sv of fa-- ~ FilterSVs[fa, NotDoomed];
inNonDoomedNewComp: Set--of sv of fa-- ~ inSameNewComp.Image[nonDoomedSVs];
crossings: LIST OF RECORD [hasNew, hasnt: StatVertex, d: Int2] ← NIL;
NoteCrossing:
PROC [in, out: StatVertex,
d: Int2] ~ {
IF inNonDoomedNewComp.HasMemA[in]
THEN crossings ← CONS[[in, out, d], crossings]};
tNewStat: StatRep ~ CopySubGraph[fa, HasNew, eltConnections.Invert.AsConst, NoteCrossing];
sizeRange: Range2 ~ SizeRange[fa.size2];
SetStatRep[toArrayCT, tNewStat, FALSE];
FOR crossings ← crossings, crossings.rest
WHILE crossings #
NIL
DO
rA: Range2 ~ Range2Intersection[sizeRange, Range2Off[sizeRange, Int2Neg[crossings.first.d]]];
irA: Range2 ~ Range2Div[rA, fa.basePeriod, crossings.first.hasNew.phase];
FOR i
f:
NATURAL
IN [
NATURAL[irA[Foo].min] ..
NATURAL[irA[Foo].maxPlusOne])
DO
FOR i
b:
NATURAL
IN [
NATURAL[irA[Bar].min] ..
NATURAL[irA[Bar].maxPlusOne])
DO
aiA: ArrayIndex ~ Int2Mul[[if, ib], fa.basePeriod, crossings.first.hasNew.phase];
aiB: ArrayIndex ~ Int2Add[aiA, crossings.first.d];
tep: Port ~ NARROW[eltConnections.ApplyA[crossings.first.hasNew.port, rightToLeft].MA];
tepw: Wire ~ NARROW[eltTPToWire.ApplyA[tep].MA];
fap: Port--of fromArrayCT-- ~ GetArrayPortForPort[fromArrayCT, aiB, crossings.first.hasnt.port, TRUE];
tap: Port--of toArrayCT-- ~ GetArrayPortForPort[toArrayCT, aiA, tep, TRUE];
np: BiRels.HadPair ~ arrayConnectionsV.AddAA[tap, fap];
IF np#ALL[none] AND np#ALL[same] THEN ERROR;
[] ← arrayTPToWireV.AddAA[tap, tepw];
design ← design;
ENDLOOP ENDLOOP;
ENDLOOP;
{fNewStat: StatRep ~ CopySubGraph[fa, NotDoomed, refsID, NIL];
FindRep:
PROC [left, right:
REF
ANY] ~ {
fap: Port ~ NARROW[left];
dw: DumbWire ~ NARROW[right];
fep: Port ~ ScanPortsInDumbWire[fa, dw, NotDoomed].ep;
IF fep#
NIL
THEN {
ai: ArrayIndex ~ GetInstForPortInDumbWire[fa, dw, fep];
IF ai=ALL[-1] THEN ERROR;
fNewStat.apToPAI.AddNewAA[fap, NEW [PortAtIndexPrivate ← [fep, ai]]]}
ELSE IF NOT doomedArrayPortsV.AddA[fap] THEN ERROR;
RETURN};
fa.dumrep.apToWire.EnumAA[FindRep];
SetStatRep[fromArrayCT, fNewStat, TRUE];
{arrayConnections: ConstFunction ~ arrayConnectionsV.Freeze;
doomedArrayPorts: ConstSet ~ doomedArrayPortsV.Freeze;
arrayTPToWire: ConstFunction ~ arrayTPToWireV.Freeze;
KillDoomedArrayPort:
PROC [ra:
REF
ANY] ~ {
p: Port--of fromArrayCT-- ~ NARROW[ra];
RemovePort[p];
RETURN};
FixArrays[design, fromArrayCT, toArrayCT, arrayConnections, doomedArrayPorts, arrayTPToWire, subTail, pairs];
FixInstances[fromArrayCT, toArrayCT, arrayConnections, doomedArrayPorts, arrayTPToWire, pairs];
doomedArrayPorts.EnumA[KillDoomedArrayPort];
RETURN}}};