Commit | Line | Data |
73f0cc2d |
1 | BEGIN { |
2 | push @INC, './lib'; |
9ad884cb |
3 | require 'regen_lib.pl'; |
73f0cc2d |
4 | } |
a8a597b2 |
5 | use strict; |
6 | my %alias_to = ( |
113d5bd9 |
7 | U32 => [qw(line_t)], |
8 | PADOFFSET => [qw(STRLEN SSize_t)], |
dea28490 |
9 | U16 => [qw(OPCODE short)], |
d5e9ef99 |
10 | U8 => [qw(char)], |
a8a597b2 |
11 | ); |
12 | |
7934575e |
13 | my @optype= qw(OP UNOP BINOP LOGOP LISTOP PMOP SVOP PADOP PVOP LOOP COP); |
a8a597b2 |
14 | |
15 | # Nullsv *must* come first in the following so that the condition |
16 | # ($$sv == 0) can continue to be used to test (sv == Nullsv). |
5c3c3f81 |
17 | my @specialsv = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no |
18 | (SV*)pWARN_ALL (SV*)pWARN_NONE (SV*)pWARN_STD); |
a8a597b2 |
19 | |
20 | my (%alias_from, $from, $tos); |
21 | while (($from, $tos) = each %alias_to) { |
22 | map { $alias_from{$_} = $from } @$tos; |
23 | } |
24 | |
25 | my $c_header = <<'EOT'; |
37442d52 |
26 | /* -*- buffer-read-only: t -*- |
27 | * |
4eb8286e |
28 | * Copyright (c) 1996-1999 Malcolm Beattie |
a8a597b2 |
29 | * |
30 | * You may distribute under the terms of either the GNU General Public |
31 | * License or the Artistic License, as specified in the README file. |
32 | * |
33 | */ |
34 | /* |
35 | * This file is autogenerated from bytecode.pl. Changes made here will be lost. |
36 | */ |
37 | EOT |
38 | |
39 | my $perl_header; |
40 | ($perl_header = $c_header) =~ s{[/ ]?\*/?}{#}g; |
41 | |
de125441 |
42 | safer_unlink "ext/B/B/Asmdata.pm"; |
a8a597b2 |
43 | |
44 | # |
45 | # Start with boilerplate for Asmdata.pm |
46 | # |
33b839e2 |
47 | open(ASMDATA_PM, ">ext/B/B/Asmdata.pm") or die "ext/B/B/Asmdata.pm: $!"; |
dfb1454f |
48 | binmode ASMDATA_PM; |
a8a597b2 |
49 | print ASMDATA_PM $perl_header, <<'EOT'; |
50 | package B::Asmdata; |
28b605d8 |
51 | |
a0edd7f8 |
52 | our $VERSION = '1.01'; |
28b605d8 |
53 | |
a8a597b2 |
54 | use Exporter; |
55 | @ISA = qw(Exporter); |
56 | @EXPORT_OK = qw(%insn_data @insn_name @optype @specialsv_name); |
1b11e67e |
57 | our(%insn_data, @insn_name, @optype, @specialsv_name); |
a8a597b2 |
58 | |
59 | EOT |
60 | print ASMDATA_PM <<"EOT"; |
61 | \@optype = qw(@optype); |
62 | \@specialsv_name = qw(@specialsv); |
63 | |
64 | # XXX insn_data is initialised this way because with a large |
65 | # %insn_data = (foo => [...], bar => [...], ...) initialiser |
66 | # I get a hard-to-track-down stack underflow and segfault. |
67 | EOT |
68 | |
93d343c6 |
69 | my $size = @specialsv; |
70 | |
a8a597b2 |
71 | my (@insn_name, $insn_num, $insn, $lvalue, $argtype, $flags, $fundtype); |
72 | |
73 | while (<DATA>) { |
1df34986 |
74 | if (/^\s*#/) { |
1df34986 |
75 | next; |
76 | } |
a8a597b2 |
77 | chop; |
a8a597b2 |
78 | next unless length; |
79 | if (/^%number\s+(.*)/) { |
80 | $insn_num = $1; |
81 | next; |
82 | } elsif (/%enum\s+(.*?)\s+(.*)/) { |
83 | create_enum($1, $2); # must come before instructions |
84 | next; |
85 | } |
86 | ($insn, $lvalue, $argtype, $flags) = split; |
b97332e7 |
87 | my $rvalcast = ''; |
88 | if ($argtype =~ m:(.+)/(.+):) { |
89 | ($rvalcast, $argtype) = ("($1)", $2); |
90 | } |
a8a597b2 |
91 | $insn_name[$insn_num] = $insn; |
92 | $fundtype = $alias_from{$argtype} || $argtype; |
93 | |
94 | # |
a8a597b2 |
95 | # Add the initialiser line for %insn_data in Asmdata.pm |
96 | # |
97 | print ASMDATA_PM <<"EOT"; |
98 | \$insn_data{$insn} = [$insn_num, \\&PUT_$fundtype, "GET_$fundtype"]; |
99 | EOT |
100 | |
101 | # Find the next unused instruction number |
102 | do { $insn_num++ } while $insn_name[$insn_num]; |
103 | } |
104 | |
105 | # |
a8a597b2 |
106 | # Finish off insn_data and create array initialisers in Asmdata.pm |
107 | # |
108 | print ASMDATA_PM <<'EOT'; |
109 | |
110 | my ($insn_name, $insn_data); |
111 | while (($insn_name, $insn_data) = each %insn_data) { |
112 | $insn_name[$insn_data->[0]] = $insn_name; |
113 | } |
114 | # Fill in any gaps |
115 | @insn_name = map($_ || "unused", @insn_name); |
116 | |
117 | 1; |
42d3a99d |
118 | |
119 | __END__ |
120 | |
121 | =head1 NAME |
122 | |
de125441 |
123 | B::Asmdata - Autogenerated data about Perl ops |
42d3a99d |
124 | |
125 | =head1 SYNOPSIS |
126 | |
4162ffa6 |
127 | use B::Asmdata qw(%insn_data @insn_name @optype @specialsv_name); |
42d3a99d |
128 | |
129 | =head1 DESCRIPTION |
130 | |
4162ffa6 |
131 | Provides information about Perl ops in order to generate bytecode via |
132 | a bunch of exported variables. Its mostly used by B::Assembler and |
133 | B::Disassembler. |
134 | |
135 | =over 4 |
136 | |
137 | =item %insn_data |
138 | |
139 | my($bytecode_num, $put_sub, $get_meth) = @$insn_data{$op_name}; |
140 | |
141 | For a given $op_name (for example, 'cop_label', 'sv_flags', etc...) |
142 | you get an array ref containing the bytecode number of the op, a |
143 | reference to the subroutine used to 'PUT', and the name of the method |
144 | used to 'GET'. |
145 | |
146 | =for _private |
147 | Add more detail about what $put_sub and $get_meth are and how to use them. |
148 | |
149 | =item @insn_name |
150 | |
151 | my $op_name = $insn_name[$bytecode_num]; |
152 | |
153 | A simple mapping of the bytecode number to the name of the op. |
154 | Suitable for using with %insn_data like so: |
155 | |
156 | my $op_info = $insn_data{$insn_name[$bytecode_num]}; |
157 | |
158 | =item @optype |
159 | |
160 | my $op_type = $optype[$op_type_num]; |
161 | |
162 | A simple mapping of the op type number to its type (like 'COP' or 'BINOP'). |
163 | |
164 | =item @specialsv_name |
165 | |
166 | my $sv_name = $specialsv_name[$sv_index]; |
167 | |
168 | Certain SV types are considered 'special'. They're represented by |
3c4b39be |
169 | B::SPECIAL and are referred to by a number from the specialsv_list. |
4162ffa6 |
170 | This array maps that number back to the name of the SV (like 'Nullsv' |
171 | or '&PL_sv_undef'). |
172 | |
173 | =back |
42d3a99d |
174 | |
175 | =head1 AUTHOR |
176 | |
177 | Malcolm Beattie, C<mbeattie@sable.ox.ac.uk> |
178 | |
179 | =cut |
37442d52 |
180 | |
181 | # ex: set ro: |
a8a597b2 |
182 | EOT |
183 | |
36bb303b |
184 | |
185 | close ASMDATA_PM or die "Error closing ASMDATA_PM: $!"; |
36bb303b |
186 | |
a8a597b2 |
187 | __END__ |
188 | # First set instruction ord("#") to read comment to end-of-line (sneaky) |
189 | %number 35 |
fe3a57c4 |
190 | comment arg comment_t |
a8a597b2 |
191 | # Then make ord("\n") into a no-op |
192 | %number 10 |
193 | nop none none |
1df34986 |
194 | |
a8a597b2 |
195 | # Now for the rest of the ordinary ones, beginning with \0 which is |
196 | # ret so that \0-terminated strings can be read properly as bytecode. |
197 | %number 0 |
198 | # |
b97332e7 |
199 | # The argtype is either a single type or "rightvaluecast/argtype". |
200 | # |
92742e37 |
201 | #opcode lvalue argtype flags |
a8a597b2 |
202 | # |
92742e37 |
203 | ret none none x |
059a8bb7 |
204 | ldsv bstate->bs_sv svindex |
92742e37 |
205 | ldop PL_op opindex |
059a8bb7 |
206 | stsv bstate->bs_sv U32 s |
92742e37 |
207 | stop PL_op U32 s |
7b2c381c |
208 | stpv bstate->bs_pv.pvx U32 x |
059a8bb7 |
209 | ldspecsv bstate->bs_sv U8 x |
566ece03 |
210 | ldspecsvx bstate->bs_sv U8 x |
87d46f97 |
211 | newsv bstate->bs_sv svtype x |
f716adb3 |
212 | newsvx bstate->bs_sv svtype x |
92742e37 |
213 | newop PL_op U8 x |
566ece03 |
214 | newopx PL_op U16 x |
92742e37 |
215 | newopn PL_op U8 x |
216 | newpv none PV |
7b2c381c |
217 | pv_cur bstate->bs_pv.xpv.xpv_cur STRLEN |
218 | pv_free bstate->bs_pv.pvx none x |
87d46f97 |
219 | sv_upgrade bstate->bs_sv svtype x |
059a8bb7 |
220 | sv_refcnt SvREFCNT(bstate->bs_sv) U32 |
221 | sv_refcnt_add SvREFCNT(bstate->bs_sv) I32 x |
222 | sv_flags SvFLAGS(bstate->bs_sv) U32 |
87a1ef3d |
223 | xrv bstate->bs_sv svindex x |
059a8bb7 |
224 | xpv bstate->bs_sv none x |
87a1ef3d |
225 | xpv_cur bstate->bs_sv STRLEN x |
226 | xpv_len bstate->bs_sv STRLEN x |
227 | xiv bstate->bs_sv IV x |
228 | xnv bstate->bs_sv NV x |
059a8bb7 |
229 | xlv_targoff LvTARGOFF(bstate->bs_sv) STRLEN |
230 | xlv_targlen LvTARGLEN(bstate->bs_sv) STRLEN |
231 | xlv_targ LvTARG(bstate->bs_sv) svindex |
232 | xlv_type LvTYPE(bstate->bs_sv) char |
233 | xbm_useful BmUSEFUL(bstate->bs_sv) I32 |
234 | xbm_previous BmPREVIOUS(bstate->bs_sv) U16 |
235 | xbm_rare BmRARE(bstate->bs_sv) U8 |
11a7ac70 |
236 | xfm_lines FmLINES(bstate->bs_sv) IV |
237 | xio_lines IoLINES(bstate->bs_sv) IV |
238 | xio_page IoPAGE(bstate->bs_sv) IV |
239 | xio_page_len IoPAGE_LEN(bstate->bs_sv) IV |
240 | xio_lines_left IoLINES_LEFT(bstate->bs_sv) IV |
1df34986 |
241 | xio_top_name IoTOP_NAME(bstate->bs_sv) pvindex |
059a8bb7 |
242 | xio_top_gv *(SV**)&IoTOP_GV(bstate->bs_sv) svindex |
1df34986 |
243 | xio_fmt_name IoFMT_NAME(bstate->bs_sv) pvindex |
059a8bb7 |
244 | xio_fmt_gv *(SV**)&IoFMT_GV(bstate->bs_sv) svindex |
1df34986 |
245 | xio_bottom_name IoBOTTOM_NAME(bstate->bs_sv) pvindex |
059a8bb7 |
246 | xio_bottom_gv *(SV**)&IoBOTTOM_GV(bstate->bs_sv) svindex |
247 | xio_subprocess IoSUBPROCESS(bstate->bs_sv) short |
248 | xio_type IoTYPE(bstate->bs_sv) char |
249 | xio_flags IoFLAGS(bstate->bs_sv) char |
1df34986 |
250 | xcv_xsubany *(SV**)&CvXSUBANY(bstate->bs_sv).any_ptr svindex |
059a8bb7 |
251 | xcv_stash *(SV**)&CvSTASH(bstate->bs_sv) svindex |
252 | xcv_start CvSTART(bstate->bs_sv) opindex |
253 | xcv_root CvROOT(bstate->bs_sv) opindex |
254 | xcv_gv *(SV**)&CvGV(bstate->bs_sv) svindex |
255 | xcv_file CvFILE(bstate->bs_sv) pvindex |
256 | xcv_depth CvDEPTH(bstate->bs_sv) long |
257 | xcv_padlist *(SV**)&CvPADLIST(bstate->bs_sv) svindex |
258 | xcv_outside *(SV**)&CvOUTSIDE(bstate->bs_sv) svindex |
f52873be |
259 | xcv_outside_seq CvOUTSIDE_SEQ(bstate->bs_sv) U32 |
059a8bb7 |
260 | xcv_flags CvFLAGS(bstate->bs_sv) U16 |
261 | av_extend bstate->bs_sv SSize_t x |
1df34986 |
262 | av_pushx bstate->bs_sv svindex x |
059a8bb7 |
263 | av_push bstate->bs_sv svindex x |
264 | xav_fill AvFILLp(bstate->bs_sv) SSize_t |
265 | xav_max AvMAX(bstate->bs_sv) SSize_t |
059a8bb7 |
266 | xhv_riter HvRITER(bstate->bs_sv) I32 |
4ba4de04 |
267 | xhv_name bstate->bs_sv pvindex x |
059a8bb7 |
268 | hv_store bstate->bs_sv svindex x |
269 | sv_magic bstate->bs_sv char x |
270 | mg_obj SvMAGIC(bstate->bs_sv)->mg_obj svindex |
271 | mg_private SvMAGIC(bstate->bs_sv)->mg_private U16 |
272 | mg_flags SvMAGIC(bstate->bs_sv)->mg_flags U8 |
1df34986 |
273 | mg_name SvMAGIC(bstate->bs_sv) pvcontents x |
274 | mg_namex SvMAGIC(bstate->bs_sv) svindex x |
03687789 |
275 | xmg_stash bstate->bs_sv svindex x |
059a8bb7 |
276 | gv_fetchpv bstate->bs_sv strconst x |
566ece03 |
277 | gv_fetchpvx bstate->bs_sv strconst x |
059a8bb7 |
278 | gv_stashpv bstate->bs_sv strconst x |
566ece03 |
279 | gv_stashpvx bstate->bs_sv strconst x |
059a8bb7 |
280 | gp_sv GvSV(bstate->bs_sv) svindex |
281 | gp_refcnt GvREFCNT(bstate->bs_sv) U32 |
282 | gp_refcnt_add GvREFCNT(bstate->bs_sv) I32 x |
283 | gp_av *(SV**)&GvAV(bstate->bs_sv) svindex |
284 | gp_hv *(SV**)&GvHV(bstate->bs_sv) svindex |
285 | gp_cv *(SV**)&GvCV(bstate->bs_sv) svindex |
f4890806 |
286 | gp_file bstate->bs_sv pvindex x |
059a8bb7 |
287 | gp_io *(SV**)&GvIOp(bstate->bs_sv) svindex |
288 | gp_form *(SV**)&GvFORM(bstate->bs_sv) svindex |
289 | gp_cvgen GvCVGEN(bstate->bs_sv) U32 |
290 | gp_line GvLINE(bstate->bs_sv) line_t |
291 | gp_share bstate->bs_sv svindex x |
292 | xgv_flags GvFLAGS(bstate->bs_sv) U8 |
92742e37 |
293 | op_next PL_op->op_next opindex |
294 | op_sibling PL_op->op_sibling opindex |
295 | op_ppaddr PL_op->op_ppaddr strconst x |
296 | op_targ PL_op->op_targ PADOFFSET |
297 | op_type PL_op OPCODE x |
2814eb74 |
298 | op_opt PL_op->op_opt U8 |
299 | op_static PL_op->op_static U8 |
92742e37 |
300 | op_flags PL_op->op_flags U8 |
301 | op_private PL_op->op_private U8 |
302 | op_first cUNOP->op_first opindex |
303 | op_last cBINOP->op_last opindex |
304 | op_other cLOGOP->op_other opindex |
92742e37 |
305 | op_pmreplroot cPMOP->op_pmreplroot opindex |
92742e37 |
306 | op_pmreplstart cPMOP->op_pmreplstart opindex |
307 | op_pmnext *(OP**)&cPMOP->op_pmnext opindex |
1df34986 |
308 | #ifdef USE_ITHREADS |
47682f07 |
309 | op_pmstashpv cPMOP pvindex x |
b97332e7 |
310 | op_pmreplrootpo cPMOP->op_pmreplroot OP*/PADOFFSET |
1df34986 |
311 | #else |
312 | op_pmstash *(SV**)&cPMOP->op_pmstash svindex |
313 | op_pmreplrootgv *(SV**)&cPMOP->op_pmreplroot svindex |
314 | #endif |
92742e37 |
315 | pregcomp PL_op pvcontents x |
316 | op_pmflags cPMOP->op_pmflags U16 |
317 | op_pmpermflags cPMOP->op_pmpermflags U16 |
1df34986 |
318 | op_pmdynflags cPMOP->op_pmdynflags U8 |
92742e37 |
319 | op_sv cSVOP->op_sv svindex |
7934575e |
320 | op_padix cPADOP->op_padix PADOFFSET |
92742e37 |
321 | op_pv cPVOP->op_pv pvcontents |
322 | op_pv_tr cPVOP->op_pv op_tr_array |
323 | op_redoop cLOOP->op_redoop opindex |
324 | op_nextop cLOOP->op_nextop opindex |
325 | op_lastop cLOOP->op_lastop opindex |
059a8bb7 |
326 | cop_label cCOP->cop_label pvindex |
1df34986 |
327 | #ifdef USE_ITHREADS |
059a8bb7 |
328 | cop_stashpv cCOP pvindex x |
329 | cop_file cCOP pvindex x |
1df34986 |
330 | #else |
331 | cop_stash cCOP svindex x |
332 | cop_filegv cCOP svindex x |
333 | #endif |
92742e37 |
334 | cop_seq cCOP->cop_seq U32 |
07910858 |
335 | cop_arybase cCOP I32 x |
1df34986 |
336 | cop_line cCOP->cop_line line_t |
5c3c3f81 |
337 | cop_warnings cCOP svindex x |
92742e37 |
338 | main_start PL_main_start opindex |
339 | main_root PL_main_root opindex |
1df34986 |
340 | main_cv *(SV**)&PL_main_cv svindex |
92742e37 |
341 | curpad PL_curpad svindex x |
059a8bb7 |
342 | push_begin PL_beginav svindex x |
343 | push_init PL_initav svindex x |
344 | push_end PL_endav svindex x |
1df34986 |
345 | curstash *(SV**)&PL_curstash svindex |
346 | defstash *(SV**)&PL_defstash svindex |
347 | data none U8 x |
0ac16f7c |
348 | incav *(SV**)&GvAV(PL_incgv) svindex |
1df34986 |
349 | load_glob none svindex x |
350 | #ifdef USE_ITHREADS |
351 | regex_padav *(SV**)&PL_regex_padav svindex |
352 | #endif |
353 | dowarn PL_dowarn U8 |
354 | comppad_name *(SV**)&PL_comppad_name svindex |
355 | xgv_stash *(SV**)&GvSTASH(bstate->bs_sv) svindex |
356 | signal bstate->bs_sv strconst x |
357 | # to be removed |
358 | formfeed PL_formfeed svindex |