[MLton] mlton code generation

Matthew Fluet fluet@cs.cornell.edu
Mon, 14 Mar 2005 12:35:40 -0500 (EST)


> Is there an easy way to instruct mlton to somehow show the code that it is
> generating for a user function.  

If you mean finding the exact sequence of C/assembly generated due to a 
particular

   fun f (...) = ...

in the source program, then you might try using the profiling 
infrastructure.  When a program is compiled with profiling, the front-end 
embeds pseudo-operations denoting the entry and exit of each function, 
which are preserved by the various optimizations and transformations, and 
should delineate the code correspoinding to a particular source function 
in the generated code.

Unfortunately, translating back from the MLtonProfileNNN labels to source 
code locations is something handled automatically by the mlprof tool, but 
could be a bit cumbersome to do by hand.  It probably wouldn't be too hard 
to augment either to compiler or mlprof to do this.  Then you could find 
all the MLtonProfileNNN labels associated with the function of interest 
and look for those labels.

You might also have luck with the -keep ssa2 -keep machine flags in 
conjunction with a -profile flag.  The SSA2 intermediate language 
displays Enter/Leave pseudo-operations with the name of source 
function/locations while the Machine intermediate language uses 
MLtonProfileNNN labels.  These two intermediate languages are only one 
lowering apart, so you might be able to find a non-profile label in the 
SSA2 IL near the beginning of the function you in which you are 
interested, and hope to find the same label in the Machine IL, now near 
the corresponding MLtonProfileNNN label.  Now you can look for that 
MLtonProfileNNN label in the generated C or assembly.