forked from rurban/perl-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOTES
194 lines (180 loc) · 8.4 KB
/
NOTES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
C backend invocation
If there are any non-option arguments, they are taken to be
names of objects to be saved (probably doesn't work properly yet).
Without extra arguments, it saves the main program.
-q Be quiet. STDOUT goes to $O::BEGIN_output
-qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT
-v Verbose (currently gives a few compilation statistics)
-- Force end of options
-uPackname Force apparently unused subs from package Packname to
be compiled. This allows programs to use eval "foo()"
even when sub foo is never seen to be used at compile
time. The down side is that any subs which really are
never used also have code generated. This option is
necessary, for example, if you have a signal handler
foo which you initialise with $SIG{BAR} = "foo".
A better fix, though, is just to change it to
$SIG{BAR} = \&foo. You can have multiple -u options.
-D Debug options (concat or separate flags like perl -D)
o OPs, prints each OP as it's processed
c COPs, prints COPs as processed (incl. file & line num)
S prints SV information on saving
A prints AV information on saving
C prints CV information on saving
M prints MAGIC information on saving
G prints GV information on saving
-f Force optimisations on or off one at a time.
cog Copy-on-grow: PVs declared and initialised statically
no-cog No copy-on-grow
-On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
Currently, -O1 and higher set -fcog.
Examples
perl -MO=C foo.pl > foo.c
perl cc_harness -o foo foo.c
perl -MO=C,-v,-DcA bar.pl > /dev/null
CC backend invocation
If there are any non-option arguments, they are taken to be names of
subs to be saved. Without extra arguments, it saves the main program.
-q Be quiet. STDOUT goes to $O::BEGIN_output
-qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT
-v Be verbose.
-- Force end of options
-uPackname Force apparently unused subs from package Packname to
be compiled. This allows programs to use eval "foo()"
even when sub foo is never seen to be used at compile
time. The down side is that any subs which really are
never used also have code generated. This option is
necessary, for example, if you have a signal handler
foo which you initialise with $SIG{BAR} = "foo".
A better fix, though, is just to change it to
$SIG{BAR} = \&foo. You can have multiple -u options.
-mModulename Instead of generating source for a runnable executable,
generate source for an XSUB module. The
boot_Modulename function (which DynaLoader can look
for) does the appropriate initialisation and runs the
main part of the Perl source that is being compiled.
-pn Generate code for perl patchlevel n (e.g. 3 or 4).
The default is to generate C code which will link
with the currently executing version of perl.
running the perl compiler.
-D Debug options (concat or separate flags like perl -D)
r Writes debugging output to STDERR just as it's about
to write to the program's runtime (otherwise writes
debugging info as comments in its C output).
O Outputs each OP as it's compiled
s Outputs the contents of the shadow stack at each OP
p Outputs the contents of the shadow pad of lexicals as
it's loaded for each sub or the main program.
q Outputs the name of each fake PP function in the queue
as it's about to processes.
l Output the filename and line number of each original
line of Perl code as it's processed (pp_nextstate).
t Outputs timing information of compilation stages
-f Force optimisations on or off one at a time.
[
cog Copy-on-grow: PVs declared and initialised statically
no-cog No copy-on-grow
These two not in CC yet.
]
freetmps-each-bblock Delays FREETMPS from the end of each
statement to the end of the each basic
block.
freetmps-each-loop Delays FREETMPS from the end of each
statement to the end of the group of
basic blocks forming a loop. At most
one of the freetmps-each-* options can
be used.
omit-taint Omits generating code for handling
perl's tainting mechanism.
-On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
Currently, -O1 sets -ffreetmps-each-bblock and -O2
sets -ffreetmps-each-loop.
Example
perl -MO=CC,-O2,-ofoo.c foo.pl
perl cc_harness -o foo foo.c
perl -MO=CC,-mFoo,-oFoo.c Foo.pm
perl cc_harness -shared -c -o Foo.so Foo.c
Bytecode backend invocation
If there are any non-option arguments, they are taken to be
names of objects to be saved (probably doesn't work properly yet).
Without extra arguments, it saves the main program.
-q Be quiet. STDOUT goes to $O::BEGIN_output
-qq Be very quiet. Also suppress "Syntax OK"
-ofilename Output to filename instead of STDOUT.
NYI -v Be verbose.
-- Force end of options.
NYI -f Force optimisations on or off one at a time.
Each can be preceded by no- to turn the option off.
NYI compress-nullops
Only fills in the necessary fields of ops which have
been optimised away by perl's internal compiler.
NYI omit-sequence-numbers
Leaves out code to fill in the op_seq field of all ops
which is only used by perl's internal compiler.
NYI bypass-nullops
If op->op_next ever points to a NULLOP, replaces the
op_next field with the first non-NULLOP in the path
of execution.
NYI strip-syntax-tree
Leaves out code to fill in the pointers which link the
internal syntax tree together. They're not needed at
run-time but leaving them out will make it impossible
to recompile or disassemble the resulting program.
It will also stop "goto label" statements from working.
NYI -On Optimisation level (n = 0, 1, 2, ...). -O means -O1.
-O1 sets -fcompress-nullops -fomit-sequence numbers.
-O6 adds -fstrip-syntax-tree.
NYI -D Debug options (concat or separate flags like perl -D)
o OPs, prints each OP as it's processed.
b print debugging information about bytecompiler progress
a tells the assembler to include source assembler lines
in its output as bytecode comments.
C prints each CV taken from the final symbol tree walk.
-S Output assembler source rather than piping it
through the assembler and outputting bytecode.
-H add #! perl shebang header
-s scan and keep keep syntax tree if goto op found.
scan the script for C<# line ..> directives and for <goto LABEL>
expressions. When gotos are found keep the syntax tree.
-b Save all the BEGIN blocks. Normally only BEGIN blocks that require
other files (ex. use Foo;) are saved.
-k keep syntax tree to disassemble the plc.
it is stripped by default.
-TI testing, dump the @INC av
-TF file testing, sets COP::file
-m Compile as a module rather than a standalone program.
Currently this just means that the bytecodes for
initialising main_start, main_root and curpad are
omitted.
Example
perl -MO=Bytecode,-O6,-H,-ofoo.plc foo.pl
perl -MO=Bytecode,-S foo.pl > foo.S
assemble foo.S > foo.plc
byteperl foo.plc
perl -MO=Bytecode,-m,-oFoo.pmc Foo.pm
Backends for debugging
perl -MO=Terse,exec foo.pl
perl -MO=Debug bar.pl
O module
Used with "perl -MO=Backend,foo,bar prog.pl" to invoke the backend
B::Backend with options foo and bar. O invokes the sub
B::Backend::compile() with arguments foo and bar at BEGIN time.
That compile() sub must do any inital argument processing replied.
If unsuccessful, it should return a string which O arranges to be
printed as an error message followed by a clean error exit. In the
normal case where any option processing in compile() is successful,
it should return a sub ref (usually a closure) to perform the
actual compilation. When O regains control, it ensures that the
"-c" option is forced (so that the program being compiled doesn't
end up running) and registers a CHECK block to call back the sub ref
returned from the backend's compile(). Perl then continues by
parsing prog.pl (just as it would with "perl -c prog.pl") and after
doing so, assuming there are no parse-time errors, the CHECK block
of O gets called and the actual backend compilation happens. Phew.
Od debugging module. See L<B::Debugger>
Used with "perl -d -MOd=Backend,foo,bar prog.pl" to invoke the backend
B::Backend with options foo and bar. Od delays the invocation of the sub
B::Backend::compile() with arguments foo and bar to the INIT block, so that
you can step through the backend with the perl source debugger.