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