DIRECTORY AMBridge, AMModel, AMModelBridge, AMTypes, Atom, Basics, BasicTime, CacheModels, Commander, CommandTool, Convert, IO, List, PrincOps, PrincOpsUtils, ProcessProps, RESIDisp, RESInterpreter, RESIStats, WrapRESIUtil, RESIXfer, Rope, ViewerIO USING [CreateViewerStreams], WorldVM; WrapDragoman: CEDAR PROGRAM IMPORTS AMBridge, AMModel, AMModelBridge, Atom, BasicTime, CommandTool, Convert, IO, List, PrincOpsUtils, ProcessProps, RESIDisp, RESInterpreter, RESIStats, WrapRESIUtil, RESIXfer, Rope, ViewerIO, WorldVM = BEGIN ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; Machine: TYPE = RESInterpreter.Machine; Handle: TYPE = REF HandleRec; -- a REF to the data for a particular instance of the sample tool; multiple instances can be created. HandleRec: TYPE = RECORD [ -- the data for a particular tool instance modelCache: BOOL, m: Machine, workingDir: Atom.PropList, parent: Commander.Handle, tsIn, tsOut: STREAM]; Output: PROC [handle: Handle, r1, r2, r3, r4, r5, r6, r7, r8: ROPE _ NIL] = { IO.PutRope[handle.tsOut, Rope.Cat[Rope.Cat[r1, r2, r3, r4], Rope.Cat[r5, r6, r7, r8]]]; }; GfiRange: PROC [gfi: PrincOps.GFTIndex] RETURNS [first, last: PrincOps.GFTIndex] = TRUSTED { gfItem: PrincOps.GFTItem _ PrincOps.GFT[gfi]; gf: PrincOps.GlobalFrameHandle; code: PrincOps.FrameCodeBase; cb: LONG POINTER TO PrincOps.CSegPrefix; gfItem.epbias _ 0; gf _ gfItem.framePtr; IF gf = NIL THEN RETURN [gfi, gfi]; first _ gf.gfi; code _ gf.code; code.out _ FALSE; cb _ code.longbase; last _ first + cb.header.info.ngfi - 1}; CallCommandTool: PROC [h: Handle] = { line: ROPE _ NARROW[Atom.GetProp[$HACK, $HACKPROP]]; IF line = NIL OR Rope.Length[line] = 0 THEN RETURN; [] _ CommandTool.DoCommand[line, h.parent]; }; Start: PROC [backingFile: ROPE _ "WrapDragoman.ts", instr, data: WrapRESIUtil.CacheIndex _ 1, traceOps: BOOL _ FALSE, countOps: BOOL _ FALSE, recordXferOut: BOOL _ TRUE, modelCache: BOOL _ TRUE, flushOnCall: BOOL _ FALSE] RETURNS [handle: Handle] = { cpl: Atom.PropList _ ProcessProps.GetPropList[]; wd: ROPE _ NARROW[List.Assoc[$WorkingDirectory, cpl]]; handle _ NEW [HandleRec _ [modelCache: modelCache]]; handle.parent _ NARROW[List.Assoc[$CommanderHandle, cpl]]; handle.workingDir _ Atom.PutPropOnList[propList: NIL, prop: $WorkingDirectory, val: wd]; handle.m _ NEW[RESInterpreter.MachineStateRec _ [ cacheData: NEW [WrapRESIUtil.CacheInfoRec _ [iCaches: instr, dCaches: data]], history: NEW [RESInterpreter.OpHistoryRec], traceOps: traceOps, flushOnCall: flushOnCall, countOps: countOps, recordXferOut: recordXferOut, opCount: NEW [ARRAY Basics.Byte OF INT _ ALL[0]], interestingGfi: NEW [RESInterpreter.BitVector _ ALL[FALSE]]]]; [handle.tsIn, handle.tsOut] _ ViewerIO.CreateViewerStreams [ name: backingFile, viewer: NIL, backingFile: backingFile, editedStream: FALSE]; }; SetInstructionCache: PROC [handle: Handle, number: WrapRESIUtil.CacheIndex, cache: CacheModels.Cache] = { cacheInfo: WrapRESIUtil.CacheInfo _ NARROW[handle.m.cacheData]; cacheInfo.iCache[number] _ cache; }; SetDataCache: PROC [handle: Handle, number: WrapRESIUtil.CacheIndex, cache: CacheModels.Cache] = { cacheInfo: WrapRESIUtil.CacheInfo _ NARROW[handle.m.cacheData]; cacheInfo.dCache[number] _ cache; }; MarkGFI: PROC [handle: Handle, name1, name2, name3, name4, name5, name6: ROPE _ NIL] = { MarkGFIInternal: PROC [name: ROPE] = { wc, cc: AMModel.Context; NoteMod: PROC [cx: AMModel.Context] RETURNS [stop: BOOL _ FALSE] = TRUSTED { SELECT AMModel.ContextClass[cx] FROM model => [] _ AMModel.ContextChildren[cx, NoteMod]; prog => { tx: AMTypes.TV = AMModelBridge.FrameFromContext[cx]; gf: PrincOps.GlobalFrameHandle = AMBridge.GFHFromTV[tx]; first, last: CARDINAL; [first, last] _ GfiRange[gf.gfi]; min _ MIN[min, first]; max _ MAX[max, last]}; ENDCASE; }; min: CARDINAL _ CARDINAL.LAST; max: CARDINAL _ CARDINAL.FIRST; TRUSTED {wc _ AMModel.RootContext[WorldVM.LocalWorld[]]}; IF name = NIL THEN RETURN; TRUSTED {cc _ AMModel.MostRecentNamedContext[name, wc]}; IF cc = NIL THEN {Output[handle, "MarkGFI: ", name, " not found\n"]; RETURN}; [] _ NoteMod[cc]; Output[handle, "MarkGFI: ", name, " gfi's are marked (", Convert.RopeFromInt[min], "-", Convert.RopeFromInt[max], ")\n"]; FOR i: CARDINAL IN [min..max] DO handle.m.interestingGfi[i] _ TRUE; ENDLOOP; }; MarkGFIInternal[name1]; MarkGFIInternal[name2]; MarkGFIInternal[name3]; MarkGFIInternal[name4]; MarkGFIInternal[name5]; MarkGFIInternal[name6]; }; Run: PROC [handle: Handle, name: ROPE, recordXferOut: BOOL _ TRUE] = { commandToolGfi: CARDINAL; Init: PROC [h: Handle, topProc: PROC] = TRUSTED { link: PrincOps.ControlLink = LOOPHOLE[topProc]; MarkInteresting[h.m, link.gfi]; RESIXfer.Xfer[ m: h.m, dst: link, src: RESInterpreter.MagicReturn, push: FALSE]; }; MarkInteresting: PROC [m: Machine, gfi: PrincOps.GFTIndex] = { first, last: CARDINAL; [first, last] _ GfiRange[gfi]; FOR i: CARDINAL IN [first..last] DO m.interestingGfi[i] _ TRUE; ENDLOOP; }; RunInContext: SAFE PROC = TRUSTED {RESIDisp.Execute[handle.m]}; gf: PrincOps.GlobalFrameHandle; gf _ PrincOpsUtils.GlobalFrame[CommandTool.DoCommand]; TRUSTED {commandToolGfi _ gf.gfi}; Output[handle, "Initializing to run command tool\n"]; Atom.PutProp[$HACK, $HACKPROP, name]; Init[handle, LOOPHOLE[CallCommandTool]]; -- we're going to push parameters WrapRESIUtil.Push2[handle.m, LOOPHOLE[handle]]; MarkInteresting[handle.m, commandToolGfi]; BEGIN ENABLE { UNWIND => {}; RESInterpreter.FinishedExecution => {GO TO done}; ABORTED => {Output[handle, " aborted"]; GO TO done}}; handle.m.breakPC _ 0; handle.m.breakGF _ LOOPHOLE[0]; handle.m.recordXferOut _ recordXferOut; WrapRESIUtil.EnableCaches[m: handle.m, state: handle.modelCache]; handle.m.singleStep _ FALSE; handle.m.startOps _ handle.m.iCount; handle.m.startPulses _ BasicTime.GetClockPulses[]; ProcessProps.AddPropList[handle.workingDir, RunInContext]; GO TO done; EXITS done => { et: REAL; et _ BasicTime.PulsesToSeconds[BasicTime.GetClockPulses[] - handle.m.startPulses]; Output[handle, IO.PutFR["Executed %g instr in %g secs (%g/sec)\n", [cardinal[handle.m.iCount - handle.m.startOps]], [real[et]], [real[(handle.m.iCount - handle.m.startOps)/et]]]]; IF recordXferOut THEN RESIStats.PrintProcCounts[handle.tsOut, handle.m]; WrapRESIUtil.PrintCacheStats[handle.tsOut, handle.m]; }; END; }; End: PROC [handle: Handle] = { handle.tsOut.Close[]; }; END. °WrapDragoman.mesa Created by Bertrand Serlet, April 2, 1985 11:55:39 am PST Last Edited by: Serlet, April 26, 1985 11:40:41 pm PST Types Utilities User Callable procs ΚΜ˜code– "Cedar" stylešœ™K™9K™6—šΟk ˜ K˜*K˜K˜ Kšœ ˜ K˜ Kšœ œ˜K˜K˜ Kšœ=˜=Kšœ˜Kšœ œ˜%Kšœ˜—K™šΟb œœœ˜KšœΗ˜ΞKš˜K˜šœ™K˜Kšœœœ˜Kšœœœœ˜Kšœ œ˜'Kšœœœ ΟcΠckŸ]˜ƒšœ œœŸ+˜EKšœ œ˜K˜ Kšœ˜Kšœ˜Kšœ œ˜——K˜™ K˜šΟnœœ2œœ˜MKšœU˜WKšœ˜—K˜š‘œœœ$œ˜\K˜-K˜Kšœ˜Kšœœœœ˜(K˜K˜Kšœœœœ ˜#Kšœ˜Kšœ˜Kšœ œ˜K˜Kšœ(˜(K˜—š‘œœ˜%Kšœœœ!˜4Kš œœœœœ˜3Kšœ+˜+Kšœ˜——K˜™K˜š‘œœœJœœ œœœœœœœœœ˜ϊKšœ0˜0Kšœœœ%˜6Kšœ œ(˜4Kšœœ$˜:Kšœ1œ$˜Xšœ œ#˜1Kšœ œ?˜MKšœ œ˜+Kšœ˜Kšœ˜Kšœ˜Kšœ˜Kš œ œœ œœœ˜1Kšœœœœ˜>—šœ<˜Kšœ œ˜K˜Kš œœœœœœ˜HK˜—Kš‘ œœœœ˜?K˜K˜K˜6Kšœ˜"Kšœ5˜5Kšœ%˜%Kšœ œŸ!˜JKšœœ ˜/Kšœ*˜*š˜šœ˜Kšœ˜ Kšœ%œœ˜1Kšœ!œœ˜5—K˜Kšœ˜Kšœœ˜Kšœ'˜'KšœA˜AK˜Kšœœ˜K˜$Kšœ2˜2Kšœ:˜:Kšœœ˜ š˜šœ ˜ Kšœœ˜ JšœR˜RJšœœ’˜³Kšœœ3˜HKšœ6˜6K˜——Kšœ˜—K˜——K˜š‘œœ˜Kšœ˜K˜—K˜Kšœ˜—K˜—…—Μ H