CellCommands.mesa (part of ChipNDale)
by Christian Jacobi July 11, 1983 3:42 pm
last edited Christian Jacobi March 5, 1984 7:58:41 pm PST
DIRECTORY
CD,
CDOps,
CDCells,
CDDirectory,
CDMarks,
CDSequencer,
TerminalIO,
Rope;
CellCommands:
CEDAR
PROGRAM
IMPORTS CDOps, CDCells, CDDirectory, CDMarks, CDSequencer, TerminalIO =
BEGIN
GetCell:
PROC [comm: CDSequencer.Command] =
BEGIN
name: Rope.ROPE;
cellOb: CD.ObPtr;
found: BOOLEAN;
TerminalIO.WriteRope["Include cell; "];
DO
name ← TerminalIO.RequestRope["type name\n"! TerminalIO.UserAbort => {GOTO aborted}];
[found, cellOb] ← CDDirectory.Fetch[comm.design, name];
IF found
THEN
BEGIN
CDOps.AddAnObject[
design: comm.design,
ob: cellOb,
location: comm.pos,
orientation: 0];
TerminalIO.WriteRope[name];
TerminalIO.WriteRope[" inserted\n"];
RETURN
END;
TerminalIO.WriteRope[name]; TerminalIO.WriteRope[" not found\n"];
IF
NOT TerminalIO.UserSaysYes[label: "another try ?"
! TerminalIO.UserAbort => {GOTO aborted}] THEN RETURN;
ENDLOOP
END;
DeleteCell:
PROC [comm: CDSequencer.Command] =
BEGIN
EachEntryCheck: CDDirectory.EachEntryAction
-- PROC [name: Rope.ROPE, ob: CD.ObPtr] RETURNS [quit: BOOLLSE]-- =
BEGIN
IF ob.marked#mark
AND ob#toDeleteOb
THEN {
-- an occurence of cellOb should not be marked
CDMarks.MarkUnMarkedInclusiveChildren[comm.design, ob, mark];
IF toDeleteOb.marked=mark
THEN {
usedBy ← name;
quit ← TRUE
}
};
END;
-- DeleteCell
name: Rope.ROPE←NIL;
usedBy: Rope.ROPE←NIL;
toDeleteOb: CD.ObPtr;
found: BOOLEAN;
mark: CDMarks.MarkRange;
TerminalIO.WriteRope["delete cell; "];
name ← TerminalIO.RequestRope["type name\n"! TerminalIO.UserAbort => {GOTO aborted}];
[found, toDeleteOb] ← CDDirectory.Fetch[comm.design, name];
IF ~found
THEN
BEGIN
TerminalIO.WriteRope[name]; TerminalIO.WriteRope[" not found\n"];
RETURN
END;
-- mark all entries (excluding toDeleteOb), and all their children
-- test then if toDeleteOb is marked; if it is, it is a child and used
mark ← CDMarks.GetNewMark[comm.design];
IF CDDirectory.Enumerate[comm.design, EachEntryCheck].quit
THEN {
TerminalIO.WriteRope[name]; TerminalIO.WriteRope[" is used by "];
TerminalIO.WriteRope[usedBy];
TerminalIO.WriteRope[" (and maybe others); not deleted\n"];
RETURN
};
IF CDDirectory.Remove[comm.design, name, toDeleteOb]
THEN {
TerminalIO.WriteRope[" deleted\n"];
}
ELSE {
TerminalIO.WriteRope[" not deleted; error in delete routine\n"];
}
END;
EachEntryDisplay: CDDirectory.EachEntryAction
--[name: Rope.ROPE, ob: CD.ObPtr] RETURNS [quit: BOOL] -- =
BEGIN
WITH ob.specificRef
SELECT
FROM
cp:
CD.CellPtr => {
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[cp.name];
};
ENDCASE => {
TerminalIO.WriteRope[" ("]; TerminalIO.WriteRope[name];
TerminalIO.WriteRope[") "];
TerminalIO.WriteRope[CDOps.Info[ob]];
};
TerminalIO.WriteLn[];
quit ← FALSE
END;
DisplayCellNames:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Display cell names\n"];
IF CDDirectory.Enumerate[comm.design, EachEntryDisplay] THEN TerminalIO.WriteRope["stopped\n"]
ELSE TerminalIO.WriteRope["---\n"]
END;
CreateCell:
PROC [comm: CDSequencer.Command] =
BEGIN
done: BOOL;
TerminalIO.WriteRope["Create cell "];
[done: done] ← CDCells.CreateCellSelected[comm.design];
IF ~done THEN TerminalIO.WriteRope[" not done\n"];
END;
PushIntoCellS:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Push into cell "];
IF CDCells.PushInCellSelected[comm.design]
THEN
{TerminalIO.WriteRope[comm.design.actual.first.specific.name]; TerminalIO.WriteLn[]}
ELSE TerminalIO.WriteRope["not done\n"];
END;
PushIntoCellP:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Push into cell "];
IF CDCells.PushInCellPointed[comm.design, comm.pos]
THEN
{TerminalIO.WriteRope[comm.design.actual.first.specific.name]; TerminalIO.WriteLn[]}
ELSE TerminalIO.WriteRope["not done\n"];
END;
PopFromCell:
PROC [comm: CDSequencer.Command] =
BEGIN
IF ~CDCells.PopFromCell[comm.design]
THEN
TerminalIO.WriteRope["pop not done\n"];
END;
CleanUpDirectory:
PROC [comm: CDSequencer.Command] ~
BEGIN
RemoveIfNotMarked:
PROC [name: Rope.
ROPE, ob:
CD.ObPtr]
RETURNS [quit:
BOOL←
FALSE] ~
BEGIN
IF ob.marked#m
THEN {
[] ← CDDirectory.Remove[design: comm.design, name: name, expectObject: ob];
}
END;
ListNotMarked:
PROC [name: Rope.
ROPE, ob:
CD.ObPtr]
RETURNS [quit:
BOOL←
FALSE] ~
BEGIN
IF ob.marked#m
THEN {
TerminalIO.WriteRope[" - "]; TerminalIO.WriteRope[name]; TerminalIO.WriteLn[];
cnt ← cnt + 1
}
END;
cnt: NAT ← 0;
m: CDMarks.MarkRange;
TerminalIO.WriteRope["Clean up library\n"];
m ← CDMarks.GetNewMark[comm.design];
FOR l:
LIST
OF
CD.PushRec ← comm.design.actual, l.rest
WHILE l#
NIL
DO
IF l.first.mightReplace#
NIL
THEN {
CDMarks.MarkUnMarkedInclusiveChildren[comm.design, l.first.mightReplace.ob, m];
};
CDMarks.MarkUnMarkedInclusiveChildren[comm.design, l.first.dummyCell.ob, m];
ENDLOOP;
TerminalIO.WriteRope[" List of objects not used:\n"];
[] ← CDDirectory.Enumerate[design: comm.design, action: ListNotMarked];
TerminalIO.WriteRope[" "];
TerminalIO.WriteInt[cnt];
TerminalIO.WriteRope[" objects not used in design\n"];
IF cnt>0
THEN {
IF TerminalIO.UserSaysYes[
label: "delete them?",
text: " you may delete all the listed objects\n (deletion must be performed atomic)\n"
] THEN {
TerminalIO.WriteRope[" **** start atomic\n"];
TerminalIO.WriteRope[" if for any reason it crashes while deleting,\n"];
TerminalIO.WriteRope[" the deleting process must be repeated before\n"];
TerminalIO.WriteRope[" the design is otherwise used\n"];
[] ← CDDirectory.Enumerate[design: comm.design, action: RemoveIfNotMarked];
TerminalIO.WriteRope[" **** end atomic\n finished successfully\n"];
}
ELSE TerminalIO.WriteRope[" not done\n"];
}
END;
SetSimplification:
PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.ApplicationPtr;
multiple: BOOL;
TerminalIO.WriteRope["Set cell simplification\n"];
[ap, multiple] ← CDOps.SelectedApplication[comm.design];
IF multiple THEN TerminalIO.WriteRope[" multiple selection; not done\n"]
ELSE IF ap=NIL THEN TerminalIO.WriteRope[" no selection; not done\n"]
ELSE
{
TerminalIO.WriteRope[ap.ob.p.describe[ap.ob]];
IF
ISTYPE[ap.ob.specificRef,
CD.CellPtr]
THEN {
cptr: CD.CellPtr ~ NARROW[ap.ob.specificRef];
TerminalIO.WriteRope[" [currently: simplification if height < "];
TerminalIO.WriteInt[cptr.simplifyOn];
cptr.simplifyOn ←
MIN[
MAX[
TerminalIO.RequestInt[" pixels] type > "],
0],
LAST[NAT]
];
TerminalIO.WriteRope[" done\n"]
}
ELSE TerminalIO.WriteRope[" not a cell; not done\n"];
}
END;
RenameSelectedObject:
PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.ApplicationPtr;
multiple: BOOL;
TerminalIO.WriteRope["rename selected object\n"];
[ap, multiple] ← CDOps.SelectedApplication[comm.design];
IF multiple THEN TerminalIO.WriteRope[" multiple selection; not done\n"]
ELSE IF ap=NIL THEN TerminalIO.WriteRope[" no selection; not done\n"]
ELSE {
TerminalIO.WriteRope[ap.ob.p.describe[ap.ob]];
IF NOT ap.ob.p.hasChildren THEN TerminalIO.WriteRope[" has no name; not done\n"]
ELSE {
newName: Rope.ROPE = TerminalIO.RequestRope[" new name > "];
IF CDDirectory.Rename[comm.design, ap.ob, newName] THEN TerminalIO.WriteRope["done\n"]
ELSE TerminalIO.WriteRope["not done\n"]
}
}
END;
Impl:
PROC [] =
BEGIN
CDSequencer.ImplementCommand[$Pop, PopFromCell];
CDSequencer.ImplementCommand[$PushS, PushIntoCellS];
CDSequencer.ImplementCommand[$PushP, PushIntoCellP];
CDSequencer.ImplementCommand[$CreateCellS, CreateCell];
CDSequencer.ImplementCommand[$DisplayCellNames, DisplayCellNames];
CDSequencer.ImplementCommand[$DrawCell, GetCell];
CDSequencer.ImplementCommand[$RemoveCell, DeleteCell];
CDSequencer.ImplementCommand[$DeleteUnUsedObjects, CleanUpDirectory];
CDSequencer.ImplementCommand[$SetSimplification, SetSimplification];
CDSequencer.ImplementCommand[$RenameS, RenameSelectedObject];
END;
Impl[];
END.