| 1 |
= ToMachine |
| 2 |
|
| 3 |
<<ToMachine#>> is a translation pass from the <<RSSA#>> |
| 4 |
<<IntermediateLanguage#>> to the <<Machine#>> <<IntermediateLanguage#>>. |
| 5 |
|
| 6 |
== Description |
| 7 |
|
| 8 |
This pass converts from a <<RSSA#>> program into a <<Machine#>> program. |
| 9 |
|
| 10 |
It uses <<AllocateVariables#>>, <<Chunkify#>>, and <<ParallelMove#>>. |
| 11 |
|
| 12 |
== Implementation |
| 13 |
|
| 14 |
* https://github.com/MLton/mlton/blob/master/mlton/backend/backend.sig[`backend.sig`] |
| 15 |
* https://github.com/MLton/mlton/blob/master/mlton/backend/backend.fun[`backend.fun`] |
| 16 |
|
| 17 |
== Details and Notes |
| 18 |
|
| 19 |
Because the MLton runtime system is shared by all <<Codegen#,codegens>>, it is most |
| 20 |
convenient to decide on stack layout _before_ any <<Codegen#,codegen>> takes over. |
| 21 |
In particular, we compute all the stack frame info for each <<RSSA#>> |
| 22 |
function, including stack size, <<GarbageCollection#,garbage collector>> |
| 23 |
masks for each frame, etc. To do so, the <<Machine#>> |
| 24 |
<<IntermediateLanguage#>> imagines an abstract machine with an infinite |
| 25 |
number of temporaries of every size. A liveness analysis |
| 26 |
determines, for each variable, whether or not it is live across a |
| 27 |
point where the runtime system might take over (for example, any |
| 28 |
garbage collection point) or a non-tail call to another <<RSSA#>> |
| 29 |
function. Those that are live go on the stack, while those that |
| 30 |
aren't live go into temporaries. From this information, we know |
| 31 |
all we need to about each stack frame. On the downside, nothing |
| 32 |
further on is allowed to change this stack info; it is set in stone. |