B::C - Perl compiler's C backend
perl -MO=C[,OPTIONS] foo.pl
This compiler backend takes Perl source and generates C source code corresponding to the internal structures that perl uses to run your program. When the generated C source is compiled and run, it cuts out the time which perl would have taken to load and parse your program into its internal semi-compiled form. That means that compiling with this backend will not help improve the runtime execution speed of your program but may improve the start-up time. Depending on the environment in which your program runs this may be either a help or a hindrance.
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.
Output to filename instead of STDOUT
Verbose compilation. Currently gives a few compilation statistics.
Force end of options
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 $SIG{BAR} = "foo". A better fix, though, is just to change it to $SIG{BAR} = \&foo. You can have multiple -u 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 A::B) where package A does not contain any subs.
$SIG{BAR} = "foo"
$SIG{BAR} = \&foo
A::B
A
[OPTIONS]
Debug options (concatenated or separate flags like perl -D). Verbose debugging options are crucial, because we have no interactive debugger at the early CHECK step, where the compilation happens.
perl -D
All Walkop'ed OPs
OP Type,Flags,Private
prints SV/RE/RV information on saving
COPs, prints COPs as processed (incl. file & line num)
prints AV information on saving
prints CV information on saving
prints GV information on saving
prints MAGIC information on saving
prints cached package information, if used or not.
Together with -Dp also prints every walked package symbol.
do not print -D information when parsing for the unused subs.
Force options/optimisations on or off one at a time. You can explicitly disable an option using -fno-option. All options default to disabled.
Copy-on-grow: PVs declared and initialised statically. Does not work yet with Perl 5.10 and higher.
Save package::DATA filehandles ( only available with PerlIO ). Does not work yet on Perl 5.6, 5.11 and non-threaded 5.10, and is enabled automatically where it is known to work.
Optimize the initialization of op_ppaddr.
Optimize the initialization of cop_warnings.
Use the script name instead of the program name as $0.
Save compile-time modifications to the %SIG hash.
Omit COP info (nextstate without labels, unneeded NULL ops, files, linenumbers) for ~10% faster execution and less space, but warnings and errors will have no file and line infos. It will most likely not work yet. (was -fbypass-nullops in earlier compilers)
Faster pre-initialization of AVs (arrays)
Optimisation level (n = 0, 1, 2, 3, 4). -O means -O1.
Disable all optimizations.
Enable -fcog.
Enable -O1 plus -fppaddr, -fwarn-sv, -fav-init.
Enable -O2 plus -fsave-sig-hash, -fsave-data.
Enable -O3 plus -fcop. Very unsafe.
Some C compilers impose an arbitrary limit on the length of string constants (e.g. 2048 characters for Microsoft Visual C++). The -llimit options tells the C backend not to generate string literals exceeding that limit.
Evaluate ARG at startup
perl -MO=C,-ofoo.c foo.pl perl cc_harness -o foo foo.c
Note that cc_harness lives in the B subdirectory of your perl library directory. The utility called perlcc may also be used to help make use of this compiler.
cc_harness
B
perlcc
perlcc foo.pl perl -MO=C,-v,-DcA,-l2048 bar.pl > /dev/null
A few. Current status: experimental.
5.6: reading from __DATA__ handles (15) AUTOLOAD xsubs (27)
5.8: AUTOLOAD xsubs (27)
5.10: reading from __DATA__ handles (15) non-threaded destruction of static pvs for -O1
5.11: reading from __DATA__ handles (15)
Malcolm Beattie, mbeattie@sable.ox.ac.uk, Reini Urban, rurban@cpan.org
mbeattie@sable.ox.ac.uk
rurban@cpan.org
perlcompiler for a general overview, B::CC for the optimising C compiler, B::Bytecode + ByteLoader for the bytecode compiler, Od for source level debugging in the B::Debugger, illguts for the illustrated Perl guts, perloptree for the Perl optree.
To install B::C, copy and paste the appropriate command in to your terminal.
cpanm
cpanm B::C
CPAN shell
perl -MCPAN -e shell install B::C
For more information on module installation, please visit the detailed CPAN module installation guide.