Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \subsection{Rename operator}
- \begin{PipsPass}{rename_operator}
- This transformation replaces all language operators by functions calls.
- \end{PipsPass}
- \begin{PipsMake}
- rename_operator > MODULE.code
- < MODULE.code
- < PROGRAM.entities
- \end{PipsMake}
- Function name is deduced from operator name, operator arguments type and a prefix. Each function name is built using the pattern [PREFIX][OP~NAME][SUFFIX] (eg: \emph{int} + \emph{int} will lead to \emph{op\_addi}). The replacement function must have been declared, otherwise a warning is asserted and the operator is ignored.
- \newline
- \begin{minipage}{\textwidth}
- For instance, the following code:
- \begin{lstlisting}
- float foo(float a, float b)
- {
- return a + b;
- }
- \end{lstlisting}
- \end{minipage}
- \begin{minipage}{\textwidth}
- would become using the default configuration:
- \begin{lstlisting}
- float foo(float a, float b)
- {
- return op_addf(a, b);
- }
- \end{lstlisting}
- \end{minipage}
- \emph{OP~NAME} is given by the following table:
- \begin{center}
- \begin{tabular}{r l}
- + & add \\
- - & sub \\
- * & mul \\
- / & div \\
- \end{tabular}
- \end{center}
- Using the property \PipsPropRef{RENAME_OPERATOR_OPS}, it is possible to give a restrictive list of operator name on which operator renaming should be applied. Every operator not listed in this list will be ignored.
- \begin{PipsProp}{RENAME_OPERATOR_OPS}
- RENAME_OPERATOR_OPS "add sub mul div"
- \end{PipsProp}
- Assuming that all arguments of the operator have the same type. \emph{SUFFIX} is deduced using the following table:
- \begin{center}
- \begin{tabular}{r l}
- int & i \\
- float & f \\
- \end{tabular}
- \end{center}
- Using the property \PipsPropRef{RENAME_OPERATOR_SUFFIXES}, it is possible to give a restrictive list of suffix on which operator renaming should be applied. Every type not listed in this list will be ignored.
- \begin{PipsProp}{RENAME_OPERATOR_SUFFIXES}
- RENAME_OPERATOR_SUFFIXES "i f"
- \end{PipsProp}
- The \emph{PREFIX} is a common prefix defined by the property \PipsPropRef{RENAME_OPERATOR_PREFIX} which is applied to each operators. It can be used to choose between multiple implementations of the same operator. The default value is \emph{op\_}.
- \begin{PipsProp}{RENAME_OPERATOR_PREFIX}
- RENAME_OPERATOR_PREFIX "op_"
- \end{PipsProp}
- In Pips, C For loop like \lstinline$for(i=0; i < n; i++)$ is represented by a Fortran-like range-based Do loop \lstinline$do i = 1,n-1$. Thus, the code:
- \begin{lstlisting}
- for(i=0; i < n; i++)
- \end{lstlisting}
- will be rewritten :
- \begin{lstlisting}
- for(i=0; i <= op_subi(n,1); i++)
- \end{lstlisting}
- If you want it to be rewritten :
- \begin{lstlisting}
- for(op_assigni(&i,0); op_leqi(i,op_subi(n,1)); op_inci(i,1))
- \end{lstlisting}
- you should set the property \PipsPropRef{RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE} to \emph{TRUE}.
- This is not the default behaviour, because in most case you don't want to rewrite For loop like this.
- \begin{PipsProp}{RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE}
- RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE FALSE
- \end{PipsProp}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement