HandCodingSupport.mesa
Copyright © 1984, 1985, 1986 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) September 10, 1986 11:06:08 pm PDT
McCreight October 27, 1986 3:38:19 pm PST
DIRECTORY
Atom USING [PropList],
DragOpsCross USING [Byte, Inst, ShortRegQR, Word],
HandCoding USING [Lit16, Lit8, RegSpec, ShortRegSpec],
IO USING [STREAM];
HandCodingSupport: CEDAR DEFINITIONS
= BEGIN OPEN DragOpsCross, HandCoding;
CARD: TYPE = LONG CARDINAL;
Inst: TYPE = DragOpsCross.Inst;
PropList: TYPE = Atom.PropList;
Format Common Routines
OQBcommon: PROC[op: Inst, rest: Word];
OIcommon: PROC[op: Inst];
LRcommon: PROC[op: Inst, reg: RegSpec];
QRcommon: PROC[op: Inst, left: ShortRegQR, right: RegSpec];
OBcommon: PROC[op: Inst, lit: Lit8];
LRBcommon: PROC[op: Inst, reg: RegSpec, lit: Lit8];
RRcommon: PROC[op: Inst, c: RegSpec, a,b: RegSpec];
RJBcommon: PROC[op: Inst, left: ShortRegSpec, right: RegSpec, dist: Lit8];
ODBcommon: PROC[op: Inst, lit: Lit16];
LRRBcommon: PROC[op: Inst, reg1,reg2: RegSpec, disp: Lit8];
JBBcommon: PROC[op: Inst, dist: Lit8, lit: Lit8];
Output area stuff
Area: TYPE = REF AreaRep;
AreaRep: TYPE = RECORD [
name: ATOM, -- name of output area
props: PropList, -- properties for this area
currentPC: CARD, -- current output program PC (byte address)
currentData: CARD, -- current output data PC (byte address)
currentWord: Word, -- current partial word
currentDirty: BOOL, -- TRUE if the current word was written
getWord: GetProc, -- proc to get a word from the area
putWord: PutProc, -- proc to put a word into the area
data: REF-- data for getWord/putWord
];
GetProc: TYPE = PROC [data: REF, pc: INT] RETURNS [Word];
PutProc: TYPE = PROC [data: REF, pc: INT, word: Word];
ProcList: TYPE = LIST OF PROC;
NewArea: PROC [name: ATOM, getWord: GetProc, putWord: PutProc, data: REFNIL] RETURNS [Area];
Creates a new code area
GenWithArea: PROC [area: Area, list: ProcList];
Places the area on the process property list under the property $CurrentArea, then calls each procedure in the procedure list, then returns (with the process property list reset to its original value).
Gen1WithArea: PROC [area: Area, proc: PROC];
Places the area on the process property list under the property $CurrentArea, then calls proc (which may be a nested procedure), then returns (with the process property list reset to its original value).
ForceOut: PROC [area: Area];
Forces the area to dump any buffering it has into the output.
GetCurrentArea: PROC [nilOK: BOOLFALSE] RETURNS [Area];
EmptyArea: ERROR;
Gets the current output area as established by GenWithArea. If not nilOK, EmptyArea will be generated instead of returning NIL.
LoadArea: PROC [st, errs: IO.STREAM, area: Area ← NIL];
Reads a Ascii stream (usually from a .quad file) into area.
Directives to control output
(if area = NIL, gets the area from the current area established by GenWithArea)
GetOutputPC: PROC [area: Area ← NIL] RETURNS [pc: CARD];
gets the current output PC
SetOutputPC: PROC [pc: CARD, area: Area ← NIL];
sets the current output PC
WordAlign: PROC [area: Area ← NIL];
make the code generation PC word-aligned
ReserveData: PROC [words: CARD, area: Area ← NIL] RETURNS [pc: CARD];
reserve some # of words of data
Directives to make output
(if area = NIL, gets the area from the current area established by GenWithArea)
OutputByte: PROC [area: Area, byte: Byte];
output the given byte into the current output area
OutputOneByte: PROC [area: Area, word: Word];
output the low-order byte of the word into the current output area
OutputAlphaBeta: PROC [area: Area, lit: CARDINAL];
output the literal as necessary for the ODB format of the word into the current output area
OutputAlphaBetaGammaDelta: PROC [area: Area, word: Word];
output the given literal as AlphaBetaGammaDelta (Alpha is the low-order byte, Beta the next higher, and so on). The order of bytes in the output stream is reversed from the order in the word.
OutputWord: PROC [area: Area, word: Word, align: BOOLFALSE];
output the given word into the output area, force alignment first if align = TRUE
END.