-- file PeepholeDefs.mesa
-- last edited by Sweet March 17, 1980  11:43 AM
-- last edited by Satterthwaite  2-Oct-81 15:32:54

DIRECTORY
  Alloc: TYPE USING [Notifier],
  CodeDefs: TYPE USING [
    Byte, CCIndex, CodeCCIndex, CodeCCNull, JumpCCIndex, JumpCCNull],
  FOpCodes: TYPE USING [qNOOP],
  PrincOps: TYPE USING [FieldDescriptor];

PeepholeDefs: DEFINITIONS =
  BEGIN

  PeepComponent: TYPE = RECORD [
    index: CodeDefs.CodeCCIndex,
    inst: CodeDefs.Byte,
    min: BOOLEAN,
    params: ARRAY [1..3] OF WORD];
  NullComponent: PeepComponent = [
    index: CodeDefs.CodeCCNull,
    inst: FOpCodes.qNOOP,
    min: FALSE,
    params: [0,0,0]];

  PeepState: TYPE = RECORD [ -- can't use current Machine Dep since holes
    SELECT OVERLAID * FROM
      old => [
	a: CodeDefs.CodeCCIndex,
	aInst: CodeDefs.Byte,
	aMin: BOOLEAN,
	aP: ARRAY [1..3] OF WORD,
	b: CodeDefs.CodeCCIndex,
	bInst: CodeDefs.Byte,
	bMin: BOOLEAN,
	bP: ARRAY [1..3] OF WORD,
	c: CodeDefs.CodeCCIndex,
	cInst: CodeDefs.Byte,
	cMin: BOOLEAN,
	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: CodeDefs.Byte,
    bMin: BOOLEAN,
    b: CodeDefs.CodeCCIndex,
    cInst: CodeDefs.Byte,
    cMin: BOOLEAN];
  NullJumpState: JumpPeepState = [
    c: CodeDefs.JumpCCNull,
    bP: [0,0,0],
    cP: [0,0,0],
    bInst: FOpCodes.qNOOP,
    bMin: FALSE,
    b: CodeDefs.CodeCCNull,
    cInst: FOpCodes.qNOOP,
    cMin: FALSE];

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

  SetRealInst: PROC [BOOLEAN];
  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];
  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];
  PeepZ: PROC [start: CodeDefs.CodeCCIndex];
  HalfByteGlobal: PROC [c: CodeDefs.CCIndex] RETURNS [BOOLEAN];
  HalfByteLocal: PROC [c: CodeDefs.CCIndex] RETURNS [BOOLEAN];
  LoadInst: PROC [c: CodeDefs.CCIndex] RETURNS [BOOLEAN];
  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];
  MC0: PROC [i: CodeDefs.Byte, minimal: BOOLEAN];
  Delete2: PROC [a,b: CodeDefs.CCIndex];
  Delete3: PROC [a,b,c: CodeDefs.CCIndex];
  RemoveThisPop: PROC [ci: CodeDefs.CCIndex] RETURNS [didThisTime: BOOLEAN];

  PeepholeUNotify, PeepholeZNotify: Alloc.Notifier;

  END.