CountsImpl.mesa (a ChipNDale module)
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
Created by Preas May 19, 1989 5:08:19 pm PDT
DIRECTORY
CD,
CDBasics,
CDCells,
CDCommandOps,
CDDirectory,
CDRects,
CDOps,
CDSequencer,
IO,
TerminalIO;
CountsImpl: CEDAR PROGRAM
IMPORTS CD, CDCells, CDCommandOps, CDDirectory, CDOps, CDRects, IO, TerminalIO
SHARES CDCells, CDRects =
BEGIN
ToCell: PROC [obj: CD.Object, comm: CDSequencer.Command] RETURNS [cell: CD.Object] ~ {
if object is composed, convert to a cell, else return object
ob: CD.Object ← obj;
IF obj.class.composed THEN {
WHILE ob#NIL AND ~CDCells.IsCell[ob] DO
ob ← CDDirectory.ExpandRecursed[ob, comm.design, comm.design];
IF ob=obj THEN ob ← NIL; --to exit loop
ENDLOOP;
};
cell ← ob};
CountWithEnum: PROC [instance: CD.Instance, comm: CDSequencer.Command] ~ {
rectangles, wellRectangles, atomicObjects: INT ← 0;
EachInst: CDCells.InstEnumerator ~ {
-- PROC [inst: CD.Instance] RETURNS [quit: BOOL�LSE];
CountRects[inst.ob]
};
CountRects: PROC [obj: CD.Object] ~ {
class: CD.ObjectClass ← obj.class;
IF class = CDRects.bareRectClass THEN rectangles ← rectangles + 1
ELSE IF class = CDRects.wellRectClass THEN wellRectangles ← wellRectangles + 1
ELSE IF class.atomicOb THEN atomicObjects ← atomicObjects + 1
ELSE IF class.composed THEN
[] ← CDCells.EnumerateInstances[ToCell[obj, comm], EachInst];
};
CountRects[instance.ob];
TerminalIO.PutF1["well rectangles = %g\n", IO.int[wellRectangles]];
TerminalIO.PutF1["rectangles = %g\n", IO.int[rectangles]];
TerminalIO.PutF1["atomic objects (transistors or vias) = %g\n", IO.int[atomicObjects]];
};
CountCommWithEnum: PROC [comm: CDSequencer.Command] = {
instance: CD.Instance ← CDOps.TheInstance[comm.design, "count rectangles using enumeration\n"];
IF instance#NIL THEN {
CountWithEnum[instance, comm];
TerminalIO.PutRope["--done\n"]
};
};
MyDrawChild: CD.DrawProc = {
PROC [pr: CD.DrawRef, ob: CD.Object, trans: CD.Transformation←[], readOnlyInstProps: CD.PropList←NIL];
objectCount ← objectCount+1;
CD.DrawOb[ob: ob, trans: trans, pr: pr, readOnlyInstProps: readOnlyInstProps];
};
MyDrawRect: CD.DrawRectProc = {
PROC [pr: CD.DrawRef, r: CD.Rect, l: CD.Layer];
rectangleCount ← rectangleCount+1;
};
rectangleCount, objectCount: INT;
CountWithDraw: PROC [instance: CD.Instance, comm: CDSequencer.Command] ~ {
Count rectangles and objects using ChnpnDale's draw mechnism
myDrawRef: CD.DrawRef ← CD.CreateDrawRef[[
interestClip: CDBasics.universe,
drawChild: MyDrawChild,
drawRect: MyDrawRect,
design: comm.design
]];
rectangleCount ← objectCount ← 0;
CD.DrawOb[myDrawRef, instance.ob, instance.trans, instance.properties];
myDrawRef ← NIL;
TerminalIO.PutF1["objects = %g\n", IO.int[objectCount]];
TerminalIO.PutF1["rectangles = %g\n", IO.int[rectangleCount]];
};
CountCommWithDraw: PROC [comm: CDSequencer.Command] = {
instance: CD.Instance ← CDOps.TheInstance[comm.design, "count rectangles using draw mechanism\n"];
IF instance#NIL THEN {
CountWithDraw[instance, comm];
TerminalIO.PutRope["--done\n"]
};
};
CountCommProtected: PROC [comm: CDSequencer.Command] = {
[] ← CDCommandOps.DoWithResource[CountCommWithDraw, comm, $myDrawRef];
};
CDCommandOps.RegisterWithMenu[menu: $ProgramMenu, entry: "count rectangles (enum)", proc: CountCommWithEnum, key: $CDCountRectanglesWithEnum];
CDCommandOps.RegisterWithMenu[menu: $ProgramMenu, entry: "count rectangles (draw)", proc: CountCommProtected, key: $CDCountRectanglesWithDraw];
END.