DEFINITION MODULE M2CM;
(*$ LargeVars:=FALSE NameChk:=FALSE LongAlign:=FALSE *)
FROM M2DM IMPORT
 Register,RegisterSet,StrPtr,ObjPtr,ParPtr,ConstValue;
FROM M2XM IMPORT
 Item;

CONST
 MaxExit=15; (* number of EXITs-1 per block *)

TYPE
 LabelRange=RECORD low,high:ConstValue; label:INTEGER END;
 ExitTable=ARRAY [0..MaxExit] OF INTEGER;
 RegPtr=POINTER TO RegNode;
 RegNode=RECORD next:RegPtr; reg:Register; typ:StrPtr; END;
 CallInfo=RECORD
   busy,
   extend1to4,
   extend2to4,
   lock,
   saved:RegisterSet;
   isCode:BOOLEAN; (* merkt sich fuer Extend, nur bei CODE! *)
   stacked:RegPtr;
 END;

VAR
 wlev:INTEGER; (* WITH nesting level *)
 curPrio:LONGINT;

(* muß in m2cm!?*)
(*packe adr(x) nach const mit relocation*)
PROCEDURE GenCRel(VAR c:ConstValue; offs:INTEGER; VAR x:Item);

PROCEDURE GenAssign(VAR x,y:Item);
PROCEDURE GenItem(VAR x:Item; y,scope:ObjPtr);

PROCEDURE GenFJ(VAR loc:INTEGER); (* forward jump; loc:=pc *)
PROCEDURE GenCFJ(VAR x:Item; VAR loc:INTEGER);
PROCEDURE GenBJ(loc:INTEGER); (* backward jump to loc *)
PROCEDURE GenCBJ(VAR x:Item; loc:INTEGER);

PROCEDURE PrepCall(VAR x:Item; VAR fp:ParPtr; VAR ci:CallInfo);
PROCEDURE GenParam(VAR ap:Item; f:ParPtr; VAR ci:CallInfo);
PROCEDURE GenCall(VAR x:Item; ci:CallInfo);
PROCEDURE GenEnter(lev,pno:INTEGER; size:LONGINT);
PROCEDURE GenResult(VAR x:Item; proc:ObjPtr; VAR l:INTEGER);
PROCEDURE GenReturn(proc:ObjPtr; returnL:INTEGER);

PROCEDURE GenCase1(VAR x:Item; VAR l0:INTEGER);
PROCEDURE GenCase2;
PROCEDURE GenCase3(VAR x:Item; l0,l1,n:INTEGER;
                   VAR tab:ARRAY OF LabelRange);

PROCEDURE GenFor1(v:Item; VAR e1:Item);
PROCEDURE GenFor2(v:Item; VAR e1,e2:Item);
PROCEDURE GenFor3(v:Item; VAR e2,e3:Item; VAR l0,l1:INTEGER);
PROCEDURE GenFor4(v:Item; VAR e2,e3:Item; l0,l1:INTEGER);

PROCEDURE GenWith(VAR x:Item; fadr:LONGINT);
PROCEDURE GenWith2;

PROCEDURE GenLoop1(VAR s,m:INTEGER; n:INTEGER);
PROCEDURE GenLoop2(s,m:INTEGER; VAR n:INTEGER; VAR tab:ExitTable);
PROCEDURE GenExit(VAR n:INTEGER; VAR tab:ExitTable);

PROCEDURE GenEnterMod(VAR l:INTEGER);
PROCEDURE GenCloseMod(VAR l:INTEGER);
PROCEDURE GenExitClose(VAR l:INTEGER);
PROCEDURE GenEnterLocMod(mno:INTEGER);
PROCEDURE InitLocMods(ob:ObjPtr);

END M2CM.
