Initial check-in of perl compiler.
[p5sagit/p5-mst-13.2.git] / NOTES
1 C backend invocation
2         If there are any non-option arguments, they are taken to be
3         names of objects to be saved (probably doesn't work properly yet).
4         Without extra arguments, it saves the main program.
5         -ofilename      Output to filename instead of STDOUT
6         -v              Verbose (currently gives a few compilation statistics)
7         --              Force end of options
8         -uPackname      Force apparently unused subs from package Packname to
9                         be compiled. This allows programs to use eval "foo()"
10                         even when sub foo is never seen to be used at compile
11                         time. The down side is that any subs which really are
12                         never used also have code generated. This option is
13                         necessary, for example, if you have a signal handler
14                         foo which you initialise with $SIG{BAR} = "foo".
15                         A better fix, though, is just to change it to
16                         $SIG{BAR} = \&foo. You can have multiple -u options.
17         -D              Debug options (concat or separate flags like perl -D)
18                 o       OPs, prints each OP as it's processed
19                 c       COPs, prints COPs as processed (incl. file & line num)
20                 A       prints AV information on saving
21                 C       prints CV information on saving
22                 M       prints MAGIC information on saving
23         -f              Force optimisations on or off one at a time.
24                 cog     Copy-on-grow: PVs declared and initialised statically
25                 no-cog  No copy-on-grow
26         -On             Optimisation level (n = 0, 1, 2, ...). -O means -O1.
27                         Currently, -O1 and higher set -fcog.
28
29 Examples
30         perl -MO=C foo.pl > foo.c
31         perl cc_harness -o foo foo.c
32
33         perl -MO=C,-v,-DcA bar.pl > /dev/null
34
35 CC backend invocation
36         If there are any non-option arguments, they are taken to be names of
37         subs to be saved. Without extra arguments, it saves the main program.
38         -ofilename      Output to filename instead of STDOUT
39         --              Force end of options
40         -uPackname      Force apparently unused subs from package Packname to
41                         be compiled. This allows programs to use eval "foo()"
42                         even when sub foo is never seen to be used at compile
43                         time. The down side is that any subs which really are
44                         never used also have code generated. This option is
45                         necessary, for example, if you have a signal handler
46                         foo which you initialise with $SIG{BAR} = "foo".
47                         A better fix, though, is just to change it to
48                         $SIG{BAR} = \&foo. You can have multiple -u options.
49         -D              Debug options (concat or separate flags like perl -D)
50                 r       Writes debugging output to STDERR just as it's about
51                         to write to the program's runtime (otherwise writes
52                         debugging info as comments in its C output).
53                 O       Outputs each OP as it's compiled
54                 s       Outputs the contents of the shadow stack at each OP
55                 p       Outputs the contents of the shadow pad of lexicals as
56                         it's loaded for each sub or the main program.
57                 q       Outputs the name of each fake PP function in the queue
58                         as it's about to processes.
59                 l       Output the filename and line number of each original
60                         line of Perl code as it's processed (pp_nextstate).
61                 t       Outputs timing information of compilation stages
62         -f              Force optimisations on or off one at a time.
63                 [
64                 cog     Copy-on-grow: PVs declared and initialised statically
65                 no-cog  No copy-on-grow
66                 These two not in CC yet.
67                 ]
68                 freetmps-each-bblock    Delays FREETMPS from the end of each
69                                         statement to the end of the each basic
70                                         block.
71                 freetmps-each-loop      Delays FREETMPS from the end of each
72                                         statement to the end of the group of
73                                         basic blocks forming a loop. At most
74                                         one of the freetmps-each-* options can
75                                         be used.
76                 omit-taint              Omits generating code for handling
77                                         perl's tainting mechanism.
78         -On             Optimisation level (n = 0, 1, 2, ...). -O means -O1.
79                         Currently, -O1 sets -ffreetmps-each-bblock and -O2
80                         sets -ffreetmps-each-loop.
81
82 Example
83         perl -MO=CC,-O2,-ofoo.c foo.pl
84         perl cc_harness -o foo foo.c
85
86
87 Bytecode backend invocation
88
89         If there are any non-option arguments, they are taken to be
90         names of objects to be saved (probably doesn't work properly yet).
91         Without extra arguments, it saves the main program.
92         -ofilename      Output to filename instead of STDOUT.
93         --              Force end of options.
94         -f              Force optimisations on or off one at a time.
95                         Each can be preceded by no- to turn the option off.
96                 compress-nullops
97                         Only fills in the necessary fields of ops which have
98                         been optimised away by perl's internal compiler.
99                 omit-sequence-numbers
100                         Leaves out code to fill in the op_seq field of all ops
101                         which is only used by perl's internal compiler.
102                 bypass-nullops
103                         If op->op_next ever points to a NULLOP, replaces the
104                         op_next field with the first non-NULLOP in the path
105                         of execution.
106                 strip-syntax-tree
107                         Leaves out code to fill in the pointers which link the
108                         internal syntax tree together. They're not needed at
109                         run-time but leaving them out will make it impossible
110                         to recompile or disassemble the resulting program.
111                         It will also stop "goto label" statements from working.
112         -On             Optimisation level (n = 0, 1, 2, ...). -O means -O1.
113                         -O1 sets -fcompress-nullops -fomit-sequence numbers.
114                         -O6 adds -fstrip-syntax-tree.
115         -D              Debug options (concat or separate flags like perl -D)
116                 o       OPs, prints each OP as it's processed.
117                 a       tells the assembler to include source assembler lines
118                         in its output as bytecode comments.
119                 C       prints each CV taken from the final symbol tree walk.
120         -S              Output assembler source rather than piping it
121                         through the assembler and outputting bytecode.
122         -m              Compile as a module rather than a standalone program.
123                         Currently this just means that the bytecodes for
124                         initialising main_start, main_root and curpad are
125                         omitted.
126
127 Example
128         perl -MO=Bytecode,-O6,-o,foo.plc foo.pl
129
130         perl -MO=Bytecode,-S foo.pl > foo.S
131         assemble foo.S > foo.plc
132         byteperl foo.plc
133
134         perl -MO=Bytecode,-m,-oFoo.pmc Foo.pm
135
136 Backends for debugging
137         perl -MO=Terse,exec foo.pl
138         perl -MO=Debug bar.pl
139
140 O module
141         Used with "perl -MO=Backend,foo,bar prog.pl" to invoke the backend
142         B::Backend with options foo and bar. O invokes the sub
143         B::Backend::compile() with arguments foo and bar at BEGIN time.
144         That compile() sub must do any inital argument processing replied.
145         If unsuccessful, it should return a string which O arranges to be
146         printed as an error message followed by a clean error exit. In the
147         normal case where any option processing in compile() is successful,
148         it should return a sub ref (usually a closure) to perform the
149         actual compilation. When O regains control, it ensures that the
150         "-c" option is forced (so that the program being compiled doesn't
151         end up running) and registers an END block to call back the sub ref
152         returned from the backend's compile(). Perl then continues by
153         parsing prog.pl (just as it would with "perl -c prog.pl") and after
154         doing so, assuming there are no parse-time errors, the END block
155         of O gets called and the actual backend compilation happens. Phew.