PreviousUpNext

15.3.222  src/lib/compiler/execution/compiledfile/compiledfile.api

## compiledfile.api
## author: Matthias Blume (blume@research.bell-labs.com

# Compiled by:
#     src/lib/compiler/execution/execute.sublib


# For a high-level overview see:
#
#     src/A.COMPILEDFILE.OVERVIEW


# This revised version of api Compiledfile is now machine-independent.
# Moreover, it deals with the file format only and does not know how to
# create new compiledfile contents (aka "compile") or how to interpret the
# pickles.  As a result, it does not statically depend on the compiler.
# (Eventually we might want to support a light-weight compiledfile loader.)

# This api is implemented in:
#
#     src/lib/compiler/execution/compiledfile/compiledfile.pkg

stipulate
    package bio =  data_file__premicrothread;                   # data_file__premicrothread             is from   src/lib/std/src/posix/data-file--premicrothread.pkg
    package cs  =  code_segment;                                # code_segment                          is from   src/lib/compiler/execution/code-segments/code-segment.pkg
    package it  =  import_tree;                                 # import_tree                           is from   src/lib/compiler/execution/main/import-tree.pkg
    package ph  =  picklehash;                                  # picklehash                            is from   src/lib/compiler/front/basics/map/picklehash.pkg
    package lt  =  linking_mapstack;                            # linking_mapstack                      is from   src/lib/compiler/execution/linking-mapstack/linking-mapstack.pkg
    package sa  =  supported_architectures;                     # supported_architectures               is from   src/lib/compiler/front/basics/main/supported-architectures.pkg
herein

    api Compiledfile {
        #
        #
        Compiledfile;

        exception FORMAT_ERROR;


        # When the compiler is done with a sourcefile,
        # it reports the sizes of the various principal
        # compile outputs using this type:
        #
        Component_Bytesizes
            =
            { symbolmapstack_bytesize:  Int,            # symbol table of externally visible functions, types etc.
              inlinables_bytesize:      Int,            # machine-independent code for exported inlinable functions, in A-Normal form.
              data_bytesize:            Int,            # Literals.
              code_bytesize:            Int             # The compiled code proper.
            };



        # A pickle is a bytestring representation of some
        # in-memory datastructure such as a symbol table
        # or compiled code segments.
        #
        # We pervasively use hashes of these pickles as
        # compact and convenient names for them.
        #
        Pickle
            =
            { picklehash: ph::Picklehash,
              pickle:     vector_of_one_byte_unts::Vector
            };

        hash_of_symbolmapstack_pickle:  Compiledfile ->           ph::Picklehash;
        hash_of_pickled_exports:      Compiledfile ->  Null_Or( ph::Picklehash );
        hash_of_pickled_inlinables:   Compiledfile ->           ph::Picklehash;

        picklehash_list:              Compiledfile ->  List( ph::Picklehash );
        pickle_of_symbolmapstack:       Compiledfile ->  Pickle;
        pickle_of_inlinables:         Compiledfile ->  Pickle;

        get_compiledfile_version:     Compiledfile -> String;                           # Something like:   "version-$ROOT/src/app/makelib/(makelib-lib.lib):compilable/thawedlib-tome.pkg-1187780741.285"



        # Create the abstract compiledfile contents 
        #
        make_compiledfile
          :
          { import_trees:           List( it::Import_Tree ),
            export_picklehash:      Null_Or( ph::Picklehash ),
            picklehash_list:        List(    ph::Picklehash ),
            symbolmapstack:         Pickle,
            inlinables:             Pickle,
            compiledfile_version:   String,                                             # Something like:   "version-$ROOT/src/app/makelib/(makelib-lib.lib):compilable/thawedlib-tome.pkg-1187780741.285"
            code_and_data_segments: cs::Code_And_Data_Segments
          }
          ->
          Compiledfile;



        # Read just the version: 
        #
        read_version:  bio::Input_Stream -> String;



        read_compiledfile                                                               # Read compiledfile contents from an IO stream -- in practice, from disk. 
          :
          { stream:                     bio::Input_Stream,
            architecture:               sa::Supported_Architectures,                    # Used to prevent linking into a program of compiled code for an inappropriate machine architecture -- see read_compiledfile logic.
            compiler_version_id:        List(Int)
            
          }
          ->
          { compiledfile:               Compiledfile,
            component_bytesizes:        Component_Bytesizes
          };



        write_compiledfile                                                              # Write compiledfile contents to an IO stream -- in practice, to disk.
          :
          { compiledfile:                       Compiledfile,
            drop_symbol_and_inlining_mapstacks: Bool,                                   # We keep symbol tables in foo.pkg.compiled files, drop them in foo.lib.frozen files.
            stream:                             bio::Output_Stream,
            #
            architecture:                       sa::Supported_Architectures,            # Used to prevent linking into a program of compiled code for an inappropriate machine architecture -- see read_compiledfile logic.
            compiler_version_id:                List(Int)
          }
          ->
          Component_Bytesizes;


        compiledfile_bytesize_on_disk                                                   # Pre-compute the eventual disk size of a compiledfile.  We need this when computing library header info etc.
            :
            { compiledfile:                     Compiledfile,
              drop_symbol_and_inlining_mapstacks:       Bool                                    # Must match value to be used in write_compiledfile
            }
            ->
            Int;




        # Given a linking dictionary, link in
        # the code chunk contained in some given
        # compiledfile.
        #
        # The result is the delta dictionary
        # containing the exports (if any)
        # resulting from this link operation.
        #
        link_and_run_compiledfile
            :
            ( Compiledfile,
              lt::Picklehash_To_Heapchunk_Mapstack,
              (Exception -> Exception)
            )
            ->
            lt::Picklehash_To_Heapchunk_Mapstack;
    };
end;


## (C) 2001 Lucent Technologies, Bell Labs
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext