RecognizerImpl.mesa
Last Edited by: Gbier, July 11, 1985 12:18:45 pm PDT
Last Edidmd by: Gbier, July 26, 1985 1:41:17 pm PDT
Jacobi, March 19, 1986 6:33:30 pm PST
DIRECTORY
CD,
CDBasics,
CStitching,
CDOrient,
CDCells,
Recognizer,
TerminalIO;
RecognizerImpl: CEDAR MONITOR
IMPORTS CD, CDBasics, CStitching, CDCells, TerminalIO
EXPORTS Recognizer =
BEGIN
RegionList: TYPE = LIST OF REF CStitching.Region;
Plane: TYPE = CStitching.Tesselation;
PossibleProcedureRec: TYPE = RECORD [
technology: CD.Technology,
rectCount: INT,
instProc: Recognizer.PossibleInstanceProc --the procedure that will return possible instances
];
procRegistration: LIST OF REF PossibleProcedureRec ← NIL; --Contains registered possible procedures
ActiveLayersRec: TYPE = RECORD [
technology: CD.Technology,
active1: CD.Layer,
active2: CD.Layer,
layerList: LIST OF CD.Layer
];
layerRegistration: LIST OF REF ActiveLayersRec ← NIL; --Contains registered active layer pairs
Handle: TYPE = REF HandleRep;
HandleRep: TYPE = RECORD [
design: CD.Design,
cellOb: CD.Object,
active1: CD.Layer ← CD.undefLayer,
active2: CD.Layer ← CD.undefLayer,
overlapPlane: Plane ← NIL,
active1CheckTess: Plane ← NIL,
active2CheckTess: Plane ← NIL,
coveredList: LIST OF REF CStitching.Region ← NIL,
matches: BOOLTRUE,
layerPlanes: ARRAY CD.Layer OF Plane ← ALL[NIL]
];
Free: PROC [p: Plane] = {
CStitching.ResetTesselation[p];
};
RecognizeObjects: PUBLIC PROC [design: CD.Design, cellOb: CD.Object] =
BEGIN
FOR activeList: LIST OF REF ActiveLayersRec ← layerRegistration, activeList.rest WHILE activeList#NIL DO
IF activeList.first.technology = design.technology THEN {
h: Handle ← NEW[HandleRep ← [design, cellOb]];
h.active1 ← activeList.first.active1;
h.active2 ← activeList.first.active2;
h.layerPlanes[h.active1] ← CStitching.NewTesselation[];
h.layerPlanes[h.active2] ← CStitching.NewTesselation[];
FOR layerList: LIST OF CD.Layer ← activeList.first.layerList, layerList.rest WHILE layerList#NIL DO
h.layerPlanes[layerList.first] ← CStitching.NewTesselation[];
ENDLOOP;
FillPlanesByDrawingRects[design, h];
h.overlapPlane ← CStitching.NewTesselation[];
FormOverlapPlane[plane1: h.layerPlanes[h.active1], plane2: h.layerPlanes[h.active2], overlapPlane: h.overlapPlane];
CStitching.EnumerateArea[plane: h.overlapPlane, rect: CDBasics.universe, skip: $none, eachTile: GrowTransistorTile, data: h];
--help the garbage collector
Free[h.overlapPlane];
FOR layerList: LIST OF CD.Layer ← activeList.first.layerList, layerList.rest WHILE layerList#NIL DO
Free[h.layerPlanes[layerList.first]];
ENDLOOP;
Free[h.layerPlanes[h.active1]];
Free[h.layerPlanes[h.active2]];
};
[] ← CDCells.RepositionCell[cellOb, design];
ENDLOOP;
END;
FillPlanesByDrawingRects: PROC [design: CD.Design, h: Handle] =
BEGIN
dummyInst: CD.Instance ~ NEW[CD.InstanceRep ← [ob: h.cellOb]];
pr: CD.DrawRef ← CD.CreateDrawRef[[
design: h.design,
drawRect: DrawRectIntoPlane,
drawChild: DrawChildIntoPlane,
devicePrivate: h
]];
h.cellOb.class.drawMe[inst: dummyInst, pos: [0, 0], orient: CD.original, pr: pr];
END;
DrawChildIntoPlane: CD.DrawProc =
BEGIN
IF inst.ob.class.wireTyped THEN inst.ob.class.drawMe[inst, pos, orient, pr]
END;
DrawRectIntoPlane: PROC [r: CD.Rect, l: CD.Layer, pr: CD.DrawRef] =
BEGIN
h: Handle ~ NARROW[pr.devicePrivate];
IF h.layerPlanes[l]#NIL THEN
CStitching.ChangeRect[plane: h.layerPlanes[l], rect: r, new: $cover];
END;
FormOverlapPlane: PUBLIC PROC [plane1, plane2, overlapPlane: Plane] =
--Overlapping regions between plane1 and plane2 will be added to the overlapPlane
BEGIN
FOR rl1: RegionList ← CStitching.ListArea[plane1, CDBasics.universe, $none], rl1.rest WHILE rl1#NIL DO
IF rl1.first.value=$cover THEN
FOR ovL: RegionList ← CStitching.ListArea[plane2, rl1.first.rect, $none], ovL.rest WHILE ovL#NIL DO
IF ovL.first.value=$cover THEN
CStitching.ChangeRect[plane: overlapPlane, rect: ovL.first.rect, new: $cover];
ENDLOOP;
ENDLOOP;
END;
GrowTransistorTile: PROC [tile: CStitching.Tile, data: REF ANY] =
--A new tesselation called currentTess is formed which contains the maximum connected region that has the same value as tile and contains tile.
BEGIN
IF tile.value = $cover THEN {
currentTess: Plane ~ CStitching.NewTesselation[];
h: Handle ← NARROW[data];
tileList: LIST OF CStitching.Tile ← LIST[tile];
WHILE tileList#NIL DO
tile: CStitching.Tile ← tileList.first;
tileList ← tileList.rest;
IF tile.value#$done THEN {
tileList ← GetNeighborsSameAsMe[tile, h.overlapPlane, tileList];
CStitching.ChangeRect[currentTess, CStitching.Area[tile], $cover];
tile.value ← $done;
};
ENDLOOP;
AnalyzeTransistor[currentTess, h];
Free[currentTess];
}
END;
GetNeighborsSameAsMe: PROC [tile: CStitching.Tile, tess: Plane, tileList: LIST OF CStitching.Tile] RETURNS [newList: LIST OF CStitching.Tile] =
--Returns all tiles adjacent to tile that have the same value as tile
BEGIN
cur: CStitching.Tile;
newList ← tileList;
cur ← CStitching.EN[tile];
WHILE CStitching.WS[cur] = tile DO
IF cur.value = tile.value THEN
newList ← CONS[cur, newList];
cur ← CStitching.SW[cur];
ENDLOOP;
IF cur.value = tile.value THEN newList ← CONS[cur, newList];
cur ← CStitching.SW[tile];
WHILE CStitching.NE[cur] = tile DO
IF cur.value = tile.value THEN
newList ← CONS[cur, newList];
cur ← CStitching.EN[cur];
ENDLOOP;
IF cur.value = tile.value THEN newList ← CONS[cur, newList];
cur ← CStitching.WS[tile];
WHILE CStitching.EN[cur] = tile DO
IF cur.value = tile.value THEN
newList ← CONS[cur, newList];
cur ← CStitching.NE[cur];
ENDLOOP;
IF cur.value = tile.value THEN newList ← CONS[cur, newList];
cur ← CStitching.NE[tile];
WHILE CStitching.SW[cur] = tile DO
IF cur.value = tile.value THEN
newList ← CONS[cur, newList];
cur ← CStitching.WS[cur];
ENDLOOP;
IF cur.value = tile.value THEN newList ← CONS[cur, newList];
END;
AnalyzeTransistor: PROC [plane: Plane, h: Handle] =
--Enumerates plane, counting the covered regions and storing the covered regions on h.coveredList. The count and technology are used to select the proper Possible Instance Procedures to call. The Possible Instance Procedures return a list of possible instances which are then searched for a match.
BEGIN
currentList: RegionList ← CStitching.ListArea[plane, CDBasics.universe, $none];
count: INT ← 0;
possibleInstListPtr: REF Recognizer.InstAndForbidLayerList ← NEW[Recognizer.InstAndForbidLayerList ← NIL];
h.coveredList ← NIL;
FOR countList: RegionList ← currentList, countList.rest WHILE countList#NIL DO
IF countList.first.value#NIL THEN {
count ← count + 1;
h.coveredList ← CONS[countList.first, h.coveredList];
};
ENDLOOP;
FOR procList: LIST OF REF PossibleProcedureRec ← procRegistration, procList.rest WHILE procList#NIL DO
IF procList.first.technology = h.design.technology AND procList.first.rectCount = count THEN
procList.first.instProc[h.active1, h.active2, h.coveredList, possibleInstListPtr];
ENDLOOP;
WHILE possibleInstListPtr^#NIL DO
IF InstanceMatches[possibleInstListPtr^.first.instance, h] AND NoForbiddenOverlap[possibleInstListPtr^.first.forbidLayerList, h] THEN {
newInst: CD.Instance ← CDCells.IncludeOb[
design: h.design,
cell: h.cellOb,
ob: possibleInstListPtr^.first.instance.ob,
position: possibleInstListPtr^.first.instance.location,
orientation: possibleInstListPtr^.first.instance.orientation,
cellCSystem: cdCoords,
obCSystem: cdCoords,
mode: dontPropagate
].newInst;
newInst.selected ← TRUE;
EXIT;
}
ELSE
possibleInstListPtr^ ← possibleInstListPtr^.rest;
ENDLOOP;
END;
InstanceMatches: PROC [instance: CD.Instance, h: Handle] RETURNS [BOOLFALSE] =
--Draws the instance using the instances drawMe procedure
BEGIN
pr: CD.DrawRef ← CD.CreateDrawRef[[
design: h.design,
devicePrivate: h,
drawRect: DrawRectAgainstTess
]];
h.matches ← TRUE;
h.active1CheckTess ← CStitching.NewTesselation[];
h.active2CheckTess ← CStitching.NewTesselation[];
instance.ob.class.drawMe[inst: instance, pos: instance.location, orient: instance.orientation, pr: pr];
IF h.matches THEN
RETURN[OverlapRegionsMatch[h]];
Reaching here means that the instance drawn against the design matched. However it is still neccessary to make sure that the overlapping region in the instance matches what is on the coveredList. This guarantees that the matching instance is exactly the same size as the overlapping region in question in the design.
END;
DrawRectAgainstTess: PROC [r: CD.Rect, l: CD.Layer, pr: CD.DrawRef] =
--The rect is enumerated against its layer plane, if it is not covered then h.matches is set to false.
BEGIN
h: Handle ← NARROW[pr.devicePrivate];
checkPlane: Plane ← h.layerPlanes[l];
IF CDBasics.NonEmpty[r] THEN {
IF l = h.active1 THEN CStitching.ChangeRect[h.active1CheckTess, r, $cover]
ELSE IF l = h.active2 THEN CStitching.ChangeRect[h.active2CheckTess, r, $cover];
IF checkPlane = NIL THEN {
h.matches ← FALSE;
TerminalIO.WriteRope["Unexpected Layer Encountered\n"];
RETURN
};
FOR checkList: RegionList ← CStitching.ListArea[checkPlane, r, $none], checkList.rest WHILE checkList#NIL DO
IF checkList.first.value = NIL THEN {
h.matches ← FALSE;
RETURN
}
ENDLOOP;
}
END;
OverlapRegionsMatch: PROC [h: Handle] RETURNS [b: BOOLTRUE] =
--Forms the overlap of what is stored in active1CheckTess and active2CheckTess and makes sure that everthing on the coveredList is really covered by the overlap
BEGIN
checkTess: Plane ← CStitching.NewTesselation[];
FOR list1: RegionList ← CStitching.ListArea[plane: h.active1CheckTess, rect: CDBasics.universe, skip: $none], list1.rest WHILE list1#NIL DO
IF list1.first.value#NIL THEN
FOR overlapList: RegionList ← CStitching.ListArea[plane: h.active2CheckTess, rect: list1.first.rect, skip: $none], overlapList.rest WHILE overlapList#NIL DO
IF overlapList.first.value#NIL THEN
CStitching.ChangeRect[checkTess, overlapList.first.rect, $cover];
ENDLOOP;
ENDLOOP;
b ← RegionAndTessOverlapCompletely[h.coveredList, checkTess];
Free[checkTess];
END;
NoForbiddenOverlap: PROC [layerList: LIST OF CD.Layer, h: Handle] RETURNS [BOOLTRUE] =
--h.coveredList is enumerated against the layerList. Returns FALSE if any piece of the coveredList is covered on any of the layers.
BEGIN
WHILE layerList#NIL DO
IF h.layerPlanes[layerList.first] = NIL THEN {
TerminalIO.WriteRope["Unexpected Layer Encountered\n"];
RETURN [FALSE];
}
ELSE
IF RegionAndTessIntersect[h.coveredList, h.layerPlanes[layerList.first]] THEN RETURN [FALSE]
ELSE layerList ← layerList.rest;
ENDLOOP;
END;
RegionAndTessOverlapCompletely: PROC [checkList: RegionList, tess: Plane] RETURNS [BOOLTRUE] =
--Returns true if everything on checkList is covered on the Tesselation
BEGIN
FOR list: RegionList ← checkList, list.rest WHILE list#NIL DO
FOR list2: RegionList ← CStitching.ListArea[plane: tess, rect: list.first.rect, skip: $none], list2.rest WHILE list2#NIL DO
IF list2.first.value = NIL THEN RETURN[FALSE]
ENDLOOP;
ENDLOOP;
END;
RegionAndTessIntersect: PROC [checkList: RegionList, tess: Plane] RETURNS [BOOLFALSE] =
--Returns true if the intersection between items on the checklist and the tesselation is non-empty
BEGIO
WHILE checkList#NIL DO
FOR intersectList: RegionList ← CStitching.ListArea[tess, checkList.first.rect, $none], intersectList.rest WHILE intersectList#NIL DO
IF intersectList.first.value#NIL THEN RETURN [TRUE];
ENDLOOP;
checkList ← checkList.res|;
ENDLOOP;
END;
RegisterPossibleInstanceProc: PUBLIC ENTRY PROC [technology: CD.Technology, rectCount: INT, instProc: Recognizer.PossibleInstanceProc] =
BEGIN
procRegistration ← CONS[NEW[PossibleProcedureRec ← [technology, rectCount, instProc]], procRegistration];
END;
RegisterLayerList: PUBLIC ENTRY PROC [technology: CD.Technology, active1, active2: CD.Layer, layerList: LIST OF CD.Layer] =
BEGIN
layerRegistration ← CONS[NEW[ActiveLayersRec ← [technology, active1, active2, layerList]], layerRegistration];
END;
END.