-- file PeepholeDefs.mesa
-- last edited by Sweet 9-Oct-81  9:41:10
-- last edited by Satterthwaite December 16, 1982 8:51 am

DIRECTORY
  Alloc: TYPE USING [Notifier],
  CodeDefs: TYPE USING [
    BYTE, CCIndex, CodeCCIndex, CodeCCNull, JumpCCIndex, JumpType, JumpCCNull],
  FOpCodes: TYPE USING [qNULL],
  PrincOps: TYPE USING [FieldDescriptor];

PeepholeDefs: DEFINITIONS = {

  BYTE: TYPE = CodeDefs.BYTE;
  
  PeepComponent: TYPE = RECORD [
    index: CodeDefs.CodeCCIndex,
    inst: BYTE,
    params: ARRAY [1..3] OF WORD];
  NullComponent: PeepComponent = [
    index: CodeDefs.CodeCCNull,
    inst: FOpCodes.qNULL,
    params: [0,0,0]];

  PeepState: TYPE = RECORD [ -- can't use current Machine Dep since holes
    SELECT OVERLAID * FROM
      old => [
	a: CodeDefs.CodeCCIndex,
	aInst: BYTE,
	aP: ARRAY [1..3] OF WORD,
	b: CodeDefs.CodeCCIndex,
	bInst: BYTE,
	bP: ARRAY [1..3] OF WORD,
	c: CodeDefs.CodeCCIndex,
	cInst: BYTE,
	cP: ARRAY [1..3] OF WORD],
      fast => [aComp, bComp, cComp: PeepComponent],
      ENDCASE];
  NullState: PeepState = [fast[NullComponent, NullComponent, NullComponent]];

  JumpPeepState: TYPE = RECORD[
    c: CodeDefs.JumpCCIndex,
    bP, cP: ARRAY [1..3] OF WORD,
    bInst: BYTE,
    b: CodeDefs.CodeCCIndex,
    cInst: BYTE];
  NullJumpState: JumpPeepState = [
    c: CodeDefs.JumpCCNull,
    bP: [0,0,0],
    cP: [0,0,0],
    bInst: FOpCodes.qNULL,
    b: CodeDefs.CodeCCNull,
    cInst: FOpCodes.qNULL];
    
  ConsPeepState: TYPE = RECORD [a, b, c, d: PeepComponent];
  NullConsState: ConsPeepState = [
    NullComponent, NullComponent, NullComponent, NullComponent];

  StateExtent: TYPE = {abc, bc, c};

  CJump: ARRAY CodeDefs.JumpType[JumpE..ZJumpN] OF CodeDefs.JumpType = [
	JumpN, JumpE, JumpGE, JumpL, JumpLE, JumpG,
	UJumpGE, UJumpL, UJumpLE, UJumpG, ZJumpN, ZJumpE];

  SetRealInst: PROC [BOOL];
  NextInteresting: PROC [c: CodeDefs.CCIndex] RETURNS [CodeDefs.CCIndex];
  PrevInteresting: PROC [c: CodeDefs.CCIndex] RETURNS [CodeDefs.CCIndex];
  InitParameters: PROC [
    p: POINTER TO PeepState, ci: CodeDefs.CodeCCIndex, extent: StateExtent];
  InitConsState: PROC [p: POINTER TO ConsPeepState, di: CodeDefs.CodeCCIndex];
  InitJParametersBC: PROC [
    p: POINTER TO JumpPeepState, ci: CodeDefs.JumpCCIndex];
  SlidePeepState2: PROC [p: POINTER TO PeepState, ci: CodeDefs.CodeCCIndex];
  SlidePeepState1: PROC [p: POINTER TO PeepState, ci: CodeDefs.CodeCCIndex];
  SlideConsState: PROC [p: POINTER TO ConsPeepState, di: CodeDefs.CodeCCIndex];
  PeepZ: PROC [start: CodeDefs.CodeCCIndex];
  HalfByteGlobal: PROC [c: CodeDefs.CCIndex, double: BOOL ← FALSE] RETURNS [BOOL];
  HalfByteLocal: PROC [c: CodeDefs.CCIndex, double: BOOL ← FALSE] RETURNS [BOOL];
  LoadInst: PROC [c: CodeDefs.CCIndex] RETURNS [BOOL];
  DblLoadInst: PROC [c: CodeDefs.CCIndex] RETURNS [BOOL];
  PackPair: PROC [l, r: [0..16)] RETURNS [w: WORD];
  UnpackPair: PROC [w: WORD] RETURNS [l, r: [0..16)];
  UnpackFD: PROC [d: PrincOps.FieldDescriptor] RETURNS [p, s: CARDINAL];
  Delete2: PROC [a, b: CodeDefs.CCIndex];
  Delete3: PROC [a, b, c: CodeDefs.CCIndex];
  RemoveThisPop: PROC [ci: CodeDefs.CCIndex] RETURNS [didThisTime: BOOL];
  CommuteCells: PUBLIC PROC [a, b: CodeDefs.CCIndex];
  start: VAR CodeDefs.CodeCCIndex;

  NextIsPush: PROC [c: CodeDefs.CCIndex] RETURNS [BOOL];
  Peep1, Peep2, Peep3, Peep4, Peep5, Peep6, Peep7, Peep8, 
  Peep9, Peep10, Peep11, Peep12: PROC;

  PeepholeANotify, PeepholeUNotify, PeepholeZNotify: Alloc.Notifier;

  }.