PreviousUpNext

15.3.168  src/lib/compiler/back/low/tools/arch/adl-rtl-comp.api

## adl-rtl-comp.api -- derived from ~/src/sml/nj/smlnj-110.60/MLRISC/Tools/ADL/mdl-rtl-comp.sig
#
# "rtl" == "Register Transfer Language" -- an intermediate code format.
#
# Process rtl descriptions

# Compiled by:
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-backend-packages.lib

stipulate
    package ard =  architecture_description;                                    # architecture_description                              is from   src/lib/compiler/back/low/tools/arch/architecture-description.pkg
    package raw =  adl_raw_syntax_form;                                         # adl_raw_syntax_form                                   is from   src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.pkg
herein

    # This api is implemented in:
    #     src/lib/compiler/back/low/tools/arch/adl-rtl-comp-g.pkg
    #
    api Adl_Rtl_Comp {
        #
        package rtl:  Treecode_Rtl;                                             # Treecode_Rtl                                          is from   src/lib/compiler/back/low/treecode/treecode-rtl.api
        package lct:  Lowhalf_Types;                                            # Lowhalf_Types                                         is from   src/lib/compiler/back/low/tools/arch/lowhalf-types.api

        sharing lct::rtl == rtl;

        Compiled_Rtls;                                                          # rtl in digested form 

        Rtl_Def = RTLDEF  { id: raw::Id,
                            args:       List( raw::Id ),
                            rtl:        rtl::Rtl
                          };

        current_rtls:  Ref( List(Rtl_Def) );                                    # Current set of rtls.

        compile:  ard::Architecture_Description -> Compiled_Rtls;                       # Process the rtl.

        architecture_description_of:    Compiled_Rtls -> ard::Architecture_Description; # Extract the architecture description component.

        rtls:                   Compiled_Rtls -> List( Rtl_Def );               # Extract the rtls.

        gen:                    Compiled_Rtls -> Void;                          # Emit and execute code for building the rtls.

        dump_log:               Compiled_Rtls -> Void;                          # Dump out all the rtl definitions.

        # A generic combinator to generate query functions.
        # Use this method if you want to create new query routines.

        make_query
            :
            Compiled_Rtls
            ->
            { name:             raw::Id,                                        # Name of function.
              named_arguments:  Bool,                                           # Use record arguments? 
              args:             List(  List(raw::Id )),                         # Labeled arguments, may be curried. 
              decls:            List( raw::Declaration ),                               # Local definitions.
              case_args:        List( raw::Id ),                                # Extra arguments to the case expression 

              # Callback to generate the actual code. 
              # An instruction constructor may represent a set of
              # different instructions with different rtl templates.
              # We enumerate all of them and let you decide 
              # how to generate the code.
              #
              body: { instruction:      raw::Constructor,                               # Current instruction.
                      rtl:              Rtl_Def,                                        # Rtl for this instruction.
                      const:    raw::Expression                         # Callback for making constants.
                                    ->
                                    raw::Expression
                    }
                    ->
                    { case_pats:        List( raw::Pattern ),                   # Extra patterns.
                      expression:       raw::Expression                         # And clause.
                    }
            }
            ->
            raw::Declaration
            ;


        # A generic routine for generating def/use like queries:
        #
        make_def_use_query
            :
            Compiled_Rtls
            ->
              { name:           raw::Id,                                        # Name of function.
                args:           List(  List(raw::Id) ),
                named_arguments:        Bool,
                decls:          List( raw::Declaration ),                       # Local definitions.
                #
                def:            ( raw::Expression,
                                      rtl::Expression,
                                      raw::Expression
                                    )
                                    ->
                                    Null_Or(raw::Expression),

                use:            ( raw::Expression,
                                      rtl::Expression,
                                      raw::Expression
                                    )
                                    ->
                                    Null_Or( raw::Expression )
              }
            ->
            raw::Declaration
            ;



        # Analyze all the arguments in an expression according
        # to its  rtl definition.
        #
        forall_args
            :
              { instruction:    raw::Constructor,                               # Current instruction.
                #
                rtl:            Rtl_Def,                                        # Current rtl 
                #
                rtl_arg:                ( raw::Id,
                                      raw::Type,
                                      rtl::Expression,
                                      rtl::Pos,
                                      X
                                    )
                                    -> X,
                #
                non_rtl_arg:    ( raw::Id,
                                      raw::Type,
                                      X
                                    )
                                    -> X
              }
            -> X
            -> X
            ;

        # Analyze all the arguments in an expression according to its 
        # rtl definition, create an expression that recreate that instruction.
        #
        map_instr
            :
              { instruction:    raw::Constructor,                               # Current instruction.
                rtl:            Rtl_Def,                                        # Current rtl.
                #
                rtl_arg:                ( raw::Id,
                                      raw::Type,
                                      rtl::Expression,
                                      rtl::Pos
                                    )
                                    -> Null_Or( raw::Expression ),

                non_rtl_arg:    ( raw::Id,
                                      raw::Type
                                    )
                                    -> Null_Or( raw::Expression )
              }
            ->
            raw::Expression
            ;

        # Make an error handler 
        #
        simple_error_handler:       String -> raw::Declaration;
        complex_error_handler:      String -> raw::Declaration;
        complex_error_handler_def:  Void   -> raw::Declaration;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext