CDSimplifyStructureImpl.mesa (a ChipNDale module)
Copyright © 1986, 1987 by Xerox Corporation. All rights reserved.
Created by Christian October 28, 1986 10:47:15 am PST
Last edited by: Christian Jacobi, February 13, 1987 1:16:44 pm PST
DIRECTORY
CD,
CDBottomUp,
CDCells,
CDCommandOps,
CDInstances,
CDOps,
CDProperties,
CDSequencer,
CDSimplifyStructure,
IO,
Rope,
TerminalIO;
CDSimplifyStructureImpl:
CEDAR
PROGRAM
IMPORTS CD, CDBottomUp, CDCells, CDCommandOps, CDInstances, CDOps, CDProperties, IO, Rope, TerminalIO
EXPORTS CDSimplifyStructure =
BEGIN
Simplify:
PUBLIC
PROC [design:
CD.Design, root:
CD.Object, log:
IO.
STREAM←
NIL] = {
IF log=NIL THEN log ← TerminalIO.TOS[];
[] ← CDBottomUp.StartRecurse[simplifyClass, root, design, log];
};
CellSingleInst:
PROC [ob:
CD.Object]
RETURNS [instOrNil:
CD.Instance←
NIL] =
INLINE {
WITH ob.specific
SELECT
FROM
cp:
CD.CellSpecific => {
IF cp.sequence=
NIL
OR cp.sequence.length=0
THEN {
IF cp.contents#NIL AND cp.contents.rest=NIL THEN RETURN [cp.contents.first]
}
ELSE
IF cp.sequence.length=1
THEN {
IF cp.contents=NIL THEN RETURN [cp.sequence[0]]
}
};
ENDCASE => NULL;
};
DoSimplify: CDBottomUp.DoProc = {
IF CDCells.IsCell[ob]
THEN {
cnt: INT ← 0;
EachInst: CDCells.InstEnumerator = {
subInst: CD.Instance ← CellSingleInst[inst.ob];
IF subInst#NIL
THEN {
stream: IO.STREAM ← NARROW[handle.data];
composed: CD.Instance ← CDInstances.Composed[subInst, inst.trans];
composed.properties ← CDProperties.DAppendProps[winner: inst.properties, looser: composed.properties];
IF (cnt𡤌nt+1)=1
THEN
IO.PutRope[stream, Rope.Cat["in ", CD.Describe[ob], "\n"]];
IO.PutRope[stream, Rope.Cat[" instance of ", CD.Describe[inst.ob], " replaced by ", CD.Describe[composed.ob], "\n"]];
inst^ ← composed^;
}
};
[] ← CDCells.EnumerateInstances[ob, EachInst];
};
};
HierarchicalSimplificationComm:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "hierarchical simplification\n"];
IF inst#
NIL
THEN {
Simplify[comm.design, inst.ob];
TerminalIO.PutRope["--finished\n"]
}
};
simplifyClass: CDBottomUp.Class ← CDBottomUp.Register[DoSimplify,
NIL, $CDSimplify, $CDSimplify];
--use the CDBottomUp mechanism because we want to deal every object just once but
--some silly user didn't include the objects in the directory.
CDCommandOps.RegisterWithMenu[menu: $ProgramMenu, entry: "Hierarchical Simplification", proc: HierarchicalSimplificationComm, key: $CDSimplify];
END.