perlcompile.pod 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. =head1 NAME
  2. perlcompile - Introduction to the Perl Compiler-Translator
  3. =head1 DESCRIPTION
  4. Perl has always had a compiler: your source is compiled into an
  5. internal form (a parse tree, "optree") which is then optimized before
  6. being run. Since version 5.005, Perl has shipped with a module
  7. capable of inspecting the optimized optree (L<B>), and this has been
  8. used to write many useful utilities, including the L<B::C> and
  9. L<B::CC> modules that lets you turn your Perl into C source code that
  10. can be compiled into a native executable.
  11. The C<B> module provides access to the optree, and other modules
  12. ("backends") do things with the tree. Some write it out as bytecode
  13. L<B::Bytecode>, C source code L<B::C>, or a semi-human-readable text.
  14. Another L<B::Xref> traverses the parse tree to build a cross-reference
  15. of which subroutines, formats, and variables are used where. Another
  16. L<B::Lint> checks your code for dubious constructs. L<B::Deparse>
  17. dumps the parse tree back out as Perl source, acting as a source code
  18. beautifier or deobfuscator.
  19. Because its original purpose was to be a way to produce C code
  20. corresponding to a Perl program, and in turn a native executable, the
  21. C<B> module and its associated backends, mainly L<B::C>, L<B::CC> and
  22. L<B::Bytecode> are known as "the compiler", even though they don't
  23. really compile anything.
  24. This document covers the use of the Perl compiler: which modules
  25. it comprises, how to use the most important of the backend modules,
  26. what problems there are, and how to work around them.
  27. =head2 Layout
  28. The compiler backends are in the C<B::> hierarchy, and the front-end
  29. (the module that you, the user of the compiler, will sometimes
  30. interact with) is the O module. Some backends (e.g., C<B::C>) have
  31. programs (e.g., I<perlcc>) to hide the modules' complexity.
  32. Since Perl 5.10 the three code-producing backends (C<B::C>, C<B::CC>
  33. and C<B::Bytecode>), aka the compiler, have been removed from
  34. CORE Perl and are available as seperate CPAN module
  35. L<http://search.cpan.org/dist/B-C/>.
  36. Here are the important backends to know about, with their status
  37. expressed as a number from 0 (outline for later implementation) to
  38. 10:
  39. =over 4
  40. =item The B::Bytecode backend
  41. Stores the parse tree in a machine-independent format, suitable
  42. for later reloading through the L</"ByteLoader"> module.
  43. Status: 7 (5.18 and higher is broken).
  44. =item The B::C backend
  45. Creates a C source file containing code to rebuild the parse tree
  46. and resume the interpreter.
  47. Status: 9 (most applications work out of the box, some need cmdline flags)
  48. 5.14 works best. See L<STATUS>
  49. B::C is stable and used in production for -O0 and -O3. For some programs
  50. not all methods in certain packages or eval strings might be detected,
  51. you'd need to add them manually via -u<packagename>.
  52. Still missing in general are:
  53. - attribute handlers (i.e. run-time attributes)
  54. - compile-time perlio layers
  55. - re-eval groups (?{})
  56. - smartmatch subrefs
  57. - compile-time stash-magic delete renames to ANON
  58. =item The B::CC backend
  59. Creates a C source file corresponding to the run time code path in
  60. the parse tree. This is the closest to a Perl-to-C translator there
  61. is, but the code it generates is almost incomprehensible because it
  62. translates the parse tree into a giant switch structure that
  63. manipulates Perl structures. Eventual goal is to reduce (given
  64. sufficient type information in the Perl program) some of the
  65. Perl data structure manipulations into manipulations of C-level
  66. ints, floats, etc.
  67. Status: 5 (some applications work).
  68. =item B::Lint
  69. Complains if it finds dubious constructs in your source code. Status:
  70. 6 (it works adequately, but only has a very limited number of areas
  71. that it checks).
  72. =item B::Deparse
  73. Recreates the Perl source, making an attempt to format it coherently.
  74. Status: 8 (it works nicely, but a few obscure things are missing).
  75. =item B::Xref
  76. Reports on the declaration and use of subroutines and variables.
  77. Status: 8 (it works nicely, but still has a few lingering bugs).
  78. =back
  79. =head1 Using The Backends
  80. The following sections describe how to use the various compiler back
  81. ends. They're presented roughly in order of maturity, so that the
  82. most stable and proven backends are described first, and the most
  83. experimental and incomplete backends are described last.
  84. The C<O> module automatically enabled the B<-c> flag to Perl, which
  85. prevents Perl from executing your code once it has been compiled.
  86. This is why all the backends print:
  87. myperlprogram syntax OK
  88. before producing any other output.
  89. =head2 The Cross Referencing Backend
  90. The cross referencing backend (C<B::Xref>) produces a report on your program,
  91. breaking down declarations and uses of subroutines and variables (and
  92. formats) by file and subroutine. For instance, here's part of the
  93. report from the I<pod2man> program that comes with Perl:
  94. Subroutine clear_noremap
  95. Package (lexical)
  96. $ready_to_print i1069, 1079
  97. Package main
  98. $& 1086
  99. $. 1086
  100. $0 1086
  101. $1 1087
  102. $2 1085, 1085
  103. $3 1085, 1085
  104. $ARGV 1086
  105. %HTML_Escapes 1085, 1085
  106. This shows the variables used in the subroutine C<clear_noremap>. The
  107. variable C<$ready_to_print> is a my() (lexical) variable,
  108. B<i>ntroduced (first declared with my()) on line 1069, and used on
  109. line 1079. The variable C<$&> from the main package is used on 1086,
  110. and so on.
  111. A line number may be prefixed by a single letter:
  112. =over 4
  113. =item i
  114. Lexical variable introduced (declared with my()) for the first time.
  115. =item &
  116. Subroutine or method call.
  117. =item s
  118. Subroutine defined.
  119. =item r
  120. Format defined.
  121. =back
  122. The most useful option the cross referencer has is to save the report
  123. to a separate file. For instance, to save the report on
  124. I<myperlprogram> to the file I<report>:
  125. $ perl -MO=Xref,-oreport myperlprogram
  126. =head2 The Decompiling Backend
  127. The Deparse backend turns your Perl source back into Perl source. It
  128. can reformat along the way, making it useful as a de-obfuscator. The
  129. most basic way to use it is:
  130. $ perl -MO=Deparse myperlprogram
  131. You'll notice immediately that Perl has no idea of how to paragraph
  132. your code. You'll have to separate chunks of code from each other
  133. with newlines by hand. However, watch what it will do with
  134. one-liners:
  135. $ perl -MO=Deparse -e '$op=shift||die "usage: $0
  136. code [...]";chomp(@ARGV=<>)unless@ARGV; for(@ARGV){$was=$_;eval$op;
  137. die$@ if$@; rename$was,$_ unless$was eq $_}'
  138. -e syntax OK
  139. $op = shift @ARGV || die("usage: $0 code [...]");
  140. chomp(@ARGV = <ARGV>) unless @ARGV;
  141. foreach $_ (@ARGV) {
  142. $was = $_;
  143. eval $op;
  144. die $@ if $@;
  145. rename $was, $_ unless $was eq $_;
  146. }
  147. The decompiler has several options for the code it generates. For
  148. instance, you can set the size of each indent from 4 (as above) to
  149. 2 with:
  150. $ perl -MO=Deparse,-si2 myperlprogram
  151. The B<-p> option adds parentheses where normally they are omitted:
  152. $ perl -MO=Deparse -e 'print "Hello, world\n"'
  153. -e syntax OK
  154. print "Hello, world\n";
  155. $ perl -MO=Deparse,-p -e 'print "Hello, world\n"'
  156. -e syntax OK
  157. print("Hello, world\n");
  158. See L<B::Deparse> for more information on the formatting options.
  159. =head2 The Lint Backend
  160. The lint backend C<B::Lint> inspects programs for poor style. One
  161. programmer's bad style is another programmer's useful tool, so options
  162. let you select what is complained about.
  163. To run the style checker across your source code:
  164. $ perl -MO=Lint myperlprogram
  165. To disable context checks and undefined subroutines:
  166. $ perl -MO=Lint,-context,-undefined-subs myperlprogram
  167. See L<B::Lint> for information on the options.
  168. =head2 The Simple C Backend
  169. The C<B::C> module saves the internal compiled state of your Perl program
  170. to a C source file, which can be turned into a native executable
  171. for that particular platform using a C compiler. The resulting
  172. program links against the Perl interpreter library, so it
  173. will not save you disk space (unless you build Perl with a shared
  174. library) or program size. It may, however, save you startup time.
  175. The C<perlcc> tool generates such executables by default.
  176. perlcc myperlprogram.pl
  177. =head3 C Backend Invocation
  178. If there are any non-option arguments, they are taken to be
  179. names of objects to be saved (probably doesn't work properly yet).
  180. Without extra arguments, it saves the main program.
  181. -q Be quiet. STDOUT goes to $O::BEGIN_output
  182. -qq Be very quiet. Also suppress "Syntax OK"
  183. -o<filename> Output to filename instead of STDOUT
  184. -v Be verbose. Currently gives a few compilation statistics.
  185. -- Force end of options
  186. -u<package> use package or filename. Force apparently unused subs from
  187. package to be compiled. This allows programs to use run-time
  188. eval "foo()" even when sub foo is never seen to be used at compile
  189. time. The down side is that any subs which really are
  190. never used also have code generated. This option is
  191. necessary, for example, if you have a signal handler
  192. foo which you initialise with $SIG{BAR} = "foo".
  193. A better fix, though, is just to change it to
  194. $SIG{BAR} = \&foo. You can have multiple -u or -U options.
  195. -U<package> Unuse package or filename. Ignore all subs from package to be compiled.
  196. Certain packages might not be needed at run-time, even if the
  197. pessimistic walker detects it. If required those packages will be
  198. run-time loaded then.
  199. -e ARG Eval ARG at startup
  200. -c Check and abort (used to print warnings)
  201. NYI -w Warn on undefined SYMs
  202. -l LIMIT Force max linelength to LIMIT (e.g. MSVC to 2048)
  203. -D Debug options (concat or separate flags like perl -D)
  204. o Print walkoptree OPs
  205. O Prints more OP information
  206. c COPs, prints COPs as processed (incl. file & line num)
  207. S prints SV/RE information on saving
  208. A prints AV information on saving
  209. C prints CV information on saving
  210. M prints MAGIC information on saving
  211. G prints GV information on saving
  212. u Do not print -D information when parsing unused subs.
  213. -f Force optimisations on or off one at a time.
  214. cog Copy-on-grow: PVs declared and initialised statically
  215. no-cog No copy-on-grow
  216. save-data Save package::DATA filehandles ( only available with PerlIO::scalar )
  217. ppaddr Optimize the initialization of op_ppaddr.
  218. warn-sv Optimize the initialization of cop_warnings.
  219. av-init Faster initialization of AVs.
  220. av-init2 Initialization of AVs via ptmalloc3 independent_comalloc().
  221. use-script-name Use the script name instead of the program name as $0.
  222. ro-inc Readonly @INC and %INC pathnames.
  223. const-strings Declares static readonly strings as const.
  224. save-sig-hash Save compile-time modifications to the %SIG hash.
  225. no-destruct Faster destruction.
  226. no-fold Do not compile unicode foldings tables, needed for m//i
  227. no-warnings Do not compile warnings hashes.
  228. stash Add all stash hashes even if not used.
  229. no-delete-pkg Do not delete compiler-internal and dependent packages.
  230. no-dyn-padlist Disable dynamic padlists (5.18). This is faster but might cause
  231. die and exit to crash.
  232. cop Omit COP, no file+line info for warnings
  233. -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
  234. -O1 -fcog -fav-init2/-fav-init -fppaddr -fwarn-sv
  235. -O2 -O1 -fro-inc -fsave-data
  236. -O3 -O2 -fsave-sig-hash -fno-destruct fconst-strings
  237. -O4 -O3 -fcop -fno-dyn-padlist
  238. =head3 C Examples
  239. perl -MO=C foo.pl > foo.c
  240. perl cc_harness -o foo foo.c
  241. perl -MO=C,-v,-DcA bar.pl > /dev/null
  242. For more information, see L<perlcc> and L<B::C>.
  243. =head2 The Bytecode Backend
  244. This backend is only useful if you also have a way to load and execute the
  245. bytecode that it produces. The L</ByteLoader> module provides this
  246. functionality.
  247. To turn a Perl program into executable byte code, you can use C<perlcc>
  248. with the C<-B> switch:
  249. perlcc -B myperlprogram.pl
  250. The byte code is machine independent, so once you have a compiled
  251. module or program, it is as portable as Perl source (assuming that
  252. the user of the module or program has a modern-enough Perl interpreter
  253. to decode the byte code).
  254. =head3 Bytecode Backend Invocation
  255. If there are any non-option arguments, they are taken to be
  256. names of objects to be saved (probably doesn't work properly yet).
  257. Without extra arguments, it saves the main program.
  258. -q Be quiet. STDOUT goes to $O::BEGIN_output
  259. -qq Be very quiet. Also suppress "Syntax OK"
  260. -ofilename Output to filename instead of STDOUT.
  261. NYI -v Be verbose.
  262. -- Force end of options.
  263. NYI -f Force optimisations on or off one at a time.
  264. Each can be preceded by no- to turn the option off.
  265. compress-nullops
  266. Only fills in the necessary fields of ops which have
  267. been optimised away by perl's internal compiler.
  268. omit-sequence-numbers
  269. Leaves out code to fill in the op_seq field of all ops
  270. which is only used by perl's internal compiler.
  271. bypass-nullops
  272. If op->op_next ever points to a NULLOP, replaces the
  273. op_next field with the first non-NULLOP in the path
  274. of execution.
  275. -s strip-syntax-tree
  276. Leaves out code to fill in the pointers which link the
  277. internal syntax tree together. They're not needed at
  278. run-time but leaving them out will make it impossible
  279. to recompile or disassemble the resulting program.
  280. It will also stop "goto label" statements from working.
  281. NYI -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
  282. -O1 sets -fcompress-nullops -fomit-sequence numbers.
  283. -O6 adds -fstrip-syntax-tree.
  284. NYI -D Debug options (concat or separate flags like perl -D)
  285. O OPs, prints each OP as it's processed.
  286. b print debugging information about bytecompiler progress
  287. a tells the assembler to include source assembler lines
  288. in its output as bytecode comments.
  289. C prints each CV taken from the final symbol tree walk.
  290. -S Output assembler source rather than piping it
  291. through the assembler and outputting bytecode.
  292. -H add #! perl shebang header
  293. -s scan and keep keep syntax tree if goto op found.
  294. scan the script for C<# line ..> directives and for <goto LABEL>
  295. expressions. When gotos are found keep the syntax tree.
  296. -b Save all the BEGIN blocks. Normally only BEGIN blocks that require
  297. other files (ex. use Foo;) are saved.
  298. -k keep syntax tree to disassemble the plc.
  299. it is stripped by default.
  300. -TI testing, dump the @INC av
  301. -TF file testing, sets COP::file
  302. -m Compile as a module rather than a standalone program.
  303. Currently this just means that the bytecodes for
  304. initialising main_start, main_root and curpad are
  305. omitted.
  306. =head3 Bytecode Invocation Examples
  307. perl -MO=Bytecode,-O6,-H,-ofoo.plc foo.pl
  308. ./foo.plc
  309. perl -MO=Bytecode,-S foo.pl > foo.S
  310. assemble foo.S > foo.plc
  311. perl -MByteLoader foo.plc
  312. perl -MO=Bytecode,-m,-oFoo.pmc Foo.pm
  313. =head2 The Optimized C Backend
  314. The C<B::CC> optimized C backend will turn your Perl program's run time
  315. code-path into an equivalent (but optimized) C program that manipulates
  316. the Perl data structures directly. The program will still link against
  317. the Perl interpreter library, to allow for eval(), C<s///e>,
  318. C<require>, etc.
  319. The C<perlcc> tool generates such executables when using the C<-O>
  320. switch. To compile a Perl program (ending in C<.pl> or C<.p>):
  321. perlcc -O myperlprogram.pl
  322. To produce a shared library from a Perl module (ending in C<.pm>):
  323. perlcc -O Myperlmodule.pm
  324. =head3 CC Backend Invocation
  325. If there are any non-option arguments, they are taken to be names of
  326. subs to be saved. Without extra arguments, it saves the main program.
  327. B::C takes all B::C options plus a few new ones:
  328. -D Debug options (concat or separate flags like perl -D)
  329. o Enable B debugging
  330. r Writes debugging output to STDERR just as it's about
  331. to write to the program's runtime. Otherwise writes
  332. debugging info as comments in its C output.
  333. O Outputs each OP as it's compiled
  334. s Outputs the contents of the shadow stack at each OP
  335. p Outputs the contents of the shadow pad of lexicals as
  336. it's loaded for each sub or the main program.
  337. q Outputs the name of each fake PP function in the queue
  338. as it's about to processes.
  339. l Output the filename and line number of each original
  340. line of Perl code as it's processed (pp_nextstate).
  341. t Outputs timing information of compilation stages
  342. -f Force optimisations on or off one at a time.
  343. cog Copy-on-grow: PVs declared and initialised statically
  344. freetmps-each-bblock Delays FREETMPS from the end of each
  345. statement to the end of the each basic
  346. block.
  347. freetmps-each-loop Delays FREETMPS from the end of each
  348. statement to the end of the group of
  349. basic blocks forming a loop. At most
  350. one of the freetmps-each-* options can
  351. be used.
  352. no-inline-ops Turn off aggressive inlining of ops
  353. omit-taint Omits generating code for handling
  354. perl's tainting mechanism.
  355. -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
  356. -O1 -ffreetmps-each-bblock
  357. -O2 -O1 -ffreetmps-each-loop
  358. All B::C -O3 optimisations are automatically used.
  359. =head3 CC Invocation Example
  360. perl -MO=CC,-O2,-ofoo.c foo.pl
  361. perl cc_harness -o foo foo.c
  362. perl -MO=CC,-mFoo,-oFoo.c Foo.pm
  363. perl cc_harness -shared -c -o Foo.so Foo.c
  364. perlcc -O myperlprogram.pl
  365. perlcc -O MyperlModule.pm
  366. See also L<perlcc> and L<B::CC>.
  367. =head2 Backends For Debugging
  368. perl -MO=Terse,exec foo.pl
  369. perl -MO=Debug bar.pl
  370. =head1 Module List for the Compiler Suite
  371. =over 4
  372. =item B
  373. This module is the introspective ("reflective" in Java terms)
  374. module, which allows a Perl program to inspect its innards. The
  375. backend modules all use this module to gain access to the compiled
  376. parse tree. You, the user of a backend module, will not need to
  377. interact with B.
  378. =item O
  379. This module is the front-end to the compiler's backends. Normally
  380. called something like this:
  381. $ perl -MO=Deparse,-q myperlprogram
  382. This is like saying C<use O 'Deparse' qw(-q)> in your Perl program.
  383. Used with "perl -MO=Backend,-foo,-obar prog.pl" to invoke the backend
  384. B::Backend with options -foo and -obar. O invokes the sub
  385. B::Backend::compile() with arguments -foo and -obar at BEGIN time.
  386. That compile() sub must do any inital argument processing replied.
  387. If unsuccessful, it should return a string which O arranges to be
  388. printed as an error message followed by a clean error exit. In the
  389. normal case where any option processing in compile() is successful,
  390. it should return a sub ref (usually a closure) to perform the
  391. actual compilation. When O regains control, it ensures that the
  392. "-c" option is forced (so that the program being compiled doesn't
  393. end up running) and registers a CHECK block to call back the sub ref
  394. returned from the backend's compile(). Perl then continues by
  395. parsing prog.pl (just as it would with "perl -c prog.pl") and after
  396. doing so, assuming there are no parse-time errors, the CHECK block
  397. of O gets called and the actual backend compilation happens. Phew.
  398. =item ByteLoader
  399. This run-time module parses and executes the binary bytecode
  400. produced by L</"B::Bytecode">. These are normally C<.plc> for
  401. scripts and C<.pmc> files for modules.
  402. Note that Perl CORE favors C<.pmc> over C<.pm> files, so it would
  403. be wise to add the ByteLoader module in advance.
  404. Either statically linked into your perl (see C<Config{static_ext}>)
  405. or with C<-MByteLoader> on the command line.
  406. =item B::Asmdata
  407. This module is used by the B::Assembler module, which is in turn used
  408. by the B::Bytecode module, which stores a parse-tree as
  409. bytecode for later loading. It's not a backend itself, but rather a
  410. component of a backend.
  411. =item B::Assembler
  412. This module turns a parse-tree into data suitable for storing
  413. and later decoding back into a parse-tree. It's not a backend
  414. itself, but rather a component of a backend. It's used by the
  415. I<assemble> program that produces C<.plc> bytecode.
  416. =item B::Bblock
  417. This module is used by the B::CC backend. It walks "basic blocks".
  418. A basic block is a series of operations which is known to execute from
  419. start to finish, with no possibility of branching or halting or
  420. jumps into inner ops.
  421. =item B::Bytecode
  422. This module is a backend that generates bytecode from a program's parse tree.
  423. This bytecode is written to a C<.plc> file, from where it can later be
  424. reconstructed back into a parse tree. The goal is to do the expensive program
  425. compilation once, save the interpreter's state into a file, and then restore the
  426. state from the file when the program is to be executed. See L</"The Bytecode
  427. Backend"> for details about usage.
  428. With the -M switch you can also produce bytecode compiled modules as
  429. C<.pmc> files, which if pesent in the @INC patch are favored over
  430. normal C<.pm> files. You need to load the L</ByteLoader> module then also,
  431. which is a problem, because it is not in CORE anymore.
  432. =item B::C
  433. This module writes out C code corresponding to the parse tree and
  434. other interpreter internal structures. You compile the corresponding
  435. C file, and get an executable file that will restore the internal
  436. structures and the Perl interpreter will begin running the
  437. program. See L</"The Simple C Backend"> for details about usage.
  438. =item B::CC
  439. This module writes out C code corresponding to your program's
  440. operations. Unlike the C<B::C> module, which merely stores the
  441. interpreter and its state in a C program, the C<B::CC> module makes a
  442. C program that does not involve the interpreter. As a consequence,
  443. programs translated into C by C<B::CC> can execute faster than normal
  444. interpreted programs. See L</"The Optimized C Backend"> for
  445. details about usage.
  446. =item B::Concise
  447. This module prints a concise (but complete) version of the Perl parse
  448. tree. Its output is more customizable than the one of B::Terse or
  449. B::Debug (and it can emulate them). This module useful for people who
  450. are writing their own backend, or who are learning about the Perl
  451. internals. It's not useful to the average programmer.
  452. =item B::Debug
  453. This module dumps the Perl parse tree in verbose detail to STDOUT.
  454. It's useful for people who are writing their own backend, or who
  455. are learning about the Perl internals. It's not useful to the
  456. average programmer.
  457. =item B::Deparse
  458. This module produces Perl source code from the compiled parse tree.
  459. It is useful in debugging and deconstructing other people's code,
  460. also as a pretty-printer for your own source. See
  461. L</"The Decompiling Backend"> for details about usage.
  462. =item B::Disassembler
  463. This module decodes C<.plc> bytecode back into a readable parse-tree,
  464. the reverse of the L</"B::Assembler">.
  465. It's not a backend itself, but rather a component of a backend.
  466. It's used by the I<disassemble> program that produces bytecode.
  467. =item B::Lint
  468. This module inspects the compiled form of your source code for things
  469. which, while some people frown on them, aren't necessarily bad enough
  470. to justify a warning. For instance, use of an array in scalar context
  471. without explicitly saying C<scalar(@array)> is something that Lint
  472. can identify. See L</"The Lint Backend"> for details about usage.
  473. =item B::Showlex
  474. This module prints out the my() variables used in a function or a
  475. file. To get a list of the my() variables used in the subroutine
  476. mysub() defined in the file myperlprogram:
  477. $ perl -MO=Showlex,mysub myperlprogram
  478. To get a list of the my() variables used in the file myperlprogram:
  479. $ perl -MO=Showlex myperlprogram
  480. [BROKEN]
  481. =item B::Terse
  482. This module prints the contents of the parse tree, but without as much
  483. information as L</"B::Debug">. For comparison, C<print "Hello, world.">
  484. produced 96 lines of output from B::Debug, but only 6 from B::Terse.
  485. This module is useful for people who are writing their own backend,
  486. or who are learning about the Perl internals. It's not useful to the
  487. average programmer.
  488. =item B::Xref
  489. This module prints a report on where the variables, subroutines, and
  490. formats are defined and used within a program and the modules it
  491. loads. See L</"The Cross Referencing Backend"> for details about
  492. usage.
  493. =back
  494. =head1 KNOWN PROBLEMS
  495. BEGIN{} blocks are executed before compiling your code. Any external
  496. state that is initialized in BEGIN{}, such as main code in use'd
  497. modules, opening files, initiating database connections etc., do not
  498. behave properly. To work around this, Perl has an INIT{} block that
  499. corresponds to code being executed before your program begins running
  500. but after your program has finished being compiled. Execution order:
  501. BEGIN{}, (possible save of state through compiler back-end), INIT{},
  502. program runs, END{}.
  503. Yet unsupported:
  504. - attribute handlers (i.e. run-time attributes)
  505. - compile-time perlio layers
  506. - re-eval groups (?{})
  507. - smartmatch subrefs
  508. - compile-time stash-magic delete renames to ANON
  509. CC backend: goto, sort with non-default comparison. last for non-loop blocks.
  510. See F<STATUS>
  511. =head2 Other perl to exe compilers
  512. Maybe you want to look for the free L<PAR> module or some commercial
  513. products, like C<perl2exe> at L<http://www.indigostar.com/perl2exe.htm>
  514. and C<perlapp> as C<PerlDevKit> from ActiveState at
  515. L<http://www.activestate.com/Products/perl_dev_kit/>
  516. These are technically no compilers, just B<source packagers> with a
  517. simple native code unpacker. Run-time behaviour is actually slower
  518. than with a normal perl source or real compiler, because of the
  519. additional unpacking and check steps. It's just convenient to have
  520. single file applications.
  521. The simpliest windows I<"compiler"> would be then F<pl2exe.pl>
  522. in L<C::DynaLib>.
  523. Several years ago the C<undump> functionality used to work on several
  524. platforms. See L<perlrun> for C<-u>. Work is planned to revive C<undump>.
  525. =head1 AUTHOR
  526. This document was originally written by Nathan Torkington, and was
  527. maintained by the perl5-porters mailing list I<perl5-porters@perl.org>
  528. up to Perl version 5.8.
  529. This version with all the compiler options is now part of the C<B::C>
  530. compiler module, maintained by Reini Urban I<rurban@cpan.org>.
  531. =head1 SEE ALSO
  532. L<perlguts>, L<illguts>, L<perloptree>
  533. =cut