
    <<P4.Mesa>>
        <<Copyright © 1985 by Xerox Corporation.  All rights reserved.>>
        <<Satterthwaite, June 19, 1986 9:31:18 am PDT>>
        <<Maxwell, August 1, 1983 12:46 pm>>
        <<Paul Rovner, September 7, 1983 5:57 pm>>
        <<Russ Atkinson (RRA) March 6, 1985 10:16:28 pm PST>>

    DIRECTORY
        Alloc: TYPE USING [Notifier],
        BcdDefs: TYPE USING [Link, ModuleIndex],
        Literals: TYPE USING [Byte, LitDescriptor],
        PrincOpsUtils: TYPE USING [BITAND],
        Symbols: TYPE,
        Tree: TYPE USING [Index, Link, Map, NodeName, Scan];

    P4: DEFINITIONS IMPORTS PrincOpsUtils = {
        OPEN Symbols;

        mark: BOOL = FALSE;

        ownGfi: BcdDefs.ModuleIndex = 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[PrincOpsUtils.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[PrincOpsUtils.BITAND];


    <<attributes>>

        Attr: TYPE = RECORD[prop: Prop, rep: Repr];

        voidAttr: Attr = [prop: voidProp, rep: none];

        CommonAttr: PROC[Attr, Attr] RETURNS[Attr] = LOOPHOLE[PrincOpsUtils.BITAND];

    <<literal values>>

        ByteSeq: TYPE = RECORD[PACKED SEQUENCE length: CARDINAL OF Literals.Byte];
        ValueDescriptor: TYPE = REF ByteSeq;

    <<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];
        FinishBCD: Tree.Scan;
        MakeEPLink: PROC[ep: CARDINAL, gfi: BcdDefs.ModuleIndex] RETURNS[BcdDefs.Link];
        MatchBCD: PROC RETURNS[BOOL];
        ProcessDirectory: Tree.Scan;
        ProcessExports: Tree.Map;
        ProcessImports: Tree.Scan;
        ProcessSymLiterals: PROC;

    <<exported by Pass4D>>

        AUsForType: PROC[Type] RETURNS[CARD];
        BiasForType: PROC[Type] RETURNS[INTEGER];
        CanonicalType: PROC[Type] RETURNS[Type];
        ComparableType: PROC[Type] RETURNS[BOOL];
        DeclItem: Tree.Scan;
        DeclUpdate: Tree.Map;
        DefaultBasicOps: PROC[Type, BitCount] RETURNS[BOOL];
        MaxCardinality: PROC[Type, BOOL, CARD] RETURNS[CARD];
        RepForType: PROC[Type] RETURNS[Repr];
        SparseRep: PROC[Type] RETURNS[BOOL];
        TypeExp: PROC[typeExp: Tree.Link, body, indirect: BOOL_FALSE];
        TypeForTree: PROC[Tree.Link] RETURNS[Type];

        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];

        BoolTest: PROC[Tree.Link] RETURNS[BOOL];
        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[CARD] 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[CARD];
        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, Type] RETURNS[Tree.Link];
        Construct: PROC[node: Tree.Index, cs: ConsState_$init] RETURNS[Tree.Link];
        Cover: PROC[lType: Type, lRep: Repr, rType: Type, rRep: Repr] RETURNS[Covering];
        Dollar: PROC[Tree.Index] RETURNS[Tree.Link];
        Dot: PROC[Tree.Index, Repr] RETURNS[Tree.Link];
        Extract: PROC[Tree.Index] RETURNS[Tree.Link];
        Index: PROC[Tree.Index] RETURNS[Tree.Link];
        ListCons: PUBLIC 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];
        OperandStruct: PROC[Tree.Link] RETURNS[CSEIndex];
        PadRecord: PROC[t: Tree.Link, lType: Type] RETURNS[Tree.Link];
        RewriteAssign: PROC[Tree.Index, Type] RETURNS[Tree.Link];
        Reloc: PROC[Tree.Index] RETURNS[Tree.Link];
        Rhs: PROC[exp: Tree.Link, lhsType: Type, 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];
        SetType: PROC[Type];
        Substx: PROC[Tree.Index] RETURNS[Tree.Link];
        Union: PROC[node: Tree.Index, cs: ConsState_$init] RETURNS[Tree.Link];

    <<exported by Pass4Xb>>

        ExpInit: PROC;
        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[bytes: ValueDescriptor, origin: CARDINAL, t: Tree.Link];
        ForceType: PROC[Tree.Link, Type] RETURNS[Tree.Link];
        LiteralAttr: PROC[Repr] RETURNS[Attr];
        MakeStructuredLiteral: PROC[val: WORD, type: Type] RETURNS[Tree.Link];
        NeutralExp: Tree.Map;
        OperandType: PROC[Tree.Link] RETURNS[Type];
        RegsForType: PROC[Type] 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;

        }.

