perlcompile.pod 26 KB

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