FloorPlan:
PUBLIC
PROC[top: IPTop.Ref, depth:
NAT ←
LAST[
NAT], firstCut:
IP.OrientationTypes] ={
BEGIN
--(1) Prepare top for floor planning
IF ~IPTop.NoTopology[top] THEN IPTop.ClearChannels[top];
RemoveFakeComps[top, FALSE]
END;
BEGIN
--(2) Do initial floor plan and call RecursiveFloorPlanning
mcTree: IPSimpleTree.Ref ← IPFloorMinCut.DoMinCut[top];
mcRoot: IPSimpleTree.Node ← IPSimpleTree.GetRoot[mcTree];
sqDim: INT ← Real.InlineRound[Real.SqRt[mcRoot.areaEstimate]];
rootComp: IPCoTab.Component ← IPCoTab.CreateComponent2[top.coTab, mcRoot.name, IP.ShapeRep[dim: IPBasicOps.NuNatVector[sqDim, sqDim]], TRUE, original, [0, 0]];
rootComp.any ← mcRoot;
[] ← IPTop.ReDefineChs[top];
RecursiveFP[top, mcTree, rootComp, depth, firstCut];
IPTop.Geometrize[top]
END;
}; --FloorPlan
AssignLot:
PUBLIC
PROC[top: IPTop.Ref, reversible:
BOOL] ={
compsToSwap: LIST OF IPCoTab.Component ← NIL;
CollectComps: IPCoTab.EachComponentAction ={
IF co.any #
NIL
AND
ISTYPE[co.any, IPSimpleTree.Node]
THEN{
coNode: IPSimpleTree.Node ← NARROW[co.any];
IF coNode.any #
NIL
AND
ISTYPE[coNode.any, IPCoTab.Component]
--found a fake leaf node. Swap with real ones
THEN compsToSwap ← CONS[co, compsToSwap]};
}; -- CollectComps
IPCoTab.Components[top.coTab, CollectComps];
UNTIL compsToSwap
= NIL DO
fakeComp: IPCoTab.Component ← compsToSwap.first;
realComp: IPCoTab.Component←NARROW[NARROW[fakeComp.any, IPSimpleTree.Node].any];
[] ← IPTopOps.SwapComponents[top, fakeComp, realComp, TRUE];
compsToSwap ← compsToSwap.rest
ENDLOOP;
IF ~ reversible
THEN {
RemoveFakeComps[top, TRUE];
IPTopOps.ResetStacks[top]
};
IPTop.Geometrize[top]
}; --AssignLot
RemoveFakeComps:
PROC[top: IPTop.Ref, nonActiveOnly:
BOOL] ={
fakeComps: LIST OF IPCoTab.Component ← NIL;
CollectFakeComps: IPCoTab.EachComponentAction ={
IF nonActiveOnly AND IPCoTab.CoActive[co] THEN RETURN;
IF co.any #
NIL
AND
ISTYPE[co.any, IPSimpleTree.Node]
THEN fakeComps ← CONS[co, fakeComps]
}; --CollectFakeComps
IPCoTab.AllComponents[top.coTab, CollectFakeComps];
UNTIL fakeComps =
NIL
DO
IPCoTab.DestroyComponent2[top.coTab, fakeComps.first];
fakeComps ← fakeComps.rest;
ENDLOOP;
}; --RemoveFakeComps
RecursiveFP:
PROC[top: IPTop.Ref, mcTree: IPSimpleTree.Ref, comp: IPCoTab.Component, depth:
NAT, cutHint:
IP.OrientationTypes] ={
compNode: IPSimpleTree.Node ← NARROW[comp.any];
nodeChildrens: LIST OF IPSimpleTree.Node;
negChild, posChild: IPSimpleTree.Node;
negComp, posComp: IPCoTab.Component;
negChildShape, posChildShape: IP.ShapeRep;
xDim, yDim: INT;
IF depth = 0 OR compNode.children = NIL THEN RETURN;
nodeChildrens ← IPSimpleTree.GetChildren[mcTree, compNode];
IF nodeChildrens.rest.rest #
NIL
THEN ERROR IP.Error[callingError, "Input Min-Cut Tree is Not a Binary Tree"];
negChild ← nodeChildrens.first;
posChild ← nodeChildrens.rest.first;
[xDim, yDim] ← IPCoTab.GetDim[comp];
SELECT cutHint
FROM
--Check cutHint
hor => IF xDim > yDim THEN cutHint ← ver; --can't honor hint
ver => IF xDim < yDim THEN cutHint ← hor; --can't honor hint
ENDCASE => ERROR;
SELECT cutHint
FROM
hor => {
yN: INT ← yDim * negChild.areaEstimate/(negChild.areaEstimate + posChild.areaEstimate);
yP: INT ← yDim - yN;
negChildShape ← [dim: IPBasicOps.NuNatVector[xDim, yN]];
posChildShape ← [dim: IPBasicOps.NuNatVector[xDim, yP]]};
ver => {
xN: INT ← xDim * negChild.areaEstimate/(negChild.areaEstimate + posChild.areaEstimate);
xP: INT ← xDim - xN;
negChildShape ← [dim: IPBasicOps.NuNatVector[xN, yDim]];
posChildShape ← [dim: IPBasicOps.NuNatVector[xP, yDim]]};
ENDCASE => ERROR;
[] ← IPTopOps.SpawnComps[top, comp, negChild.name, posChild.name, negChildShape, posChildShape, cutHint];
negComp ← IPCoTab.GetComponent[top.coTab, negChild.name];
posComp ← IPCoTab.GetComponent[top.coTab, posChild.name];
negComp.any ← negChild;
posComp.any ← posChild;
RecursiveFP[top, mcTree, negComp, depth.PRED, IPBasicOps.OTFlip[cutHint]];
RecursiveFP[top, mcTree, posComp, depth.PRED, IPBasicOps.OTFlip[cutHint]];
}; --RecursiveFP