DEFINITION MODULE M2HM;
(*$ LargeVars:=FALSE NameChk:=FALSE LongAlign:=FALSE *)
FROM M2DM IMPORT
 ObjPtr,StrPtr,WidType,ConstValue,Condition;
FROM M2SM IMPORT
 Symbol;
FROM M2XM IMPORT
 Item;

TYPE
 ShiType=(Asl,Asr,Lsl,Lsr,Rol,Ror);
VAR
 constOp: BOOLEAN;
 resultTyp:StrPtr;
 profDataOffset: LONGINT; (* adr der Profiler-Var *)
 profActAncestor:ObjPtr;
 (*
  * Muß leider globle Var sein, sonst GROSSER Compiler-Umbau nötig!
  * Enthält immer den aktuellen Ancestor von m2c.Block.
  * Nötig wegen id=pno oder mno
  *)
 lastProfOff:INTEGER;  (* ip beim letzten Timer off, wird durch
			* M2HM.GenProf ausgewertet und gesetzt und
			* von M2XM.AllRegsDestroyed gelöscht
			*)

PROCEDURE SetupSL(plev:INTEGER);      (* push Static Link to stack *)
PROCEDURE GenHalt(haltindex:INTEGER); (* call System.HALTX proc. *)
PROCEDURE GenStkChk(s: LONGINT);      (* s is ADDED to SP (so normally s<=0) *)
PROCEDURE Trap(nr: INTEGER; cc: Condition); (* optimize trap instructions *)

PROCEDURE Neg1(VAR x:Item); (* x:=-x *)
PROCEDURE Not1(VAR x:Item);
PROCEDURE Abs1(VAR x:Item);
PROCEDURE Cap1(VAR x:Item);
PROCEDURE Tst1(VAR x:Item; c:Condition); (* x-0 *)
PROCEDURE Com1(VAR x:Item); (* x:=complement(x) *)
PROCEDURE Inc1(VAR x:Item);
PROCEDURE Dec1(VAR x:Item);
PROCEDURE And1(VAR x:Item);
PROCEDURE Or1(VAR x:Item);

PROCEDURE Add2(VAR x,y:Item);
PROCEDURE Sub2(VAR x,y:Item);
PROCEDURE And2(VAR x,y:Item);
PROCEDURE Or2(VAR x,y:Item);
PROCEDURE IAnd2(VAR x,y:Item);
PROCEDURE IOr2(VAR x,y:Item);
PROCEDURE IEor2(VAR x,y:Item);
PROCEDURE Div2(VAR x,y:Item);
PROCEDURE Mod2(VAR x,y:Item);
PROCEDURE Quo2(VAR x,y:Item);
PROCEDURE Rem2(VAR x,y:Item);
PROCEDURE Mul2(VAR x,y:Item);
PROCEDURE Cmp2(VAR x,y:Item; c:Condition);
PROCEDURE In2(VAR x,y:Item);
PROCEDURE Shi2(VAR x,y:Item; shiftop:ShiType);
PROCEDURE Ash2(VAR x,y :Item; shiftop:ShiType);

PROCEDURE ConIndex(VAR x:Item; inc:LONGINT);
(* constant offset/index inc to base x *)

PROCEDURE VarIndex(VAR x,y:Item; elsize:LONGINT);
(* variable offset/index y to base x (elements of size elsize) *)

PROCEDURE GetHigh(VAR x:Item);
(* get high bound of dynamic array parameter x *)

PROCEDURE Normalize(VAR x:Item; i:LONGINT);
(* normalize subrange x to zero by lowbound i *)

PROCEDURE CheckHigh(VAR x,high:Item);
(* check x in the variable range [ 0..high ] *)

PROCEDURE CheckClimit(VAR x:Item; limit:LONGINT);
(* check x in the constant interval [ 0..limit ] *)

PROCEDURE PreProcess(VAR op:Symbol; VAR x,y:Item);

PROCEDURE DynArray(VAR x,y:Item);
(* descriptor for dynamic array parameter *)

PROCEDURE CopyDynArray(a,s:INTEGER);
(* value for dynamic array parameter *)

PROCEDURE EnterCase(VAR x:Item; base:INTEGER; lo,hi:LONGINT);
(* enter case-statement processor *)

PROCEDURE ExitCase;
(* leave case-statement processor *)

PROCEDURE Link(lev:INTEGER; size:LONGINT; link:BOOLEAN);
(* generate entry-code for procedure at level lev *)

PROCEDURE Unlink(parSize:LONGINT; lev:INTEGER; link:BOOLEAN);
(* generate exit-code for procedure at level lev *)

PROCEDURE CallInt(proc:ObjPtr); (* call of local procedure *)
PROCEDURE CallExt(proc:ObjPtr); (* call of external procedure *)
PROCEDURE CallCod(proc:ObjPtr); (* call of code procedure *)
PROCEDURE CallInd(VAR x:Item); (* call of procedure variable *)

PROCEDURE EnterModule(VAR l:INTEGER); (* main module's entry code *)
PROCEDURE EnterExitModule(VAR l:INTEGER); (* main module's close code *)
PROCEDURE ExitInit(l:INTEGER); (* main module after inits (pop counter) *)
PROCEDURE InitTraps; (* setzt trapLocs auf 0 nach EndHunk *)
PROCEDURE EnterLocMod;
PROCEDURE InitModule(m:INTEGER); (* init of imported modules *)
PROCEDURE CloseModule(m:INTEGER); (* close of imported modules *)

PROCEDURE InitM2HM;
PROCEDURE GetArts;
PROCEDURE GetProfiler;
PROCEDURE GetDebug;
PROCEDURE GenLibraryCode(proc:ObjPtr);
PROCEDURE GenProfMain(mno:INTEGER);
PROCEDURE ExitProfExit; (* im CLOSE-Teil CallProf(pExit) aufrufen *)
(* neu fuer debugger-codierung *)
PROCEDURE RefPoint; (* neu in HM statt RM wegen Debugger-Generierung *)
PROCEDURE ProcStart(pno:INTEGER);
PROCEDURE ModStart(mno:INTEGER);
PROCEDURE ProcEnd;
PROCEDURE ModEnd;
END M2HM.
