(****************************************
*                                       *
*     MODULA-2 Multi-Pass Compiler      *
*     ****************************      *
*                                       *
*       VAX/VMS Implementation          *
*                                       *
*                                       *
*     MVCR4:                            *
*                                       *
*     Codegeneration for                *
*     REAL arithmetic in Pass 4         *
*                                       * 
*                                       *
*     Version 3.1 of  1-FEB-1983        *
*                                       *
*                                       *
*                                       *
*     Based on PDP11 Implementation     *
*     Version M22 of 25.02.81           *
*                                       *
*     Institut fuer Informatik          *
*     ETH-Zentrum                       *
*     CH-8092 Zuerich                   *
*                                       *
****************************************)

(****************************************
* Updates: see implementation module    *
****************************************)

DEFINITION MODULE MVCR4; (* A. Gorrengourt / G. Maier *)
  (*Stack-oriented codegeneration for floatingpoint-arithmetic. *)

  FROM MVCAttributHandling IMPORT Attribut;

  EXPORT QUALIFIED
         OperationType,
         Push, Execute, PushExecute,
         PushPop, PushPopParameter,
         FloatPush, PushPopTrunc,
         Save, RestoreWithWord, RestoreWithReal;

  TYPE
    OperationType = (NopR, AbsR, NegR, TstR,
                     AddR, SubR, MulR, DivR, CmpR);

  PROCEDURE Push(VAR src: Attribut);
  (*The operand is moved onto the internal stack (unless it
    is already there).*)

  PROCEDURE Execute(operation: OperationType; fat: Attribut);
  (*The specified operation is executed with the top elements
    of the internal stack:
    - 'AbsR', 'NegR' and 'TstR' remove one element from the stack.
    - 'AddR' .. 'CmpR' remove two elements from the stack.
    - 'AbsR', 'NegR' and 'AddR' .. 'DivR' generate a result
    on the top of the stack.
    - 'TstR' and 'CmpR' only set the condition codes.
    Z(ero), N(egative) and V (overflow) flags must be set
    accordingly, so that a signed branch can be generated.
    The other elements of the stack are not affected.*)

  PROCEDURE PushExecute(VAR src: Attribut; operation: OperationType);
  (*This procedure may generate some more efficient code than
    the sequential use of 'Push' and 'Execute'.*)

  (*PROCEDURE Pop(VAR dst: Attribut); *)
  (*The top element of the internal stack is removed and stored.
    - 'Pop' requires just one element on the stack.*)
  (*This procedure is not exported, because it is not
    called directly by the compiler.*)

  PROCEDURE PushPop(VAR src,dst: Attribut);
  (*This procedure may generate some more efficient code than
    the sequential use of 'Push' and 'Pop'.*)

  (*PROCEDURE PopParameter; *)
  (*The top element of the internal stack is removed and pushed
    onto the normal stack. The internal stack will not
    necessarily be empty afterwards.*)
  (*This procedure is not exported, because it is not
    called directly by the compiler.*)

  PROCEDURE PushPopParameter(VAR src: Attribut);
  (*This procedure may generate some more efficient code than
    the sequential use of 'Push' and 'PopParameter'.*)

  PROCEDURE FloatPush(VAR src: Attribut);
  (*The INTEGER or CARDINAL given by 'src' is converted to
    REAL and pushed onto the internal stack. *)

  (*PROCEDURE PopTrunc; *)
  (*The top element of the internal stack is removed, converted to
    INTEGER and pushed onto the normal stack. The internal stack
    will not necessarily be empty afterwards.*)
  (*This procedure is not exported, because it is not
    called directly by the compiler.*)

  PROCEDURE PushPopTrunc(VAR src: Attribut);
  (*This procedure may generate some more efficient code than
    the sequential use of 'Push' and 'PopTrunc'.*)

  PROCEDURE Save;
  (*A function call will take place. Save the internal stack,
    so that it is free for use by the function. Before the call
    takes place the stack may still be used to evaluate some
    parameters, but these will all be removed by 'PopParameter'.*)

  PROCEDURE RestoreWithWord;
  (*A function result with the size of one word is on top of
    the normal stack. Restore the internal stack and take care
    that afterwards that function result is still on top of
    the normal stack.*)

  PROCEDURE RestoreWithReal(VAR src:Attribut);
  (*A function result of type REAL is on top of the normal stack.
    Restore the internal stack and push that function result onto
    the internal stack. Set 'src' to describe that function result
    on top of the internal stack.*)

END MVCR4.
