<> <> <> <> DIRECTORY Core, CoreFlatten, CoreOps, CoreProperties, IO, Rope, RoseEvents, RoseSimTypes, RoseWireTypes, StructuredStreams, UnparserBuffer, ViewerIO; RoseDebug: CEDAR PROGRAM IMPORTS CoreFlatten, CoreOps, CoreProperties, IO, Rope, RoseEvents, RoseSimTypes, StructuredStreams, UnparserBuffer, ViewerIO = BEGIN OPEN CO: CoreOps, RoseWireTypes, RoseSimTypes; log: IO.STREAM; driveName: ARRAY Drive OF ROPE = [ test: "test", see: "see", none: "none", chargeWeak: "chargeWeak", chargeMediumWeak: "chargeMediumWeak", charge: "charge", chargeMediumStrong: "chargeMediumStrong", chargeStrong: "chargeStrong", chargeVeryStrong: "chargeVeryStrong", driveWeak: "driveWeak", driveMediumWeak: "driveMediumWeak", drive: "drive", driveMediumStrong: "driveMediumStrong", driveStrong: "driveStrong", driveVeryStrong: "driveVeryStrong", input: "input" ]; NoteAny: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = { WriteWatched: PROC = { WITH watched SELECT FROM rci: RoseCellInstance => log.PutRope[LongName[rci]]; rw: RoseWire => log.PutRope[LongName[rw]]; sim: Simulation => log.PutRope["a simulation"]; ENDCASE => log.Put[ [refAny[watched]] ]; log.PutF[", "]; }; WriteArg: PROC = {ReallyWriteArg[arg]}; log.PutF["%g[", [atom[event]] ]; WritePiece[log, WriteWatched]; WritePiece[log, WriteArg]; log.PutRope["]\n"]; }; NoteSchedule: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = { WriteWatched: PROC = { rci: RoseCellInstance = NARROW[watched]; sch: Scheduling = rci.schIn; log.PutRope[LongName[rci]]; SELECT TRUE FROM rci.schedNext = notInCellList => log.PutRope[" not in schedule"]; rci = sch.schedFirst => log.PutRope[" at head of schedule"]; ENDCASE => log.PutRope[" somwhere in schedule"]; log.PutF[", "]; }; WriteArg: PROC = {ReallyWriteArg[arg]}; log.PutF["%g[", [atom[event]] ]; WritePiece[log, WriteWatched]; WritePiece[log, WriteArg]; log.PutRope["]\n"]; }; NoteChange: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = { rw: RoseWire = NARROW[watched]; fmt: Format = rw.type.class.super.GetFormat[rw.type, NIL]; WriteWatched: PROC = { log.PutRope[LongName[rw]]; log.PutRope[" "]; }; WriteVal: PROC = { val: ROPE = fmt.FormatValue[rw.type, fmt, rw.valPtr]; log.PutRope["_ "]; log.PutRope[val]; log.PutRope[" ("]; log.PutRope[driveName[rw.winnerStrength]]; log.PutRope[") "]; }; WriteArg: PROC = {ReallyWriteArg[arg]}; log.PutF["%g[", [atom[event]] ]; WritePiece[log, WriteWatched]; WritePiece[log, WriteVal]; WritePiece[log, WriteArg]; log.PutRope["]\n"]; }; ReallyWriteArg: PROC [arg: REF ANY] = { IF arg = NIL THEN RETURN; WITH arg SELECT FROM rms: REF ModelSlot => { IF rms^ = nilModelSlot THEN log.PutRope["nilModelSlot"] ELSE log.PutF[ "ModelSlot[%g, %g]", [rope[LongName[rms.cell]]], [refAny[rms.portPath]] ]; }; ENDCASE => log.Put[ [refAny[arg]] ]; }; WritePiece: PROC [to: IO.STREAM, write: PROC] = { StructuredStreams.Bp[to, FALSE, 3]; StructuredStreams.Begin[to]; write[ !UNWIND => StructuredStreams.End[to] ]; StructuredStreams.End[to]; }; LongName: PROC [ra: REF ANY] RETURNS [name: ROPE] = { IF ra = NIL THEN RETURN ["NIL"]; WITH ra SELECT FROM rw: RoseWire => name _ LongName[rw.core]; cw: Core.Wire => { ws: CoreFlatten.WireSource = NARROW [CoreProperties.GetProp [cw.properties, CoreFlatten.wireSource] ]; IF ws = NIL THEN name _ CO.GetWireName[cw] ELSE { prefix: ROPE = LongName[ws.instantiationPath]; name _ CO.GetWireName[ws.wire]; IF ws.instance # NIL THEN name _ NameCat[ws.instance.name, name]; name _ NameCat[prefix, name]; }; }; ip: CoreFlatten.InstantiationPath => { IF ip = NIL THEN name _ NIL ELSE { name _ ip.first.name; FOR ip _ ip.rest, ip.rest WHILE ip # NIL DO name _ NameCat[ip.first.name, name]; ENDLOOP; name _ name; }; }; rci: RoseCellInstance => name _ LongName[rci.core]; ci: CellInstance => { is: CoreFlatten.InstanceSource = NARROW [CoreProperties.GetProp [ci.properties, CoreFlatten.instanceSource] ]; IF is = NIL THEN name _ ci.name ELSE { name _ NIL; IF is.instantiationPath # NIL THEN name _ LongName[is.instantiationPath]; name _ NameCat[name, is.instance.name]; }; }; ENDCASE => ERROR; }; NameCat: PROC [n1, n2: ROPE] RETURNS [n: ROPE] = { IF n1.Length[] = 0 THEN RETURN [n2]; n _ n1.Cat[".", n2]; }; Start: PROC = { ubh: UnparserBuffer.Handle _ UnparserBuffer.NewHandle[ [stream[ViewerIO.CreateViewerStreams["Rosemary Debug log"].out]] ]; ubh.margin _ 70; log _ StructuredStreams.Create[ubh]; RoseEvents.AddWatcher[$Settled, [NoteAny], RoseEvents.all]; RoseEvents.AddWatcher[$Eval, [NoteAny], RoseEvents.all]; RoseEvents.AddWatcher[$Schedule, [NoteSchedule], RoseEvents.all]; RoseEvents.AddWatcher[$Found, [NoteAny], RoseEvents.all]; RoseEvents.AddWatcher[$NewNodeQ, [NoteChange], RoseEvents.all]; RoseEvents.AddWatcher[$NewNodeUD, [NoteChange], RoseEvents.all]; RoseEvents.AddWatcher[$Perturbed, [NoteAny], RoseEvents.all]; RoseEvents.AddWatcher[$ChangeEarly, [NoteChange], RoseEvents.all]; }; Stop: PROC = { RoseEvents.RemoveWatcher[$Settled, [NoteAny], RoseEvents.all]; RoseEvents.RemoveWatcher[$Eval, [NoteAny], RoseEvents.all]; RoseEvents.RemoveWatcher[$Schedule, [NoteSchedule], RoseEvents.all]; RoseEvents.RemoveWatcher[$Found, [NoteAny], RoseEvents.all]; RoseEvents.RemoveWatcher[$NewNodeQ, [NoteChange], RoseEvents.all]; RoseEvents.RemoveWatcher[$NewNodeUD, [NoteChange], RoseEvents.all]; RoseEvents.RemoveWatcher[$Perturbed, [NoteAny], RoseEvents.all]; RoseEvents.RemoveWatcher[$ChangeEarly, [NoteChange], RoseEvents.all]; }; Start[]; END.