<Cedar5.2>System>spMain.mesa>> <> <<>> DIRECTORY BasicTime USING [Now], CommandTool USING [Run], FS USING [Error], IO USING [PutF, rope], MessageWindow USING [Append], PrincOps USING [NoTimeout], Process USING [Abort, Detach, GetPriority, Priority, priorityBackground, SetPriority, SetTimeout], <> Real USING [FixC], RefText USING [New], Rope USING [Equal, Find, IsEmpty, ROPE, Substr], RopeFrom USING [String], spGlobals USING [Aborted, bomb, CircuitRec, CleanUp, defineCircuit, dumpAll, error, ErrWarnSummary, fileStackSeq, function, functionTable, FuncTableBlk, Handle, keys, makePlotList, makePrintList, maxInclude, maxLog, maxPlots, maxPrints, model, modFuncPtr, modelTable, ModelTableBlk, nameBlk, namePtr, next, openInputFile, output, PlotSeq, printHole, PrintSeq, PutMsgLine, runIt, searchKey, SetCursor, setICs, topoAnalysis, Variables, WorstNodeLog], ViewerClasses USING [Viewer], ViewerTools USING [SetContents]; spMain: CEDAR MONITOR IMPORTS BasicTime, CommandTool, FS, IO, MessageWindow, Process, Real, --RecursivelyNIL, --RefText, Rope, RopeFrom, spGlobals, ViewerTools EXPORTS spGlobals= { OPEN spGlobals; EnterModels: PUBLIC ENTRY PROC[entry: ModelTableBlk]= { ENABLE UNWIND => NULL; FOR m: LIST OF REF ModelTableBlk _ modelTable, m.rest UNTIL m=NIL DO IF Rope.Equal[m.first.name, entry.name] THEN { m.first^ _ entry; RETURN; }; ENDLOOP; modelTable _ CONS[NEW[ModelTableBlk_ entry], modelTable]; }; -- EnterModels EnterFunctions: PUBLIC ENTRY PROC[entry: FuncTableBlk]= { ENABLE UNWIND => NULL; FOR f: LIST OF REF FuncTableBlk _ functionTable, f.rest UNTIL f=NIL DO IF Rope.Equal[f.first.name, entry.name] THEN { f.first^ _ entry; RETURN; }; ENDLOOP; functionTable _ CONS[NEW[FuncTableBlk_ entry], functionTable]; }; -- EnterFunctions <> findModel: PUBLIC ENTRY PROC[name: Rope.ROPE] RETURNS[REF ModelTableBlk]= { ENABLE UNWIND => NULL; FOR m: LIST OF REF ModelTableBlk _ modelTable, m.rest UNTIL m=NIL DO IF Rope.Equal[m.first.name, name] THEN RETURN[m.first]; ENDLOOP; RETURN[NIL]; }; -- findModel findFunction: PUBLIC ENTRY PROC[name: Rope.ROPE] RETURNS[REF FuncTableBlk]= { ENABLE UNWIND => NULL; FOR f: LIST OF REF FuncTableBlk_ functionTable, f.rest UNTIL f=NIL DO IF Rope.Equal[f.first.name, name] THEN RETURN[f.first]; ENDLOOP; RETURN[NIL]; }; -- findFunction ResetCheckPoint: PUBLIC ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; handle.vars.checkPoint_ FALSE }; Canned: PUBLIC ENTRY PROC[handle: Handle] RETURNS[BOOL]= { ENABLE UNWIND => NULL; RETURN[handle.vars.canned]}; ForcedDump: PUBLIC ENTRY PROC[handle: Handle] RETURNS[BOOL]= { ENABLE UNWIND => NULL; RETURN[handle.vars.forcedDump]}; CheckPoint: PUBLIC ENTRY PROC[handle: Handle] RETURNS[BOOL]= { ENABLE UNWIND => NULL; RETURN[handle.vars.checkPoint]}; ShowDetails: PUBLIC ENTRY PROC[handle: Handle] RETURNS[BOOL]= { ENABLE UNWIND => NULL; RETURN[handle.showTimeStep]}; StopIt: PUBLIC ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; IF handle # NIL THEN { IF handle.vars # NIL THEN { handle.vars.forcedDump_ FALSE; handle.vars.canned_ TRUE; }; AbortCheckPoint[handle]; }; }; -- StopIt DumpIt: PUBLIC ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; IF handle # NIL THEN { IF handle.vars # NIL THEN { handle.vars.forcedDump_ TRUE; handle.vars.canned_ TRUE; }; AbortCheckPoint[handle]; }; }; -- DumpIt ToggleShowDetails: PUBLIC ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; handle.showTimeStep_ ~handle.showTimeStep; }; -- ToggleShowDetails NormalRun: PUBLIC ENTRY PROC[handle: Handle, detach: BOOL _ TRUE]= { ENABLE UNWIND => NULL; IF handle = NIL THEN RETURN; IF handle.stage=idle AND handle.simulation=NIL THEN { curPriority: Process.Priority = Process.GetPriority[]; handle.stage_ input; SetCursor[handle]; Process.SetPriority[Process.priorityBackground]; handle.outer.inhibitDestroy _ TRUE; handle.simulation_ FORK Simulate[handle]; Process.SetPriority[curPriority]; IF detach THEN TRUSTED {Process.Detach[handle.simulation]}; } ELSE MessageWindow.Append[ message: "Previous simulation has not finished yet.", clearFirst: TRUE]; }; -- NormalRun BatchRun: PUBLIC PROC[handle: Handle, inputFile: Rope.ROPE _ NIL]= { IF handle = NIL THEN RETURN; IF inputFile # NIL THEN ViewerTools.SetContents[handle.input, inputFile]; NormalRun[handle, FALSE]; IF handle.simulation # NIL THEN TRUSTED {JOIN handle.simulation}; }; -- BatchRun NextStage: PUBLIC ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; SELECT handle.stage FROM input, bomb, topo => { handle.stage_ SUCC[handle.stage]; SetCursor[handle]; }; run => { handle.vars.runState _ (handle.vars.runState + 1) MOD 4; SetCursor[handle]; }; ENDCASE => MessageWindow.Append[ -- should not get here message: "* Weird situation detected in 'NextStage', please inform SChen.pa", clearFirst: TRUE]; }; -- NextStage PeriodicSetCheckPoint: ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; WHILE handle # NIL DO ENABLE ABORTED => EXIT; WAIT handle.checkPointCV; IF handle # NIL THEN IF handle.vars # NIL THEN handle.vars.checkPoint_ TRUE ELSE EXIT; ENDLOOP; IF handle # NIL THEN TRUSTED {Process.SetTimeout[@handle.checkPointCV, PrincOps.NoTimeout]}; }; -- PeriodicSetCheckPoint CleanIt: ENTRY PROC[handle: Handle]= { ENABLE UNWIND => NULL; CleanUp[handle]; }; -- CleanIt AbortCheckPoint: INTERNAL PROC[handle: Handle]= { IF handle = NIL THEN RETURN; IF handle.stage=run AND handle.checkProcess # NIL THEN { TRUSTED {Process.Abort[LOOPHOLE[handle.checkProcess, UNSPECIFIED]]}; handle.checkProcess_ NIL; }; }; -- AbortCheckPoint AddLibrary: PROC[handle: Handle]= { next[handle]; IF handle.vars.item=leftB THEN next[handle] ELSE error[handle, 801, TRUE]; IF handle.vars.item=name THEN { originalName, nameRoot, errMsg: Rope.ROPE; dotPosition: INT; originalName_ RopeFrom.String[handle.vars.newString]; dotPosition_ Rope.Find[originalName, "."]; nameRoot_ IF dotPosition=-1 THEN originalName ELSE Rope.Substr[originalName, 0, dotPosition-1]; IF NOT (Rope.Equal[nameRoot, "MosModels", FALSE] OR Rope.Equal[nameRoot, "StdFunctions", FALSE] OR Rope.Equal[nameRoot, "Level2Model", FALSE]) THEN { [errMsg, ]_ CommandTool.Run[originalName]; IF NOT errMsg.IsEmpty[] THEN PutMsgLine[handle, errMsg]; }; next[handle]; } ELSE error[handle, 804, TRUE]; IF handle.vars.item=rightB THEN next[handle] ELSE error[handle, 802, FALSE]; IF handle.vars.item=semi THEN next[handle] ELSE error[handle, 800, FALSE]; }; -- AddLibrary Simulate: PROC[handle: Handle]= { ENABLE { Aborted => GOTO stop; ABORTED => {handle.vars.canned _ TRUE; GOTO dumpStop}; FS.Error => { handle.msgStream.PutF["%g\nProgram stopped.\n", IO.rope[error.explanation]]; GOTO stop; }; }; InitVars[handle]; openInputFile[handle]; next[handle]; <> WHILE handle.vars.item=name DO IF Canned[handle] THEN GOTO stop; IF searchKey[handle]=libraryKey THEN AddLibrary[handle] ELSE EXIT; ENDLOOP; <> IF handle.vars.item=name AND searchKey[handle]=circuitKey THEN { theRoot: namePtr_ NEW[nameBlk_ [name: "Main Circuit", details: NEW[CircuitRec_ []]] ]; defineCircuit[handle: handle, ckt: theRoot, root: TRUE]; -- may signal Aborted } ELSE error[handle, 820, TRUE]; IF handle.vars.item=slash AND handle.vars.errCount <= 0 THEN { next[handle]; output[handle, handle.vars.cktRoot, 0]; }; <> IF handle.vars.item#semi THEN error[handle, 800,, FALSE] ELSE IF handle.vars.errCount <= 0 THEN { NextStage[handle]; bomb[handle]; -- may signal Aborted next[handle]; IF handle.vars.item=plus THEN {next[handle]; printHole[handle]}; }; <<>> <> IF handle.vars.errCount <= 0 THEN { NextStage[handle]; topoAnalysis[handle]; IF Canned[handle] THEN GOTO stop; }; <<>> <> IF handle.vars.errCount <= 0 THEN { NextStage[handle]; WHILE handle.vars.item=name DO OPEN handle.vars; key: keys_ searchKey[handle]; next[handle]; SELECT key FROM runKey=> { TRUSTED { Process.SetTimeout[@handle.checkPointCV, Real.FixC[60.0*checkPointInterval]]; Process.Detach[handle.checkProcess_ FORK PeriodicSetCheckPoint[handle]]; }; lastTime_ runIt[handle]; IF NOT Canned[handle] THEN PutMsgLine[handle, "Done."]; }; printKey=> makePrintList[handle]; plotKey => makePlotList[handle]; icKey => setICs[handle]; dumpKey => IF ~ForcedDump[handle] THEN dumpAll[handle, lastTime]; checkPointKey=> { IF item=leftB THEN next[handle] ELSE error[handle, 801]; IF item=number THEN { checkPointInterval_ value; next[handle] } ELSE error[handle, 809, FALSE]; IF item=rightB THEN next[handle] ELSE error[handle, 802]; } ENDCASE=> GOTO err1; IF item=eof THEN EXIT; IF item=semi THEN next[handle] ELSE error[handle, 800,, FALSE]; REPEAT err1=> error[handle, 821, TRUE]; ENDLOOP; }; -- run IF ForcedDump[handle] THEN dumpAll[handle, handle.vars.lastTime]; ErrWarnSummary[handle]; <> GOTO stop; EXITS dumpStop=> { dumpAll[handle, handle.vars.lastTime]; handle.msgStream.PutF["Last state is dumped in the dump file."]; CleanIt[handle]; }; stop=> CleanIt[handle]; }; -- Simulate <<>> InitVars: PROC[handle: Handle]= { handle.vars_ NEW[Variables_ [ ]]; {OPEN handle.vars; simTime _ BasicTime.Now[]; line_ RefText.New[256]; newString_ RefText.New[256]; line.length_ 0; newString.length_ 0; fileStack_ NEW[fileStackSeq[maxInclude]]; FOR i: NAT IN [0..maxInclude) DO fileStack[i] _ NIL ENDLOOP; prints_ NEW[PrintSeq[maxPrints]]; FOR i: NAT IN [0..maxPrints) DO prints[i] _ [] ENDLOOP; plots_ NEW[PlotSeq[maxPlots]]; FOR i: NAT IN [0..maxPlots) DO plots[i] _ [] ENDLOOP; worstNodeLog_ NEW[WorstNodeLog[maxLog]]; FOR i: NAT IN [0..maxLog) DO worstNodeLog[i] _ []; ENDLOOP; }; }; -- InitVars <<>> }. <<>> <> <> <> <> <> <> <>