FSMExtras.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
Don Curry June 11, 1988 11:23:23 am PDT
DIRECTORY CD, CDCells, CDCommandOps, CDDirectory, CDOps, CDProperties, CDSequencer, Core, CoreGeometry, CoreOps, FSM, IO, Rope, IconConstruction, Sisyph, TerminalIO;
FSMExtras: CEDAR PROGRAM
IMPORTS CDCells, CDCommandOps, CDDirectory, CDOps, CDProperties, CoreOps, FSM, IO, Rope, IconConstruction, Sisyph, TerminalIO
SHARES Sisyph
= BEGIN
Common Types and Declarations
Create FSM Icon
CreateFSMIconSch: PROC [comm: CDSequencer.Command] ~ {
fsmName:  Rope.ROPE;
shortName: Rope.ROPE;
iconName: Rope.ROPE;
icon:   CD.Object;
cell:   Core.CellType;
shell:   IconConstruction.Shell;
nms:   ARRAY CoreGeometry.Side OF LIST OF Rope.ROPE;
side:   CoreGeometry.Side ← left;
codeLine:  IO.ROPE;
cx:    Sisyph.Context ← Sisyph.Create[comm.design];
selected:  CD.Instance = CDOps.TheInstance[comm.design, "CreateFSMIcon\n"];
-- Get name of source and target
IF selected=NIL THEN RETURN;
fsmName ← CDDirectory.Name[selected.ob, comm.design];
IF fsmName.IsEmpty[] THEN
{TerminalIO.PutF["*** Selected schematic has no name.\n"]; RETURN};
IF ~Rope.Match["*.fsm", fsmName] THEN
TerminalIO.PutF["*** Convention for FSM schematics is to suffix them with '.fsm'.\n"];
shortName ← TerminalIO.RequestRope["Type icon short name: "];
IF shortName.IsEmpty[]
THEN shortName ← fsmName.Substr[0, fsmName.Index[0, "."]]
ELSE shortName ← shortName.Substr[0, shortName.Index[0, "."]];
iconName ← shortName.Concat[".icon"];
IF CDDirectory.Fetch[comm.design, iconName]#NIL THEN
{TerminalIO.PutF["*** The icon %g already exists!\n", IO.rope[iconName]]; RETURN};
-- Get the source cell type
cell ← FSM.SchMachine[cx, fsmName];
-- Get the names
FOR i: INT IN [0..cell.public.size) DO
nm: IO.ROPE ← CoreOps.GetShortWireName[cell.public[i]];
IF nm.Equal["Gnd"] OR nm.Equal["Vdd"] THEN {side ← right; LOOP};
nms[side] ← CONS[nm, nms[side]] ENDLOOP;
-- Build the object, instantiate it & return
shell ← IconConstruction.NewShell[shortName, nms, comm.design];
shell.grid ← CDOps.GetGrid[comm.design, comm]; -- default might not be perfect...
icon ← IconConstruction.ShellObject[shell];
CDProperties.PutObjectProp[icon, Sisyph.mode.extractProcProp, $SisyphExtractCellIcon];
codeLine ← IO.PutFR["FSM.SchMachine[cx, \"%g\"]", IO.rope[fsmName]];
CDProperties.PutObjectProp[icon, $CodeFor, codeLine];
CDCells.SetSimplificationTreshhold[cell: icon, val: 30, inPixels: TRUE];
IF NOT CDDirectory.Include[comm.design, icon, iconName] THEN ERROR; -- Abnormal
[] ← CDOps.IncludeObjectI[comm.design, icon, comm.pos];
TerminalIO.PutF["%g generated\n", IO.rope[iconName]]};
CreateFSMIconCode: PROC [comm: CDSequencer.Command] ~ {
shortName: Rope.ROPE;
iconName: Rope.ROPE;
codeFor:  Rope.ROPE;
icon:   CD.Object;
cell:   Core.CellType;
shell:   IconConstruction.Shell;
nms:   ARRAY CoreGeometry.Side OF LIST OF Rope.ROPE;
side:   CoreGeometry.Side ← left;
cx:    Sisyph.Context ← Sisyph.Create[comm.design];
-- Get name of source and target
shortName ← TerminalIO.RequestRope["Short name: "];
shortName ← shortName.Substr[0, shortName.Index[0, "."]];
iconName  ← shortName.Concat[".icon"];
IF CDDirectory.Fetch[comm.design, iconName]#NIL THEN
{TerminalIO.PutF["*** The icon %g already exists!\n", IO.rope[iconName]]; RETURN};
codeFor  ← TerminalIO.RequestRope["Code: "];
-- Get the source cell type
cell ← NARROW[Sisyph.EvalToRef[cx, codeFor]];
-- Get the names
FOR i: INT IN [0..cell.public.size) DO
nm: IO.ROPE ← CoreOps.GetShortWireName[cell.public[i]];
IF nm.Equal["Gnd"] OR nm.Equal["Vdd"] THEN {side ← right; LOOP};
nms[side] ← CONS[nm, nms[side]] ENDLOOP;
-- Build the object, instantiate it & return
shell ← IconConstruction.NewShell[shortName, nms, comm.design];
shell.grid ← CDOps.GetGrid[comm.design, comm]; -- default might not be perfect...
icon ← IconConstruction.ShellObject[shell];
CDProperties.PutObjectProp[icon, Sisyph.mode.extractProcProp, $SisyphExtractCellIcon];
CDProperties.PutObjectProp[icon, $CodeFor, codeFor];
CDCells.SetSimplificationTreshhold[cell: icon, val: 30, inPixels: TRUE];
IF NOT CDDirectory.Include[comm.design, icon, iconName] THEN ERROR; -- Abnormal
[] ← CDOps.IncludeObjectI[comm.design, icon, comm.pos];
TerminalIO.PutF["%g generated\n", IO.rope[iconName]]};
Runtime Loading
CDCommandOps.RegisterWithMenu[
menu:  $SisyphIconMenu,
entry:  "Create Icon for FSM schematic",
doc:  "Create Icon for finite state machine schematic",
key:  $CreateFSMIconSch,
proc:  CreateFSMIconSch ];
CDCommandOps.RegisterWithMenu[
menu:  $SisyphIconMenu,
entry:  "Create Icon for FSM code",
doc:  "Create Icon for finite state machine code",
key:  $CreateFSMIconCode,
proc:  CreateFSMIconCode ];
END.