-- file P4.Mesa
-- last modified by Satterthwaite, February 22, 1983 4:13 pm

DIRECTORY
  Alloc: TYPE USING [Notifier],
  BcdDefs: TYPE USING [GFTIndex, Link],
  Inline: TYPE USING [BITAND],
  LiteralOps: TYPE USING [ValueDescriptor],
  Literals: TYPE USING [LitDescriptor],
  Symbols: TYPE,
  Tree: TYPE USING [Index, Link, Map, NodeName, Scan];

P4: DEFINITIONS IMPORTS Inline = {
  OPEN Symbols;

  mark: BOOL = FALSE;

  ownGfi: BcdDefs.GFTIndex = 1;

 -- representations (interim)

  Repr: TYPE = [none..all];
    signed: CARDINAL = 1;
    unsigned: CARDINAL = 2;
    long: CARDINAL = 4;
    other: CARDINAL = 8;

    none: CARDINAL = 0;
    both: CARDINAL = signed+unsigned;
    all: CARDINAL = other+long+both;

  CommonRep: PROC [Repr, Repr] RETURNS [Repr] = LOOPHOLE[Inline.BITAND];


 -- properties (synthesized)
 
  Prop: TYPE = RECORD [
    noAssign: BOOL,
    noXfer: BOOL,
    noSelect: BOOL,
    noFreeVar: BOOL,
    immutable: BOOL];
    
  fullProp: Prop = [
    noAssign:TRUE, noXfer:TRUE, noSelect:TRUE, noFreeVar:TRUE, immutable:TRUE];
  emptyProp: Prop = [
    noAssign:FALSE, noXfer:FALSE, noSelect:FALSE, noFreeVar:FALSE, immutable:FALSE];
  voidProp: Prop = fullProp;
  
  CommonProp: PROC [Prop, Prop] RETURNS [Prop] = LOOPHOLE[Inline.BITAND];


 -- attributes
 
  Attr: TYPE = RECORD [prop: Prop, rep: Repr];
    
  voidAttr: Attr = [prop: voidProp, rep: none];
  
  CommonAttr: PROC [Attr, Attr] RETURNS [Attr] = LOOPHOLE[Inline.BITAND];
    
    
 -- lengths and register counts

  OpWordCount: TYPE = CARDINAL;	-- size of operands for builtins
  
  RegCount: TYPE = [0..32);
  maxRegs: RegCount = RegCount.LAST;

 -- notifiers

  BCDNotify, DeclNotify, LayoutNotify, StmtNotify: Alloc.Notifier;
  OpsNotify, ExpANotify, ExpBNotify, ExpCNotify: Alloc.Notifier;

 -- exported by Pass4B

  AssignImports: Tree.Scan;
  InitBCD: PROC [Tree.Link, UNCOUNTED ZONE];
  FinishBCD: Tree.Scan;
  MakeEPLink: PROC [ep: CARDINAL, gfi: BcdDefs.GFTIndex] RETURNS [BcdDefs.Link];
  MatchBCD: PROC RETURNS [BOOL];
  ProcessDirectory: Tree.Scan;
  ProcessExports: Tree.Map;
  ProcessImports: Tree.Scan;
  ProcessSymLiterals: PROC;

 -- exported by Pass4D

  BiasForType: PROC [CSEIndex] RETURNS [INTEGER];
  CanonicalType: PROC [CSEIndex] RETURNS [CSEIndex];
  ComparableType: PROC [CSEIndex] RETURNS [BOOL];
  DeclItem: Tree.Scan;
  DeclUpdate: Tree.Map;
  DefaultBasicOps: PROC [Type, BitCount] RETURNS [BOOL];
  MaxCardinality: PROC [Type, BOOL, WordCount] RETURNS [LONG CARDINAL];
  RepForType: PROC [CSEIndex] RETURNS [Repr];
  SparseRep: PROC [CSEIndex] RETURNS [BOOL];
  TypeExp: PROC [typeExp: Tree.Link, body, indirect: BOOL←FALSE];
  TypeForTree: PROC [Tree.Link] RETURNS [Type];
  WordsForType: PROC [CSEIndex] RETURNS [WordCount];

  VarInit: SIGNAL RETURNS [BOOL];

 -- exported by Pass4L

  AssignEntries: PROC [BTIndex];
  BitsForType: PROC [Type] RETURNS [BitCount];
  CheckBlock: PROC [BTIndex];
  CheckFields: PROC [RecordSEIndex, CARDINAL];
  LayoutArgs: PROC [RecordSEIndex, CARDINAL, BOOL] RETURNS [CARDINAL];
  LayoutBlock: PROC [BTIndex, CARDINAL] RETURNS [CARDINAL];
  LayoutFields: PROC [RecordSEIndex, CARDINAL];
  LayoutGlobals: PROC [bti: CBTIndex, stopping, fragments: BOOL] RETURNS [CARDINAL];
  LayoutInterface: PROC [CBTIndex] RETURNS [CARDINAL];
  LayoutLocals: PROC [CBTIndex] RETURNS [CARDINAL];

 -- exported by Pass4S

  currentLevel: VAR ContextLevel;
  checked: VAR BOOL;

  BindCase: PROC [
      Tree.Index, Tree.NodeName, PROC [Tree.Link, INTEGER] RETURNS [Tree.Link]]
    RETURNS [Tree.Link];
  BindType: PROC [Tree.Index, Tree.Map] RETURNS [Tree.Link];
  Body: PROC [CBTIndex];
  CaseDriver: PROC [Tree.Index, Tree.Map, INTEGER] RETURNS [Tree.Link];
  CatchNest: PROC [Tree.Link];
  MarkString: PROC [local: BOOL←TRUE];
  Subst: PROC [Tree.Index] RETURNS [Tree.Link];

 -- exported by Pass4Ops

  RelOp: TYPE = Tree.NodeName [relE .. relLE];

  FoldExpr: PROC [Tree.Index, Repr] RETURNS [Tree.Link];
  IntervalTest: PROC [l,r: Tree.Link, rep: Repr] RETURNS [BOOL];
  IntToReal: PROC [Tree.Index] RETURNS [Tree.Link];
  LiteralRep: PROC [Tree.Link, Repr] RETURNS [Repr];
  LongToShort: PROC [Tree.Index, Repr] RETURNS [Tree.Link];
  MakeTreeLiteral: PROC [WORD] RETURNS [Tree.Link];
  RelTest: PROC [l,r: Tree.Link, op: RelOp, rep: Repr] RETURNS [BOOL];
  ShortToLong: PROC [Tree.Index, Repr] RETURNS [Tree.Link];
  StructuredLiteral: PROC [Tree.Link] RETURNS [BOOL];
  TreeLiteral: PROC [Tree.Link] RETURNS [BOOL];
  TreeLiteralDesc: PROC [Tree.Link] RETURNS [Literals.LitDescriptor];
  TreeLiteralValue: PROC [Tree.Link] RETURNS [WORD];
  ZeroP: PROC [Tree.Link] RETURNS [BOOL];

 -- exported by Pass4Xa

  ConsState: TYPE = {init, first, rest};
  Covering: TYPE = {none, partial, full};

  All: PROC [node: Tree.Index, cs: ConsState←$init] RETURNS [Tree.Link];
  Assignment: PROC [Tree.Index] RETURNS [Tree.Link];
  Call: PROC [Tree.Index] RETURNS [Tree.Link];
  CheckRange: PROC [Tree.Link, CARDINAL, CSEIndex] RETURNS [Tree.Link];
  Construct: PROC [node: Tree.Index, cs: ConsState←$init] RETURNS [Tree.Link];
  Cover: PROC [lType: CSEIndex, lRep: Repr, rType: CSEIndex, rRep: Repr]
    RETURNS [Covering];
  Dollar: PROC [Tree.Index] RETURNS [Tree.Link];
  Extract: PROC [Tree.Index] RETURNS [Tree.Link];
  Index: PROC [Tree.Index] RETURNS [Tree.Link];
  MakeArgRecord: PROC [RecordSEIndex, Tree.Link] RETURNS [Tree.Link];
  Narrow: PROC [Tree.Index] RETURNS [Tree.Link];
  New: PROC [Tree.Index] RETURNS [Tree.Link];
  PadRecord: PROC [t: Tree.Link, lType: CSEIndex] RETURNS [Tree.Link];
  RewriteAssign: PROC [Tree.Index, CSEIndex] RETURNS [Tree.Link];
  Reloc: PROC [Tree.Index] RETURNS [Tree.Link];
  Rhs: PROC [exp: Tree.Link, lType: CSEIndex, cs: ConsState←$init, voidOK: BOOL←FALSE]
    RETURNS [Tree.Link];
  RowConstruct: PROC [node: Tree.Index, cs: ConsState←$init] RETURNS [Tree.Link];
  SeqIndex: PROC [Tree.Index] RETURNS [Tree.Link];
  Substx: PROC [Tree.Index] RETURNS [Tree.Link];
  Union: PROC [node: Tree.Index, cs: ConsState←$init] RETURNS [Tree.Link];

 -- exported by Pass4Xb

  ExpInit: PROC [UNCOUNTED ZONE];
  ExpReset: PROC;

  AdjustBias: PROC [Tree.Link, INTEGER] RETURNS [Tree.Link];
  BoolValue: PROC [t: Tree.Link] RETURNS [Tree.Link] = INLINE {
    RETURN [RValue[t, 0, unsigned]]};
  ComputeIndexRegs: PROC [Tree.Index] RETURNS [RegCount];
  Exp: PROC [Tree.Link, Repr] RETURNS [Tree.Link];
  FillMultiWord: PROC [
    words: LiteralOps.ValueDescriptor, origin: CARDINAL, t: Tree.Link];
  ForceType: PROC [Tree.Link, CSEIndex] RETURNS [Tree.Link];
  LiteralAttr: PROC [Repr] RETURNS [Attr];
  MakeStructuredLiteral: PROC [val: WORD, type: CSEIndex] RETURNS [Tree.Link];
  NeutralExp: Tree.Map;
  OperandType: PROC [Tree.Link] RETURNS [CSEIndex];
  RegsForType: PROC [CSEIndex] RETURNS [RegCount];
  RValue: PROC [exp: Tree.Link, bias: INTEGER, target: Repr] RETURNS [Tree.Link];
  VAttr: PROC RETURNS [Attr];
  VBias: PROC RETURNS [INTEGER];
  VPop: PROC;
  VProp: PROC RETURNS [Prop];
  VPush: PROC [bias: INTEGER, attr: Attr, nRegs: RegCount];
  VRegs: PROC RETURNS [RegCount];
  VRep: PROC RETURNS [Repr];

 -- exported by Pass4Xc

  AddrOp: PROC [Tree.Index] RETURNS [Tree.Link];
  ConstantInterval: PROC [Tree.Index] RETURNS [origin, range: INTEGER];
  Interval: PROC [Tree.Index, INTEGER, Repr] RETURNS [const: BOOL];
  Nil: PROC [Tree.Index] RETURNS [Tree.Link];
  NormalizeRange: PROC [Tree.Link] RETURNS [Tree.Link];
  MiscXfer: PROC [Tree.Index] RETURNS [Tree.Link];
  TypeOp: PROC [Tree.Index] RETURNS [Tree.Link];

  EmptyInterval: SIGNAL;

  }.