## find-set-of-compiledfiles-for-executable.pkg
# Compiled by:
#
src/app/makelib/makelib.sublib# A Mythryl "executable" is really the heap image from a running
# process, saved on disk: the only way to run it is to have
# bin/mythryl-runtime-intel32 load it into memory and continue execution.
#
# (These "executable" files have "#!/usr/bin/mythryl-runtime-intel32" lines at
# the top to make this process transparent to the casual user.)
#
# Building such an "executable" file involves four basic steps:
#
# 1) Compile all the source files for the application
# into .compiled files. (We may optionally combine some
# or all of these .compiled files into libraries.)
#
# 2) Make up a list of all the .compiled files needed
# by the application.
#
# 3) Topologically sort this list by dependencies,
# so that no .compiled file depends upon one later in
# in the sequence. (Later, by loading the .compiled
# files in this order, we will guarantee that
# when each one executes, all the resources it
# needs will be available.
#
# 4) Invoke the bare Mythryl runtime bin/mythryl-runtime-intel32
# with --runtime-compiledfiles-to-load=COMPILED_FILES_TO_LOAD
# where the latter file contains the above topologically
# sorted list. The last .compiled file in the list will
# contain code to dump the heap image via lib7::spawn_to_disk
# or a similar call.
#
# In this file we handle step (2) in the above sequence.
#
# Our main entrypoint is find_set_of_compiled_files_for_executable.
#
# We are given as input the root node of the file
# dependency graph for the application.
#
# We traverse this graph to find all reachable nodes --
# which is to say, all .compiled files needed by the application --
# and return this list.
stipulate
package tlt = thawedlib_tome; # thawedlib_tome is from
src/app/makelib/compilable/thawedlib-tome.pkg package flt = frozenlib_tome; # frozenlib_tome is from
src/app/makelib/freezefile/frozenlib-tome.pkg package sdg = scan_dependency_graph; # scan_dependency_graph is from
src/app/makelib/depend/scan-dependency-graph.pkg package shm = sharing_mode; # sharing_mode is from
src/app/makelib/stuff/sharing-mode.pkgherein
package find_set_of_compiled_files_for_executable {
# =========================================
#
scan_dependency_graph
=
sdg::scan_dependency_graph;
Info = FROZENLIB_TOME flt::Frozenlib_Tome
| THAWEDLIB_TOME tlt::Thawedlib_Tome
;
# Used (only) once, in makelib-g.pkg,
# to search library() return value:
#
fun same_info (FROZENLIB_TOME i )
(FROZENLIB_TOME i')
=>
flt::compare (i, i') == EQUAL;
same_info (THAWEDLIB_TOME i )
(THAWEDLIB_TOME i')
=>
tlt::compare (i, i') == EQUAL;
same_info _ _
=>
FALSE;
end;
#
fun find_set_of_compiled_files_for_executable
filepath_to_string # This is actually a String -> String fn -- probably needs to be renamed.
dependency_graph_root
=
{ nil = { l => [],
ss => frozenlib_tome_set::empty
};
#
fun cons ( { x, s => NULL }, { l, ss } ) => { l => x ! l, ss };
cons ( { x, s => THE i }, { l, ss } ) => { l => x ! l, ss => frozenlib_tome_set::add (ss, i) };
end;
#
fun a7file_info (flt: flt::Frozenlib_Tome)
=
# Now we implement part of the kludge which lets
# Mythryl code call functions in the C-coded runtime.
# For details, see the comments in
#
src/lib/core/init/runtime.pkg # Here, when we hit the runtime.pkg.compiled
# file, instead of writing out a normal line, we write out a
#
# RUNTIME_PACKAGE_PICKLEHASH=...
#
# line. Later,
#
# load_compiled_files__may_heapclean() in src/c/main/load-compiledfiles.c
#
# will key on this to substitute the special C-coded runtime exports list
#
# runtime_package__global
#
# for that generated by runtime.pkg.compiled:
#
case flt.runtime_package_picklehash
#
THE p
=>
{ x => ( FROZENLIB_TOME flt,
"RUNTIME_PACKAGE_PICKLEHASH=" + picklehash::to_hex p
),
s => NULL
};
#
NULL
=>
{ x = cat [ filepath_to_string flt.freezefile_name,
"@",
int::to_string flt.byte_offset_in_freezefile,
":",
flt::describe_frozenlib_tome flt
];
s = case flt.sharing_mode
#
shm::DO_NOT_SHARE => NULL;
_ => THE flt;
esac;
{ x => (FROZENLIB_TOME flt, x),
s
};
};
esac;
#
fun thawedlib_tome tome
=
{ x => (THAWEDLIB_TOME tome, filepath_to_string (tlt::make_compiledfile_name tome)),
s => NULL
};
per_graph_node
=
{ a7file_info, # What to extract from a built-library node.
thawedlib_tome, # What to extract from other nodes.
cons, # How to add one of above two to return my.
nil # Initial return value.
};
# Process every node reachable
# from inter_library_dependency_graph node 'dependency_graph_root'
# and return resulting Cons-ed up result:
#
sdg::scan_dependency_graph
per_graph_node
dependency_graph_root;
};
};
end;
## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.