<> <> <<>> DIRECTORY Convert, Rope, SC, SCInstUtil, SCInitialPlace, SCPlaceUtil, SCPrivate, SCRowUtil, TerminalIO; SCInitialPlaceImpl: CEDAR PROGRAM IMPORTS Convert, Rope, SC, SCInstUtil, SCPlaceUtil, SCRowUtil, TerminalIO EXPORTS SCInitialPlace SHARES SC = { <> PosInitBp: PROCEDURE[handle: SC.Handle, side: SC.Side] = { <> PreAssign: SCRowUtil.EachInstProc = { <> Check: SCRowUtil.EachInstProc = { <> IF firstInst.fnlPos = instance.fnlPos THEN { TerminalIO.PutRope[Rope.Cat[" Two instances have same position: ", firstInst.name, " and ", instance.name]]; TerminalIO.PutRope[Rope.Cat["\n pos = ", Convert.RopeFromInt[instance.fnlPos], "\n"]]}}; firstInst: SCPrivate.Instance _ instance; IF firstInst.fnlPos > 0 THEN [] _ SCRowUtil.EnumerateInstsOnSide[handle, side, pos +1, bpRow.nBpsOnSide, Check]}; <> Sort: SCRowUtil.EachInstProc = { <> InnerSort: SCRowUtil.EachInstProc = { <> IF bpRow.bpsOnSide[pos].fnlPos < bpRow.bpsOnSide[firstPos].fnlPos THEN { bpRow.bpsOnSide[pos] _ bpRow.bpsOnSide[firstPos]; bpRow.bpsOnSide[firstPos] _ instance}}; firstInst: SCPrivate.Instance _ instance; firstPos: INT _ pos; [] _ SCRowUtil.EnumerateInstsOnSide[handle, side, pos +1, bpRow.nBpsOnSide, InnerSort]}; <> FixUp: SCRowUtil.EachInstProc = { <> instance _ bpRow.bpsOnSide[pos]; instance.curPos _ pos}; layoutData: SCPrivate.LayoutData _ NARROW[handle.layoutData]; bpRow: SCPrivate.BpRow _ layoutData.bpRows[side]; <> IF bpRow.fnlBpFxd OR bpRow.initBpFxd THEN { <> [] _ SCRowUtil.EnumerateAllInstsOnSide[handle, side, PreAssign]; <<>> <> [] _ SCRowUtil.EnumerateAllInstsOnSide[handle, side, Sort]; <> [] _ SCRowUtil.EnumerateAllInstsOnSide[handle, side, FixUp]} ELSE {-- positions on side were not specified assign positions <<>> <> [] _ SCRowUtil.EnumerateAllInstsOnSide[handle, side, FixUp]}; SCInstUtil.BpOffsets[handle, side, 0, SCPrivate.maxPos]}; <> PosInitLg: PROCEDURE[handle: SC.Handle, row: SCPrivate.MaxRowSr] = { <> PreAssign: SCRowUtil.EachInstProc = { <> Check: SCRowUtil.EachInstProc = { <> IF firstInst.fnlPos = instance.fnlPos THEN { TerminalIO.PutRope[Rope.Cat[" Two instances have same position: ", firstInst.name, " and ", instance.name]]; TerminalIO.PutRope[Rope.Cat["\n pos = ", Convert.RopeFromInt[instance.fnlPos], "\n"]]}}; firstInst: SCPrivate.Instance _ instance; IF firstInst.fnlPos > 0 THEN [] _ SCRowUtil.EnumerateInstsOnRow[handle, row, pos +1, lgRow.nLgsOnRow, Check]}; <> Sort: SCRowUtil.EachInstProc = { <> InnerSort: SCRowUtil.EachInstProc = { <> IF lgRow.lgsOnRow[pos].fnlPos < lgRow.lgsOnRow[firstPos].fnlPos THEN { lgRow.lgsOnRow[pos] _ lgRow.lgsOnRow[firstPos]; lgRow.lgsOnRow[firstPos] _ instance}}; firstInst: SCPrivate.Instance _ instance; firstPos: INT _ pos; [] _ SCRowUtil.EnumerateInstsOnRow[handle, row, pos +1, lgRow.nLgsOnRow, InnerSort]}; <> FixUp: SCRowUtil.EachInstProc = { <> instance _ lgRow.lgsOnRow[pos]; instance.curPos _ pos}; layoutData: SCPrivate.LayoutData _ NARROW[handle.layoutData]; lgRow: SCPrivate.LgRow _ layoutData.lgRows.rows[row]; <> IF lgRow.fnlLgFxd OR lgRow.initLgFxd THEN { <> [] _ SCRowUtil.EnumerateAllInstsOnRow[handle, row, PreAssign]; <> [] _ SCRowUtil.EnumerateAllInstsOnRow[handle, row, Sort]; <<>> <> [] _ SCRowUtil.EnumerateAllInstsOnRow[handle, row, FixUp]} ELSE { -- positions on row were not specified assign positions <<>> <> [] _ SCRowUtil.EnumerateAllInstsOnRow[handle, row, FixUp]}; SCInstUtil.LgOffsets[handle, row, 0, SCPrivate.maxPos]}; PosInit: PUBLIC PROCEDURE [handle: SC.Handle] = { <> DoRow: SCRowUtil.EachRowProc = { PosInitLg[handle, row]}; [] _ SCRowUtil.EnumerateRows[handle, DoRow]; <> <> PosInitBp[handle, bottom]; PosInitBp[handle, top]}; RowInit: PUBLIC PROCEDURE [handle: SC.Handle] = { NextUnplaced: PROCEDURE [handle: SC.Handle] RETURNS [inst: SCPrivate.Instance _ NIL] = { EachInstance: SCInstUtil.EachInstanceProc = { SELECT instance.whichClass FROM logic => IF instance.curRow = 0 THEN inst _ instance; io => IF instance.curSide = none THEN inst _ instance; ENDCASE; quit _ inst = instance}; [] _ SCInstUtil.EnumerateAllInstances[handle, EachInstance]}; RowPlacInit: PROCEDURE [handle: SC.Handle, instance: SCPrivate.Instance] = { PutRow: SCRowUtil.EachRowProc = { IF lgRow.size.p <= minRowLength THEN IF ~lgRow.fnlLgFxd THEN {minRow _ row; minRowLength _ lgRow.size.p; useRow _ row}}; minRow, useRow: SCPrivate.ZMaxRowSr _ 0; minRowLength: SC.Number _ LAST[INT]; [] _ SCRowUtil.EnumerateRows[handle, PutRow]; IF useRow = 0 THEN {SC.Signal[callingError, Rope.Cat["no valid row to place instance: ", instance.name, "\n"]]; useRow _ 1}; SCPlaceUtil.PutLgRow[handle, instance, useRow]}; SidePlacInit: PROCEDURE [handle: SC.Handle, instance: SCPrivate.Instance] = { PutSide: SCRowUtil.EachSideProc = { IF bpRow.nBpsOnSide <= minSideLength THEN IF ~bpRow.fnlBpFxd AND bpRow.nBpsOnSide < bpRow.maxBpsOnSide THEN {minSide _ side; minSideLength _ bpRow.nBpsOnSide; useSide _ side}}; minSide, useSide: SC.SideOrNone _ none; minSideLength: SC.Number _ LAST[INT]; [] _ SCRowUtil.EnumerateSides[handle, PutSide]; IF useSide = none THEN {SC.Signal[callingError, Rope.Cat["no valid side to place instance: ", instance.name, "\n"]]; useSide _ left}; SCPlaceUtil.PutBpSide[handle, instance, useSide]}; <> <> FOR instance: SCPrivate.Instance _ NextUnplaced[handle], NextUnplaced[handle] WHILE instance # NIL DO IF instance.whichClass = logic THEN RowPlacInit[handle, instance] ELSE IF instance.whichClass = io THEN SidePlacInit[handle, instance]; ENDLOOP; <> PosInitBp[handle, left]; PosInitBp[handle, right]}; }.