(?p{}) has been deprecated for a long time.
[p5sagit/p5-mst-13.2.git] / bytecode.pl
1 BEGIN {
2   push @INC, './lib';
3   require 'regen_lib.pl';
4 }
5 use strict;
6 my %alias_to = (
7     U32 => [qw(line_t)],
8     PADOFFSET => [qw(STRLEN SSize_t)],
9     U16 => [qw(OPCODE short)],
10     U8  => [qw(char)],
11 );
12
13 my @optype= qw(OP UNOP BINOP LOGOP LISTOP PMOP SVOP PADOP PVOP LOOP COP);
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).
17 my @specialsv = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no
18                    (SV*)pWARN_ALL (SV*)pWARN_NONE (SV*)pWARN_STD);
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';
26 /* -*- buffer-read-only: t -*-
27  *
28  *      Copyright (c) 1996-1999 Malcolm Beattie
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
42 safer_unlink "ext/B/B/Asmdata.pm";
43
44 #
45 # Start with boilerplate for Asmdata.pm
46 #
47 open(ASMDATA_PM, ">ext/B/B/Asmdata.pm") or die "ext/B/B/Asmdata.pm: $!";
48 binmode ASMDATA_PM;
49 print ASMDATA_PM $perl_header, <<'EOT';
50 package B::Asmdata;
51
52 our $VERSION = '1.01';
53
54 use Exporter;
55 @ISA = qw(Exporter);
56 @EXPORT_OK = qw(%insn_data @insn_name @optype @specialsv_name);
57 our(%insn_data, @insn_name, @optype, @specialsv_name);
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
69 my $size = @specialsv;
70
71 my (@insn_name, $insn_num, $insn, $lvalue, $argtype, $flags, $fundtype);
72
73 while (<DATA>) {
74     if (/^\s*#/) {
75         next;
76     }
77     chop;
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;
87     my $rvalcast = '';
88     if ($argtype =~ m:(.+)/(.+):) {
89         ($rvalcast, $argtype) = ("($1)", $2);
90     }
91     $insn_name[$insn_num] = $insn;
92     $fundtype = $alias_from{$argtype} || $argtype;
93
94     #
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 #
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;
118
119 __END__
120
121 =head1 NAME
122
123 B::Asmdata - Autogenerated data about Perl ops
124
125 =head1 SYNOPSIS
126
127         use B::Asmdata qw(%insn_data @insn_name @optype @specialsv_name);
128
129 =head1 DESCRIPTION
130
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
169 B::SPECIAL and are referred to by a number from the specialsv_list.
170 This array maps that number back to the name of the SV (like 'Nullsv'
171 or '&PL_sv_undef').
172
173 =back
174
175 =head1 AUTHOR
176
177 Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
178
179 =cut
180
181 # ex: set ro:
182 EOT
183
184
185 close ASMDATA_PM or die "Error closing ASMDATA_PM: $!";
186
187 __END__
188 # First set instruction ord("#") to read comment to end-of-line (sneaky)
189 %number 35
190 comment         arg                     comment_t
191 # Then make ord("\n") into a no-op
192 %number 10
193 nop             none                    none
194
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 #
199 # The argtype is either a single type or "rightvaluecast/argtype".
200 #
201 #opcode         lvalue                                  argtype         flags   
202 #
203 ret             none                                    none            x
204 ldsv            bstate->bs_sv                           svindex
205 ldop            PL_op                                   opindex
206 stsv            bstate->bs_sv                           U32             s
207 stop            PL_op                                   U32             s
208 stpv            bstate->bs_pv.pvx                       U32             x
209 ldspecsv        bstate->bs_sv                           U8              x
210 ldspecsvx       bstate->bs_sv                           U8              x
211 newsv           bstate->bs_sv                           svtype          x
212 newsvx          bstate->bs_sv                           svtype          x
213 newop           PL_op                                   U8              x
214 newopx          PL_op                                   U16             x
215 newopn          PL_op                                   U8              x
216 newpv           none                                    PV
217 pv_cur          bstate->bs_pv.xpv.xpv_cur               STRLEN
218 pv_free         bstate->bs_pv.pvx                       none            x
219 sv_upgrade      bstate->bs_sv                           svtype          x
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
223 xrv             bstate->bs_sv                           svindex         x
224 xpv             bstate->bs_sv                           none            x
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
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
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
241 xio_top_name    IoTOP_NAME(bstate->bs_sv)               pvindex
242 xio_top_gv      *(SV**)&IoTOP_GV(bstate->bs_sv)         svindex
243 xio_fmt_name    IoFMT_NAME(bstate->bs_sv)               pvindex
244 xio_fmt_gv      *(SV**)&IoFMT_GV(bstate->bs_sv)         svindex
245 xio_bottom_name IoBOTTOM_NAME(bstate->bs_sv)            pvindex
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
250 xcv_xsubany     *(SV**)&CvXSUBANY(bstate->bs_sv).any_ptr        svindex
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
259 xcv_outside_seq CvOUTSIDE_SEQ(bstate->bs_sv)            U32
260 xcv_flags       CvFLAGS(bstate->bs_sv)                  U16
261 av_extend       bstate->bs_sv                           SSize_t         x
262 av_pushx        bstate->bs_sv                           svindex         x
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
266 xhv_riter       HvRITER(bstate->bs_sv)                  I32
267 xhv_name        bstate->bs_sv                           pvindex         x
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
273 mg_name         SvMAGIC(bstate->bs_sv)                  pvcontents      x
274 mg_namex        SvMAGIC(bstate->bs_sv)                  svindex         x
275 xmg_stash       bstate->bs_sv                           svindex         x
276 gv_fetchpv      bstate->bs_sv                           strconst        x
277 gv_fetchpvx     bstate->bs_sv                           strconst        x
278 gv_stashpv      bstate->bs_sv                           strconst        x
279 gv_stashpvx     bstate->bs_sv                           strconst        x
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
286 gp_file         bstate->bs_sv                           pvindex         x
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
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
298 op_opt          PL_op->op_opt                           U8
299 op_static       PL_op->op_static                        U8
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
305 op_pmreplroot   cPMOP->op_pmreplroot                    opindex
306 op_pmreplstart  cPMOP->op_pmreplstart                   opindex
307 op_pmnext       *(OP**)&cPMOP->op_pmnext                opindex
308 #ifdef USE_ITHREADS
309 op_pmstashpv    cPMOP                                   pvindex         x
310 op_pmreplrootpo cPMOP->op_pmreplroot                    OP*/PADOFFSET
311 #else
312 op_pmstash      *(SV**)&cPMOP->op_pmstash               svindex
313 op_pmreplrootgv *(SV**)&cPMOP->op_pmreplroot            svindex
314 #endif
315 pregcomp        PL_op                                   pvcontents      x
316 op_pmflags      cPMOP->op_pmflags                       U16
317 op_pmpermflags  cPMOP->op_pmpermflags                   U16
318 op_pmdynflags   cPMOP->op_pmdynflags                    U8
319 op_sv           cSVOP->op_sv                            svindex
320 op_padix        cPADOP->op_padix                        PADOFFSET
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
326 cop_label       cCOP->cop_label                         pvindex
327 #ifdef USE_ITHREADS
328 cop_stashpv     cCOP                                    pvindex         x
329 cop_file        cCOP                                    pvindex         x
330 #else
331 cop_stash       cCOP                                    svindex         x
332 cop_filegv      cCOP                                    svindex         x
333 #endif
334 cop_seq         cCOP->cop_seq                           U32
335 cop_arybase     cCOP                                    I32             x
336 cop_line        cCOP->cop_line                          line_t
337 cop_warnings    cCOP                                    svindex         x
338 main_start      PL_main_start                           opindex
339 main_root       PL_main_root                            opindex
340 main_cv         *(SV**)&PL_main_cv                      svindex
341 curpad          PL_curpad                               svindex         x
342 push_begin      PL_beginav                              svindex         x
343 push_init       PL_initav                               svindex         x
344 push_end        PL_endav                                svindex         x
345 curstash        *(SV**)&PL_curstash                     svindex
346 defstash        *(SV**)&PL_defstash                     svindex
347 data            none                                    U8              x
348 incav           *(SV**)&GvAV(PL_incgv)                  svindex
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