Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / B / CC.html
blobd9ad8d3bc731eb9636a7cd42e63d74f2e1adf25c
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>B::CC - Perl compiler's optimized C translation backend</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;B::CC - Perl compiler's optimized C translation backend</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#options">OPTIONS</a></li>
26 <li><a href="#examples">EXAMPLES</a></li>
27 <li><a href="#bugs">BUGS</a></li>
28 <li><a href="#differences">DIFFERENCES</a></li>
29 <ul>
31 <li><a href="#loops">Loops</a></li>
32 <li><a href="#context_of___">Context of ``..''</a></li>
33 <li><a href="#arithmetic">Arithmetic</a></li>
34 <li><a href="#deprecated_features">Deprecated features</a></li>
35 </ul>
37 <li><a href="#author">AUTHOR</a></li>
38 </ul>
39 <!-- INDEX END -->
41 <hr />
42 <p>
43 </p>
44 <h1><a name="name">NAME</a></h1>
45 <p>B::CC - Perl compiler's optimized C translation backend</p>
46 <p>
47 </p>
48 <hr />
49 <h1><a name="synopsis">SYNOPSIS</a></h1>
50 <pre>
51 perl -MO=CC[,OPTIONS] foo.pl</pre>
52 <p>
53 </p>
54 <hr />
55 <h1><a name="description">DESCRIPTION</a></h1>
56 <p>This compiler backend takes Perl source and generates C source code
57 corresponding to the flow of your program. In other words, this
58 backend is somewhat a ``real'' compiler in the sense that many people
59 think about compilers. Note however that, currently, it is a very
60 poor compiler in that although it generates (mostly, or at least
61 sometimes) correct code, it performs relatively few optimisations.
62 This will change as the compiler develops. The result is that
63 running an executable compiled with this backend may start up more
64 quickly than running the original Perl program (a feature shared
65 by the <strong>C</strong> compiler backend--see <em>B::C</em>) and may also execute
66 slightly faster. This is by no means a good optimising compiler--yet.</p>
67 <p>
68 </p>
69 <hr />
70 <h1><a name="options">OPTIONS</a></h1>
71 <p>If there are any non-option arguments, they are taken to be
72 names of objects to be saved (probably doesn't work properly yet).
73 Without extra arguments, it saves the main program.</p>
74 <dl>
75 <dt><strong><a name="item__2dofilename"><strong>-ofilename</strong></a></strong>
77 <dd>
78 <p>Output to filename instead of STDOUT</p>
79 </dd>
80 </li>
81 <dt><strong><a name="item__2dv"><strong>-v</strong></a></strong>
83 <dd>
84 <p>Verbose compilation (currently gives a few compilation statistics).</p>
85 </dd>
86 </li>
87 <dt><strong><a name="item__2d_2d"><strong>--</strong></a></strong>
89 <dd>
90 <p>Force end of options</p>
91 </dd>
92 </li>
93 <dt><strong><a name="item__2dupackname"><strong>-uPackname</strong></a></strong>
95 <dd>
96 <p>Force apparently unused subs from package Packname to be compiled.
97 This allows programs to use eval ``foo()'' even when sub foo is never
98 seen to be used at compile time. The down side is that any subs which
99 really are never used also have code generated. This option is
100 necessary, for example, if you have a signal handler foo which you
101 initialise with <code>$SIG{BAR} = &quot;foo&quot;</code>. A better fix, though, is just
102 to change it to <code>$SIG{BAR} = \&amp;foo</code>. You can have multiple <strong>-u</strong>
103 options. The compiler tries to figure out which packages may possibly
104 have subs in which need compiling but the current version doesn't do
105 it very well. In particular, it is confused by nested packages (i.e.
106 of the form <code>A::B</code>) where package <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#item_a"><code>A</code></a> does not contain any subs.</p>
107 </dd>
108 </li>
109 <dt><strong><a name="item__2dmmodulename"><strong>-mModulename</strong></a></strong>
111 <dd>
112 <p>Instead of generating source for a runnable executable, generate
113 source for an XSUB module. The boot_Modulename function (which
114 DynaLoader can look for) does the appropriate initialisation and runs
115 the main part of the Perl source that is being compiled.</p>
116 </dd>
117 </li>
118 <dt><strong><a name="item__2dd"><strong>-D</strong></a></strong>
120 <dd>
121 <p>Debug options (concatenated or separate flags like <code>perl -D</code>).</p>
122 </dd>
123 </li>
124 <dt><strong><a name="item__2ddr"><strong>-Dr</strong></a></strong>
126 <dd>
127 <p>Writes debugging output to STDERR just as it's about to write to the
128 program's runtime (otherwise writes debugging info as comments in
129 its C output).</p>
130 </dd>
131 </li>
132 <dt><strong><a name="item__2ddo"><strong>-DO</strong></a></strong>
134 <dd>
135 <p>Outputs each OP as it's compiled</p>
136 </dd>
137 </li>
138 <dt><strong><a name="item__2dds"><strong>-Ds</strong></a></strong>
140 <dd>
141 <p>Outputs the contents of the shadow stack at each OP</p>
142 </dd>
143 </li>
144 <dt><strong><a name="item__2ddp"><strong>-Dp</strong></a></strong>
146 <dd>
147 <p>Outputs the contents of the shadow pad of lexicals as it's loaded for
148 each sub or the main program.</p>
149 </dd>
150 </li>
151 <dt><strong><a name="item__2ddq"><strong>-Dq</strong></a></strong>
153 <dd>
154 <p>Outputs the name of each fake PP function in the queue as it's about
155 to process it.</p>
156 </dd>
157 </li>
158 <dt><strong><a name="item__2ddl"><strong>-Dl</strong></a></strong>
160 <dd>
161 <p>Output the filename and line number of each original line of Perl
162 code as it's processed (<code>pp_nextstate</code>).</p>
163 </dd>
164 </li>
165 <dt><strong><a name="item__2ddt"><strong>-Dt</strong></a></strong>
167 <dd>
168 <p>Outputs timing information of compilation stages.</p>
169 </dd>
170 </li>
171 <dt><strong><a name="item__2df"><strong>-f</strong></a></strong>
173 <dd>
174 <p>Force optimisations on or off one at a time.</p>
175 </dd>
176 </li>
177 <dt><strong><a name="item__2dffreetmps_2deach_2dbblock"><strong>-ffreetmps-each-bblock</strong></a></strong>
179 <dd>
180 <p>Delays FREETMPS from the end of each statement to the end of the each
181 basic block.</p>
182 </dd>
183 </li>
184 <dt><strong><a name="item__2dffreetmps_2deach_2dloop"><strong>-ffreetmps-each-loop</strong></a></strong>
186 <dd>
187 <p>Delays FREETMPS from the end of each statement to the end of the group
188 of basic blocks forming a loop. At most one of the freetmps-each-*
189 options can be used.</p>
190 </dd>
191 </li>
192 <dt><strong><a name="item__2dfomit_2dtaint"><strong>-fomit-taint</strong></a></strong>
194 <dd>
195 <p>Omits generating code for handling perl's tainting mechanism.</p>
196 </dd>
197 </li>
198 <dt><strong><a name="item__2don"><strong>-On</strong></a></strong>
200 <dd>
201 <p>Optimisation level (n = 0, 1, 2, ...). <strong>-O</strong> means <strong>-O1</strong>.
202 Currently, <strong>-O1</strong> sets <strong>-ffreetmps-each-bblock</strong> and <strong>-O2</strong>
203 sets <strong>-ffreetmps-each-loop</strong>.</p>
204 </dd>
205 </li>
206 </dl>
208 </p>
209 <hr />
210 <h1><a name="examples">EXAMPLES</a></h1>
211 <pre>
212 perl -MO=CC,-O2,-ofoo.c foo.pl
213 perl cc_harness -o foo foo.c</pre>
214 <p>Note that <code>cc_harness</code> lives in the <code>B</code> subdirectory of your perl
215 library directory. The utility called <code>perlcc</code> may also be used to
216 help make use of this compiler.</p>
217 <pre>
218 perl -MO=CC,-mFoo,-oFoo.c Foo.pm
219 perl cc_harness -shared -c -o Foo.so Foo.c</pre>
221 </p>
222 <hr />
223 <h1><a name="bugs">BUGS</a></h1>
224 <p>Plenty. Current status: experimental.</p>
226 </p>
227 <hr />
228 <h1><a name="differences">DIFFERENCES</a></h1>
229 <p>These aren't really bugs but they are constructs which are heavily
230 tied to perl's compile-and-go implementation and with which this
231 compiler backend cannot cope.</p>
233 </p>
234 <h2><a name="loops">Loops</a></h2>
235 <p>Standard perl calculates the target of ``next'', ``last'', and ``redo''
236 at run-time. The compiler calculates the targets at compile-time.
237 For example, the program</p>
238 <pre>
239 sub skip_on_odd { next NUMBER if $_[0] % 2 }
240 NUMBER: for ($i = 0; $i &lt; 5; $i++) {
241 skip_on_odd($i);
242 print $i;
243 }</pre>
244 <p>produces the output</p>
245 <pre>
246 024</pre>
247 <p>with standard perl but gives a compile-time error with the compiler.</p>
249 </p>
250 <h2><a name="context_of___">Context of ``..''</a></h2>
251 <p>The context (scalar or array) of the ``..'' operator determines whether
252 it behaves as a range or a flip/flop. Standard perl delays until
253 runtime the decision of which context it is in but the compiler needs
254 to know the context at compile-time. For example,</p>
255 <pre>
256 @a = (4,6,1,0,0,1);
257 sub range { (shift @a)..(shift @a) }
258 print range();
259 while (@a) { print scalar(range()) }</pre>
260 <p>generates the output</p>
261 <pre>
262 456123E0</pre>
263 <p>with standard Perl but gives a compile-time error with compiled Perl.</p>
265 </p>
266 <h2><a name="arithmetic">Arithmetic</a></h2>
267 <p>Compiled Perl programs use native C arithmetic much more frequently
268 than standard perl. Operations on large numbers or on boundary
269 cases may produce different behaviour.</p>
271 </p>
272 <h2><a name="deprecated_features">Deprecated features</a></h2>
273 <p>Features of standard perl such as <a href="file://C|\msysgit\mingw\html/pod/perlvar.html#item___"><code>$[</code></a> which have been deprecated
274 in standard perl since Perl5 was released have not been implemented
275 in the compiler.
277 </p>
279 </p>
280 <hr />
281 <h1><a name="author">AUTHOR</a></h1>
282 <p>Malcolm Beattie, <code>mbeattie@sable.ox.ac.uk</code>
284 </p>
285 <table border="0" width="100%" cellspacing="0" cellpadding="3">
286 <tr><td class="block" style="background-color: #cccccc" valign="middle">
287 <big><strong><span class="block">&nbsp;B::CC - Perl compiler's optimized C translation backend</span></strong></big>
288 </td></tr>
289 </table>
291 </body>
293 </html>