------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather package. It is free software; you may --
-- redistribute  and/or modify it under the terms of the  GNU General Public --
-- License (GPL)  as  published  by the  Free  Software  Foundation;  either --
-- version 2 of the license, or (at your option) any later version.          --
-- This  program  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/GPL for more details.        --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- The interfaces in this file are roughly in their temporal order,
-- although they may be implemented `lazily' in practice for more
-- efficiency.

abstract class $GET_OPTIONS is

    -- This prints the state of all options.
    str:STR; 

    -- This interprets the command line passed to it
    interpret(a:ARRAY{STR});
    read_env;

end;

-------------------------------------------------------------------
abstract class $PARSE is
   -- The stage in which all files are parsed and tree forms built.
   -- This stage catches both syntactic errors and multiply defined
   -- classes.  This interface allows parsing to occur lazily, as
   -- the trees are first requested.

   -- Return the code tree for the class with name `nm' and the number
   -- of type parameters `num'. Return void if no such class.
   tree_for(nm:IDENT, num:INT):AS_CLASS_DEF;
   
   -- Tell the parser to parse the file `f'.
   parse(f:STR);

end;

-------------------------------------------------------------------
abstract class $FIND_TYPES is
   -- This is the stage which finds all possible types in the program.
   -- It starts from the non-parameterized types parsed in the first 
   -- stage. It produces an IMPL for each such type and determines all
   -- types mentioned within it. If any of these types is missing or if
   -- any of the builtin types is missing an error is signalled
   -- and compilation ends. It causes errors for overloaded name
   -- conflicts.

   -- Walk through all the code trees and find all the types referred
   -- to. Cause errors for any types referred to but not existing.
   find_types; 
   
end;

-------------------------------------------------------------------
abstract class $BUILD_TYPE_GRAPH is
   -- This stage builds the type graph of the types found above. 
   -- It causes errors if there are loops.

   -- Build the type graphs for all types in the program.
   build_graphs; 
   
end;

-------------------------------------------------------------------
abstract class $CHECK_IFC_CONFORMANCE is
   -- This stage checks the conformance of interfaces for each
   -- type against its parents and children.

   check_ifc_conformance; 
   
end;

-------------------------------------------------------------------
abstract class $GET_MAIN_SIG is
    -- This stage determines the signature of main.
    
    -- Get the signature of the main routine in the class named `nm'
    -- and put it in `main_sig'.
    get_main_sig(nm:STR);

    main_sig:SIG;

end;

-------------------------------------------------------------------
abstract class $GENERATE_AM is
   -- This stage does a code walk from main and generates the AM form
   -- It causes errors for failures of type checking, name clashes,
   -- etc.  It is inlined in time with the back-end for each emitted
   -- routine.

    generate_am;
    output_sig(sig:SIG); -- output a signature, if it hasn't been done.
    -- sig_out:FSET{SIG};   -- return table of SIGs which have been output.
    sig_recursive:FSET{SIG};  -- signatures of routines known to be recursive.

end; 

-------------------------------------------------------------------
abstract class $INLINE is
    -- This stage is called on every AM_ROUT_CALL_EXPR after it and
    -- all its subexpressions have been generated.  This way any
    -- routine call can be replaced by an alternative expression.

    -- Called for every defined routine, before 'inline' is called.
    consider(am:AM_ROUT_DEF);

    -- There two different kinds of inlining. Special purpose
    -- inlining exploits certain special cases and could be
    -- done early (just after translation). General inlining 
    -- might interfere with other optimizations and is done later.
    special_inline(call:AM_ROUT_CALL_EXPR):$AM_EXPR;
    -- general_inline(call:AM_ROUT_CALL_EXPR):$AM_EXPR;
    general_inline(rout:AM_ROUT_DEF,call:AM_ROUT_CALL_EXPR):$AM_EXPR;

    special_inline(call:AM_ITER_CALL_EXPR):$AM_EXPR;
    -- general_inline(call:AM_ITER_CALL_EXPR):$AM_EXPR;
    general_inline(rout:AM_ROUT_DEF,lp:AM_LOOP_STMT,call:AM_ITER_CALL_EXPR):$AM_EXPR;

    -- True if a given signature always be inlined so that
    -- code for it need not be generated.
    inlined(s:SIG):BOOL;

    init; -- used to initialize the inliner

end;

-------------------------------------------------------------------
abstract class $OPTIMIZE is
    -- This stage is right before the back-end.  This is where
    -- expensive optimizations should be done.  It passes the optimized
    -- $AM expressions to the back-end.

    -- Initialization occurs after the layouts and sigs have
    -- been constructed.
    init; 

    -- This gets called for every routine to be optimized and generated.
    optimize(func:AM_ROUT_DEF);

    -- This gets called for every routine to be generated but not optimized.
    no_optimize(func:AM_ROUT_DEF);

    -- After all routines have been emitted, this is called.
    finalize;

end;

-------------------------------------------------------------------
-- $BACK_END is the abstract type which defines the interface that a
-- back-end must provide to the rest of the compiler.  At creation, a
-- back-end is passed a PROG object, which holds various compiler-wide
-- tables.

abstract class $BACK_END is

    -- Initialization occurs after the layouts and sigs have
    -- been constructed.
    init; 

    -- This gets called for every routine to be generated.
    emit(func:AM_ROUT_DEF);

    -- After all routines have been emitted, this is called.
    finalize;
end;

-------------------------------------------------------------------
abstract class $CHECK_AM is
   -- Check the code for routines which aren't reached, but don't output
   -- any am code for them.

   check_code; 
	 
end;

