HandCodingUtilImpl.mesa
Copyright © 1984, 1985, 1986 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) September 11, 1986 1:57:42 pm PDT
McCreight, November 7, 1985 11:35:35 am PST
DIRECTORY
DragOpsCross USING [EURegs, FieldDescriptor, FourBytes, IFURegs, Inst, JBBformat, LRRBformat, ProcessorRegister, QRformat, RJBformat, RRformat, TwoBytes, Word, ZerosByte],
DragOpsCrossUtils USING [ByteToCard, InstToBytes, InstToFormat, WordToBytes, WordToCard, WordToInt],
HandCodingUtil USING [NameArray, NameArrayRep, RegNameArray, RegNameArrayRep],
IO USING [PutF, PutFR, PutRope, STREAM],
Rope USING [ROPE];
HandCodingUtilImpl: CEDAR PROGRAM
IMPORTS DragOpsCrossUtils, IO
EXPORTS HandCodingUtil
= BEGIN OPEN DragOpsCross, HandCodingUtil;
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
ToStream: PUBLIC PROC [stream: STREAM, inst: Inst, rest: Word, pc: Word] = {
code: CARDINAL = ORD[inst];
len: CARDINAL ← DragOpsCrossUtils.InstToBytes[inst];
PutArg: PROC [prefix: ROPE, aux,opt: BOOL, reg: [0..15], dst: BOOLFALSE] = {
IO.PutRope[stream, prefix];
IF NOT opt
THEN IO.PutF[stream, IF aux THEN "a%g" ELSE "r%g", [cardinal[reg]]]
ELSE SELECT reg FROM
12 => IO.PutRope[stream, "[S]"];
13 => IO.PutRope[stream, "[S-1]"];
14 => IO.PutRope[stream, IF dst THEN "[S+1]+" ELSE "[S]-"];
15 => IO.PutRope[stream, IF dst THEN "[S+1]+" ELSE "[S-1]-"];
ENDCASE => IO.PutF[stream, "c%g", [cardinal[reg]]] };
IO.PutRope[stream, nameArray[inst]];
SELECT len FROM
1 => RETURN;
2 => {
alphaZ: CARDINAL =
DragOpsCrossUtils.ByteToCard[DragOpsCrossUtils.WordToBytes[rest][3]];
SELECT inst FROM
IN [dLRI0..dLRI15], IN [dSRI0..dSRI15] => {
IO.PutF[stream, " %w (%g)", [cardinal[alphaZ]], [cardinal[alphaZ]]];
};
IN [dQOR..dQLSUB] => {
form: DragOpsCross.QRformat = LOOPHOLE[DragOpsCross.TwoBytes[
ZerosByte, LOOPHOLE[alphaZ]]];
IO.PutRope[stream, SELECT form.aOp FROM
topAtop => " [S], [S]",
pushAtop => " [S+1]+, [S]",
pushA0 => " [S+1]+, c0",
pushA1 => " [S+1]+, c1",
ENDCASE => ERROR];
PutArg[", ", form.aux, form.opt, form.reg];
};
dJB => {
dest: INT ← alphaZ;
IF alphaZ > 127 THEN dest ← dest - 256;
dest ← DragOpsCrossUtils.WordToInt[pc] + dest;
IO.PutF[stream, " %w (pc: %w)",
[cardinal[alphaZ]], [cardinal[LOOPHOLE[dest]]]];
};
dLIP, dSIP => {
rName: ROPE = regNameArray[LOOPHOLE[alphaZ]];
IO.PutF[stream, " %g (%g)", [cardinal[alphaZ]], [rope[rName]]];
};
ENDCASE =>
IO.PutF[stream, " %w (%g)", [cardinal[alphaZ]], [cardinal[alphaZ]]];
};
3 => {
alphaZ: CARDINAL =
DragOpsCrossUtils.ByteToCard[DragOpsCrossUtils.WordToBytes[rest][2]];
betaZ: CARDINAL =
DragOpsCrossUtils.ByteToCard[DragOpsCrossUtils.WordToBytes[rest][3]];
alphaBetaZ: CARDINAL = alphaZ*256 + betaZ;
OneByteOffset: PROC [byte: CARDINAL] RETURNS [LONG CARDINAL] = {
dest: INT ← byte;
IF byte > 127 THEN dest ← dest - 256;
dest ← DragOpsCrossUtils.WordToInt[pc] + dest;
RETURN [LOOPHOLE[dest, LONG CARDINAL]];
};
SELECT DragOpsCrossUtils.InstToFormat[inst] FROM
RRformat => {
form: DragOpsCross.RRformat = LOOPHOLE[DragOpsCross.FourBytes[
ZerosByte, LOOPHOLE[alphaZ], LOOPHOLE[betaZ], ZerosByte]];
PutArg[" ", form.aux, form.cOpt, form.c, TRUE];
PutArg[", ", form.aux, form.aOpt, form.a];
PutArg[", ", form.aux, form.bOpt, form.b];
};
RJBformat => {
form: DragOpsCross.RJBformat = LOOPHOLE[DragOpsCross.FourBytes[
ZerosByte, LOOPHOLE[alphaZ], LOOPHOLE[betaZ], ZerosByte]];
IO.PutRope[stream, SELECT form.aOp FROM
c0 => " c0", c1 => " c1", top => " [S]", popTop => " [S]-", ENDCASE => ERROR];
PutArg[", ", form.aux, form.opt, form.reg];
IO.PutF[stream, ", %w (pc: %w)",
[cardinal[form.dist]], [cardinal[OneByteOffset[form.dist]]]];
};
LRRBformat => {
form: DragOpsCross.LRRBformat = LOOPHOLE[DragOpsCross.FourBytes[
ZerosByte, LOOPHOLE[alphaZ], LOOPHOLE[betaZ], ZerosByte]];
IO.PutF[stream, " r%g, r%g, %w (%g)",
[cardinal[form.reg1]], [cardinal[form.reg2]],
[cardinal[form.disp]], [cardinal[form.disp]]];
};
JBBformat => {
form: DragOpsCross.JBBformat = LOOPHOLE[DragOpsCross.FourBytes[
ZerosByte, LOOPHOLE[alphaZ], LOOPHOLE[betaZ], ZerosByte]];
IO.PutF[stream, " %w (%g), %w (pc: %w)",
[cardinal[form.lit]], [cardinal[form.lit]],
[cardinal[form.dist]], [cardinal[OneByteOffset[form.dist]]]];
};
ENDCASE => SELECT inst FROM
dJDB, dLFC => {
destPC: LONG CARDINAL = LOOPHOLE[
LOOPHOLE[alphaBetaZ, INTEGER] + DragOpsCrossUtils.WordToInt[pc],
LONG CARDINAL];
IO.PutF[stream, " %w (pc: %w)", [cardinal[alphaBetaZ]], [cardinal[destPC]]];
};
dSHL, dSHR, dSHDL, dSHDR, dFSDB => {
fd: DragOpsCross.FieldDescriptor = LOOPHOLE[alphaBetaZ];
IO.PutF[stream, " %w (", [cardinal[alphaBetaZ]]];
IF fd.reserved # 0 THEN IO.PutF[stream, "reserved: %g, ", [cardinal[fd.reserved]]];
IF fd.insert THEN IO.PutRope[stream, "insert: TRUE, "];
IO.PutF[stream, "mask: %g, shift: %g)", [cardinal[fd.mask]], [cardinal[fd.shift]]];
};
ENDCASE =>
IO.PutF[stream, " %w (%g)", [cardinal[alphaBetaZ]], [cardinal[alphaBetaZ]]];
};
5 => {
card: LONG CARDINAL = DragOpsCrossUtils.WordToCard[rest];
int: INT = DragOpsCrossUtils.WordToInt[rest];
IO.PutF[stream, " %w (%g)", [cardinal[card]], [integer[int]]];
};
ENDCASE => ERROR;
};
GetInstArray: PUBLIC PROC RETURNS [array: NameArray] = {
RETURN [nameArray];
};
GetRegArray: PUBLIC PROC RETURNS [array: RegNameArray] = {
RETURN [regNameArray];
};
InitArray: PROC RETURNS [array: NameArray] = {
array ← NEW[NameArrayRep];
FOR inst: Inst IN Inst DO
instName: ROPE ←
SELECT inst FROM
dDFC => "DFC",
dLIQB => "LIQB",
dADDQB => "ADDQB",
dSUBQB => "SUBQB",
dJ5 => "J5",
dJQB => "JQB",
dOR => "OR",
dAND => "AND",
dRX => "RX",
dBC => "BC",
dADD => "ADD",
dSUB => "SUB",
dLADD => "LADD",
dLSUB => "LSUB",
dDUP => "DUP",
dDIS => "DIS",
dEXDIS => "EXDIS",
dSFC => "SFC",
dSFCI => "SFCI",
dRETN => "RETN",
dKFC => "KFC",
dJ1 => "J1",
dJSD => "JSD",
dJSR => "JSR",
dLC0 => "LC0",
dLC1 => "LC1",
dLC2 => "LC2",
dLC3 => "LC3",
dLC4 => "LC4",
dLC5 => "LC5",
dLC6 => "LC6",
dLC7 => "LC7",
dLC8 => "LC8",
dLC9 => "LC9",
dLC10 => "LC10",
dLC11 => "LC11",
dLR0 => "LR0",
dLR1 => "LR1",
dLR2 => "LR2",
dLR3 => "LR3",
dLR4 => "LR4",
dLR5 => "LR5",
dLR6 => "LR6",
dLR7 => "LR7",
dLR8 => "LR8",
dLR9 => "LR9",
dLR10 => "LR10",
dLR11 => "LR11",
dLR12 => "LR12",
dLR13 => "LR13",
dLR14 => "LR14",
dLR15 => "LR15",
dSR0 => "SR0",
dSR1 => "SR1",
dSR2 => "SR2",
dSR3 => "SR3",
dSR4 => "SR4",
dSR5 => "SR5",
dSR6 => "SR6",
dSR7 => "SR7",
dSR8 => "SR8",
dSR9 => "SR9",
dSR10 => "SR10",
dSR11 => "SR11",
dSR12 => "SR12",
dSR13 => "SR13",
dSR14 => "SR14",
dSR15 => "SR15",
dQOR => "QOR",
dQAND => "QAND",
dQRX => "QRX",
dQBC => "QBC",
dQADD => "QADD",
dQSUB => "QSUB",
dQLADD => "QLADD",
dQLSUB => "QLSUB",
dALS => "ALS",
dAL => "AL",
dASL => "ASL",
dAS => "AS",
dCST => "CST",
dRET => "RET",
dLIP => "LIP",
dSIP => "SIP",
dLIB => "LIB",
dADDB => "ADDB",
dSUBB => "SUBB",
dJ2 => "J2",
dJB => "JB",
dRB => "RB",
dWB => "WB",
dRSB => "RSB",
dWSB => "WSB",
dPSB => "PSB",
dLRI0 => "LRI0",
dLRI1 => "LRI1",
dLRI2 => "LRI2",
dLRI3 => "LRI3",
dLRI4 => "LRI4",
dLRI5 => "LRI5",
dLRI6 => "LRI6",
dLRI7 => "LRI7",
dLRI8 => "LRI8",
dLRI9 => "LRI9",
dLRI10 => "LRI10",
dLRI11 => "LRI11",
dLRI12 => "LRI12",
dLRI13 => "LRI13",
dLRI14 => "LRI14",
dLRI15 => "LRI15",
dSRI0 => "SRI0",
dSRI1 => "SRI1",
dSRI2 => "SRI2",
dSRI3 => "SRI3",
dSRI4 => "SRI4",
dSRI5 => "SRI5",
dSRI6 => "SRI6",
dSRI7 => "SRI7",
dSRI8 => "SRI8",
dSRI9 => "SRI9",
dSRI10 => "SRI10",
dSRI11 => "SRI11",
dSRI12 => "SRI12",
dSRI13 => "SRI13",
dSRI14 => "SRI14",
dSRI15 => "SRI15",
dROR => "ROR",
dRAND => "RAND",
dRRX => "RRX",
dRBC => "RBC",
dRADD => "RADD",
dRSUB => "RSUB",
dRLADD => "RLADD",
dRLSUB => "RLSUB",
dRXOR => "RXOR",
dRFU => "RFU",
dRVADD => "RVADD",
dRVSUB => "RVSUB",
dRUADD => "RUADD",
dRUSUB => "RUSUB",
dLGF => "LGF",
dLFC => "LFC",
dLIDB => "LIDB",
dADDDB => "ADDDB",
dSUBDB => "SUBDB",
dJ3 => "J3",
dJDB => "JDB",
dRAI => "RAI",
dWAI => "WAI",
dRRI => "RRI",
dWRI => "WRI",
dIODA => "IODA",
dIOD => "IOD",
dION => "ION",
dRJEB => "RJEB",
dRJEBJ => "RJEBJ",
dRJGB => "RJGB",
dRJGBJ => "RJGBJ",
dRJGEB => "RJGEB",
dRJGEBJ => "RJGEBJ",
dRJLB => "RJLB",
dRJLBJ => "RJLBJ",
dRJLEB => "RJLEB",
dRJLEBJ => "RJLEBJ",
dRJNEB => "RJNEB",
dRJNEBJ => "RJNEBJ",
dJEBB => "JEBB",
dJEBBJ => "JEBBJ",
dJNEBB => "JNEBB",
dJNEBBJ => "JNEBBJ",
dSHL => "SHL",
dSHR => "SHR",
dSHDL => "SHDL",
dSHDR => "SHDR",
dFSDB => "FSDB",
ENDCASE => NIL;
IF instName = NIL THEN {
instName ← IO.PutFR["x%bb", [cardinal[LOOPHOLE[inst, CARDINAL]]]];
};
array[inst] ← instName;
ENDLOOP;
};
InitRegArray: PROC RETURNS [array: RegNameArray] = {
array ← NEW[RegNameArrayRep];
FOR reg: ProcessorRegister IN ProcessorRegister DO
name: ROPENIL;
regc: CARDINAL = LOOPHOLE[reg];
SELECT reg FROM
IN [euStack..euJunk) =>
name ← IO.PutFR["s%g", [cardinal[regc]]];
euJunk => name ← "euJunk";
euToKBus => name ← "euToKBus";
euMAR => name ← "euMAR";
euField => name ← "euField";
IN [euConstant..euAux) => {
base: ProcessorRegister = euConstant;
name ← IO.PutFR["c%g", [cardinal[regc - LOOPHOLE[base, CARDINAL]]]]};
IN [euAux..euBogus) => {
base: ProcessorRegister = euAux;
name ← IO.PutFR["a%g", [cardinal[regc - LOOPHOLE[base, CARDINAL]]]]};
ifuYoungestL => name ← "ifuYoungestL";
ifuYoungestPC => name ← "ifuYoungestPC";
ifuEldestL => name ← "ifuEldestL";
ifuEldestPC => name ← "ifuEldestPC";
ifuSLimit => name ← "ifuSLimit";
ifuL => name ← "ifuL";
ifuS => name ← "ifuS";
ifuPC => name ← "ifuPC";
IN DragOpsCross.EURegs => name ← IO.PutFR["eu#%g", [cardinal[regc]]];
IN DragOpsCross.IFURegs => name ← IO.PutFR["ifu#%g", [cardinal[regc]]];
ENDCASE => ERROR;
array[reg] ← name;
ENDLOOP;
};
nameArray: NameArray = InitArray[];
regNameArray: RegNameArray = InitRegArray[];
END.