MDebugLabels.mesa Edited by Sweet, 11-Sep-81 16:47:49
Sweet June 2, 1986 0:54:50 am PDT
DIRECTORY
CodeDefs USING [codeType, LabelInfoIndex, LabelInfoNull, LabelInfoRecord],
ConvertUnsafe USING [SubString],
IO USING [Close, PutF, Reset, RopeFromROS, ROS, STREAM],
MDebugDefs USING [CDCopyRead, Handle, LabelStack],
RESOut USING [
Log10, LongLog10, PChar, PCr, PDecimal, PLongNil, PNext, PNextLongNil, PNextNull, PRope,
PUnsigned],
Rope USING [ROPE],
STDebugDefs USING [PSTSubString, ShowLinks, SubStringForHash, TableBase],
Table USING [Base];
MDebugLabels: PROGRAM
IMPORTS MDebugDefs, IO, RESOut, STDebugDefs
EXPORTS MDebugDefs =
BEGIN OPEN STDebugDefs, CodeDefs, MDebugDefs, RESOut;
ROPE: TYPE = Rope.ROPE;
NullLabelInfoRecord: LabelInfoRecord ← [thread: LabelInfoNull, catchLevel: 0, body: loop[NIL, NIL]];
PutAsLabelInfoIndex: PUBLIC PROCEDURE [h: Handle, lii: CodeDefs.LabelInfoIndex] = TRUSTED
BEGIN
lir: LabelInfoRecord ← NullLabelInfoRecord;
cb: Table.Base ← TableBase[h, codeType];
CDCopyRead[h: h, to: @lir, from: @cb[lii], nwords: SIZE[LabelInfoRecord]];
PCr[h]; PRope[h, "cb["];
PDecimal[h, LOOPHOLE[lii]];
PRope[h, "] = "];
IF lir.free THEN
BEGIN
PRope[h, "FREE!"];
RETURN
END;
PRope[h, "level: "]; PUnsigned[h, lir.catchLevel];
PNextNull[h, "thread", lir.thread, LabelInfoNull];
WITH li: lir SELECT FROM
named =>
BEGIN
desc: ConvertUnsafe.SubString;
desc ← SubStringForHash[h, li.hti];
PNext[h, "hti: ", Log10[li.hti]+3+desc.length];
PUnsigned[h, li.hti]; PRope[h, " ("];
PSTSubString[h, desc]; PChar[h, ')];
PNextLongNil[h, "cci", LOOPHOLE[li.cci]];
END;
stmt =>
BEGIN
PNextLongNil[h, "RETRY", LOOPHOLE[li.retry]];
PNextLongNil[h, "CONT", LOOPHOLE[li.continue]];
END;
loop =>
BEGIN
PNextLongNil[h, "LOOP", LOOPHOLE[li.loop]];
PNextLongNil[h, "EXIT", LOOPHOLE[li.exit]];
END;
ENDCASE;
IF STDebugDefs.ShowLinks[h] THEN PNextNull[h, "thread", lir.thread, LabelInfoNull];
END;
PutLabelState: PUBLIC PROCEDURE [h: Handle] = TRUSTED
BEGIN OPEN CodeDefs;
lii: LabelInfoIndex;
lir: LabelInfoRecord ← NullLabelInfoRecord;
cb: Table.Base = STDebugDefs.TableBase[h, codeType];
desc: ConvertUnsafe.SubString;
extra: CARDINAL;
first: BOOLEANTRUE;
ros: IO.STREAMIO.ROS[];
name: ROPE;
PCr[h];
PRope[h, "labelStack: "];
lii ← LabelStack[h];
IF lii = LabelInfoNull THEN
BEGIN PRope[h, "empty"]; RETURN END;
WHILE lii # LabelInfoNull DO
extra ← 0;
CDCopyRead[h: h, to: @lir, from: @cb[lii], nwords: SIZE[LabelInfoRecord]];
ros.PutF["(%d) ", [cardinal[LONG[LOOPHOLE[lii, CARDINAL]]]]];
name ← ros.RopeFromROS[close: FALSE]; ros.Reset[];
WITH li: lir SELECT FROM
named =>
BEGIN
desc ← SubStringForHash[h, li.hti];
extra ← desc.length + 2 + Log10[LOOPHOLE[li.hti]];
END;
loop => extra ← 6 + LongLog10[LOOPHOLE[li.loop]];
stmt => extra ← 7 + LongLog10[LOOPHOLE[li.retry]];
ENDCASE;
IF first THEN
BEGIN PRope[h, name]; first ← FALSE; END
ELSE PNext[h, name, extra];
WITH li: lir SELECT FROM
named =>
BEGIN
PSTSubString[h, desc];
PRope[h, ": "];
PLongNil[h, LOOPHOLE[li.cci]];
END;
loop =>
BEGIN
PRope[h, "LOOP: "];
PLongNil[h, LOOPHOLE[li.loop]];
PNextLongNil[h, "EXIT", LOOPHOLE[li.exit]];
END;
stmt =>
BEGIN
PRope[h, "RETRY: "];
PLongNil[h, LOOPHOLE[li.retry]];
PNextLongNil[h, "CONT", LOOPHOLE[li.continue]];
END;
ENDCASE;
lii ← lir.thread;
ENDLOOP;
ros.Close[];
END;
END.