RoseTVImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Curry, October 16, 1986 5:45:45 pm PDT
Don Curry October 24, 1986 5:45:03 pm PDT
DIRECTORY CoreFlat, IO, Ports, REFBit, Rope, Rosemary, RoseTV, SafeStorage, TerminalIO;
RoseTVImpl: CEDAR PROGRAM
IMPORTS CoreFlat, IO, REFBit, Rope, Rosemary, SafeStorage, TerminalIO
EXPORTS RoseTV =
BEGIN
ROPE:    TYPE = Rosemary.ROPE;
RTVal:   TYPE = RoseTV.RTVal;
RTValRec:  TYPE = RoseTV.RTValRec;
FldBitNmProc: TYPE = RoseTV.FldBitNmProc;
New: PUBLIC PROC
[path, field: ROPE, ref: REF, struc: BOOLTRUE, fldBitNm: FldBitNmProc ← SimpleDotIndexing]
RETURNS[tv: RTVal] = {
sz:   NAT ← REFBit.Size[ref];
tv    ← NEW[RTValRec     [(IF struc THEN 1 ELSE sz)]];
tv.buf   ← NEW[Ports.LevelSequenceRec [(IF struc THEN sz ELSE 1)]];
tv.path  ← path;
tv.field  ← field;
tv.ref   ← ref;
tv.fldBitNm ← fldBitNm;
};
XFerList: PUBLIC PROC[sim: Rosemary.Simulation, rtvs: LIST OF RTVal] = {
FOR rtvs ← rtvs, rtvs.rest WHILE rtvs#NIL DO
[]←XFer[sim, rtvs.first];
ENDLOOP};
XFer: PUBLIC PROC[sim: Rosemary.Simulation, rtv: RTVal] RETURNS[ref: REF] = {
IF rtv[0].wire=NIL THEN FOR index: NAT IN [0..rtv.wwrSize) DO
signalPath: ROPE ← Rope.Cat[rtv.path, ".", rtv.fldBitNm[rtv, index] ];
rtv[index].wire ← NEW[CoreFlat.FlatWireRec];
rtv[index].wire^ ← CoreFlat.ParseWirePath[sim.cellType, signalPath
! SafeStorage.NarrowRefFault, CoreFlat.PathError =>
{TerminalIO.WriteF["Bad Path: %g\n", IO.rope[signalPath]]; LOOP}];
ENDLOOP;
rtv.bad ← FALSE;
FOR index: NAT IN [0..rtv.wwrSize) DO
IF rtv[index].wire.wire=NIL THEN RETURN[rtv.ref]; -- bad path
rtv.buf ← Rosemary.WireValue[sim, rtv[index].wire];
FOR levelBit: NAT IN [0..rtv.buf.size) DO
SELECT rtv.buf[levelBit] FROM
L, H => {
sense: BOOL ← (rtv.buf[levelBit]=H)#(rtv[index].inverted);
REFBit.Set[rtv.ref, AdjustLongNumIndex[rtv.ref, index+levelBit], sense]};
ENDCASE => {
IF NOT rtv.bad THEN TerminalIO.WriteF["Bad Value for: %g ", IO.rope[rtv.field]];
TerminalIO.WriteF["%g ", IO.int[index+levelBit]];
rtv.bad ← TRUE};
ENDLOOP ENDLOOP;
IF rtv.bad THEN TerminalIO.WriteF["\n"];
RETURN[rtv.ref]};
AdjustLongNumIndex: PROC[ref: REF, index: INT] RETURNS[INT] = {
WITH ref SELECT FROM
real: REF RoseTV.Real  => RETURN[(index+16) MOD 32]; -- swap words
int: REF RoseTV.Int   => RETURN[(index+16) MOD 32]; -- swap words
lc:  REF RoseTV.LongCard => RETURN[(index+16) MOD 32]; -- swap words
ENDCASE       => RETURN[index]};
SimpleDotIndexing: PUBLIC FldBitNmProc = {
RETURN[IF rtv.wwrSize=1
THEN ""
ELSE IO.PutFR["%g.%g", IO.rope[rtv.field], IO.int[index]] ]};
END.