-- file PeepholeDefs.mesa
-- last edited by Sweet March 17, 1980  11:43 AM
-- last edited by Satterthwaite October 18, 1982 1:16 pm

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

PeepholeDefs: DEFINITIONS = {

  PeepComponent: TYPE = RECORD [
    index: CodeDefs.CodeCCIndex,
    inst: CodeDefs.Byte,
    params: ARRAY [1..3] OF WORD];
  NullComponent: PeepComponent = [
    index: CodeDefs.CodeCCNull,
    inst: FOpCodes.qNOOP,
    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,
	aP: ARRAY [1..3] OF WORD,
	b: CodeDefs.CodeCCIndex,
	bInst: CodeDefs.Byte,
	bP: ARRAY [1..3] OF WORD,
	c: CodeDefs.CodeCCIndex,
	cInst: CodeDefs.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: CodeDefs.Byte,
    b: CodeDefs.CodeCCIndex,
    cInst: CodeDefs.Byte];
  NullJumpState: JumpPeepState = [
    c: CodeDefs.JumpCCNull,
    bP: [0,0,0],
    cP: [0,0,0],
    bInst: FOpCodes.qNOOP,
    b: CodeDefs.CodeCCNull,
    cInst: FOpCodes.qNOOP];

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

  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];
  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 [BOOL];
  HalfByteLocal: PROC [c: CodeDefs.CCIndex] RETURNS [BOOL];
  LoadInst: 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];

  PeepholeUNotify, PeepholeZNotify: Alloc.Notifier;

  }.