perlfunc
root
<P>
<FONT SIZE=-1>B::CC</FONT> - Perl compiler's optimized
<FONT SIZE=-1>C</FONT> translation backend
<P>
<HR>
<P>
<PRE> perl -MO=CC[,OPTIONS] foo.pl
</PRE>
<P>
<HR>
<P>
This compiler backend takes Perl source and generates
<FONT SIZE=-1>C</FONT> source code corresponding to the flow of your
program. In other words, this backend is somewhat a ``real'' compiler in
the sense that many people think about compilers. Note however that,
currently, it is a very poor compiler in that although it generates
(mostly, or at least sometimes) correct code, it performs relatively few
optimisations. This will change as the compiler develops. The result is
that running an executable compiled with this backend may start up more
quickly than running the original Perl program (a feature shared by the <STRONG>C</STRONG> compiler backend--see <EM>B::C</EM>) and may also execute slightly faster. This is by no means a good
optimising compiler--yet.
<P>
<HR>
<H1><A NAME="OPTIONS">OPTIONS</A></H1>
<P>
If there are any non-option arguments, they are taken to be names of
objects to be saved (probably doesn't work properly yet). Without extra
arguments, it saves the main program.
<DL>
<DT><STRONG><A NAME="item__ofilename">-ofilename</A></STRONG><P>
<DD>
Output to filename instead of
<FONT SIZE=-1>STDOUT</FONT>
<P><DT><STRONG><A NAME="item__v">-v</A></STRONG><P>
<DD>
Verbose compilation (currently gives a few compilation statistics).
<P><DT><STRONG><A NAME="item__">--</A></STRONG><P>
<DD>
Force end of options
<P><DT><STRONG><A NAME="item__uPackname">-uPackname</A></STRONG><P>
<DD>
Force apparently unused subs from package Packname to be compiled. This
allows programs to use eval ``foo()'' even when sub foo is never seen to be
used at compile time. The down side is that any subs which really are never
used also have code generated. This option is necessary, for example, if
you have a signal handler foo which you initialise with <CODE>$SIG{BAR} = "foo"</CODE>.
<FONT SIZE=-1>A</FONT> better fix, though, is just to change it to <CODE>$SIG{BAR} = \&foo</CODE>. You can have multiple <STRONG>-u</STRONG>
options. The compiler tries to figure out which packages may possibly have
subs in which need compiling but the current version doesn't do it very
well. In particular, it is confused by nested packages (i.e. of the form <CODE>A::B</CODE>) where package <CODE>A</CODE> does not contain any subs.
<P><DT><STRONG><A NAME="item__mModulename">-mModulename</A></STRONG><P>
<DD>
Instead of generating source for a runnable executable, generate source for an
<FONT SIZE=-1>XSUB</FONT> module. The boot_Modulename function (which DynaLoader can look for) does the appropriate initialisation and runs the main part of the Perl source that is being compiled.
<P><DT><STRONG><A NAME="item__D">-D</A></STRONG><P>
<DD>
Debug options (concatenated or separate flags like <CODE>perl -D</CODE>).
<P><DT><STRONG><A NAME="item__Dr">-Dr</A></STRONG><P>
<DD>
Writes debugging output to
<FONT SIZE=-1>STDERR</FONT> just as it's about to write to the program's runtime (otherwise writes debugging info as comments in its
<FONT SIZE=-1>C</FONT> output).
<P><DT><STRONG><A NAME="item__DO">-DO</A></STRONG><P>
<DD>
Outputs each
<FONT SIZE=-1>OP</FONT> as it's compiled
<P><DT><STRONG><A NAME="item__Ds">-Ds</A></STRONG><P>
<DD>
Outputs the contents of the shadow stack at each
<FONT SIZE=-1>OP</FONT>
<P><DT><STRONG><A NAME="item__Dp">-Dp</A></STRONG><P>
<DD>
Outputs the contents of the shadow pad of lexicals as it's loaded for each
sub or the main program.
<P><DT><STRONG><A NAME="item__Dq">-Dq</A></STRONG><P>
<DD>
Outputs the name of each fake
<FONT SIZE=-1>PP</FONT> function in the queue as it's about to process it.
<P><DT><STRONG><A NAME="item__Dl">-Dl</A></STRONG><P>
<DD>
Output the filename and line number of each original line of Perl code as
it's processed (<CODE>pp_nextstate</CODE>).
<P><DT><STRONG><A NAME="item__Dt">-Dt</A></STRONG><P>
<DD>
Outputs timing information of compilation stages.
<P><DT><STRONG><A NAME="item__f">-f</A></STRONG><P>
<DD>
Force optimisations on or off one at a time.
<P><DT><STRONG><A NAME="item__ffreetmps_each_bblock">-ffreetmps-each-bblock</A></STRONG><P>
<DD>
Delays
<FONT SIZE=-1>FREETMPS</FONT> from the end of each statement to the end of
the each basic block.
<P><DT><STRONG><A NAME="item__ffreetmps_each_loop">-ffreetmps-each-loop</A></STRONG><P>
<DD>
Delays
<FONT SIZE=-1>FREETMPS</FONT> from the end of each statement to the end of
the group of basic blocks forming a loop. At most one of the
freetmps-each-* options can be used.
<P><DT><STRONG><A NAME="item__fomit_taint">-fomit-taint</A></STRONG><P>
<DD>
Omits generating code for handling perl's tainting mechanism.
<P><DT><STRONG><A NAME="item__On">-On</A></STRONG><P>
<DD>
Optimisation level (n = 0, 1, 2, ...). <STRONG>-O</STRONG> means <STRONG>-O1</STRONG>. Currently, <STRONG>-O1</STRONG> sets <STRONG>-ffreetmps-each-bblock</STRONG> and <STRONG>-O2</STRONG>
sets <STRONG>-ffreetmps-each-loop</STRONG>.
</DL>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
<PRE> perl -MO=CC,-O2,-ofoo.c foo.pl
perl cc_harness -o foo foo.c
</PRE>
<P>
Note that <CODE>cc_harness</CODE> lives in the <CODE>B</CODE> subdirectory of your perl library directory. The utility called <CODE>perlcc</CODE> may also be used to help make use of this compiler.
<P>
<PRE> perl -MO=CC,-mFoo,-oFoo.c Foo.pm
perl cc_harness -shared -c -o Foo.so Foo.c
</PRE>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
Plenty. Current status: experimental.
<P>
<HR>
<H1><A NAME="DIFFERENCES">DIFFERENCES</A></H1>
<P>
These aren't really bugs but they are constructs which are heavily tied to
perl's compile-and-go implementation and with which this compiler backend
cannot cope.
<P>
<HR>
<H2><A NAME="Loops">Loops</A></H2>
<P>
Standard perl calculates the target of ``next'', ``last'', and ``redo'' at
run-time. The compiler calculates the targets at compile-time. For example,
the program
<P>
<PRE> sub skip_on_odd { next NUMBER if $_[0] % 2 }
NUMBER: for ($i = 0; $i < 5; $i++) {
skip_on_odd($i);
print $i;
}
</PRE>
<P>
produces the output
<P>
<PRE> 024
</PRE>
<P>
with standard perl but gives a compile-time error with the compiler.
<P>
<HR>
<H2><A NAME="Context_of_">Context of ".."</A></H2>
<P>
The context (scalar or array) of the ``..'' operator determines whether it
behaves as a range or a flip/flop. Standard perl delays until runtime the
decision of which context it is in but the compiler needs to know the
context at compile-time. For example,
<P>
<PRE> @a = (4,6,1,0,0,1);
sub range { (shift @a)..(shift @a) }
print range();
while (@a) { print scalar(range()) }
</PRE>
<P>
generates the output
<P>
<PRE> 456123E0
</PRE>
<P>
with standard Perl but gives a compile-time error with compiled Perl.
<P>
<HR>
<H2><A NAME="Arithmetic">Arithmetic</A></H2>
<P>
Compiled Perl programs use native
<FONT SIZE=-1>C</FONT> arithemtic much more frequently than standard perl.
Operations on large numbers or on boundary cases may produce different
behaviour.
<P>
<HR>
<H2><A NAME="Deprecated_features">Deprecated features</A></H2>
<P>
Features of standard perl such as <CODE>$[</CODE> which have been deprecated in standard perl since Perl5 was released have
not been implemented in the compiler.
<P>
<HR>
<H1><A NAME="AUTHOR">AUTHOR</A></H1>
<P>
Malcolm Beattie, <CODE>mbeattie@sable.ox.ac.uk</CODE>
<HR>