| 1 |
\section{Machine Code Emitters} |
| 2 |
|
| 3 |
\subsubsection{Overview} |
| 4 |
MLRISC lets the client to directly emit machine code and bypass the traditional |
| 5 |
assembly mechanism. |
| 6 |
|
| 7 |
Machine code emitters in MLRISC satisfy the signature |
| 8 |
\mlrischref{emit/instruction-emitter.sig}{INSTRUCTION\_EMITTER}, |
| 9 |
which is defined as: |
| 10 |
\begin{SML} |
| 11 |
signature INSTRUCTION_EMITTER = |
| 12 |
sig |
| 13 |
|
| 14 |
structure I : \href{instructions.html}{INSTRUCTIONS} |
| 15 |
structure C : \href{cells.html}{CELLS} |
| 16 |
structure S : \href{streams.html}{INSTRUCTION_STREAM} |
| 17 |
structure P : \href{pseudo-ops.html}{PSEUDO_OPS} |
| 18 |
sharing I.C = C |
| 19 |
sharing S.P = P |
| 20 |
|
| 21 |
val makeStream : Annotations.annotations -> |
| 22 |
((int -> int) -> I.instruction -> unit, |
| 23 |
unit,'b,'c,'d,'e) S.stream |
| 24 |
|
| 25 |
end |
| 26 |
\end{SML} |
| 27 |
|
| 28 |
The function \sml{makeStream} returns an instruction stream. |
| 29 |
The output, a stream of bytes, is direct to the client supplied |
| 30 |
structure which satisfy the |
| 31 |
\mlrischref{emit/code-string.sig}{CODE\_STRING} interface. |
| 32 |
This signature is defined as follows: |
| 33 |
\begin{SML} |
| 34 |
signature CODE_STRING = sig |
| 35 |
type code_string |
| 36 |
val init : int -> unit |
| 37 |
val update : int * Word8.word -> unit |
| 38 |
val getCodeString : unit -> code_string |
| 39 |
end |
| 40 |
\end{SML} |
| 41 |
|
| 42 |
\subsubsection{More Details} |
| 43 |
|
| 44 |
Machine code emitters are automatically generated by the |
| 45 |
\href{mlrisc-md.html}{MDGen} tool. Some specific generated |
| 46 |
emitters are listed below: |
| 47 |
\begin{enumerate} |
| 48 |
\item \mlrischref{sparc/emit/sparcMC.sml}{Sparc} |
| 49 |
\item \mlrischref{hppa/emit/hppaMC.sml}{Hppa} |
| 50 |
\item \mlrischref{alpha/emit/alphaMC.sml}{Alpha} |
| 51 |
\item \mlrischref{ppc/emit/ppcMC.sml}{Power PC} |
| 52 |
\item \mlrischref{x86/emit/x86MC.sml}{X86} |
| 53 |
\end{enumerate} |