Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 3.02 KB | None | 0 0
  1. \subsection{Rename operator}
  2. \begin{PipsPass}{rename_operator}
  3. This transformation replaces all language operators by functions calls.
  4. \end{PipsPass}
  5.  
  6. \begin{PipsMake}
  7. rename_operator > MODULE.code
  8.                < MODULE.code
  9.         < PROGRAM.entities
  10. \end{PipsMake}
  11.  
  12. 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.
  13. \newline
  14. \begin{minipage}{\textwidth}
  15. For instance, the following code:
  16. \begin{lstlisting}
  17. float foo(float a, float b)
  18. {
  19.    return a + b;
  20. }
  21. \end{lstlisting}
  22. \end{minipage}
  23.  
  24. \begin{minipage}{\textwidth}
  25. would become using the default configuration:
  26. \begin{lstlisting}
  27. float foo(float a, float b)
  28. {
  29.    return op_addf(a, b);
  30. }
  31. \end{lstlisting}
  32. \end{minipage}
  33.  
  34.  
  35. \emph{OP~NAME} is given by the following table:
  36. \begin{center}
  37. \begin{tabular}{r l}
  38.  + & add \\
  39.  - & sub \\
  40.  * & mul \\
  41.  / & div \\
  42. \end{tabular}
  43. \end{center}
  44.  
  45. 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.
  46.  
  47. \begin{PipsProp}{RENAME_OPERATOR_OPS}
  48. RENAME_OPERATOR_OPS "add sub mul div"
  49. \end{PipsProp}
  50.  
  51. Assuming that all arguments of the operator have the same type. \emph{SUFFIX} is deduced using the following table:
  52. \begin{center}
  53. \begin{tabular}{r l}
  54.  int & i \\
  55.  float & f \\
  56. \end{tabular}
  57. \end{center}
  58.  
  59. 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.
  60. \begin{PipsProp}{RENAME_OPERATOR_SUFFIXES}
  61. RENAME_OPERATOR_SUFFIXES "i f"
  62. \end{PipsProp}
  63.  
  64. 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\_}.
  65.  
  66. \begin{PipsProp}{RENAME_OPERATOR_PREFIX}
  67. RENAME_OPERATOR_PREFIX "op_"
  68. \end{PipsProp}
  69.  
  70. 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:
  71. \begin{lstlisting}
  72. for(i=0; i < n; i++)
  73. \end{lstlisting}
  74. will be rewritten :
  75. \begin{lstlisting}
  76. for(i=0; i <= op_subi(n,1); i++)
  77. \end{lstlisting}
  78. If you want it to be rewritten :
  79. \begin{lstlisting}
  80. for(op_assigni(&i,0); op_leqi(i,op_subi(n,1)); op_inci(i,1))
  81. \end{lstlisting}
  82. you should set the property \PipsPropRef{RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE} to \emph{TRUE}.
  83. This is not the default behaviour, because in most case you don't want to rewrite For loop like this.
  84.  
  85. \begin{PipsProp}{RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE}
  86. RENAME_OPERATOR_REWRITE_DO_LOOP_RANGE FALSE
  87. \end{PipsProp}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement