4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>ToMachine</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
19 <body class="article">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="ToMachine">ToMachine</a> is a translation pass from the <a href="RSSA">RSSA</a>
32 <a href="IntermediateLanguage">IntermediateLanguage</a> to the <a href="Machine">Machine</a> <a href="IntermediateLanguage">IntermediateLanguage</a>.</p></div>
36 <h2 id="_description">Description</h2>
37 <div class="sectionbody">
38 <div class="paragraph"><p>This pass converts from a <a href="RSSA">RSSA</a> program into a <a href="Machine">Machine</a> program.</p></div>
39 <div class="paragraph"><p>It uses <a href="AllocateRegisters">AllocateRegisters</a>, <a href="Chunkify">Chunkify</a>, and <a href="ParallelMove">ParallelMove</a>.</p></div>
43 <h2 id="_implementation">Implementation</h2>
44 <div class="sectionbody">
45 <div class="ulist"><ul>
48 <a href="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.sig"><span class="monospaced">backend.sig</span></a>
53 <a href="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.fun"><span class="monospaced">backend.fun</span></a>
60 <h2 id="_details_and_notes">Details and Notes</h2>
61 <div class="sectionbody">
62 <div class="paragraph"><p>Because the MLton runtime system is shared by all <a href="Codegen">codegens</a>, it is most
63 convenient to decide on stack layout <em>before</em> any <a href="Codegen">codegen</a> takes over.
64 In particular, we compute all the stack frame info for each <a href="RSSA">RSSA</a>
65 function, including stack size, <a href="GarbageCollection">garbage collector</a>
66 masks for each frame, etc. To do so, the <a href="Machine">Machine</a>
67 <a href="IntermediateLanguage">IntermediateLanguage</a> imagines an abstract machine with an infinite
68 number of (pseudo-)registers of every size. A liveness analysis
69 determines, for each variable, whether or not it is live across a
70 point where the runtime system might take over (for example, any
71 garbage collection point) or a non-tail call to another <a href="RSSA">RSSA</a>
72 function. Those that are live go on the stack, while those that
73 aren’t live go into psuedo-registers. From this information, we know
74 all we need to about each stack frame. On the downside, nothing
75 further on is allowed to change this stack info; it is set in stone.</p></div>
79 <div id="footnotes"><hr></div>
81 <div id="footer-text">
83 <div id="footer-badges">