| 1 |
\section{Client Defined Constants} |
| 2 |
\subsubsection{Introduction} |
| 3 |
MLRISC allows the client to inject abstract |
| 4 |
\newdef{constants} that are resolved |
| 5 |
only at the end of the compilation phase into the instruction stream. |
| 6 |
These constants can be used whereever an integer literal is expected. |
| 7 |
Typical usage are stack frame offsets for spill locations which are only |
| 8 |
known after register allocation, |
| 9 |
and garbage collection and exception map which are resolved only |
| 10 |
when all address calculation are performed. |
| 11 |
|
| 12 |
\subsubsection{The Details} |
| 13 |
Client defined constants should satsify the following signature: |
| 14 |
\begin{SML} |
| 15 |
signature \mlrischref{instructions/constant.sig}{CONSTANT} = sig |
| 16 |
type const |
| 17 |
|
| 18 |
val toString : const -> string |
| 19 |
val valueOf : const -> int |
| 20 |
val hash : const -> word |
| 21 |
val == : const * const -> bool |
| 22 |
end |
| 23 |
\end{SML} |
| 24 |
|
| 25 |
The methods are: |
| 26 |
\begin{methods} |
| 27 |
toString & a pretty printing function \\ |
| 28 |
valueOf & returns the value of the constant \\ |
| 29 |
hash & returns the hash value of the constant \\ |
| 30 |
== & compare two constants for identity \\ |
| 31 |
\end{methods} |
| 32 |
|
| 33 |
The method \sml{toString} should be implemented in all cases. |
| 34 |
The method \sml{valueOf} is necessary only if machine code generation |
| 35 |
is used. The last two methods, \sml{hash} and \sml{==} are necessary |
| 36 |
only if SSA optimizations are used. |