The C Code Generators
The remaining code generators, B::C and B::CC, both produce C code instead of serialized Perl opcodes.
The code they generate is far from readable, and if you try to read it
you’ll just go blind. It’s not something you can use to plug little
translated Perl-to-C bits into a larger C program.
The B::C module just writes out
the C data structures needed to recreate the entire Perl runtime
environment. You get a dedicated interpreter with all the compiler-built
data structures preinitialized. In some senses, the code generated is
like what B::Bytecode produces. Both are a straight translation of the opcode
trees that the compiler built, but where B::Bytecode lays them out in symbolic form to
be recreated later and plugged into a running Perl interpreter, B::C lays those opcodes down in C. When you
compile this C code with your C compiler and link in the Perl library,
the resulting program won’t need a Perl interpreter installed on the
target system. (It might need some shared libraries, though, if you
didn’t link everything statically.) However, this program isn’t really
any different than the regular Perl interpreter that runs your script.
It’s just precompiled into a standalone executable image.
The B::CC module, however,
tries to do more than that. The beginning of the C source file it
generates looks pretty much like what B::C produced[170] but, eventually, any similarity ends. In the B::C code, you have a big opcode table in C that’s manipulated just as the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access