1*0Sstevel@tonic-gate=head1 NAME 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateperlcompile - Introduction to the Perl Compiler-Translator 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gate=head1 DESCRIPTION 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gatePerl has always had a compiler: your source is compiled into an 8*0Sstevel@tonic-gateinternal form (a parse tree) which is then optimized before being 9*0Sstevel@tonic-gaterun. Since version 5.005, Perl has shipped with a module 10*0Sstevel@tonic-gatecapable of inspecting the optimized parse tree (C<B>), and this has 11*0Sstevel@tonic-gatebeen used to write many useful utilities, including a module that lets 12*0Sstevel@tonic-gateyou turn your Perl into C source code that can be compiled into a 13*0Sstevel@tonic-gatenative executable. 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gateThe C<B> module provides access to the parse tree, and other modules 16*0Sstevel@tonic-gate("back ends") do things with the tree. Some write it out as 17*0Sstevel@tonic-gatebytecode, C source code, or a semi-human-readable text. Another 18*0Sstevel@tonic-gatetraverses the parse tree to build a cross-reference of which 19*0Sstevel@tonic-gatesubroutines, formats, and variables are used where. Another checks 20*0Sstevel@tonic-gateyour code for dubious constructs. Yet another back end dumps the 21*0Sstevel@tonic-gateparse tree back out as Perl source, acting as a source code beautifier 22*0Sstevel@tonic-gateor deobfuscator. 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gateBecause its original purpose was to be a way to produce C code 25*0Sstevel@tonic-gatecorresponding to a Perl program, and in turn a native executable, the 26*0Sstevel@tonic-gateC<B> module and its associated back ends are known as "the 27*0Sstevel@tonic-gatecompiler", even though they don't really compile anything. 28*0Sstevel@tonic-gateDifferent parts of the compiler are more accurately a "translator", 29*0Sstevel@tonic-gateor an "inspector", but people want Perl to have a "compiler 30*0Sstevel@tonic-gateoption" not an "inspector gadget". What can you do? 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gateThis document covers the use of the Perl compiler: which modules 33*0Sstevel@tonic-gateit comprises, how to use the most important of the back end modules, 34*0Sstevel@tonic-gatewhat problems there are, and how to work around them. 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate=head2 Layout 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gateThe compiler back ends are in the C<B::> hierarchy, and the front-end 39*0Sstevel@tonic-gate(the module that you, the user of the compiler, will sometimes 40*0Sstevel@tonic-gateinteract with) is the O module. Some back ends (e.g., C<B::C>) have 41*0Sstevel@tonic-gateprograms (e.g., I<perlcc>) to hide the modules' complexity. 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gateHere are the important back ends to know about, with their status 44*0Sstevel@tonic-gateexpressed as a number from 0 (outline for later implementation) to 45*0Sstevel@tonic-gate10 (if there's a bug in it, we're very surprised): 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate=over 4 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate=item B::Bytecode 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gateStores the parse tree in a machine-independent format, suitable 52*0Sstevel@tonic-gatefor later reloading through the ByteLoader module. Status: 5 (some 53*0Sstevel@tonic-gatethings work, some things don't, some things are untested). 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate=item B::C 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gateCreates a C source file containing code to rebuild the parse tree 58*0Sstevel@tonic-gateand resume the interpreter. Status: 6 (many things work adequately, 59*0Sstevel@tonic-gateincluding programs using Tk). 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate=item B::CC 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gateCreates a C source file corresponding to the run time code path in 64*0Sstevel@tonic-gatethe parse tree. This is the closest to a Perl-to-C translator there 65*0Sstevel@tonic-gateis, but the code it generates is almost incomprehensible because it 66*0Sstevel@tonic-gatetranslates the parse tree into a giant switch structure that 67*0Sstevel@tonic-gatemanipulates Perl structures. Eventual goal is to reduce (given 68*0Sstevel@tonic-gatesufficient type information in the Perl program) some of the 69*0Sstevel@tonic-gatePerl data structure manipulations into manipulations of C-level 70*0Sstevel@tonic-gateints, floats, etc. Status: 5 (some things work, including 71*0Sstevel@tonic-gateuncomplicated Tk examples). 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate=item B::Lint 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gateComplains if it finds dubious constructs in your source code. Status: 76*0Sstevel@tonic-gate6 (it works adequately, but only has a very limited number of areas 77*0Sstevel@tonic-gatethat it checks). 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate=item B::Deparse 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gateRecreates the Perl source, making an attempt to format it coherently. 82*0Sstevel@tonic-gateStatus: 8 (it works nicely, but a few obscure things are missing). 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate=item B::Xref 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gateReports on the declaration and use of subroutines and variables. 87*0Sstevel@tonic-gateStatus: 8 (it works nicely, but still has a few lingering bugs). 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate=back 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate=head1 Using The Back Ends 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gateThe following sections describe how to use the various compiler back 94*0Sstevel@tonic-gateends. They're presented roughly in order of maturity, so that the 95*0Sstevel@tonic-gatemost stable and proven back ends are described first, and the most 96*0Sstevel@tonic-gateexperimental and incomplete back ends are described last. 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gateThe O module automatically enabled the B<-c> flag to Perl, which 99*0Sstevel@tonic-gateprevents Perl from executing your code once it has been compiled. 100*0Sstevel@tonic-gateThis is why all the back ends print: 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate myperlprogram syntax OK 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gatebefore producing any other output. 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate=head2 The Cross Referencing Back End 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gateThe cross referencing back end (B::Xref) produces a report on your program, 109*0Sstevel@tonic-gatebreaking down declarations and uses of subroutines and variables (and 110*0Sstevel@tonic-gateformats) by file and subroutine. For instance, here's part of the 111*0Sstevel@tonic-gatereport from the I<pod2man> program that comes with Perl: 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate Subroutine clear_noremap 114*0Sstevel@tonic-gate Package (lexical) 115*0Sstevel@tonic-gate $ready_to_print i1069, 1079 116*0Sstevel@tonic-gate Package main 117*0Sstevel@tonic-gate $& 1086 118*0Sstevel@tonic-gate $. 1086 119*0Sstevel@tonic-gate $0 1086 120*0Sstevel@tonic-gate $1 1087 121*0Sstevel@tonic-gate $2 1085, 1085 122*0Sstevel@tonic-gate $3 1085, 1085 123*0Sstevel@tonic-gate $ARGV 1086 124*0Sstevel@tonic-gate %HTML_Escapes 1085, 1085 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gateThis shows the variables used in the subroutine C<clear_noremap>. The 127*0Sstevel@tonic-gatevariable C<$ready_to_print> is a my() (lexical) variable, 128*0Sstevel@tonic-gateB<i>ntroduced (first declared with my()) on line 1069, and used on 129*0Sstevel@tonic-gateline 1079. The variable C<$&> from the main package is used on 1086, 130*0Sstevel@tonic-gateand so on. 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gateA line number may be prefixed by a single letter: 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate=over 4 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate=item i 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gateLexical variable introduced (declared with my()) for the first time. 139*0Sstevel@tonic-gate 140*0Sstevel@tonic-gate=item & 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gateSubroutine or method call. 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate=item s 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gateSubroutine defined. 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate=item r 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gateFormat defined. 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate=back 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gateThe most useful option the cross referencer has is to save the report 155*0Sstevel@tonic-gateto a separate file. For instance, to save the report on 156*0Sstevel@tonic-gateI<myperlprogram> to the file I<report>: 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate $ perl -MO=Xref,-oreport myperlprogram 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate=head2 The Decompiling Back End 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gateThe Deparse back end turns your Perl source back into Perl source. It 163*0Sstevel@tonic-gatecan reformat along the way, making it useful as a de-obfuscator. The 164*0Sstevel@tonic-gatemost basic way to use it is: 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate $ perl -MO=Deparse myperlprogram 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gateYou'll notice immediately that Perl has no idea of how to paragraph 169*0Sstevel@tonic-gateyour code. You'll have to separate chunks of code from each other 170*0Sstevel@tonic-gatewith newlines by hand. However, watch what it will do with 171*0Sstevel@tonic-gateone-liners: 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate $ perl -MO=Deparse -e '$op=shift||die "usage: $0 174*0Sstevel@tonic-gate code [...]";chomp(@ARGV=<>)unless@ARGV; for(@ARGV){$was=$_;eval$op; 175*0Sstevel@tonic-gate die$@ if$@; rename$was,$_ unless$was eq $_}' 176*0Sstevel@tonic-gate -e syntax OK 177*0Sstevel@tonic-gate $op = shift @ARGV || die("usage: $0 code [...]"); 178*0Sstevel@tonic-gate chomp(@ARGV = <ARGV>) unless @ARGV; 179*0Sstevel@tonic-gate foreach $_ (@ARGV) { 180*0Sstevel@tonic-gate $was = $_; 181*0Sstevel@tonic-gate eval $op; 182*0Sstevel@tonic-gate die $@ if $@; 183*0Sstevel@tonic-gate rename $was, $_ unless $was eq $_; 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gateThe decompiler has several options for the code it generates. For 187*0Sstevel@tonic-gateinstance, you can set the size of each indent from 4 (as above) to 188*0Sstevel@tonic-gate2 with: 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate $ perl -MO=Deparse,-si2 myperlprogram 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gateThe B<-p> option adds parentheses where normally they are omitted: 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate $ perl -MO=Deparse -e 'print "Hello, world\n"' 195*0Sstevel@tonic-gate -e syntax OK 196*0Sstevel@tonic-gate print "Hello, world\n"; 197*0Sstevel@tonic-gate $ perl -MO=Deparse,-p -e 'print "Hello, world\n"' 198*0Sstevel@tonic-gate -e syntax OK 199*0Sstevel@tonic-gate print("Hello, world\n"); 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gateSee L<B::Deparse> for more information on the formatting options. 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate=head2 The Lint Back End 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gateThe lint back end (B::Lint) inspects programs for poor style. One 206*0Sstevel@tonic-gateprogrammer's bad style is another programmer's useful tool, so options 207*0Sstevel@tonic-gatelet you select what is complained about. 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gateTo run the style checker across your source code: 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate $ perl -MO=Lint myperlprogram 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gateTo disable context checks and undefined subroutines: 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate $ perl -MO=Lint,-context,-undefined-subs myperlprogram 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gateSee L<B::Lint> for information on the options. 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate=head2 The Simple C Back End 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gateThis module saves the internal compiled state of your Perl program 222*0Sstevel@tonic-gateto a C source file, which can be turned into a native executable 223*0Sstevel@tonic-gatefor that particular platform using a C compiler. The resulting 224*0Sstevel@tonic-gateprogram links against the Perl interpreter library, so it 225*0Sstevel@tonic-gatewill not save you disk space (unless you build Perl with a shared 226*0Sstevel@tonic-gatelibrary) or program size. It may, however, save you startup time. 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gateThe C<perlcc> tool generates such executables by default. 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate perlcc myperlprogram.pl 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate=head2 The Bytecode Back End 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gateThis back end is only useful if you also have a way to load and 235*0Sstevel@tonic-gateexecute the bytecode that it produces. The ByteLoader module provides 236*0Sstevel@tonic-gatethis functionality. 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gateTo turn a Perl program into executable byte code, you can use C<perlcc> 239*0Sstevel@tonic-gatewith the C<-B> switch: 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate perlcc -B myperlprogram.pl 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gateThe byte code is machine independent, so once you have a compiled 244*0Sstevel@tonic-gatemodule or program, it is as portable as Perl source (assuming that 245*0Sstevel@tonic-gatethe user of the module or program has a modern-enough Perl interpreter 246*0Sstevel@tonic-gateto decode the byte code). 247*0Sstevel@tonic-gate 248*0Sstevel@tonic-gateSee B<B::Bytecode> for information on options to control the 249*0Sstevel@tonic-gateoptimization and nature of the code generated by the Bytecode module. 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate=head2 The Optimized C Back End 252*0Sstevel@tonic-gate 253*0Sstevel@tonic-gateThe optimized C back end will turn your Perl program's run time 254*0Sstevel@tonic-gatecode-path into an equivalent (but optimized) C program that manipulates 255*0Sstevel@tonic-gatethe Perl data structures directly. The program will still link against 256*0Sstevel@tonic-gatethe Perl interpreter library, to allow for eval(), C<s///e>, 257*0Sstevel@tonic-gateC<require>, etc. 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gateThe C<perlcc> tool generates such executables when using the -O 260*0Sstevel@tonic-gateswitch. To compile a Perl program (ending in C<.pl> 261*0Sstevel@tonic-gateor C<.p>): 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate perlcc -O myperlprogram.pl 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gateTo produce a shared library from a Perl module (ending in C<.pm>): 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate perlcc -O Myperlmodule.pm 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gateFor more information, see L<perlcc> and L<B::CC>. 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate=head1 Module List for the Compiler Suite 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate=over 4 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate=item B 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gateThis module is the introspective ("reflective" in Java terms) 278*0Sstevel@tonic-gatemodule, which allows a Perl program to inspect its innards. The 279*0Sstevel@tonic-gateback end modules all use this module to gain access to the compiled 280*0Sstevel@tonic-gateparse tree. You, the user of a back end module, will not need to 281*0Sstevel@tonic-gateinteract with B. 282*0Sstevel@tonic-gate 283*0Sstevel@tonic-gate=item O 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gateThis module is the front-end to the compiler's back ends. Normally 286*0Sstevel@tonic-gatecalled something like this: 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate $ perl -MO=Deparse myperlprogram 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gateThis is like saying C<use O 'Deparse'> in your Perl program. 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate=item B::Asmdata 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gateThis module is used by the B::Assembler module, which is in turn used 295*0Sstevel@tonic-gateby the B::Bytecode module, which stores a parse-tree as 296*0Sstevel@tonic-gatebytecode for later loading. It's not a back end itself, but rather a 297*0Sstevel@tonic-gatecomponent of a back end. 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate=item B::Assembler 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gateThis module turns a parse-tree into data suitable for storing 302*0Sstevel@tonic-gateand later decoding back into a parse-tree. It's not a back end 303*0Sstevel@tonic-gateitself, but rather a component of a back end. It's used by the 304*0Sstevel@tonic-gateI<assemble> program that produces bytecode. 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate=item B::Bblock 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gateThis module is used by the B::CC back end. It walks "basic blocks". 309*0Sstevel@tonic-gateA basic block is a series of operations which is known to execute from 310*0Sstevel@tonic-gatestart to finish, with no possibility of branching or halting. 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gate=item B::Bytecode 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gateThis module is a back end that generates bytecode from a 315*0Sstevel@tonic-gateprogram's parse tree. This bytecode is written to a file, from where 316*0Sstevel@tonic-gateit can later be reconstructed back into a parse tree. The goal is to 317*0Sstevel@tonic-gatedo the expensive program compilation once, save the interpreter's 318*0Sstevel@tonic-gatestate into a file, and then restore the state from the file when the 319*0Sstevel@tonic-gateprogram is to be executed. See L</"The Bytecode Back End"> 320*0Sstevel@tonic-gatefor details about usage. 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gate=item B::C 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gateThis module writes out C code corresponding to the parse tree and 325*0Sstevel@tonic-gateother interpreter internal structures. You compile the corresponding 326*0Sstevel@tonic-gateC file, and get an executable file that will restore the internal 327*0Sstevel@tonic-gatestructures and the Perl interpreter will begin running the 328*0Sstevel@tonic-gateprogram. See L</"The Simple C Back End"> for details about usage. 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate=item B::CC 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gateThis module writes out C code corresponding to your program's 333*0Sstevel@tonic-gateoperations. Unlike the B::C module, which merely stores the 334*0Sstevel@tonic-gateinterpreter and its state in a C program, the B::CC module makes a 335*0Sstevel@tonic-gateC program that does not involve the interpreter. As a consequence, 336*0Sstevel@tonic-gateprograms translated into C by B::CC can execute faster than normal 337*0Sstevel@tonic-gateinterpreted programs. See L</"The Optimized C Back End"> for 338*0Sstevel@tonic-gatedetails about usage. 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate=item B::Concise 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gateThis module prints a concise (but complete) version of the Perl parse 343*0Sstevel@tonic-gatetree. Its output is more customizable than the one of B::Terse or 344*0Sstevel@tonic-gateB::Debug (and it can emulate them). This module useful for people who 345*0Sstevel@tonic-gateare writing their own back end, or who are learning about the Perl 346*0Sstevel@tonic-gateinternals. It's not useful to the average programmer. 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate=item B::Debug 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gateThis module dumps the Perl parse tree in verbose detail to STDOUT. 351*0Sstevel@tonic-gateIt's useful for people who are writing their own back end, or who 352*0Sstevel@tonic-gateare learning about the Perl internals. It's not useful to the 353*0Sstevel@tonic-gateaverage programmer. 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate=item B::Deparse 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gateThis module produces Perl source code from the compiled parse tree. 358*0Sstevel@tonic-gateIt is useful in debugging and deconstructing other people's code, 359*0Sstevel@tonic-gatealso as a pretty-printer for your own source. See 360*0Sstevel@tonic-gateL</"The Decompiling Back End"> for details about usage. 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate=item B::Disassembler 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gateThis module turns bytecode back into a parse tree. It's not a back 365*0Sstevel@tonic-gateend itself, but rather a component of a back end. It's used by the 366*0Sstevel@tonic-gateI<disassemble> program that comes with the bytecode. 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gate=item B::Lint 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gateThis module inspects the compiled form of your source code for things 371*0Sstevel@tonic-gatewhich, while some people frown on them, aren't necessarily bad enough 372*0Sstevel@tonic-gateto justify a warning. For instance, use of an array in scalar context 373*0Sstevel@tonic-gatewithout explicitly saying C<scalar(@array)> is something that Lint 374*0Sstevel@tonic-gatecan identify. See L</"The Lint Back End"> for details about usage. 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate=item B::Showlex 377*0Sstevel@tonic-gate 378*0Sstevel@tonic-gateThis module prints out the my() variables used in a function or a 379*0Sstevel@tonic-gatefile. To get a list of the my() variables used in the subroutine 380*0Sstevel@tonic-gatemysub() defined in the file myperlprogram: 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate $ perl -MO=Showlex,mysub myperlprogram 383*0Sstevel@tonic-gate 384*0Sstevel@tonic-gateTo get a list of the my() variables used in the file myperlprogram: 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate $ perl -MO=Showlex myperlprogram 387*0Sstevel@tonic-gate 388*0Sstevel@tonic-gate[BROKEN] 389*0Sstevel@tonic-gate 390*0Sstevel@tonic-gate=item B::Stackobj 391*0Sstevel@tonic-gate 392*0Sstevel@tonic-gateThis module is used by the B::CC module. It's not a back end itself, 393*0Sstevel@tonic-gatebut rather a component of a back end. 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate=item B::Stash 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gateThis module is used by the L<perlcc> program, which compiles a module 398*0Sstevel@tonic-gateinto an executable. B::Stash prints the symbol tables in use by a 399*0Sstevel@tonic-gateprogram, and is used to prevent B::CC from producing C code for the 400*0Sstevel@tonic-gateB::* and O modules. It's not a back end itself, but rather a 401*0Sstevel@tonic-gatecomponent of a back end. 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate=item B::Terse 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gateThis module prints the contents of the parse tree, but without as much 406*0Sstevel@tonic-gateinformation as B::Debug. For comparison, C<print "Hello, world."> 407*0Sstevel@tonic-gateproduced 96 lines of output from B::Debug, but only 6 from B::Terse. 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gateThis module is useful for people who are writing their own back end, 410*0Sstevel@tonic-gateor who are learning about the Perl internals. It's not useful to the 411*0Sstevel@tonic-gateaverage programmer. 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate=item B::Xref 414*0Sstevel@tonic-gate 415*0Sstevel@tonic-gateThis module prints a report on where the variables, subroutines, and 416*0Sstevel@tonic-gateformats are defined and used within a program and the modules it 417*0Sstevel@tonic-gateloads. See L</"The Cross Referencing Back End"> for details about 418*0Sstevel@tonic-gateusage. 419*0Sstevel@tonic-gate 420*0Sstevel@tonic-gate=back 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate=head1 KNOWN PROBLEMS 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gateThe simple C backend currently only saves typeglobs with alphanumeric 425*0Sstevel@tonic-gatenames. 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gateThe optimized C backend outputs code for more modules than it should 428*0Sstevel@tonic-gate(e.g., DirHandle). It also has little hope of properly handling 429*0Sstevel@tonic-gateC<goto LABEL> outside the running subroutine (C<goto &sub> is okay). 430*0Sstevel@tonic-gateC<goto LABEL> currently does not work at all in this backend. 431*0Sstevel@tonic-gateIt also creates a huge initialization function that gives 432*0Sstevel@tonic-gateC compilers headaches. Splitting the initialization function gives 433*0Sstevel@tonic-gatebetter results. Other problems include: unsigned math does not 434*0Sstevel@tonic-gatework correctly; some opcodes are handled incorrectly by default 435*0Sstevel@tonic-gateopcode handling mechanism. 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gateBEGIN{} blocks are executed while compiling your code. Any external 438*0Sstevel@tonic-gatestate that is initialized in BEGIN{}, such as opening files, initiating 439*0Sstevel@tonic-gatedatabase connections etc., do not behave properly. To work around 440*0Sstevel@tonic-gatethis, Perl has an INIT{} block that corresponds to code being executed 441*0Sstevel@tonic-gatebefore your program begins running but after your program has finished 442*0Sstevel@tonic-gatebeing compiled. Execution order: BEGIN{}, (possible save of state 443*0Sstevel@tonic-gatethrough compiler back-end), INIT{}, program runs, END{}. 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate=head1 AUTHOR 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gateThis document was originally written by Nathan Torkington, and is now 448*0Sstevel@tonic-gatemaintained by the perl5-porters mailing list 449*0Sstevel@tonic-gateI<perl5-porters@perl.org>. 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate=cut 452