Problems? Is your data what you think it is? | |
PerlMonks |
perlman:B::CCby root (Monk) |
on Dec 23, 1999 at 00:50 UTC ( [id://1156]=perlfunc: print w/replies, xml ) | Need Help?? |
B::CCSee the current Perl documentation for B::CC. Here is our local, out-dated (pre-5.6) version: B::CC - Perl compiler's optimized C translation backend
perl -MO=CC[,OPTIONS] foo.pl
This compiler backend takes Perl source and generates C 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 C compiler backend--see B::C) and may also execute slightly faster. This is by no means a good optimising compiler--yet.
OPTIONSIf 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.
EXAMPLES
perl -MO=CC,-O2,-ofoo.c foo.pl perl cc_harness -o foo foo.c
Note that
perl -MO=CC,-mFoo,-oFoo.c Foo.pm perl cc_harness -shared -c -o Foo.so Foo.c
BUGSPlenty. Current status: experimental.
DIFFERENCESThese 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.
LoopsStandard perl calculates the target of ``next'', ``last'', and ``redo'' at run-time. The compiler calculates the targets at compile-time. For example, the program
sub skip_on_odd { next NUMBER if $_[0] % 2 } NUMBER: for ($i = 0; $i < 5; $i++) { skip_on_odd($i); print $i; } produces the output
024 with standard perl but gives a compile-time error with the compiler.
Context of ".."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,
@a = (4,6,1,0,0,1); sub range { (shift @a)..(shift @a) } print range(); while (@a) { print scalar(range()) } generates the output
456123E0 with standard Perl but gives a compile-time error with compiled Perl.
ArithmeticCompiled Perl programs use native C arithemtic much more frequently than standard perl. Operations on large numbers or on boundary cases may produce different behaviour.
Deprecated features
Features of standard perl such as
AUTHOR
Malcolm Beattie, |
|