PWCTilingClassImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reversed.
Created by Bertrand Serlet September 19, 1986 1:48:15 pm PDT
Bertrand Serlet October 17, 1986 10:14:57 pm PDT
Barth, October 16, 1986 6:39:20 pm PDT
Don Curry November 3, 1986 11:47:44 am PST
DIRECTORY CD, CDInstances, CDLayers, Core, CoreClasses, CoreCreate, CoreOps, CoreProperties, CoreGeometry, HashTable, PW, PWC, Sisyph, PWCTilingClass;
PWCTilingClassImpl: CEDAR PROGRAM
IMPORTS CD, CDInstances, CDLayers, CoreClasses, CoreCreate, CoreOps, CoreProperties, CoreGeometry, HashTable, PW, PWC, Sisyph
EXPORTS PWCTilingClass
~ BEGIN OPEN PWCTilingClass;
Utilities
PutTileInstance: PROC [tile: Tile, instance: CoreClasses.CellInstance] = {
tile.properties ← CoreProperties.PutProp[tile.properties, $PWCTilingClassInstance, instance];
};
GetTileInstance: PROC [tile: Tile] RETURNS [instance: CoreClasses.CellInstance] = {
RETURN [NARROW [CoreProperties.GetProp[tile.properties, $PWCTilingClassInstance]]];
};
Replace: PROC [fused: HashTable.Table, old: Wire] RETURNS [new: Wire] = {
new ← RootWire[fused, old];
FOR i: NAT IN [0 .. old.size) DO new[i] ← Replace[fused, old[i]] ENDLOOP;
};
RootWire: PROC [fused: HashTable.Table, wire: Wire] RETURNS [root: Wire] = {
root ← NARROW [HashTable.Fetch[fused, wire].value];
IF root=NIL THEN RETURN [wire];
IF root=wire THEN ERROR;
root ← RootWire[fused, root];
[] ← HashTable.Replace[fused, wire, root];
};
Fuse: PROC [fused: HashTable.Table, wire1, wire2: Wire] = {
root1: Wire = RootWire[fused, wire1];
root2: Wire = RootWire[fused, wire2];
IF root1=root2 THEN RETURN;
IF root1.size#root2.size THEN ERROR;
[] ← HashTable.Store[fused, root1, root2];
FOR i: NAT IN [0 .. root1.size) DO Fuse[fused, root1[i], root2[i]] ENDLOOP;
};
CreateBindingTable: PUBLIC PROC [wire1, wire2: Wire] RETURNS [table: HashTable.Table] = {
AddInTable: CoreOps.EachWirePairProc = {[] ← HashTable.Store[table, actualWire, publicWire]};
table ← HashTable.Create[wire1.size];
[] ← CoreOps.VisitBinding[wire1, wire2, AddInTable];
};
WirePair: TYPE = RECORD [wire1, wire2: Wire];
PublicPairsToWirePairs: PROC [tile1, tile2: Tile, publicPairs: LIST OF PublicPair] RETURNS [wirePairs: LIST OF WirePair ← NIL] = {
WHILE publicPairs#NIL DO
pub1: Wire = CoreCreate.FindWire[tile1.type.public, publicPairs.first.public1];
pub2: Wire = CoreCreate.FindWire[tile2.type.public, publicPairs.first.public2];
IF pub1=NIL OR pub2=NIL THEN ERROR; -- wrong NeighborProc
wirePairs ← CONS [[pub1, pub2], wirePairs];
publicPairs ← publicPairs.rest;
ENDLOOP;
};
FuseNeighbors: PROC [cellType: CellType, neighbor: NeighborProc, tile1, tile2: Tile, fused: HashTable.Table, cache: HashTable.Table] = {
wirePairs: LIST OF WirePair ← NIL;
subCache: HashTable.Table ← NIL;
value: REFNIL;
found: BOOLFALSE;
IF cache#NIL THEN subCache ← NARROW [HashTable.Fetch[cache, tile1].value];
IF subCache#NIL THEN [found, value] ← HashTable.Fetch[subCache, tile2];
IF found THEN wirePairs ← NARROW [value] ELSE {
wirePairs ← PublicPairsToWirePairs[tile1, tile2, neighbor[cellType, tile1, tile2]];
IF cache#NIL AND subCache=NIL THEN subCache ← HashTable.Create[5];
IF subCache#NIL THEN [] ← HashTable.Store[subCache, tile2, wirePairs];
IF cache#NIL THEN [] ← HashTable.Store[cache, tile1, subCache];
};
FOR list: LIST OF WirePair ← wirePairs, list.rest WHILE list#NIL DO
Fuse[fused, CoreClasses.CorrespondingActual[GetTileInstance[tile1], list.first.wire1], CoreClasses.CorrespondingActual[GetTileInstance[tile2], list.first.wire2]];
ENDLOOP;
};
CreateActual: PROC [subPublicToActual: HashTable.Table, public: Wire] RETURNS [actual: Wire] = {
actual ← NARROW [HashTable.Fetch[subPublicToActual, public].value];
IF actual#NIL THEN RETURN;
actual ← CoreOps.CreateWires[size: public.size];
[] ← HashTable.Store[subPublicToActual, public, actual];
FOR i: NAT IN [0 .. public.size) DO
actual[i] ← CreateActual[subPublicToActual, public[i]];
ENDLOOP;
};
CreateInstance: PROC [public: Wire, tile: Tile] RETURNS [instance: CoreClasses.CellInstance]= {
subPublicToActual: HashTable.Table = HashTable.Create[];
actual: Wire = CoreOps.CreateWires[size: tile.type.public.size];
make a simpler renaming table [public of tile -> public of me.public]
FOR list: LIST OF PA ← tile.renaming, list.rest WHILE list#NIL DO
pub: Wire = CoreCreate.FindWire[tile.type.public, list.first.public];
act: Wire = CoreCreate.FindWire[public, list.first.actual];
IF pub=NIL OR act=NIL THEN ERROR; -- bad renaming list
[] ← HashTable.Store[subPublicToActual, pub, act];
ENDLOOP;
FOR i: NAT IN [0 .. tile.type.public.size) DO
actual[i] ← CreateActual[subPublicToActual, tile.type.public[i]];
ENDLOOP;
instance ← CoreClasses.CreateInstance[actual, tile.type];
};
Tiling
TilingData: TYPE = REF TilingDataRec;
TilingDataRec: TYPE = RECORD [
tileArray: TileArray,
neighborX, neighborY: NeighborProc,
cache: HashTable.Table ← NIL
];
pwcTilingClass: PUBLIC Core.CellClass ← NEW [Core.CellClassRec ← [name: "2DTiling", recast: RecastTiling, layersProps: FALSE, properties: CoreProperties.Props[[$Layout, $Recast]]]];
CreateTiling: PUBLIC PROC [public: Wire, tileArray: TileArray, neighborX, neighborY: NeighborProc, name: ROPENIL, props: Properties ← NIL, cacheNeighbor: BOOLTRUE] RETURNS [tiling: CellType] = {
tiling ← CoreOps.CreateCellType[
class: pwcTilingClass,
public: public,
data: NEW [TilingDataRec ← [tileArray: tileArray, neighborX: neighborX, neighborY: neighborY, cache: IF cacheNeighbor THEN HashTable.Create[5] ELSE NIL]],
name: name, props: props
];
};
RecastTiling: Core.RecastProc = {
tilingData: TilingData = NARROW [me.data];
public: Wire = CoreOps.CopyWire[me.public];
fused: HashTable.Table = CreateBindingTable[me.public, public]; -- keys are fused to values
tiles: TileArray = tilingData.tileArray;
sizeX: NAT = tiles[0].size;
sizeY: NAT = tiles.size;
internalsOnly: Wires ← NIL;
instances: LIST OF CoreClasses.CellInstance ← NIL;
Create instances (even with not the right wires yet)
FOR i: NAT IN [0 .. sizeY) DO
IF tiles[i].size#sizeX THEN ERROR;
FOR j: NAT IN [0 .. sizeX) DO
tile: Tile = tiles[i][j];
instance: CoreClasses.CellInstance ← CreateInstance[me.public, tile];
PutTileInstance[tile, instance];
IF tile.flatten THEN {
rct: CoreClasses.RecordCellType = NARROW [tile.type.data];
publicToActual: HashTable.Table = CreateBindingTable[instance.type.public, instance.actual];
FOR ii: NAT IN [0 .. rct.size) DO
actual: Wire = CoreOps.CreateWires[size: rct[ii].type.public.size];
FOR k: NAT IN [0 .. rct[ii].type.public.size) DO
actual[k] ← NARROW [HashTable.Fetch[publicToActual, rct[ii].actual[k]].value];
ENDLOOP;
instances ← CONS [CoreClasses.CreateInstance[actual, rct[ii].type], instances];
ENDLOOP;
} ELSE instances ← CONS [instance, instances];
ENDLOOP;
ENDLOOP;
Find who to fuse, first progressing in rows
FOR i: NAT IN [0 .. sizeY) DO
FOR j: NAT IN [1 .. sizeX) DO
FuseNeighbors[me, tilingData.neighborX, tiles[i][j-1], tiles[i][j], fused, tilingData.cache];
ENDLOOP;
ENDLOOP;
Find who to fuse, progressing in columns
FOR j: NAT IN [0 .. sizeX) DO
FOR i: NAT IN [1 .. sizeY) DO
FuseNeighbors[me, tilingData.neighborY, tiles[i-1][j], tiles[i][j], fused, tilingData.cache];
ENDLOOP;
ENDLOOP;
Replace the public
FOR i: NAT IN [0 .. public.size) DO
public[i] ← Replace[fused, public[i]];
ENDLOOP;
Replace in instances the actuals
FOR list: LIST OF CoreClasses.CellInstance ← instances, list.rest WHILE list#NIL DO
instance: CoreClasses.CellInstance = list.first;
instance.actual ← Replace[fused, instance.actual];
IF NOT CoreOps.Conform[instance.actual, instance.type.public] THEN ERROR; -- the tiles shorts parts of the public together
Compute the internal only wires
FOR k: NAT IN [0 .. instance.actual.size) DO
wire: Wire = instance.actual[k];
IF NOT CoreOps.RecursiveMember[public, wire] AND NOT CoreOps.Member[internalsOnly, wire] THEN internalsOnly ← CONS [wire, internalsOnly];
ENDLOOP;
ENDLOOP;
IF NOT CoreOps.Conform[public, me.public] THEN ERROR; -- the tiles shorts parts of the public together
-- Preparing the decoration by storing on each tile the list of publics which decorations should be offset and added and the list of corresponding actuals [part of public].
FOR i: NAT IN [0 .. sizeY) DO
FOR j: NAT IN [0 .. sizeX) DO
IF i=0 OR i=sizeY-1 OR j=0 OR j=sizeX-1 THEN {
tile: Tile = tiles[i][j];
pubs: LIST OF Wire ← NIL;
acts: LIST OF Wire ← NIL;
DecorateIfOutside: PROC [pub: Wire] = {
act: Wire = RootWire[fused, CoreClasses.CorrespondingActual[GetTileInstance[tile], pub]];
IF act=NIL THEN ERROR;
IF NOT CoreOps.RecursiveMember[public, act] THEN RETURN;
pubs ← CONS [pub, pubs];
acts ← CONS [act, acts];
};
CoreOps.VisitRootAtomics[tile.type.public, DecorateIfOutside];
tile.properties ← CoreProperties.PutProp[tile.properties, $PWCTilingClassPubs, pubs];
tile.properties ← CoreProperties.PutProp[tile.properties, $PWCTilingClassActs, acts];
};
ENDLOOP;
ENDLOOP;
Cleanup
FOR i: NAT DECREASING IN [0 .. sizeY) DO
FOR j: NAT DECREASING IN [0 .. sizeX) DO
PutTileInstance[tiles[i][j], NIL];
ENDLOOP;
ENDLOOP;
new ← CoreClasses.CreateRecordCell[
public: public,
internal: CoreOps.UnionWire[public, CoreOps.CreateWire[internalsOnly]],
instances: instances,
props: CoreProperties.Props[[$Layout, $Tiling], [$Tiles, tiles]]
];
};
LayoutTiling: PWC.LayoutProc = {
SmashPins: PROC [wire: Wire] = {CoreGeometry.PutPins[PWC.extractMode.decoration, wire, NIL]};
Layout: PROC [i, j: NAT] RETURNS [CD.Object] = {RETURN [PWC.Layout[tiles[i][j].type]]};
tiles: TileArray = NARROW [CoreProperties.GetCellTypeProp[cellType, $Tiles]];
sizeX: NAT = tiles[0].size;
sizeY: NAT = tiles.size;
offset: CD.Position ← [0, 0];
ir: CD.Rect;
Generating the layout, now
obj ← PW.CreateEmptyCell[];
We check that sizes of the IR verify the assumptions
FOR i: NAT IN [0 .. sizeY) DO
height: INT = CD.InterestSize[Layout[i, 0]].y;
FOR j: NAT IN [1 .. sizeX) DO
IF height#CD.InterestSize[Layout[i, j]].y THEN ERROR; -- assumption not verified
ENDLOOP;
ENDLOOP;
FOR j: NAT IN [0 .. sizeX) DO
width: INT = CD.InterestSize[Layout[0, j]].x;
FOR i: NAT IN [1 .. sizeY) DO
IF width#CD.InterestSize[Layout[i, j]].x THEN ERROR; -- assumption not verified
ENDLOOP;
ENDLOOP;
We tile
FOR i: NAT IN [0 .. sizeY) DO
offset.x ← 0;
FOR j: NAT IN [0 .. sizeX) DO
[] ← PW.IncludeInCell[obj, Layout[i, j], offset];
offset.x ← offset.x + CD.InterestSize[Layout[i, j]].x;
ENDLOOP;
offset.y ← offset.y + CD.InterestSize[Layout[i, 0]].y;
ENDLOOP;
PW.SetInterestRect[obj, offset];
PW.RepositionCell[obj];
ir ← CD.InterestRect[obj];
Getting rid of copied properties (one day not necessary)
CoreOps.VisitRootAtomics[cellType.public, SmashPins];
Decorating cellType (we do a second pass because of reposition!)
offset.y ← ir.y1;
FOR i: NAT IN [0 .. sizeY) DO
offset.x ← ir.x1;
FOR j: NAT IN [0 .. sizeX) DO
tile: Tile = tiles[i][j];
pubs: LIST OF Wire ← NARROW [CoreProperties.GetProp[tile.properties, $PWCTilingClassPubs]];
acts: LIST OF Wire ← NARROW [CoreProperties.GetProp[tile.properties, $PWCTilingClassActs]];
origin: CD.Rect = CD.InterestRect[Layout[i, j]];
transf: CD.Instance = CDInstances.NewInst[CDCells.CreateEmptyCell[], [offset.x-origin.x1, offset.y-origin.y1]];
WHILE pubs#NIL DO
pins: CoreGeometry.Instances ← CoreGeometry.GetPins[PWC.extractMode.decoration, acts.first];
FOR list: CoreGeometry.Instances ← CoreGeometry.GetPins[PWC.extractMode.decoration, pubs.first], list.rest WHILE list#NIL DO
IF CoreGeometry.TransfedNotAtEdge[transf, ir, list.first] THEN LOOP;
pins ← CONS [CoreGeometry.Transform[transf, list.first], pins];
ENDLOOP;
CoreGeometry.PutPins[PWC.extractMode.decoration, acts.first, pins];
pubs ← pubs.rest; acts ← acts.rest;
ENDLOOP;
offset.x ← offset.x + CD.InterestSize[Layout[i, j]].x;
ENDLOOP;
offset.y ← offset.y + CD.InterestSize[Layout[i, 0]].y;
ENDLOOP;
CoreGeometry.PutIR[PWC.extractMode.decoration, cellType, ir];
};
Predefined NeighborProcs
WMML: TYPE = RECORD [wire: Wire, min, max: INT, layer: CD.Layer];
ListSide: PROC [tile: Tile, side: CoreGeometry.Side, decoration: CoreGeometry.Decoration] RETURNS [list: LIST OF WMMLNIL] = {
EachSortedPin: CoreGeometry.EachSortedPinProc = {
list ← CONS [[wire, min, max, layer], list];
};
[] ← CoreGeometry.EnumerateSortedSides[decoration, tile.type, side, EachSortedPin];
};
AddPublicPairs: PROC [wire1, wire2: Wire, old: LIST OF PublicPair] RETURNS [new: LIST OF PublicPair] = {
FOR list: LIST OF PublicPair ← old, list.rest WHILE list#NIL DO
IF list.first=[wire1, wire2] THEN RETURN [old];
ENDLOOP;
RETURN [CONS [[wire1, wire2], old]];
};
IntersectLists: PROC [list1, list2: LIST OF WMML, usedLayers: LIST OF CD.Layer] RETURNS [publicPairs: LIST OF PublicPair ← NIL] = {
FOR layers: LIST OF CD.Layer ← usedLayers, layers.rest WHILE layers#NIL DO
layer: CD.Layer ← CDLayers.AbstractToPaint[layers.first];
FOR l1: LIST OF WMML ← list1, l1.rest WHILE l1#NIL DO
IF l1.first.layer#layer THEN LOOP;
FOR l2: LIST OF WMML ← list2, l2.rest WHILE l2#NIL DO
IF l2.first.layer#layer THEN LOOP;
IF l2.first.min>l1.first.max OR l1.first.min>l2.first.max THEN LOOP;
publicPairs ← AddPublicPairs[l1.first.wire, l2.first.wire, publicPairs];
ENDLOOP;
ENDLOOP;
ENDLOOP;
};
LayoutNeighborX: PUBLIC NeighborProc = {
[] ← PWC.InterestRect[tile1.type]; -- to make sure the cellType is decorated
[] ← PWC.InterestRect[tile2.type]; -- to make sure the cellType is decorated
publicPairs ← IntersectLists[
ListSide[tile1, right, PWC.extractMode.decoration],
ListSide[tile2, left, PWC.extractMode.decoration],
CD.FetchTechnology[$cmosB].usedLayers
];
};
LayoutNeighborY: PUBLIC NeighborProc = {
[] ← PWC.InterestRect[tile1.type]; -- to make sure the cellType is decorated
[] ← PWC.InterestRect[tile2.type]; -- to make sure the cellType is decorated
publicPairs ← IntersectLists[
ListSide[tile1, top, PWC.extractMode.decoration],
ListSide[tile2, bottom, PWC.extractMode.decoration],
CD.FetchTechnology[$cmosB].usedLayers
];
};
SchematicsNeighborX: PUBLIC NeighborProc ={
publicPairs ← IntersectLists[
ListSide[tile1, right, Sisyph.mode.decoration],
ListSide[tile2, left, Sisyph.mode.decoration],
LIST [CD.commentLayer]
];
};
SchematicsNeighborY: PUBLIC NeighborProc ={
publicPairs ← IntersectLists[
ListSide[tile1, top, Sisyph.mode.decoration],
ListSide[tile2, bottom, Sisyph.mode.decoration],
LIST [CD.commentLayer]
];
};
Initialization
[] ← PWC.RegisterLayoutAtom[$Tiling, LayoutTiling, NIL];
END.