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