Eliminate another warning.
[suif.git] / html / suif1_90.html
blob752d92f2b2a99bd1e79d1f9c8991a3069c3d3cd5
1 <HTML>
2 <HEAD>
3 <!-- This HTML file has been created by texi2html 1.54
4 from suif1.texi on 28 April 1999 -->
6 <TITLE>The SUIF Version 1 Library - Call-By-Ref Parameters</TITLE>
7 <link href="suif1_91.html" rel=Next>
8 <link href="suif1_89.html" rel=Previous>
9 <link href="suif1_toc.html" rel=ToC>
11 </HEAD>
12 <BODY>
13 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_89.html">previous</A>, <A HREF="suif1_91.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
14 <P><HR><P>
17 <H2><A NAME="SEC90" HREF="suif1_toc.html#TOC90">Call-By-Reference Parameters</A></H2>
18 <P>
19 <A NAME="IDX649"></A>
21 </P>
22 <P>
23 Procedure parameters in Fortran are passed by reference. SUIF uses
24 call-by-value parameters and implements call-by-reference parameters by
25 passing pointers to the actual arguments. When the formal parameters
26 are used, the pointers must be dereferenced. However, one of the
27 primary advantages of compiling Fortran programs is that there are no
28 pointers in the source code. If not for the call-by-reference parameter
29 pointers, most compiler passes that only deal with Fortran can be
30 simplified by not having to deal with pointers. Thus the SUIF Fortran
31 form automatically converts the code to make it appear that the
32 parameters are passed by reference. The parameters are changed to
33 call-by-reference types instead of pointers and the pointer dereferences
34 are temporarily removed.
36 </P>
37 <P>
38 <A NAME="IDX650"></A>
39 <A NAME="IDX651"></A>
40 The <CODE>make_ref_params</CODE> function is used to convert call-by-reference
41 parameters in a procedure to the Fortran form. It must be called before
42 converting the procedure body to expression trees. This is done
43 automatically by the <CODE>read_proc</CODE> method for a <CODE>proc_sym</CODE> if
44 the <CODE>use_fortran_form</CODE> flag is set. Before writing a procedure to
45 an output file, the call-by-reference parameters must be converted back
46 to pointers using the <CODE>undo_ref_params</CODE> function. Since it is
47 illegal to write out a procedure in the Fortran form, the
48 <CODE>write_proc</CODE> method for the <CODE>proc_sym</CODE> always calls
49 <CODE>undo_ref_params</CODE>; you do not need to call it directly. Both
50 <CODE>make_ref_params</CODE> and <CODE>undo_ref_params</CODE> are defined in the
51 file <TT>`callbyref.cc'</TT>.
53 </P>
54 <P>
55 The Fortran front-end must identify call-by-reference formal parameters
56 by putting <CODE>call_by_ref</CODE> annotations (see section <A HREF="suif1_76.html#SEC76">Call-By-Reference Annotations</A>)
57 on the pointer types used by those parameters. Before actually changing
58 the type of a call-by-reference parameter and removing its dereferences,
59 <CODE>make_ref_params</CODE> checks that the pointer parameter is neither
60 addressed nor assigned within the procedure. If this check fails, the
61 pointer is not a valid call-by-reference parameter, so
62 <CODE>make_ref_params</CODE> prints a warning message and does not convert
63 that parameter. Otherwise, it goes ahead and changes the type of the
64 parameter from a pointer to a call-by-reference type (see section <A HREF="suif1_67.html#SEC67">Modifier Types</A>). Any dereferences of that pointer within the procedure are
65 removed, and other references to the pointer are changed to <CODE>ldc</CODE>
66 (load constant) instructions that take the address of the parameter.
67 The end result of all this is that it appears that the parameters are
68 passed by reference. Note that the call sites are not changed; the
69 actual arguments for call-by-reference parameters are still passed as
70 pointers.
72 </P>
73 <P>
74 The <CODE>undo_ref_params</CODE> function does as its name suggests and undoes
75 the transformations applied by <CODE>make_ref_params</CODE>. The only
76 potential complication is that while in the Fortran form the user may
77 have used the call-by-reference parameters in ways that cannot be
78 expressed outside of the Fortran form. Specifically, the
79 call-by-reference parameters cannot be used as index variables of
80 <CODE>for</CODE> loops (see section <A HREF="suif1_17.html#SEC17">For Nodes</A>), and they cannot be used as bounds
81 in array types (see section <A HREF="suif1_63.html#SEC63">Array Types</A>). Both of those uses require direct
82 references to variable symbols, and there is no place to insert the
83 pointer dereferences required outside of Fortran form.
85 </P>
87 <P><HR><P>
88 <p>Go to the <A HREF="suif1_1.html">first</A>, <A HREF="suif1_89.html">previous</A>, <A HREF="suif1_91.html">next</A>, <A HREF="suif1_113.html">last</A> section, <A HREF="suif1_toc.html">table of contents</A>.
89 </BODY>
90 </HTML>