SCUtilImpl.mesa
Copyright Ó 1985, 1986, 1987 by Xerox Corporation. All rights reserved.
Bryan Preas, August 20, 1987 12:26:24 pm PDT
Christian Le Cocq July 9, 1987 3:02:26 pm PDT
DIRECTORY
Basics, CD, CDSymbolicObjects, Core, CoreGeometry, CoreProperties, FS, IO, RedBlackTree, Rope, RTBasic, SC, SCInstUtil, SCPrivate, SCUtil, TerminalIO;
SCUtilImpl: CEDAR PROGRAM
IMPORTS Basics, CoreProperties, FS, IO, RedBlackTree, Rope, RTBasic, SC, SCInstUtil, TerminalIO
EXPORTS SCUtil
SHARES SC =
BEGIN
FindPin: PUBLIC PROCEDURE [object: SCPrivate.Object, pinName: Rope.ROPE] RETURNS [pin: SCPrivate.ObjectPin ← NIL] =
BEGIN
pins: SCPrivate.ObjectPins ← object.pins;
FOR pinIndex: NAT IN [0 .. object.numPins) WHILE pin = NIL DO
IF Rope.Equal[pinName, pins.p[pinIndex].name] THEN pin ← pins.p[pinIndex];
ENDLOOP;
END;
FindPinByWire: PUBLIC PROCEDURE [object: SCPrivate.Object, wire: Core.Wire] RETURNS [pin: SCPrivate.ObjectPin ← NIL] =
BEGIN
pins: SCPrivate.ObjectPins ← object.pins;
FOR pinIndex: NAT IN [0 .. object.numPins) WHILE pin = NIL DO
IF wire = pins.p[pinIndex].publicWire THEN pin ← pins.p[pinIndex];
ENDLOOP;
END;
FindNet: PUBLIC PROCEDURE [handle: SC.Handle, netName: Rope.ROPE] RETURNS [net: SCPrivate.Net ← NIL] =
BEGIN
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
nets: SCPrivate.Nets ← structureData.nets;
FOR netIndex: NAT IN [1 .. nets.count] WHILE net = NIL DO
IF Rope.Equal[netName, nets.nets[netIndex].name] THEN net ← nets.nets[netIndex];
ENDLOOP;
END;
FindNetByWire: PUBLIC PROCEDURE [handle: SC.Handle, wire: Core.Wire] RETURNS [net: SCPrivate.Net ← NIL] =
BEGIN
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
nets: SCPrivate.Nets ← structureData.nets;
FOR netIndex: NAT IN [1 .. nets.count] WHILE net = NIL DO
IF wire = nets.nets[netIndex].wire THEN net ← nets.nets[netIndex];
ENDLOOP;
END;
FindObject: PUBLIC PROCEDURE [handle: SC.Handle, objectName: Rope.ROPE] RETURNS [object: SCPrivate.Object ← NIL] =
BEGIN
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
objects: SCPrivate.Objects ← structureData.objects;
FOR objectIndex: NAT IN [1 .. objects.count] WHILE object = NIL DO
IF Rope.Equal[objectName, objects.ob[objectIndex].name] THEN object ← objects.ob[objectIndex];
ENDLOOP;
END;
FindObjectByCell: PUBLIC PROCEDURE [handle: SC.Handle, cellType: Core.CellType] RETURNS [object: SCPrivate.Object ← NIL] =
BEGIN
objects: SCPrivate.Objects ← NARROW[handle.structureData, SCPrivate.StructureData].objects;
FOR objectIndex: NAT IN [1 .. objects.count] WHILE object = NIL DO
IF cellType = objects.ob[objectIndex].cellType THEN object ← objects.ob[objectIndex];
ENDLOOP;
END;
FindInstance: PUBLIC PROCEDURE [handle: SC.Handle, instanceName: Rope.ROPE] RETURNS [instance: SCPrivate.Instance ← NIL] =
BEGIN
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
instances: SCPrivate.Instances ← structureData.instances;
FOR instanceIndex: NAT IN [1 .. instances.count] WHILE instance = NIL DO
IF Rope.Equal[instanceName, instances.inst[instanceIndex].name] THEN instance ← instances.inst[instanceIndex];
ENDLOOP;
END;
IsPowerName: PUBLIC PROCEDURE [handle: SC.Handle, name: Rope.ROPE] RETURNS [found: BOOLEANFALSE] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
powerBuses: SCPrivate.PowerBuses ← layoutData.powerBuses;
IF Rope.Equal[name, powerBuses[left].name, FALSE] OR Rope.Equal[name, powerBuses[right].name, FALSE] THEN found ← TRUE};
DirectionFromSide: PUBLIC PROC [side: CoreGeometry.Side] RETURNS [CDSymbolicObjects.Direction] ~ {
RETURN[SELECT side FROM
bottom=> south, right => east, top => north, left => west, ENDCASE => SC.Error[callingError, "Not suppose to happen."]]};
WriteResults: PUBLIC PROCEDURE [title: Rope.ROPE, handle: SC.Handle, startArea: SC.Number] RETURNS [area: SC.Number] = {
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
lambda: SC.Number ← handle.rules.rowParms.technology.lambda;
width: SC.Number ← layoutData.totWidth/lambda;
height: SC.Number ← layoutData.totHeight/lambda;
area ← width*height;
TerminalIO.PutRope[title];
TerminalIO.PutF1[" width = %g", IO.int[width]];
TerminalIO.PutF1[", height = %g", IO.int[height]];
TerminalIO.PutF1[", area = %g", IO.int[area]];
IF startArea > 0 THEN {
reduction: SC.Number ← (startArea - area)*100/startArea;
TerminalIO.PutRope[IO.PutFR[" reduction = %g%%\n", IO.real[reduction]]]};
TerminalIO.PutRope["\n"];
};
WriteStructure: PUBLIC PROCEDURE [handle: SC.Handle] = {
EachInstance: SCInstUtil.EachInstanceProc = {
EachPin: SCInstUtil.EachPinProc = {
TerminalIO.PutRope[Rope.Cat[" Pin: ", netPin.pin.name, " Net: ", netPin.net.name, "\n"]]};
TerminalIO.PutRope[Rope.Cat[" Instance: ", instance.name, " Object: ", instance.object.name, "\n"]];
[] ← SCInstUtil.EnumeratePinsOnInst[instance, EachPin]};
TerminalIO.PutRope[Rope.Cat["Handle: ", handle.name, "\n"]];
[] ← SCInstUtil.EnumerateAllInstances[handle, EachInstance]};
XYToPQ: PUBLIC PROC [handle: SC.Handle, pos: SC.Pos] RETURNS [pqPos: RTBasic.PQPos] = {
convert a position from x-y to p-q space.
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
rowDirection: SC.Direction ← layoutData.layoutParms.rowDirection;
RETURN[RTBasic.XYToPQ[rowDirection, pos]]};
PQToXY: PUBLIC PROC [handle: SC.Handle, pqPos: RTBasic.PQPos] RETURNS [pos: SC.Pos] = {
convert a position from p-q to x-y space.
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
rowDirection: SC.Direction ← layoutData.layoutParms.rowDirection;
RETURN[RTBasic.PQToXY[rowDirection, pqPos]]};
DestroyRules: PUBLIC PROC [handle: SC.Handle] ~ {
rules: SC.DesignRules ← handle.rules;
rules.rowRules.technology ← NIL;
rules.rowRules ← NIL;
rules.sideRules.technology ← NIL;
rules.sideRules ← NIL;
handle.rules ← NIL};
DestroyParms: PUBLIC PROC [handle: SC.Handle] = {
parms: SCPrivate.Parms ← NARROW[handle.parms];
parms.libDesign ← NIL;
parms.ftObject ← NIL;
parms.portObject ← NIL;
handle.parms ← NIL};
Memb: PROC [rope: Rope.ROPE, list: LIST OF Rope.ROPE] RETURNS [BOOL] = {
UNTIL list = NIL DO
IF Rope.Equal[list.first, rope] THEN RETURN[TRUE];
list ← list.rest;
ENDLOOP;
RETURN[FALSE];
};
GetCoreInvestmentProp: PUBLIC PROC [cellType: Core.CellType, prop: ATOM] RETURNS [SC.HowLongToWork] ~ {
get an investment property from a cell
value: ATOMNARROW[CoreProperties.GetCellTypeProp[cellType, prop]];
investment: SC.HowLongToWork ← SELECT value FROM
SC.veryLongValue => veryLong,
SC.longValue => long,
SC.mediumValue => medium,
SC.shortValue => short,
SC.veryShortValue => veryShort,
ENDCASE => noInvestmentProp;
RETURN[investment]};
WriteTWFiles: PUBLIC PROC [handle: SC.Handle] ~ {
write the timberWolf files
EachInstance: SCInstUtil.EachInstanceProc ~ {
PROC [instance: SCPrivate.Instance] RETURNS [quit: BOOLFALSE];
EachPin: SCInstUtil.EachPinProc ~ {
PROC [instance: SCPrivate.Instance, pin: NAT, netPin: SCPrivate.PinNet] RETURNS [quit: BOOL ← FALSE];
IF netPin.net # NIL THEN
AddPin[celStream, instance, netPin.pin, netPin.net, first]; -- for TimberWolf .cel file
first ← FALSE};
first: BOOLEANTRUE;
IF instance.whichClass = logic THEN { -- for TimberWolf .cel file
AddCell[celStream, instance];
[] ← SCInstUtil.EnumeratePinsOnInst[instance, EachPin]}
ELSE IF instance.whichClass = io THEN
AddPad[padTable, instance]};
netStream: FS.STREAMFS.StreamOpen[Rope.Cat[handle.name, ".net"], $create];
parStream: FS.STREAMFS.StreamOpen[Rope.Cat[handle.name, ".par"], $create];
blkStream: FS.STREAMFS.StreamOpen[Rope.Cat[handle.name, ".blk"], $create];
celStream: FS.STREAMFS.StreamOpen[Rope.Cat[handle.name, ".cel"], $create];
padTable: RedBlackTree.Table ← RedBlackTree.Create[GetKey, Compare];
parms: SCPrivate.Parms ← NARROW[handle.parms];
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
first the net file
IO.Put[netStream, IO.rope["allnets HVweights 1.0 1.0\n"]];
IO.Flush[netStream]; IO.Close[netStream];
next the parameter file
IO.Put[parStream, IO.rope["indent 1.0\n"]];
IO.Put[parStream, IO.rope["rowSep 1.0\n"]];
IO.Put[parStream, IO.rope["implicit.feed.thru.range 0.25\n"]];
IO.Put[parStream, IO.rope["feedThruWidth "], IO.int[parms.ftObject.size.p], IO.rope["\n"]];
IO.Flush[parStream]; IO.Close[parStream];
next the row definitions
FOR row: INT IN [1 .. layoutData.lgRows.count] DO
IO.Put[blkStream, IO.rope["block height "], IO.int[parms.ftObject.size.q], IO.rope[" class 1\n"]];
ENDLOOP;
IO.Flush[blkStream]; IO.Close[blkStream];
finally the connectivity
[] ← SCInstUtil.EnumerateAllInstances[handle, EachInstance];
CopyPadToCel[celStream, padTable]; -- pads must go at the end in position order
IO.Flush[celStream]; IO.Close[celStream]};
AddCell: PROC [celStream: FS.STREAM, instance: SCPrivate.Instance] ~ {
add a cell to the .cel file
middleX: INT ← instance.object.orgin.p + instance.object.size.p/2;
middleY: INT ← instance.object.orgin.q + instance.object.size.q/2;
IO.Put[celStream, IO.rope["cell "], IO.int[instance.num]];
IO.Put[celStream, IO.rope[" "], IO.rope[instance.name]];
IO.Put[celStream, IO.rope["\n"]];
IO.Put[celStream, IO.rope[" left "], IO.int[instance.object.orgin.p - middleX]];
IO.Put[celStream, IO.rope[" right "], IO.int[instance.object.orgin.p + instance.object.size.p - middleX]];
IO.Put[celStream, IO.rope[" bottom "], IO.int[instance.object.orgin.q - middleY]];
IO.Put[celStream, IO.rope[" top "], IO.int[instance.object.orgin.q + instance.object.size.q - middleY], IO.rope["\n"]]};
AddPin: PROC [celStream: FS.STREAM, instance: SCPrivate.Instance, pin: SCPrivate.ObjectPin, net: SCPrivate.Net, first: BOOLEAN] ~ {
add a pin to the .cel file
middleX: INT ← instance.object.orgin.p + instance.object.size.p/2;
middleY: INT ← instance.object.orgin.q + instance.object.size.q/2;
pinPos: CD.Position ← SELECT pin.pinPos.side FROM
bottom => [pin.pinPos.location - middleX, instance.object.orgin.q - middleY],
top => [pin.pinPos.location - middleX, instance.object.orgin.q + instance.object.size.q - middleY],
left => [instance.object.orgin.p - middleX, pin.pinPos.location - middleY],
right => [instance.object.orgin.p + instance.object.size.p - middleX, pin.pinPos.location - middleY],
ENDCASE => SC.Error[callingError, "pin on invalid side"];
IF first THEN {
IO.Put[celStream, IO.rope[" pin name "], IO.rope[pin.name]];
IO.Put[celStream, IO.rope[" signal "], IO.rope[net.name]]}
ELSE
IO.Put[celStream, IO.rope[" equiv name "], IO.rope[pin.name]];
IO.Put[celStream, IO.rope[" "], IO.int[pinPos.x]];
IO.Put[celStream, IO.rope[" "], IO.int[pinPos.y]];
IO.Put[celStream, IO.rope["\n"]]};
record to save pad information; TimberWolf requires the pads to be sorted
Pad: TYPE = REF PadRec;
PadRec: TYPE = RECORD [
instance: SCPrivate.Instance,
pathName: Rope.ROPE];
AddPad: PROC [padTable: RedBlackTree.Table, instance: SCPrivate.Instance] ~ {
insert a pad into an ordered table
pad: Pad ← NEW[PadRec ← [instance: instance, pathName: instance.name]];
RedBlackTree.Insert[padTable, pad, instance]};
CopyPadToCel: PROC [celStream: FS.STREAM, padTable: RedBlackTree.Table] ~ {
pads must be at the end of the .cel file; write to .cel from the ordered symbol table
WriteNode: RedBlackTree.EachNode ~ {
PROC [data: UserData] RETURNS [stop: BOOLFALSE];
pad: Pad ← NARROW[data];
sideRope: Rope.ROPESELECT pad.instance.curSide FROM
bottom => "B", right => "R", top => "T", left => "L", ENDCASE => "NONE";
orient: INTSELECT pad.instance.curSide FROM
bottom => 0, right => 6, top => 3, left => 7, ENDCASE => 0;
IO.Put[celStream, IO.rope["pad "], IO.int[pad.instance.num]];
IO.Put[celStream, IO.rope[" "], IO.rope[pad.pathName]];
IO.Put[celStream, IO.rope[" orient "], IO.int[orient], IO.rope["\n"]];
IO.Put[celStream, IO.rope[" padside "], IO.rope[sideRope], IO.rope["\n"]];
IO.Put[celStream, IO.rope[" left "], IO.int[-pad.instance.object.size.p]];
IO.Put[celStream, IO.rope[" right "], IO.int[pad.instance.object.size.p]];
IO.Put[celStream, IO.rope[" bottom "], IO.int[-pad.instance.object.size.q]];
IO.Put[celStream, IO.rope[" top "], IO.int[pad.instance.object.size.q], IO.rope["\n"]];
IO.Put[celStream, IO.rope[" pin name io signal "], IO.rope[pad.pathName]];
IO.Put[celStream, IO.rope[" "], IO.int[0]];
IO.Put[celStream, IO.rope[" "], IO.int[pad.instance.object.size.q]];
IO.Put[celStream, IO.rope["\n"]]};
RedBlackTree.EnumerateIncreasing[padTable, WriteNode]};
GetKey: RedBlackTree.GetKey ~ {
Callback proc: Given the user data in a node, return the key
PROC [data: UserData] RETURNS [Key];
pad: Pad ← NARROW[data];
RETURN[pad.instance]};
Compare: RedBlackTree.Compare ~ {
Callback proc type: Given a key and the user data in a node, return the comparison of the keys
PROC [k: Key, data: UserData] RETURNS [Basics.Comparison];
instance: SCPrivate.Instance ← NARROW[k];
pad: Pad ← NARROW[data];
instanceSide: Rope.ROPESELECT instance.curSide FROM
bottom => "B", right => "R", top => "T", left => "L", ENDCASE => "NONE";
padSide: Rope.ROPESELECT pad.instance.curSide FROM
bottom => "B", right => "R", top => "T", left => "L", ENDCASE => "NONE";
result: Basics.Comparison ← Rope.Compare[padSide, instanceSide];
IF result = Basics.Comparison[equal] THEN result ← Basics.CompareInt[pad.instance.fnlPos, instance.fnlPos];
IF result = Basics.Comparison[equal] THEN result ← Rope.Compare[pad.instance.name, instance.name];
RETURN[result]};
ReadTWPlace: PUBLIC PROC [handle: SC.Handle]~ {
read timberWolf placement
placeStream: FS.STREAMFS.StreamOpen[Rope.Cat[handle.name, ".pl1"], $read];
[] ← IO.SkipWhitespace[placeStream];
WHILE ~IO.EndOf[placeStream] DO
name: Rope.ROPEIO.GetTokenRope[placeStream, IO.IDProc].token;
left: INTIO.GetInt[placeStream];
lower: INTIO.GetInt[placeStream];
right: INTIO.GetInt[placeStream];
upper: INTIO.GetInt[placeStream];
orient: INTIO.GetInt[placeStream];
row: INTIO.GetInt[placeStream];
dontCare: INTIO.SkipWhitespace[placeStream];
instance: SCPrivate.Instance ← FindInstance[handle, name];
IF instance # NIL THEN {
SELECT instance.whichClass FROM
logic =>
{instance.fnlRow ← row; instance.fnlPos ← left};
io =>
HACK !!! TimberWolf does not provide side information. Have to use orientation
BUG: TimberWolf sometimes provides identical locations for pads on same side!!
{SELECT orient FROM
0 => {instance.fnlPos ← left; instance.fnlSide ← bottom};
6 => {instance.fnlPos ← lower; instance.fnlSide ← right};
3 => {instance.fnlPos ← left; instance.fnlSide ← top};
7 => {instance.fnlPos ← lower; instance.fnlSide ← left};
ENDCASE => {instance.fnlPos ← 0; instance.fnlSide ← none}};
ENDCASE}
ELSE ERROR; -- the TW file & the extraction disagree...
ENDLOOP;
IO.Close[placeStream]};
translate: PUBLIC ARRAY SC.Side OF ARRAY SCPrivate.OrientationOrNone OF SC.Side;
translate[bottom] ← [bottom, bottom, left, top, right, bottom, top, left, right];
translate[left] ← [left, left, top, right, bottom, right, left, bottom, top];
translate[top] ← [top, top, right, bottom, left, top, bottom, right, left];
translate[right] ← [right, right, bottom, left, top, left, right, top, bottom];
END.