Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "PERLCOMPILE 1" | |
132 | .TH PERLCOMPILE 1 "2006-01-07" "perl v5.8.8" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | perlcompile \- Introduction to the Perl Compiler\-Translator | |
135 | .SH "DESCRIPTION" | |
136 | .IX Header "DESCRIPTION" | |
137 | Perl has always had a compiler: your source is compiled into an | |
138 | internal form (a parse tree) which is then optimized before being | |
139 | run. Since version 5.005, Perl has shipped with a module | |
140 | capable of inspecting the optimized parse tree (\f(CW\*(C`B\*(C'\fR), and this has | |
141 | been used to write many useful utilities, including a module that lets | |
142 | you turn your Perl into C source code that can be compiled into a | |
143 | native executable. | |
144 | .PP | |
145 | The \f(CW\*(C`B\*(C'\fR module provides access to the parse tree, and other modules | |
146 | (\*(L"back ends\*(R") do things with the tree. Some write it out as | |
147 | bytecode, C source code, or a semi-human-readable text. Another | |
148 | traverses the parse tree to build a cross-reference of which | |
149 | subroutines, formats, and variables are used where. Another checks | |
150 | your code for dubious constructs. Yet another back end dumps the | |
151 | parse tree back out as Perl source, acting as a source code beautifier | |
152 | or deobfuscator. | |
153 | .PP | |
154 | Because its original purpose was to be a way to produce C code | |
155 | corresponding to a Perl program, and in turn a native executable, the | |
156 | \&\f(CW\*(C`B\*(C'\fR module and its associated back ends are known as \*(L"the | |
157 | compiler\*(R", even though they don't really compile anything. | |
158 | Different parts of the compiler are more accurately a \*(L"translator\*(R", | |
159 | or an \*(L"inspector\*(R", but people want Perl to have a \*(L"compiler | |
160 | option\*(R" not an \*(L"inspector gadget\*(R". What can you do? | |
161 | .PP | |
162 | This document covers the use of the Perl compiler: which modules | |
163 | it comprises, how to use the most important of the back end modules, | |
164 | what problems there are, and how to work around them. | |
165 | .Sh "Layout" | |
166 | .IX Subsection "Layout" | |
167 | The compiler back ends are in the \f(CW\*(C`B::\*(C'\fR hierarchy, and the front-end | |
168 | (the module that you, the user of the compiler, will sometimes | |
169 | interact with) is the O module. Some back ends (e.g., \f(CW\*(C`B::C\*(C'\fR) have | |
170 | programs (e.g., \fIperlcc\fR) to hide the modules' complexity. | |
171 | .PP | |
172 | Here are the important back ends to know about, with their status | |
173 | expressed as a number from 0 (outline for later implementation) to | |
174 | 10 (if there's a bug in it, we're very surprised): | |
175 | .IP "B::Bytecode" 4 | |
176 | .IX Item "B::Bytecode" | |
177 | Stores the parse tree in a machine-independent format, suitable | |
178 | for later reloading through the ByteLoader module. Status: 5 (some | |
179 | things work, some things don't, some things are untested). | |
180 | .IP "B::C" 4 | |
181 | .IX Item "B::C" | |
182 | Creates a C source file containing code to rebuild the parse tree | |
183 | and resume the interpreter. Status: 6 (many things work adequately, | |
184 | including programs using Tk). | |
185 | .IP "B::CC" 4 | |
186 | .IX Item "B::CC" | |
187 | Creates a C source file corresponding to the run time code path in | |
188 | the parse tree. This is the closest to a Perl-to-C translator there | |
189 | is, but the code it generates is almost incomprehensible because it | |
190 | translates the parse tree into a giant switch structure that | |
191 | manipulates Perl structures. Eventual goal is to reduce (given | |
192 | sufficient type information in the Perl program) some of the | |
193 | Perl data structure manipulations into manipulations of C\-level | |
194 | ints, floats, etc. Status: 5 (some things work, including | |
195 | uncomplicated Tk examples). | |
196 | .IP "B::Lint" 4 | |
197 | .IX Item "B::Lint" | |
198 | Complains if it finds dubious constructs in your source code. Status: | |
199 | 6 (it works adequately, but only has a very limited number of areas | |
200 | that it checks). | |
201 | .IP "B::Deparse" 4 | |
202 | .IX Item "B::Deparse" | |
203 | Recreates the Perl source, making an attempt to format it coherently. | |
204 | Status: 8 (it works nicely, but a few obscure things are missing). | |
205 | .IP "B::Xref" 4 | |
206 | .IX Item "B::Xref" | |
207 | Reports on the declaration and use of subroutines and variables. | |
208 | Status: 8 (it works nicely, but still has a few lingering bugs). | |
209 | .SH "Using The Back Ends" | |
210 | .IX Header "Using The Back Ends" | |
211 | The following sections describe how to use the various compiler back | |
212 | ends. They're presented roughly in order of maturity, so that the | |
213 | most stable and proven back ends are described first, and the most | |
214 | experimental and incomplete back ends are described last. | |
215 | .PP | |
216 | The O module automatically enabled the \fB\-c\fR flag to Perl, which | |
217 | prevents Perl from executing your code once it has been compiled. | |
218 | This is why all the back ends print: | |
219 | .PP | |
220 | .Vb 1 | |
221 | \& myperlprogram syntax OK | |
222 | .Ve | |
223 | .PP | |
224 | before producing any other output. | |
225 | .Sh "The Cross Referencing Back End" | |
226 | .IX Subsection "The Cross Referencing Back End" | |
227 | The cross referencing back end (B::Xref) produces a report on your program, | |
228 | breaking down declarations and uses of subroutines and variables (and | |
229 | formats) by file and subroutine. For instance, here's part of the | |
230 | report from the \fIpod2man\fR program that comes with Perl: | |
231 | .PP | |
232 | .Vb 12 | |
233 | \& Subroutine clear_noremap | |
234 | \& Package (lexical) | |
235 | \& $ready_to_print i1069, 1079 | |
236 | \& Package main | |
237 | \& $& 1086 | |
238 | \& $. 1086 | |
239 | \& $0 1086 | |
240 | \& $1 1087 | |
241 | \& $2 1085, 1085 | |
242 | \& $3 1085, 1085 | |
243 | \& $ARGV 1086 | |
244 | \& %HTML_Escapes 1085, 1085 | |
245 | .Ve | |
246 | .PP | |
247 | This shows the variables used in the subroutine \f(CW\*(C`clear_noremap\*(C'\fR. The | |
248 | variable \f(CW$ready_to_print\fR is a \fImy()\fR (lexical) variable, | |
249 | \&\fBi\fRntroduced (first declared with \fImy()\fR) on line 1069, and used on | |
250 | line 1079. The variable \f(CW$&\fR from the main package is used on 1086, | |
251 | and so on. | |
252 | .PP | |
253 | A line number may be prefixed by a single letter: | |
254 | .IP "i" 4 | |
255 | .IX Item "i" | |
256 | Lexical variable introduced (declared with \fImy()\fR) for the first time. | |
257 | .IP "&" 4 | |
258 | Subroutine or method call. | |
259 | .IP "s" 4 | |
260 | .IX Item "s" | |
261 | Subroutine defined. | |
262 | .IP "r" 4 | |
263 | .IX Item "r" | |
264 | Format defined. | |
265 | .PP | |
266 | The most useful option the cross referencer has is to save the report | |
267 | to a separate file. For instance, to save the report on | |
268 | \&\fImyperlprogram\fR to the file \fIreport\fR: | |
269 | .PP | |
270 | .Vb 1 | |
271 | \& $ perl -MO=Xref,-oreport myperlprogram | |
272 | .Ve | |
273 | .Sh "The Decompiling Back End" | |
274 | .IX Subsection "The Decompiling Back End" | |
275 | The Deparse back end turns your Perl source back into Perl source. It | |
276 | can reformat along the way, making it useful as a de\-obfuscator. The | |
277 | most basic way to use it is: | |
278 | .PP | |
279 | .Vb 1 | |
280 | \& $ perl -MO=Deparse myperlprogram | |
281 | .Ve | |
282 | .PP | |
283 | You'll notice immediately that Perl has no idea of how to paragraph | |
284 | your code. You'll have to separate chunks of code from each other | |
285 | with newlines by hand. However, watch what it will do with | |
286 | one\-liners: | |
287 | .PP | |
288 | .Vb 12 | |
289 | \& $ perl -MO=Deparse -e '$op=shift||die "usage: $0 | |
290 | \& code [...]";chomp(@ARGV=<>)unless@ARGV; for(@ARGV){$was=$_;eval$op; | |
291 | \& die$@ if$@; rename$was,$_ unless$was eq $_}' | |
292 | \& -e syntax OK | |
293 | \& $op = shift @ARGV || die("usage: $0 code [...]"); | |
294 | \& chomp(@ARGV = <ARGV>) unless @ARGV; | |
295 | \& foreach $_ (@ARGV) { | |
296 | \& $was = $_; | |
297 | \& eval $op; | |
298 | \& die $@ if $@; | |
299 | \& rename $was, $_ unless $was eq $_; | |
300 | \& } | |
301 | .Ve | |
302 | .PP | |
303 | The decompiler has several options for the code it generates. For | |
304 | instance, you can set the size of each indent from 4 (as above) to | |
305 | 2 with: | |
306 | .PP | |
307 | .Vb 1 | |
308 | \& $ perl -MO=Deparse,-si2 myperlprogram | |
309 | .Ve | |
310 | .PP | |
311 | The \fB\-p\fR option adds parentheses where normally they are omitted: | |
312 | .PP | |
313 | .Vb 6 | |
314 | \& $ perl -MO=Deparse -e 'print "Hello, world\en"' | |
315 | \& -e syntax OK | |
316 | \& print "Hello, world\en"; | |
317 | \& $ perl -MO=Deparse,-p -e 'print "Hello, world\en"' | |
318 | \& -e syntax OK | |
319 | \& print("Hello, world\en"); | |
320 | .Ve | |
321 | .PP | |
322 | See B::Deparse for more information on the formatting options. | |
323 | .Sh "The Lint Back End" | |
324 | .IX Subsection "The Lint Back End" | |
325 | The lint back end (B::Lint) inspects programs for poor style. One | |
326 | programmer's bad style is another programmer's useful tool, so options | |
327 | let you select what is complained about. | |
328 | .PP | |
329 | To run the style checker across your source code: | |
330 | .PP | |
331 | .Vb 1 | |
332 | \& $ perl -MO=Lint myperlprogram | |
333 | .Ve | |
334 | .PP | |
335 | To disable context checks and undefined subroutines: | |
336 | .PP | |
337 | .Vb 1 | |
338 | \& $ perl -MO=Lint,-context,-undefined-subs myperlprogram | |
339 | .Ve | |
340 | .PP | |
341 | See B::Lint for information on the options. | |
342 | .Sh "The Simple C Back End" | |
343 | .IX Subsection "The Simple C Back End" | |
344 | This module saves the internal compiled state of your Perl program | |
345 | to a C source file, which can be turned into a native executable | |
346 | for that particular platform using a C compiler. The resulting | |
347 | program links against the Perl interpreter library, so it | |
348 | will not save you disk space (unless you build Perl with a shared | |
349 | library) or program size. It may, however, save you startup time. | |
350 | .PP | |
351 | The \f(CW\*(C`perlcc\*(C'\fR tool generates such executables by default. | |
352 | .PP | |
353 | .Vb 1 | |
354 | \& perlcc myperlprogram.pl | |
355 | .Ve | |
356 | .Sh "The Bytecode Back End" | |
357 | .IX Subsection "The Bytecode Back End" | |
358 | This back end is only useful if you also have a way to load and | |
359 | execute the bytecode that it produces. The ByteLoader module provides | |
360 | this functionality. | |
361 | .PP | |
362 | To turn a Perl program into executable byte code, you can use \f(CW\*(C`perlcc\*(C'\fR | |
363 | with the \f(CW\*(C`\-B\*(C'\fR switch: | |
364 | .PP | |
365 | .Vb 1 | |
366 | \& perlcc -B myperlprogram.pl | |
367 | .Ve | |
368 | .PP | |
369 | The byte code is machine independent, so once you have a compiled | |
370 | module or program, it is as portable as Perl source (assuming that | |
371 | the user of the module or program has a modern-enough Perl interpreter | |
372 | to decode the byte code). | |
373 | .PP | |
374 | See \fBB::Bytecode\fR for information on options to control the | |
375 | optimization and nature of the code generated by the Bytecode module. | |
376 | .Sh "The Optimized C Back End" | |
377 | .IX Subsection "The Optimized C Back End" | |
378 | The optimized C back end will turn your Perl program's run time | |
379 | code-path into an equivalent (but optimized) C program that manipulates | |
380 | the Perl data structures directly. The program will still link against | |
381 | the Perl interpreter library, to allow for \fIeval()\fR, \f(CW\*(C`s///e\*(C'\fR, | |
382 | \&\f(CW\*(C`require\*(C'\fR, etc. | |
383 | .PP | |
384 | The \f(CW\*(C`perlcc\*(C'\fR tool generates such executables when using the \-O | |
385 | switch. To compile a Perl program (ending in \f(CW\*(C`.pl\*(C'\fR | |
386 | or \f(CW\*(C`.p\*(C'\fR): | |
387 | .PP | |
388 | .Vb 1 | |
389 | \& perlcc -O myperlprogram.pl | |
390 | .Ve | |
391 | .PP | |
392 | To produce a shared library from a Perl module (ending in \f(CW\*(C`.pm\*(C'\fR): | |
393 | .PP | |
394 | .Vb 1 | |
395 | \& perlcc -O Myperlmodule.pm | |
396 | .Ve | |
397 | .PP | |
398 | For more information, see perlcc and B::CC. | |
399 | .SH "Module List for the Compiler Suite" | |
400 | .IX Header "Module List for the Compiler Suite" | |
401 | .IP "B" 4 | |
402 | .IX Item "B" | |
403 | This module is the introspective (\*(L"reflective\*(R" in Java terms) | |
404 | module, which allows a Perl program to inspect its innards. The | |
405 | back end modules all use this module to gain access to the compiled | |
406 | parse tree. You, the user of a back end module, will not need to | |
407 | interact with B. | |
408 | .IP "O" 4 | |
409 | .IX Item "O" | |
410 | This module is the front-end to the compiler's back ends. Normally | |
411 | called something like this: | |
412 | .Sp | |
413 | .Vb 1 | |
414 | \& $ perl -MO=Deparse myperlprogram | |
415 | .Ve | |
416 | .Sp | |
417 | This is like saying \f(CW\*(C`use O 'Deparse'\*(C'\fR in your Perl program. | |
418 | .IP "B::Asmdata" 4 | |
419 | .IX Item "B::Asmdata" | |
420 | This module is used by the B::Assembler module, which is in turn used | |
421 | by the B::Bytecode module, which stores a parse-tree as | |
422 | bytecode for later loading. It's not a back end itself, but rather a | |
423 | component of a back end. | |
424 | .IP "B::Assembler" 4 | |
425 | .IX Item "B::Assembler" | |
426 | This module turns a parse-tree into data suitable for storing | |
427 | and later decoding back into a parse\-tree. It's not a back end | |
428 | itself, but rather a component of a back end. It's used by the | |
429 | \&\fIassemble\fR program that produces bytecode. | |
430 | .IP "B::Bblock" 4 | |
431 | .IX Item "B::Bblock" | |
432 | This module is used by the B::CC back end. It walks \*(L"basic blocks\*(R". | |
433 | A basic block is a series of operations which is known to execute from | |
434 | start to finish, with no possibility of branching or halting. | |
435 | .IP "B::Bytecode" 4 | |
436 | .IX Item "B::Bytecode" | |
437 | This module is a back end that generates bytecode from a | |
438 | program's parse tree. This bytecode is written to a file, from where | |
439 | it can later be reconstructed back into a parse tree. The goal is to | |
440 | do the expensive program compilation once, save the interpreter's | |
441 | state into a file, and then restore the state from the file when the | |
442 | program is to be executed. See \*(L"The Bytecode Back End\*(R" | |
443 | for details about usage. | |
444 | .IP "B::C" 4 | |
445 | .IX Item "B::C" | |
446 | This module writes out C code corresponding to the parse tree and | |
447 | other interpreter internal structures. You compile the corresponding | |
448 | C file, and get an executable file that will restore the internal | |
449 | structures and the Perl interpreter will begin running the | |
450 | program. See \*(L"The Simple C Back End\*(R" for details about usage. | |
451 | .IP "B::CC" 4 | |
452 | .IX Item "B::CC" | |
453 | This module writes out C code corresponding to your program's | |
454 | operations. Unlike the B::C module, which merely stores the | |
455 | interpreter and its state in a C program, the B::CC module makes a | |
456 | C program that does not involve the interpreter. As a consequence, | |
457 | programs translated into C by B::CC can execute faster than normal | |
458 | interpreted programs. See \*(L"The Optimized C Back End\*(R" for | |
459 | details about usage. | |
460 | .IP "B::Concise" 4 | |
461 | .IX Item "B::Concise" | |
462 | This module prints a concise (but complete) version of the Perl parse | |
463 | tree. Its output is more customizable than the one of B::Terse or | |
464 | B::Debug (and it can emulate them). This module useful for people who | |
465 | are writing their own back end, or who are learning about the Perl | |
466 | internals. It's not useful to the average programmer. | |
467 | .IP "B::Debug" 4 | |
468 | .IX Item "B::Debug" | |
469 | This module dumps the Perl parse tree in verbose detail to \s-1STDOUT\s0. | |
470 | It's useful for people who are writing their own back end, or who | |
471 | are learning about the Perl internals. It's not useful to the | |
472 | average programmer. | |
473 | .IP "B::Deparse" 4 | |
474 | .IX Item "B::Deparse" | |
475 | This module produces Perl source code from the compiled parse tree. | |
476 | It is useful in debugging and deconstructing other people's code, | |
477 | also as a pretty-printer for your own source. See | |
478 | \&\*(L"The Decompiling Back End\*(R" for details about usage. | |
479 | .IP "B::Disassembler" 4 | |
480 | .IX Item "B::Disassembler" | |
481 | This module turns bytecode back into a parse tree. It's not a back | |
482 | end itself, but rather a component of a back end. It's used by the | |
483 | \&\fIdisassemble\fR program that comes with the bytecode. | |
484 | .IP "B::Lint" 4 | |
485 | .IX Item "B::Lint" | |
486 | This module inspects the compiled form of your source code for things | |
487 | which, while some people frown on them, aren't necessarily bad enough | |
488 | to justify a warning. For instance, use of an array in scalar context | |
489 | without explicitly saying \f(CW\*(C`scalar(@array)\*(C'\fR is something that Lint | |
490 | can identify. See \*(L"The Lint Back End\*(R" for details about usage. | |
491 | .IP "B::Showlex" 4 | |
492 | .IX Item "B::Showlex" | |
493 | This module prints out the \fImy()\fR variables used in a function or a | |
494 | file. To get a list of the \fImy()\fR variables used in the subroutine | |
495 | \&\fImysub()\fR defined in the file myperlprogram: | |
496 | .Sp | |
497 | .Vb 1 | |
498 | \& $ perl -MO=Showlex,mysub myperlprogram | |
499 | .Ve | |
500 | .Sp | |
501 | To get a list of the \fImy()\fR variables used in the file myperlprogram: | |
502 | .Sp | |
503 | .Vb 1 | |
504 | \& $ perl -MO=Showlex myperlprogram | |
505 | .Ve | |
506 | .Sp | |
507 | [\s-1BROKEN\s0] | |
508 | .IP "B::Stackobj" 4 | |
509 | .IX Item "B::Stackobj" | |
510 | This module is used by the B::CC module. It's not a back end itself, | |
511 | but rather a component of a back end. | |
512 | .IP "B::Stash" 4 | |
513 | .IX Item "B::Stash" | |
514 | This module is used by the perlcc program, which compiles a module | |
515 | into an executable. B::Stash prints the symbol tables in use by a | |
516 | program, and is used to prevent B::CC from producing C code for the | |
517 | B::* and O modules. It's not a back end itself, but rather a | |
518 | component of a back end. | |
519 | .IP "B::Terse" 4 | |
520 | .IX Item "B::Terse" | |
521 | This module prints the contents of the parse tree, but without as much | |
522 | information as B::Debug. For comparison, \f(CW\*(C`print "Hello, world."\*(C'\fR | |
523 | produced 96 lines of output from B::Debug, but only 6 from B::Terse. | |
524 | .Sp | |
525 | This module is useful for people who are writing their own back end, | |
526 | or who are learning about the Perl internals. It's not useful to the | |
527 | average programmer. | |
528 | .IP "B::Xref" 4 | |
529 | .IX Item "B::Xref" | |
530 | This module prints a report on where the variables, subroutines, and | |
531 | formats are defined and used within a program and the modules it | |
532 | loads. See \*(L"The Cross Referencing Back End\*(R" for details about | |
533 | usage. | |
534 | .SH "KNOWN PROBLEMS" | |
535 | .IX Header "KNOWN PROBLEMS" | |
536 | The simple C backend currently only saves typeglobs with alphanumeric | |
537 | names. | |
538 | .PP | |
539 | The optimized C backend outputs code for more modules than it should | |
540 | (e.g., DirHandle). It also has little hope of properly handling | |
541 | \&\f(CW\*(C`goto LABEL\*(C'\fR outside the running subroutine (\f(CW\*(C`goto &sub\*(C'\fR is okay). | |
542 | \&\f(CW\*(C`goto LABEL\*(C'\fR currently does not work at all in this backend. | |
543 | It also creates a huge initialization function that gives | |
544 | C compilers headaches. Splitting the initialization function gives | |
545 | better results. Other problems include: unsigned math does not | |
546 | work correctly; some opcodes are handled incorrectly by default | |
547 | opcode handling mechanism. | |
548 | .PP | |
549 | BEGIN{} blocks are executed while compiling your code. Any external | |
550 | state that is initialized in BEGIN{}, such as opening files, initiating | |
551 | database connections etc., do not behave properly. To work around | |
552 | this, Perl has an INIT{} block that corresponds to code being executed | |
553 | before your program begins running but after your program has finished | |
554 | being compiled. Execution order: BEGIN{}, (possible save of state | |
555 | through compiler back\-end), INIT{}, program runs, END{}. | |
556 | .SH "AUTHOR" | |
557 | .IX Header "AUTHOR" | |
558 | This document was originally written by Nathan Torkington, and is now | |
559 | maintained by the perl5\-porters mailing list | |
560 | \&\fIperl5\-porters@perl.org\fR. |