3 U32 => [qw(PADOFFSET STRLEN)],
4 I32 => [qw(SSize_t long)],
5 U16 => [qw(OPCODE line_t short)],
7 objindex => [qw(svindex opindex)]
10 my @optype= qw(OP UNOP BINOP LOGOP CONDOP LISTOP PMOP SVOP GVOP PVOP LOOP COP);
12 # Nullsv *must* come first in the following so that the condition
13 # ($$sv == 0) can continue to be used to test (sv == Nullsv).
14 my @specialsv = qw(Nullsv &sv_undef &sv_yes &sv_no);
16 my (%alias_from, $from, $tos);
17 while (($from, $tos) = each %alias_to) {
18 map { $alias_from{$_} = $from } @$tos;
21 my $c_header = <<'EOT';
23 * Copyright (c) 1996-1998 Malcolm Beattie
25 * You may distribute under the terms of either the GNU General Public
26 * License or the Artistic License, as specified in the README file.
30 * This file is autogenerated from bytecode.pl. Changes made here will be lost.
35 ($perl_header = $c_header) =~ s{[/ ]?\*/?}{#}g;
37 unlink "byterun.c", "byterun.h", "ext/B/Asmdata.pm";
40 # Start with boilerplate for Asmdata.pm
42 open(ASMDATA_PM, ">ext/B/Asmdata.pm") or die "Asmdata.pm: $!";
43 print ASMDATA_PM $perl_header, <<'EOT';
47 @EXPORT_OK = qw(%insn_data @insn_name @optype @specialsv_name);
48 use vars qw(%insn_data @insn_name @optype @specialsv_name);
51 print ASMDATA_PM <<"EOT";
52 \@optype = qw(@optype);
53 \@specialsv_name = qw(@specialsv);
55 # XXX insn_data is initialised this way because with a large
56 # %insn_data = (foo => [...], bar => [...], ...) initialiser
57 # I get a hard-to-track-down stack underflow and segfault.
61 # Boilerplate for byterun.c
63 open(BYTERUN_C, ">byterun.c") or die "byterun.c: $!";
64 print BYTERUN_C $c_header, <<'EOT';
71 #ifdef INDIRECT_BGET_MACROS
77 #endif /* INDIRECT_BGET_MACROS */
81 while ((insn = FGETC()) != EOF) {
86 my (@insn_name, $insn_num, $insn, $lvalue, $argtype, $flags, $fundtype);
90 s/#.*//; # remove comments
92 if (/^%number\s+(.*)/) {
95 } elsif (/%enum\s+(.*?)\s+(.*)/) {
96 create_enum($1, $2); # must come before instructions
99 ($insn, $lvalue, $argtype, $flags) = split;
100 $insn_name[$insn_num] = $insn;
101 $fundtype = $alias_from{$argtype} || $argtype;
104 # Add the case statement and code for the bytecode interpreter in byterun.c
106 printf BYTERUN_C "\t case INSN_%s:\t\t/* %d */\n\t {\n",
107 uc($insn), $insn_num;
108 my $optarg = $argtype eq "none" ? "" : ", arg";
110 printf BYTERUN_C "\t\t$argtype arg;\n\t\tBGET_%s(arg);\n", $fundtype;
113 print BYTERUN_C "\t\tBSET_$insn($lvalue$optarg);\n";
114 } elsif ($flags =~ /s/) {
115 # Store instructions store to obj_list[arg]. "lvalue" field is rvalue.
116 print BYTERUN_C "\t\tBSET_OBJ_STORE($lvalue$optarg);\n";
118 elsif ($optarg && $lvalue ne "none") {
119 print BYTERUN_C "\t\t$lvalue = arg;\n";
121 print BYTERUN_C "\t\tbreak;\n\t }\n";
124 # Add the initialiser line for %insn_data in Asmdata.pm
126 print ASMDATA_PM <<"EOT";
127 \$insn_data{$insn} = [$insn_num, \\&PUT_$fundtype, "GET_$fundtype"];
130 # Find the next unused instruction number
131 do { $insn_num++ } while $insn_name[$insn_num];
135 # Finish off byterun.c
137 print BYTERUN_C <<'EOT';
139 croak("Illegal bytecode instruction %d\n", insn);
147 # Write the instruction and optype enum constants into byterun.h
149 open(BYTERUN_H, ">byterun.h") or die "byterun.h: $!";
150 print BYTERUN_H $c_header, <<'EOT';
151 #ifdef INDIRECT_BGET_MACROS
154 int (*fgetc)(void *);
155 int (*fread)(char *, size_t, size_t, void*);
156 void (*freadpv)(U32, void*);
158 void freadpv _((U32, void *));
159 void byterun _((struct bytestream));
161 void byterun _((FILE *));
162 #endif /* INDIRECT_BGET_MACROS */
165 #include "patchlevel.h"
167 #if PATCHLEVEL < 4 || (PATCHLEVEL == 4 && SUBVERSION < 50)
168 #define dTHR extern int errno
175 my $add_enum_value = 0;
177 for ($i = 0; $i < @insn_name; $i++) {
178 $insn = uc($insn_name[$i]);
179 if (defined($insn)) {
181 if ($add_enum_value) {
182 print BYTERUN_H " INSN_$insn = $i,\t\t\t/* $i */\n";
185 print BYTERUN_H " INSN_$insn,\t\t\t/* $i */\n";
192 print BYTERUN_H " MAX_INSN = $max_insn\n};\n";
194 print BYTERUN_H "\nenum {\n";
195 for ($i = 0; $i < @optype - 1; $i++) {
196 printf BYTERUN_H " OPt_%s,\t\t/* %d */\n", $optype[$i], $i;
198 printf BYTERUN_H " OPt_%s\t\t/* %d */\n};\n\n", $optype[$i], $i;
199 print BYTERUN_H <<'EOT';
200 EXT int optype_size[]
204 for ($i = 0; $i < @optype - 1; $i++) {
205 printf BYTERUN_H " sizeof(%s),\n", $optype[$i], $i;
207 printf BYTERUN_H " sizeof(%s)\n}\n", $optype[$i], $i;
208 print BYTERUN_H <<'EOT';
214 printf BYTERUN_H <<'EOT', scalar(@specialsv);
215 EXT SV * specialsv_list[%d];
216 #define INIT_SPECIALSV_LIST STMT_START { \
218 for ($i = 0; $i < @specialsv; $i++) {
219 print BYTERUN_H "specialsv_list[$i] = $specialsv[$i]; \\\n";
221 print BYTERUN_H <<'EOT';
226 # Finish off insn_data and create array initialisers in Asmdata.pm
228 print ASMDATA_PM <<'EOT';
230 my ($insn_name, $insn_data);
231 while (($insn_name, $insn_data) = each %insn_data) {
232 $insn_name[$insn_data->[0]] = $insn_name;
235 @insn_name = map($_ || "unused", @insn_name);
241 # First set instruction ord("#") to read comment to end-of-line (sneaky)
244 # Then make ord("\n") into a no-op
247 # Now for the rest of the ordinary ones, beginning with \0 which is
248 # ret so that \0-terminated strings can be read properly as bytecode.
251 #opcode lvalue argtype flags
263 pv_cur pv.xpv_cur STRLEN
266 sv_refcnt SvREFCNT(sv) U32
267 sv_refcnt_add SvREFCNT(sv) I32 x
268 sv_flags SvFLAGS(sv) U32
274 xlv_targoff LvTARGOFF(sv) STRLEN
275 xlv_targlen LvTARGLEN(sv) STRLEN
276 xlv_targ LvTARG(sv) svindex
277 xlv_type LvTYPE(sv) char
278 xbm_useful BmUSEFUL(sv) I32
279 xbm_previous BmPREVIOUS(sv) U16
280 xbm_rare BmRARE(sv) U8
281 xfm_lines FmLINES(sv) I32
282 xio_lines IoLINES(sv) long
283 xio_page IoPAGE(sv) long
284 xio_page_len IoPAGE_LEN(sv) long
285 xio_lines_left IoLINES_LEFT(sv) long
286 xio_top_name IoTOP_NAME(sv) pvcontents
287 xio_top_gv *(SV**)&IoTOP_GV(sv) svindex
288 xio_fmt_name IoFMT_NAME(sv) pvcontents
289 xio_fmt_gv *(SV**)&IoFMT_GV(sv) svindex
290 xio_bottom_name IoBOTTOM_NAME(sv) pvcontents
291 xio_bottom_gv *(SV**)&IoBOTTOM_GV(sv) svindex
292 xio_subprocess IoSUBPROCESS(sv) short
293 xio_type IoTYPE(sv) char
294 xio_flags IoFLAGS(sv) char
295 xcv_stash *(SV**)&CvSTASH(sv) svindex
296 xcv_start CvSTART(sv) opindex
297 xcv_root CvROOT(sv) opindex
298 xcv_gv *(SV**)&CvGV(sv) svindex
299 xcv_filegv *(SV**)&CvFILEGV(sv) svindex
300 xcv_depth CvDEPTH(sv) long
301 xcv_padlist *(SV**)&CvPADLIST(sv) svindex
302 xcv_outside *(SV**)&CvOUTSIDE(sv) svindex
303 xcv_flags CvFLAGS(sv) U8
304 av_extend sv SSize_t x
306 xav_fill AvFILLp(sv) SSize_t
307 xav_max AvMAX(sv) SSize_t
308 xav_flags AvFLAGS(sv) U8
309 xhv_riter HvRITER(sv) I32
310 xhv_name HvNAME(sv) pvcontents
311 hv_store sv svindex x
313 mg_obj SvMAGIC(sv)->mg_obj svindex
314 mg_private SvMAGIC(sv)->mg_private U16
315 mg_flags SvMAGIC(sv)->mg_flags U8
316 mg_pv SvMAGIC(sv) pvcontents x
317 xmg_stash *(SV**)&SvSTASH(sv) svindex
318 gv_fetchpv sv strconst x
319 gv_stashpv sv strconst x
320 gp_sv GvSV(sv) svindex
321 gp_refcnt GvREFCNT(sv) U32
322 gp_refcnt_add GvREFCNT(sv) I32 x
323 gp_av *(SV**)&GvAV(sv) svindex
324 gp_hv *(SV**)&GvHV(sv) svindex
325 gp_cv *(SV**)&GvCV(sv) svindex
326 gp_filegv *(SV**)&GvFILEGV(sv) svindex
327 gp_io *(SV**)&GvIOp(sv) svindex
328 gp_form *(SV**)&GvFORM(sv) svindex
329 gp_cvgen GvCVGEN(sv) U32
330 gp_line GvLINE(sv) line_t
331 gp_share sv svindex x
332 xgv_flags GvFLAGS(sv) U8
333 op_next op->op_next opindex
334 op_sibling op->op_sibling opindex
335 op_ppaddr op->op_ppaddr strconst x
336 op_targ op->op_targ PADOFFSET
338 op_seq op->op_seq U16
339 op_flags op->op_flags U8
340 op_private op->op_private U8
341 op_first cUNOP->op_first opindex
342 op_last cBINOP->op_last opindex
343 op_other cLOGOP->op_other opindex
344 op_true cCONDOP->op_true opindex
345 op_false cCONDOP->op_false opindex
346 op_children cLISTOP->op_children U32
347 op_pmreplroot cPMOP->op_pmreplroot opindex
348 op_pmreplrootgv *(SV**)&cPMOP->op_pmreplroot svindex
349 op_pmreplstart cPMOP->op_pmreplstart opindex
350 op_pmnext *(OP**)&cPMOP->op_pmnext opindex
351 pregcomp op pvcontents x
352 op_pmflags cPMOP->op_pmflags U16
353 op_pmpermflags cPMOP->op_pmpermflags U16
354 op_sv cSVOP->op_sv svindex
355 op_gv *(SV**)&cGVOP->op_gv svindex
356 op_pv cPVOP->op_pv pvcontents
357 op_pv_tr cPVOP->op_pv op_tr_array
358 op_redoop cLOOP->op_redoop opindex
359 op_nextop cLOOP->op_nextop opindex
360 op_lastop cLOOP->op_lastop opindex
361 cop_label cCOP->cop_label pvcontents
362 cop_stash *(SV**)&cCOP->cop_stash svindex
363 cop_filegv *(SV**)&cCOP->cop_filegv svindex
364 cop_seq cCOP->cop_seq U32
365 cop_arybase cCOP->cop_arybase I32
366 cop_line cCOP->cop_line line_t
367 main_start main_start opindex
368 main_root main_root opindex
369 curpad curpad svindex x