SCUtilsImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Written by: Pradeep Sindhu, October 2, 1986 10:52:55 pm PDT
Pradeep Sindhu, January 21, 1988 3:53:31 pm PST
Cesar Douady January 12, 1988 8:18:59 pm PST
DIRECTORY
CD, CDIO, CDViewer, CommandTool, Convert, Core, CoreCreate, CoreGeometry, CoreOps, GList, IO, PWCore, Rope, SCParms, Sinix, Sisyph, SCUtils, TerminalIO, TilingClass;
SCUtilsImpl: CEDAR PROGRAM
IMPORTS CDViewer, CommandTool, CDIO, Convert, CoreCreate, CoreGeometry, CoreOps, GList, IO, PWCore, Rope, SCParms, Sinix, Sisyph, TerminalIO, TilingClass
EXPORTS SCUtils
~ BEGIN OPEN SCUtils;
myLogicDesign: CD.Design ← NIL;
myLayoutDesign: CD.Design ← NIL;
workingDirectory: ROPE ← CommandTool.CurrentWorkingDirectory[];
Exported Procs
Log2: PUBLIC PROC [n: INT] RETURNS [log: INT ← 0] ~ {
WHILE n > 1 DO n ← n/2; log ← log+1 ENDLOOP
};
ComRecord: PUBLIC PROC [pattern: ROPE, cx: Sisyph.Context, ctName: ROPE] RETURNS [ct: CellType] ~ {
n: Names ← NIL;
FOR i: INT DECREASING IN [0..Rope.Length[pattern]) DO
SELECT Rope.Fetch[pattern, i] FROM
'0 => n ← CONS["ComCell0.icon", n];
'1 => n ← CONS["ComCell1.icon", n];
'X => n ← CONS["ComCellX.icon", n];
'N => n ← CONS["ComCellN.icon", n];
'E => n ← CONS["ComCellE.icon", n];
ENDCASE => ERROR;
ENDLOOP;
ct ← RecordX[n, cx, Rope.Cat[ctName, pattern]];
};
This procedure constructs a tiling row from a list of object names. It is assumed that the publics of each of the objects are the same.
RecordX: PUBLIC PROC [obNames: Names, cx: Sisyph.Context, ctName: ROPE] RETURNS [ct: CellType] ~ {
count: NAT ← GList.Length[obNames];
Index: TYPE = {ComCell0, ComCell1, ComCellX, ComCellN, ComCellE};
baseCTs: CellTypes ← NIL;
public: Wire; -- public of cellType to be returned
tileRow: TilingClass.TileRow ← NEW [TilingClass.TileRowRec[count]];
tileArray: TilingClass.TileArray ← NEW [TilingClass.TileArrayRec[1]];
publicElements, arrayedWires, leftSideOnlyWires, rightSideOnlyWires, globalWires: Wires ← NIL;
EachWire: CoreOps.EachWireProc = {
sides: CoreGeometry.Sides = WireSide[wire, baseCTs.first];
vertical: BOOL = sides[top] OR sides[bottom];
IF vertical AND (sides[right] OR sides[left]) THEN WireSideProblem[wire, "touches adjacent sides", baseCTs.first];
IF vertical
THEN {
newPublic: Wire ← CoreOps.CreateWires[count, CoreOps.GetShortWireName[wire]];
arrayedWires ← CONS[wire, arrayedWires];
FOR i: INT IN [0..count) DO
newPublic[i] ← CoreOps.SetShortWireName[CoreOps.CopyWire[wire], NIL];
ENDLOOP;
publicElements ← CONS[newPublic, publicElements];
}
ELSE {
IF sides=CoreGeometry.noSide
THEN {
IF IsGlobal[wire, cx] THEN {
globalWires ← CONS [wire, globalWires];
publicElements ← CONS [wire, publicElements]
}
}
ELSE {
IF sides[left] THEN leftSideOnlyWires ← CONS[wire, leftSideOnlyWires];
IF sides[right] THEN rightSideOnlyWires ← CONS[wire, rightSideOnlyWires];
publicElements ← CONS [wire, publicElements]
}
}
};
Make the baseCellTypes
FOR l: Names ← obNames, l.rest WHILE l#NIL DO
baseCTs ← CONS[Sisyph.ExtractSchematicByName[l.first, cx], baseCTs];
ENDLOOP;
baseCTs ← NARROW[GList.Reverse[baseCTs]];
Compute the public of the cellType to be returned
[] ← CoreOps.VisitWireSeq[baseCTs.first.public, EachWire];
public ← CoreOps.CreateWire[publicElements];
Fill in the cellTypes
FOR i: INT IN [0..count) DO
tileRow[i] ← NEW [TilingClass.TileRec ← [type: baseCTs.first]];
baseCTs ← baseCTs.rest;
ENDLOOP;
Define the renaming for wires that touch the left side
FOR wl: Wires ← leftSideOnlyWires, wl.rest WHILE wl#NIL DO
wireName: ROPE ← CoreOps.GetShortWireName[wl.first];
tileRow[0].renaming ← CONS[[wireName, wireName], tileRow[0].renaming];
ENDLOOP;
Define the renaming for wires that touch the right side
FOR wl: Wires ← rightSideOnlyWires, wl.rest WHILE wl#NIL DO
wireName: ROPE ← CoreOps.GetShortWireName[wl.first];
tileRow[count-1].renaming ← CONS[[wireName, wireName], tileRow[count-1].renaming];
ENDLOOP;
Define the renaming for global wires
FOR wl: Wires ← globalWires, wl.rest WHILE wl#NIL DO
wireName: ROPE ← CoreOps.GetShortWireName[wl.first];
FOR i: NAT IN [0..count) DO
tileRow[i].renaming ← CONS[[wireName, wireName], tileRow[i].renaming];
ENDLOOP;
ENDLOOP;
Define the renaming for arrayed wires
FOR wl: Wires ← arrayedWires, wl.rest WHILE wl#NIL DO
wireName: ROPE ← CoreOps.GetShortWireName[wl.first];
FOR i: NAT IN [0..count) DO
tileRow[i].renaming ← CONS[[wireName, Rope.Cat[wireName, "[", Convert.RopeFromInt[i], "]"]], tileRow[i].renaming];
ENDLOOP;
ENDLOOP;
tileArray[0] ← tileRow;
Copying the public is necessary to avoid sharing of wires between cellTypes
ct ← TilingClass.CreateTiling[CoreOps.CopyWire[public], tileArray, TilingClass.SchematicsNeighborX, TilingClass.SchematicsNeighborY, Rope.Cat[ctName, ".RecordX"]];
};
RamInterfaceRout: PUBLIC PROC [cx: Sisyph.Context] RETURNS [ct: CellType] ~ {
Flip: TYPE ~ {normal, flipped};
BaseCells: TYPE ~ REF BaseCellsRep;
BaseCellsRep: TYPE ~ RECORD [v: SEQUENCE size: NAT OF ARRAY Flip OF RECORD [ct: CellType, w: Wire]];
index, selIndex, spareIndex: INT;
baseB: BaseCells ← NEW [BaseCellsRep[SCParms.numBytesPerWord]];
baseW: BaseCells ← NEW [BaseCellsRep[SCParms.numWordsPerLine]];
spacerB, spacerW: CellType;
spare: Wire ← CoreCreate.Seq[size: SCParms.numBitsPerCycle, name: "Spare"];
byteSel: Wire ← CoreCreate.Seq[size: SCParms.numBytesPerWord, name: "ByteSel"];
bS: Wire ← CoreCreate.Seq[size: SCParms.numBitsPerLine, name: "BS"];
wordSel: Wire ← CoreCreate.Seq[size: SCParms.numWordsPerLine, name: "WdSel"];
wS: Wire ← CoreCreate.Seq[size: SCParms.numBitsPerLine, name: "WS"];
count: INT ~ SCParms.numBitsPerLine+SCParms.numBitsPerCycle; -- Including the spare lines
tileRowB: TilingClass.TileRow ← NEW [TilingClass.TileRowRec[count]];
tileRowW: TilingClass.TileRow ← NEW [TilingClass.TileRowRec[count]];
tileArray: TilingClass.TileArray ← NEW [TilingClass.TileArrayRec[2]];
Make the baseCellTypes
FOR i: NAT IN [0..SCParms.numBytesPerWord) DO
name: ROPE = IO.PutFR["RamInterfaceBitRout2%g.sch", IO.int[i]];
bSName: ROPE = IO.PutFR["ByteSel[%g]", IO.int[i]];
baseB[i][normal].ct ← Sisyph.ExtractSchematicByName[name, Sisyph.Copy[cx]];
baseB[i][flipped].ct ← PWCore.RotateCellType[baseB[i][normal].ct, $FlipX];
FOR m: Flip IN Flip DO
baseB[i][m].w ← CoreOps.FindWire[baseB[i][m].ct.public, bSName];
ENDLOOP;
ENDLOOP;
FOR word: NAT IN [0..SCParms.numWordsPerLine) DO
name: ROPE = IO.PutFR["RamInterfaceBitRout1%g.sch", IO.int[word]];
wSName: ROPE = IO.PutFR["WdSel[%g]", IO.int[word]];
baseW[word][normal].ct ← Sisyph.ExtractSchematicByName[name, Sisyph.Copy[cx]];
baseW[word][flipped].ct ← PWCore.RotateCellType[baseW[word][normal].ct, $FlipX];
FOR m: Flip IN Flip DO
baseW[word][m].w ← CoreOps.FindWire[baseW[word][m].ct.public, wSName];
ENDLOOP;
ENDLOOP;
spacerB ← Sisyph.ExtractSchematicByName["RamInterfaceSpacerRout2.sch", cx];
spacerW ← Sisyph.ExtractSchematicByName["RamInterfaceSpacerRout1.sch", cx];
Compute the public of the cellType to be returned
Fill in the cellTypes
index ← 0; -- index in the tilling class
selIndex ← 0; -- index in the BS wire
spareIndex ← 0; -- index in the Spare wire
FOR i: INT IN [0..SCParms.numBytesPerWord) DO
FOR j: INT IN [0..SCParms.numBitsPerByte) DO
word: INT ← 0;
FOR k: INT IN [0..SCParms.numWordsPerCycle) DO
FOR l: INT IN [0..SCParms.numCyclesPerLine/2) DO
FOR m: Flip IN Flip DO
bS[selIndex] ← byteSel[i];
wS[selIndex] ← wordSel[word];
tileRowB[index] ← NEW [TilingClass.TileRec ← [
type: baseB[i][m].ct,
renaming: LIST[
[public: "ByteSel", actual: byteSel],
[public: baseB[i][m].w, actual: bS[selIndex]]
]]];
tileRowW[index] ← NEW [TilingClass.TileRec ← [
type: baseW[word][m].ct,
renaming: LIST[
[public: "WdSel", actual: wordSel],
[public: baseW[word][m].w, actual: wS[selIndex]]
]]];
selIndex ← selIndex+1;
index ← index+1;
word ← word+1;
ENDLOOP;
ENDLOOP;
tileRowB[index] ← NEW [TilingClass.TileRec ← [
type: spacerB,
renaming: LIST[
[public: "ByteSel", actual: byteSel],
[public: "Spare", actual: spare[spareIndex]]
]]];
tileRowW[index] ← NEW [TilingClass.TileRec ← [
type: spacerW,
renaming: LIST[
[public: "WdSel", actual: wordSel],
[public: "Spare", actual: spare[spareIndex]]
]]];
spareIndex ← spareIndex +1;
index ← index+1;
ENDLOOP;
IF word # SCParms.numWordsPerLine THEN ERROR;
ENDLOOP;
ENDLOOP;
IF index # count THEN ERROR;
IF selIndex # SCParms.numBitsPerLine THEN ERROR;
IF spareIndex # SCParms.numBitsPerCycle THEN ERROR;
tileArray[1] ← tileRowW;
tileArray[0] ← tileRowB;
Copying the public is necessary to avoid sharing of wires between cellTypes
ct ← TilingClass.CreateTiling[
public: CoreCreate.Wires[spare, byteSel, bS, wordSel, wS],
tileArray: tileArray,
neighborX: TilingClass.LayoutNeighborX,
neighborY: TilingClass.LayoutNeighborY,
name: "RamInterfaceRout"];
};
Interleave: PUBLIC PROC [b: NAT] RETURNS [public: Core.Wires] = {
wire: Wire ← CoreCreate.Seq["Wire", b];
interleavedWire: Wire ← CoreCreate.Seq["InterleavedWire", b];
IF b MOD 2 = 1 THEN ERROR;
IF b=0 THEN ERROR;
FOR i: NAT IN [0..b/2) DO
interleavedWire[2*i] ← wire[i];
interleavedWire[2*i+1] ← wire[b/2+i];
ENDLOOP;
public ← LIST [wire, interleavedWire];
};
Interleave2: PUBLIC PROC [b: NAT] RETURNS [public: Core.Wires] = {
wire0: Wire ← CoreCreate.Seq["Wire0", b/2];
wire1: Wire ← CoreCreate.Seq["Wire1", b/2];
interleavedWire: Wire ← CoreCreate.Seq["InterleavedWire", b];
IF b MOD 2 = 1 THEN ERROR;
IF b=0 THEN ERROR;
FOR i: NAT IN [0..b/2) DO
interleavedWire[2*i] ← wire0[i];
interleavedWire[2*i+1] ← wire1[i];
ENDLOOP;
public ← LIST [wire0, wire1, interleavedWire];
};
LogicDesign: PUBLIC PROC [] RETURNS [design: CD.Design] = {
name: ROPE ← "SCLogic"; -- must declare it as a rope!
IF myLogicDesign=NIL THEN {
myLogicDesign ← CDViewer.FindDesign[name];
IF myLogicDesign=NIL THEN myLogicDesign ← CDIO.ReadDesign[name, NIL, workingDirectory];
IF myLogicDesign = NIL THEN ERROR;
};
design ← myLogicDesign
};
LayoutDesign: PUBLIC PROC [] RETURNS [design: CD.Design] = {
name: ROPE ← "CacheCells"; -- must declare it as a rope!
IF myLayoutDesign=NIL THEN {
myLayoutDesign ← CDViewer.FindDesign[name];
IF myLayoutDesign=NIL THEN myLayoutDesign ← CDIO.ReadDesign[name, NIL, workingDirectory];
IF myLayoutDesign = NIL THEN ERROR;
};
design ← myLayoutDesign
};
Internal Utilities
IsGlobal: PROC [w: Wire, cx: Sisyph.Context] RETURNS [BOOLFALSE] = {
name: ROPE ← CoreOps.GetShortWireName[w];
FOR lr: LIST OF ROPE ← Sisyph.GetGlobalNames[cx], lr.rest WHILE lr#NIL DO
IF Rope.Equal[name, lr.first] THEN RETURN [TRUE]
ENDLOOP;
};
WireSide: PROC [wire: Wire, baseCT: CellType] RETURNS [sides: CoreGeometry.Sides ← CoreGeometry.noSide] ~ {
Finds the sides on which wire touches baseCT (of which it is a public). CoreGeometry.noSide will be returned if the wire has no pins. This should be in CoreGeometry.
EachPin: CoreGeometry.EachPinProc = {
sides[side] ← TRUE;
};
[] ← CoreGeometry.EnumerateSides[Sisyph.mode.decoration, baseCT, wire, EachPin];
};
WireSideProblem: PROC [wire: Wire, msg: ROPE, baseCT: CellType] ~ {
TerminalIO.PutF["\n*** Wire %g %g in cell %g\n",
IO.rope[CoreOps.GetFullWireName[baseCT.public, wire]],
IO.rope[msg],
IO.rope[CoreOps.GetCellTypeName[baseCT]]];
SIGNAL Sinix.CallerBug[];
};
CatIndex: PROC[name: ROPE, index: INT] RETURNS [ROPE] ~ {
RETURN [Rope.Cat[name, "[", Convert.RopeFromInt[index], "]"]]
};
END.