Re: Inspecting the ILs
Matthew Fluet <[email protected]> Wed, 5 Apr 2017 06:06:12 -0400
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <CAMrhFL4YQahMv6HkKt3G8ZcxLDBqETi+z+VF5bQQtjE3PkfEkw@mail.gmail.com> |
On Tue, Apr 4, 2017 at 10:04 PM, Jake Zimmerman <[email protected]> wrote: > Is there a way to get MLton to show what a specific file compiles to in a > given intermediate language? For example, say I have a file foo.sml and I'm > curious what the code in that file looks like in AST or CoreML. Is there a > flag for this? (I should also mention that I have the compiler source > working locally, if that opens up more possibilities). There isn't really a way to limit the IR output to that corresponding to a single input file; for MLton, the "input" is always the whole-program and some fairly significant code motion can occur. However, it often isn't that hard to find the code of interest in the output IRs, especially if you give functions distinctive names (that are, somewhat, preserved through compilation). You can also compile with "-profile alloc -profile-val true" which inserts source code information into the IRs to support profiling. In the CoreML IR, you can look for "EnterLeave" expressions annotated with source file names that wrap the bodies of functions/declarations. For example: val rec 'a_4415 rev: 'a_4415 list -> 'a_4415 list = (fn x_1481: 'a_4415 list => EnterLeave (case x_1481 of (l: 'a_4415 list) => case l of [] => [] | ::['a_4415] (x: 'a_4415, l: 'a_4415 list) => (append ('a_4415) ((rev ('a_4415) l), [x])), rev list-rev.sml: 6)) val l: int32 list = EnterLeave ((tabulate_8 (int32) (0x3E8, (fn x_1482: int32 => EnterLeave (case x_1482 of i: int32 => i, fn list-rev.sml: 11)))), <val l> list-rev.sml: 11) val _ = EnterLeave ((+ (0x1, (hd_3 (int32) (rev (int32) l)))), <val _> list-rev.sml: 12) In the XML and later IRs, there are separate "Enter" and "Leave" statements, but they should always nest in a stack-like fashion. -- You received this message because you are subscribed to the Google Groups "MLton-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot