<<--File: IPFloorPlanImpl.mesa>> <> <<>> DIRECTORY Real, IP, IPSimpleTree, IPBasicOps, IPCoTab, IPTop, IPTopOps, IPFloorMinCut, IPFloorPlan; IPFloorPlanImpl: CEDAR PROGRAM IMPORTS Real, IP, IPBasicOps, IPSimpleTree, IPCoTab, IPTopOps, IPTop, IPFloorMinCut EXPORTS IPFloorPlan = BEGIN OPEN IPFloorPlan; 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.RoundLI[Real.SqRt[mcRoot.areaEstimate]]; rootComp: IPCoTab.Component _ IPCoTab.CreateComponent2[top.coTab, mcRoot.name, IP.ShapeRep[dim: IPBasicOps.NuNatVector[sqDim, sqDim]], TRUE, 0, [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: NAT; 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: NAT _ yDim * negChild.areaEstimate/(negChild.areaEstimate + posChild.areaEstimate); yP: NAT _ yDim - yN; negChildShape _ [dim: IPBasicOps.NuNatVector[xDim, yN]]; posChildShape _ [dim: IPBasicOps.NuNatVector[xDim, yP]]}; ver => { xN: NAT _ xDim * negChild.areaEstimate/(negChild.areaEstimate + posChild.areaEstimate); xP: NAT _ 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 END.