SortEdges:
PROC [decoration: CoreGeometry.Decoration, ll:
CD.Layer, cellType: Core.CellType]
RETURNS [edges: SortedEdges] = {
FOR ss: CoreGeometry.Side
IN CoreGeometry.Side
DO
wmm: LIST OF REF WireMinMax ← NIL;
edge: LIST OF Core.Wire ← NIL;
EachWirePin: CoreGeometry.EachWirePinProc = {
IF wire.size#0 OR side#ss OR layer#ll THEN RETURN;
wmm ← CONS [NEW [WireMinMax ← [wire, min, max]], wmm];
};
CompareWMM: GList.CompareProc = {
wmm1: REF WireMinMax = NARROW [ref1];
wmm2: REF WireMinMax = NARROW [ref2];
RETURN [Basics.CompareInt[wmm2.min, wmm1.min]];
};
[] ← CoreGeometry.EnumerateNonOverlappingSides[decoration, cellType, EachWirePin];
FOR list:
LIST
OF
REF WireMinMax ←
NARROW [GList.Sort[wmm, CompareWMM]], list.rest
WHILE list#
NIL
DO
edge ← CONS [list.first.wire , edge];
ENDLOOP;
edges[ss] ← edge;
ENDLOOP;
};
MatchSourceToExtracted:
PUBLIC
PROC [sdecoration, edecoration: CoreGeometry.Decoration, slayer, elayer:
CD.Layer, source, extracted: Core.CellType, name: Core.
ROPE ←
NIL, props: Core.Properties ←
NIL]
RETURNS [new: Core.CellType] = {
sourceEdges: SortedEdges ← SortEdges[sdecoration, slayer, source];
extractedEdges: SortedEdges ← SortEdges[edecoration, elayer, extracted];
public: Core.Wire ← CoreOps.CopyWire[source.public];
table: RefTab.Ref ← RefTab.Create[]; -- from extracted to new
sourceToNew: RefTab.Ref ← CoreOps.CreateBindingTable[source.public, public]; -- from source to new
FOR side: CoreGeometry.Side
IN CoreGeometry.Side
DO
length: INT = GList.Length[sourceEdges[side]];
IF length#GList.Length[extractedEdges[side]] THEN ERROR;
THROUGH [0 .. length)
DO
sourceWire: Core.Wire ← sourceEdges[side].first;
extractedWire: Core.Wire ← extractedEdges[side].first;
newWire: Core.Wire ← NARROW [RefTab.Fetch[sourceToNew, sourceWire].val];
prevNew: Core.Wire ← NARROW [RefTab.Fetch[table, extractedWire].val];
IF prevNew#NIL AND prevNew#newWire THEN ERROR;
[] ← RefTab.Store[table, extractedWire, newWire];
sourceEdges[side] ← sourceEdges[side].rest;
extractedEdges[side] ← extractedEdges[side].rest;
ENDLOOP;
ENDLOOP;
IF RefTab.GetSize[table]#CoreOps.WireBits[public] THEN ERROR;
new ← CoreClasses.CreatePermutedRecordCell[iconPublic: public, schCell: extracted, table: table, name: name, props: props];
};