Reputation: 202675
I have software written in Standard ML (henceforth SML) which I'd like to make portable across three compilers.
Standard ML of New Jersey is the easiest, as their Compilation Manager does the dependency analysis for you.
MLton uses a similar format to SML/NJ, but it requires that files be listed in dependency order, similar to Unix libraries.
Moscow ML uses an ordinary Makefile, but requires that dependencies be listed on the command line (and so ideally go into the Makefile).
What I'd like to do is take a list of SML source files and discover dependencies between files. Here are the ways I've tried and failed:
The SML/NJ Compilation Manager produces a dependency graph, but it is not a graph of files. Instead it contains a big collection of undocumented compiler internals. Turning that into a dependency graph on files has been tried since at least 2009; nobody has done it.
If I once get files into dependency order, I can get def/use information, which includes source code position, from MLton. So if I find a partial solution that gets files in order for MLton, and I can use that to get a complete solution.
I'm looking for ideas along the lines of simple tools that would give approximate answers. My code has two special properties:
open
.It seems to me that in this situation, a simple syntactic tool might be able to find external dependencies of a file. But I don't quite know how to write one.
Ideas?
Upvotes: 3
Views: 156
Reputation: 179189
Based on this thread, which is asking a similar question, I was able to write a small program that worked for me (I copied the produced list of file names, pasted it inside an .mlb file, and MLton was able to compile my little project). So, I can't guarantee anything, but it's probably a good start. Hope it helps.
group
structure Deps
is
$/basis.cm
$/pgraph.cm
$smlnj/cm.cm
deps.sml
structure Deps =
struct
structure PG = PortableGraph
fun list () =
let
fun println s = print (s ^ "\n")
fun extractFiles def =
case def of
PG.DEF { rhs = PG.COMPILE { src, ... }, ... } => SOME (#1 src)
| _ => NONE
val PG.GRAPH { defs, ... } =
(* Replace "sources.cm" with your project's .cm file path. *)
#graph (valOf (CM.Graph.graph "sources.cm"))
val files = List.mapPartial extractFiles defs
in
List.app println files
end
end
Upvotes: 1
Reputation: 4049
In the MLton repository, there is a cm2mlb
tool that will convert a .cm
file into an MLB file (util/cm2mlb of the git repo). If you put all of your files into a .cm
file you should be able to use this to generate an MLB file that will be in dependency order.
Upvotes: 1