X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/1df3498620ecc1df99a2455e631a135f1710416f..a86a1ca71b6cc69a4a01c17f91f95d556810d9f3:/bytecode.pl?ds=sidebyside diff --git a/bytecode.pl b/bytecode.pl index e375961..95b5b12 100644 --- a/bytecode.pl +++ b/bytecode.pl @@ -4,8 +4,8 @@ BEGIN { } use strict; my %alias_to = ( - U32 => [qw(PADOFFSET STRLEN line_t)], - I32 => [qw(SSize_t long)], + U32 => [qw(line_t)], + PADOFFSET => [qw(STRLEN SSize_t)], U16 => [qw(OPCODE short)], U8 => [qw(char)], ); @@ -14,7 +14,8 @@ my @optype= qw(OP UNOP BINOP LOGOP LISTOP PMOP SVOP PADOP PVOP LOOP COP); # Nullsv *must* come first in the following so that the condition # ($$sv == 0) can continue to be used to test (sv == Nullsv). -my @specialsv = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no pWARN_ALL pWARN_NONE); +my @specialsv = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no + (SV*)pWARN_ALL (SV*)pWARN_NONE (SV*)pWARN_STD); my (%alias_from, $from, $tos); while (($from, $tos) = each %alias_to) { @@ -22,7 +23,8 @@ while (($from, $tos) = each %alias_to) { } my $c_header = <<'EOT'; -/* +/* -*- buffer-read-only: t -*- + * * Copyright (c) 1996-1999 Malcolm Beattie * * You may distribute under the terms of either the GNU General Public @@ -37,16 +39,17 @@ EOT my $perl_header; ($perl_header = $c_header) =~ s{[/ ]?\*/?}{#}g; -safer_unlink "ext/ByteLoader/byterun.c", "ext/ByteLoader/byterun.h", "ext/B/B/Asmdata.pm"; +safer_unlink "ext/B/B/Asmdata.pm"; # # Start with boilerplate for Asmdata.pm # open(ASMDATA_PM, ">ext/B/B/Asmdata.pm") or die "ext/B/B/Asmdata.pm: $!"; +binmode ASMDATA_PM; print ASMDATA_PM $perl_header, <<'EOT'; package B::Asmdata; -our $VERSION = '1.00'; +our $VERSION = '1.01'; use Exporter; @ISA = qw(Exporter); @@ -63,73 +66,12 @@ print ASMDATA_PM <<"EOT"; # I get a hard-to-track-down stack underflow and segfault. EOT -# -# Boilerplate for byterun.c -# -open(BYTERUN_C, ">ext/ByteLoader/byterun.c") or die "ext/ByteLoader/byterun.c: $!"; -print BYTERUN_C $c_header, <<'EOT'; - -#define PERL_NO_GET_CONTEXT -#include "EXTERN.h" -#include "perl.h" -#define NO_XSLOCKS -#include "XSUB.h" - -#include "byterun.h" -#include "bytecode.h" - - -static const int optype_size[] = { -EOT -my $i = 0; -for ($i = 0; $i < @optype - 1; $i++) { - printf BYTERUN_C " sizeof(%s),\n", $optype[$i], $i; -} -printf BYTERUN_C " sizeof(%s)\n", $optype[$i], $i; -print BYTERUN_C <<'EOT'; -}; - -void * -bset_obj_store(pTHX_ struct byteloader_state *bstate, void *obj, I32 ix) -{ - if (ix > bstate->bs_obj_list_fill) { - Renew(bstate->bs_obj_list, ix + 32, void*); - bstate->bs_obj_list_fill = ix + 31; - } - bstate->bs_obj_list[ix] = obj; - return obj; -} - -int -byterun(pTHX_ register struct byteloader_state *bstate) -{ - register int insn; - U32 ix; - SV *specialsv_list[6]; - - BYTECODE_HEADER_CHECK; /* croak if incorrect platform */ - New(666, bstate->bs_obj_list, 32, void*); /* set op objlist */ - bstate->bs_obj_list_fill = 31; - bstate->bs_obj_list[0] = NULL; /* first is always Null */ - -EOT - -for my $i ( 0 .. $#specialsv ) { - print BYTERUN_C " specialsv_list[$i] = $specialsv[$i];\n"; -} - -print BYTERUN_C <<'EOT'; - - while ((insn = BGET_FGETC()) != EOF) { - switch (insn) { -EOT - +my $size = @specialsv; my (@insn_name, $insn_num, $insn, $lvalue, $argtype, $flags, $fundtype); while () { if (/^\s*#/) { - print BYTERUN_C if /^\s*#\s*(?:if|endif|el)/; next; } chop; @@ -142,30 +84,14 @@ while () { next; } ($insn, $lvalue, $argtype, $flags) = split; + my $rvalcast = ''; + if ($argtype =~ m:(.+)/(.+):) { + ($rvalcast, $argtype) = ("($1)", $2); + } $insn_name[$insn_num] = $insn; $fundtype = $alias_from{$argtype} || $argtype; # - # Add the case statement and code for the bytecode interpreter in byterun.c - # - printf BYTERUN_C "\t case INSN_%s:\t\t/* %d */\n\t {\n", - uc($insn), $insn_num; - my $optarg = $argtype eq "none" ? "" : ", arg"; - if ($optarg) { - printf BYTERUN_C "\t\t$argtype arg;\n\t\tBGET_%s(arg);\n", $fundtype; - } - if ($flags =~ /x/) { - print BYTERUN_C "\t\tBSET_$insn($lvalue$optarg);\n"; - } elsif ($flags =~ /s/) { - # Store instructions store to bytecode_obj_list[arg]. "lvalue" field is rvalue. - print BYTERUN_C "\t\tBSET_OBJ_STORE($lvalue$optarg);\n"; - } - elsif ($optarg && $lvalue ne "none") { - print BYTERUN_C "\t\t$lvalue = arg;\n"; - } - print BYTERUN_C "\t\tbreak;\n\t }\n"; - - # # Add the initialiser line for %insn_data in Asmdata.pm # print ASMDATA_PM <<"EOT"; @@ -177,71 +103,6 @@ EOT } # -# Finish off byterun.c -# -print BYTERUN_C <<'EOT'; - default: - Perl_croak(aTHX_ "Illegal bytecode instruction %d\n", insn); - /* NOTREACHED */ - } - } - return 0; -} -EOT - -# -# Write the instruction and optype enum constants into byterun.h -# -open(BYTERUN_H, ">ext/ByteLoader/byterun.h") or die "ext/ByteLoader/byterun.h: $!"; -print BYTERUN_H $c_header, <<'EOT'; -struct byteloader_fdata { - SV *datasv; - int next_out; - int idx; -}; - -struct byteloader_state { - struct byteloader_fdata *bs_fdata; - SV *bs_sv; - void **bs_obj_list; - int bs_obj_list_fill; - XPV bs_pv; - int bs_iv_overflows; -}; - -int bl_getc(struct byteloader_fdata *); -int bl_read(struct byteloader_fdata *, char *, size_t, size_t); -extern int byterun(pTHX_ struct byteloader_state *); - -enum { -EOT - -my $add_enum_value = 0; -my $max_insn; -for $i ( 0 .. $#insn_name ) { - $insn = uc($insn_name[$i]); - if (defined($insn)) { - $max_insn = $i; - if ($add_enum_value) { - print BYTERUN_H " INSN_$insn = $i,\t\t\t/* $i */\n"; - $add_enum_value = 0; - } else { - print BYTERUN_H " INSN_$insn,\t\t\t/* $i */\n"; - } - } else { - $add_enum_value = 1; - } -} - -print BYTERUN_H " MAX_INSN = $max_insn\n};\n"; - -print BYTERUN_H "\nenum {\n"; -for ($i = 0; $i < @optype - 1; $i++) { - printf BYTERUN_H " OPt_%s,\t\t/* %d */\n", $optype[$i], $i; -} -printf BYTERUN_H " OPt_%s\t\t/* %d */\n};\n\n", $optype[$i], $i; - -# # Finish off insn_data and create array initialisers in Asmdata.pm # print ASMDATA_PM <<'EOT'; @@ -259,7 +120,7 @@ __END__ =head1 NAME -B::Asmdata - Autogenerated data about Perl ops, used to generate bytecode +B::Asmdata - Autogenerated data about Perl ops =head1 SYNOPSIS @@ -305,7 +166,7 @@ A simple mapping of the op type number to its type (like 'COP' or 'BINOP'). my $sv_name = $specialsv_name[$sv_index]; Certain SV types are considered 'special'. They're represented by -B::SPECIAL and are refered to by a number from the specialsv_list. +B::SPECIAL and are referred to by a number from the specialsv_list. This array maps that number back to the name of the SV (like 'Nullsv' or '&PL_sv_undef'). @@ -316,12 +177,12 @@ or '&PL_sv_undef'). Malcolm Beattie, C =cut + +# ex: set ro: EOT close ASMDATA_PM or die "Error closing ASMDATA_PM: $!"; -close BYTERUN_H or die "Error closing BYTERUN_H: $!"; -close BYTERUN_C or die "Error closing BYTERUN_C: $!"; __END__ # First set instruction ord("#") to read comment to end-of-line (sneaky) @@ -335,6 +196,8 @@ nop none none # ret so that \0-terminated strings can be read properly as bytecode. %number 0 # +# The argtype is either a single type or "rightvaluecast/argtype". +# #opcode lvalue argtype flags # ret none none x @@ -342,24 +205,27 @@ ldsv bstate->bs_sv svindex ldop PL_op opindex stsv bstate->bs_sv U32 s stop PL_op U32 s -stpv bstate->bs_pv.xpv_pv U32 x +stpv bstate->bs_pv.pvx U32 x ldspecsv bstate->bs_sv U8 x -newsv bstate->bs_sv U8 x +ldspecsvx bstate->bs_sv U8 x +newsv bstate->bs_sv svtype x +newsvx bstate->bs_sv svtype x newop PL_op U8 x +newopx PL_op U16 x newopn PL_op U8 x newpv none PV -pv_cur bstate->bs_pv.xpv_cur STRLEN -pv_free bstate->bs_pv none x -sv_upgrade bstate->bs_sv U8 x +pv_cur bstate->bs_pv.xpv.xpv_cur STRLEN +pv_free bstate->bs_pv.pvx none x +sv_upgrade bstate->bs_sv svtype x sv_refcnt SvREFCNT(bstate->bs_sv) U32 sv_refcnt_add SvREFCNT(bstate->bs_sv) I32 x sv_flags SvFLAGS(bstate->bs_sv) U32 -xrv SvRV(bstate->bs_sv) svindex +xrv bstate->bs_sv svindex x xpv bstate->bs_sv none x -xpv_cur SvCUR(bstate->bs_sv) STRLEN -xpv_len SvLEN(bstate->bs_sv) STRLEN -xiv SvIVX(bstate->bs_sv) IV -xnv SvNVX(bstate->bs_sv) NV +xpv_cur bstate->bs_sv STRLEN x +xpv_len bstate->bs_sv STRLEN x +xiv bstate->bs_sv IV x +xnv bstate->bs_sv NV x xlv_targoff LvTARGOFF(bstate->bs_sv) STRLEN xlv_targlen LvTARGLEN(bstate->bs_sv) STRLEN xlv_targ LvTARG(bstate->bs_sv) svindex @@ -397,10 +263,8 @@ av_pushx bstate->bs_sv svindex x av_push bstate->bs_sv svindex x xav_fill AvFILLp(bstate->bs_sv) SSize_t xav_max AvMAX(bstate->bs_sv) SSize_t -xav_flags AvFLAGS(bstate->bs_sv) U8 xhv_riter HvRITER(bstate->bs_sv) I32 -xhv_name HvNAME(bstate->bs_sv) pvindex -xhv_pmroot *(OP**)&HvPMROOT(bstate->bs_sv) opindex +xhv_name bstate->bs_sv pvindex x hv_store bstate->bs_sv svindex x sv_magic bstate->bs_sv char x mg_obj SvMAGIC(bstate->bs_sv)->mg_obj svindex @@ -408,16 +272,18 @@ mg_private SvMAGIC(bstate->bs_sv)->mg_private U16 mg_flags SvMAGIC(bstate->bs_sv)->mg_flags U8 mg_name SvMAGIC(bstate->bs_sv) pvcontents x mg_namex SvMAGIC(bstate->bs_sv) svindex x -xmg_stash *(SV**)&SvSTASH(bstate->bs_sv) svindex +xmg_stash bstate->bs_sv svindex x gv_fetchpv bstate->bs_sv strconst x +gv_fetchpvx bstate->bs_sv strconst x gv_stashpv bstate->bs_sv strconst x +gv_stashpvx bstate->bs_sv strconst x gp_sv GvSV(bstate->bs_sv) svindex gp_refcnt GvREFCNT(bstate->bs_sv) U32 gp_refcnt_add GvREFCNT(bstate->bs_sv) I32 x gp_av *(SV**)&GvAV(bstate->bs_sv) svindex gp_hv *(SV**)&GvHV(bstate->bs_sv) svindex gp_cv *(SV**)&GvCV(bstate->bs_sv) svindex -gp_file GvFILE(bstate->bs_sv) pvindex +gp_file bstate->bs_sv pvindex x gp_io *(SV**)&GvIOp(bstate->bs_sv) svindex gp_form *(SV**)&GvFORM(bstate->bs_sv) svindex gp_cvgen GvCVGEN(bstate->bs_sv) U32 @@ -429,7 +295,8 @@ op_sibling PL_op->op_sibling opindex op_ppaddr PL_op->op_ppaddr strconst x op_targ PL_op->op_targ PADOFFSET op_type PL_op OPCODE x -op_seq PL_op->op_seq U16 +op_opt PL_op->op_opt U8 +op_static PL_op->op_static U8 op_flags PL_op->op_flags U8 op_private PL_op->op_private U8 op_first cUNOP->op_first opindex @@ -439,8 +306,8 @@ op_pmreplroot cPMOP->op_pmreplroot opindex op_pmreplstart cPMOP->op_pmreplstart opindex op_pmnext *(OP**)&cPMOP->op_pmnext opindex #ifdef USE_ITHREADS -op_pmstashpv cPMOP->op_pmstashpv pvindex -op_pmreplrootpo (PADOFFSET)cPMOP->op_pmreplroot PADOFFSET +op_pmstashpv cPMOP pvindex x +op_pmreplrootpo cPMOP->op_pmreplroot OP*/PADOFFSET #else op_pmstash *(SV**)&cPMOP->op_pmstash svindex op_pmreplrootgv *(SV**)&cPMOP->op_pmreplroot svindex @@ -465,10 +332,9 @@ cop_stash cCOP svindex x cop_filegv cCOP svindex x #endif cop_seq cCOP->cop_seq U32 -cop_arybase cCOP->cop_arybase I32 +cop_arybase cCOP I32 x cop_line cCOP->cop_line line_t -cop_io cCOP->cop_io svindex -cop_warnings cCOP->cop_warnings svindex +cop_warnings cCOP svindex x main_start PL_main_start opindex main_root PL_main_root opindex main_cv *(SV**)&PL_main_cv svindex @@ -479,7 +345,7 @@ push_end PL_endav svindex x curstash *(SV**)&PL_curstash svindex defstash *(SV**)&PL_defstash svindex data none U8 x -incav *(SV**)&GvAVn(PL_incgv) svindex +incav *(SV**)&GvAV(PL_incgv) svindex load_glob none svindex x #ifdef USE_ITHREADS regex_padav *(SV**)&PL_regex_padav svindex