CDebugTables:
PROGRAM
IMPORTS ConvertUnsafe, MBinary, PrincOpsUtils, Rope
EXPORTS CDebugDefs = {
ROPE: TYPE = Rope.ROPE;
BYTE: TYPE = [0..256);
SubString: TYPE = ConvertUnsafe.SubString;
for all table compiled tables
CompStrDesc: TYPE = RECORD [offset, length: CARDINAL];
for MBinary ones
KnownMisc: TYPE = [0..104B];
KnownSD: TYPE = [0..142B];
MCompStrRecord:
TYPE =
RECORD [
stringOffset: MCSRptr RELATIVE POINTER TO StringBody,
miscName: ARRAY KnownMisc OF CompStrDesc,
sdName: ARRAY KnownSD OF CompStrDesc];
MCSRptr: TYPE = LONG BASE POINTER TO MCompStrRecord;
miscTab: MCSRptr ← LOOPHOLE[PrincOpsUtils.Codebase[LOOPHOLE[MBinary.MiscNameTab]]];
RopeForMisc:
PUBLIC
PROC [m:
BYTE]
RETURNS [
ROPE] = {
ss: SubString;
IF NOT (m IN KnownMisc) THEN RETURN ["?"];
ss ← [
base: @miscTab[miscTab.stringOffset],
offset: miscTab.miscName[m].offset,
length: miscTab.miscName[m].length];
RETURN[ConvertUnsafe.SubStringToRope[ss]]};
RopeForSD:
PUBLIC
PROC [m:
BYTE]
RETURNS [
ROPE] = {
ss: SubString;
IF NOT (m IN KnownSD) THEN RETURN ["?"];
ss ← [
base: @miscTab[miscTab.stringOffset],
offset: miscTab.sdName[m].offset,
length: miscTab.sdName[m].length];
RETURN[ConvertUnsafe.SubStringToRope[ss]]};
for Opnames and FOpNames
OpRecord:
TYPE =
RECORD [
stringOffset: OpPtr RELATIVE POINTER TO StringBody,
opcode: ARRAY BYTE OF CompStrDesc];
OpPtr: TYPE = LONG BASE POINTER TO OpRecord;
opNames: OpPtr ← LOOPHOLE[PrincOpsUtils.Codebase[LOOPHOLE[MBinary.OpNames]]];
fopNames: OpPtr ← LOOPHOLE[PrincOpsUtils.Codebase[LOOPHOLE[MBinary.FOpNames]]];
RopeForMop:
PUBLIC PROC [m:
BYTE]
RETURNS [
ROPE] = {
ss: SubString ← SetupOp[opNames, m];
RETURN[ConvertUnsafe.SubStringToRope[ss]]};
RopeForFop:
PUBLIC PROC [m:
BYTE]
RETURNS [
ROPE] = {
ss: SubString ← SetupOp[fopNames, m];
RETURN[ConvertUnsafe.SubStringToRope[ss]]};
MopForRope:
PUBLIC
PROC [r:
ROPE]
RETURNS [
INTEGER] = {
mop: LONG STRING ← [30];
IF Rope.Length[r] > 30 THEN RETURN[-1];
ConvertUnsafe.AppendRope[to: mop, from: r];
RETURN[SearchForOp[[base: mop, offset: 0, length: mop.length], opNames]]};
FopForRope:
PUBLIC
PROC [r:
ROPE]
RETURNS [
INTEGER] = {
fop: LONG STRING ← [30];
IF Rope.Length[r] > 30 THEN RETURN[-1];
ConvertUnsafe.AppendRope[to: fop, from: r];
RETURN[SearchForOp[[base: fop, offset: 0, length: fop.length], fopNames]]};
SetupOp:
PROC [lp: OpPtr, n:
CARDINAL]
RETURNS [ss: SubString] = {
IF lp = NIL THEN ss ← [base: NIL, length: 0, offset: 0]
ELSE {
ss.base ← @lp[lp.stringOffset];
[offset: ss.offset, length: ss.length] ← lp.opcode[n]}};
SearchForOp:
PROC [desc: SubString, lp: OpPtr]
RETURNS [
INTEGER] = {
mopdesc: SubString;
IF lp = NIL THEN RETURN[-1];
mopdesc.base ← @lp[lp.stringOffset];
FOR byte:
BYTE
IN
BYTE
DO
[offset: mopdesc.offset, length: mopdesc.length] ← lp.opcode[byte];
IF desc.length = mopdesc.length
AND
SameChars[desc, mopdesc] THEN RETURN[byte];
ENDLOOP;
RETURN[-1]};
UpperCase:
PROC [c:
CHAR]
RETURNS [
CHAR] = {
IF c IN ['a..'z] THEN RETURN [c - 'a + 'A] ELSE RETURN [c]};
SameChars:
PROC [a,b: SubString]
RETURNS [BOOLEAN] =
BEGIN
FOR i:
CARDINAL
IN [0..a.length)
DO
IF UpperCase[a.base[a.offset+i]] #
UpperCase[b.base[b.offset+i]] THEN RETURN [FALSE];
ENDLOOP;
RETURN [TRUE];
END;
}.