1N/A# Copyright (c) 1996, 1997, 1998 Malcolm Beattie 1N/A# You may distribute under the terms of either the GNU General Public 1N/A# License or the Artistic License, as specified in the README file. 1N/A# walkoptree_slow comes from B.pm (you are there), 1N/A# walkoptree comes from B.xs 1N/A # Stop "-w" from complaining about the lack of a real B::OBJECT class 1N/A # The regex below corresponds to the isCONTROLVAR macro 1N/A # When we say unicode_to_native we really mean ascii_to_native, 1N/A # which matters iff this is a non-ASCII platform (EBCDIC). 1N/A return "Total number of OPs processed: $op_count\n";
1N/A sprintf(
"%02d:%02d:%02d user=$user sys=$sys",
1N/A# warn(sprintf("savesym: sym_%x => %s\n", $$obj, $value)); # debug 1N/A while (
defined($_ =
shift)) {
1N/A s{(s\\_[
0-
9a-f]+)} {
1N/AB - The Perl Compiler 1N/AThe C<B> module supplies classes which allow a Perl program to delve 1N/Ainto its own innards. It is the module used to implement the 1N/A"backends" of the Perl compiler. Usage of the compiler does not 1N/Arequire knowledge of this module: see the F<O> module for the 1N/Auser-visible part. The C<B> module is of use to those who want to 1N/Awrite new compiler backends. This documentation assumes that the 1N/Areader knows a fair amount about perl's internals including such 1N/Athings as SVs, OPs and the internal symbol table and syntax tree 1N/AThe C<B> module contains a set of utility functions for querying the 1N/Acurrent state of the Perl interpreter; typically these functions 1N/Areturn objects from the B::SV and B::OP classes, or their derived 1N/Aclasses. These classes in turn define methods for querying the 1N/Aresulting objects about their own internal state. 1N/A=head1 Utility Functions 1N/AThe C<B> module exports a variety of functions: some are simple 1N/Autility functions, others provide a Perl program with a way to 1N/Aget an initial "handle" on an internal object. 1N/A=head2 Functions Returning C<B::SV>, C<B::AV>, C<B::HV>, and C<B::CV> objects 1N/AFor descriptions of the class hierachy of these objects and the 1N/Amethods that can be called on them, see below, L<"OVERVIEW OF 1N/ACLASSES"> and L<"SV-RELATED CLASSES">. 1N/AReturns the SV object corresponding to the C variable C<sv_undef>. 1N/AReturns the SV object corresponding to the C variable C<sv_yes>. 1N/AReturns the SV object corresponding to the C variable C<sv_no>. 1N/A=item svref_2object(SVREF) 1N/ATakes a reference to any Perl value, and turns the referred-to value 1N/Ainto an object in the appropriate B::OP-derived or B::SV-derived 1N/Aclass. Apart from functions such as C<main_root>, this is the primary 1N/Away to get an initial "handle" on an internal perl data structure 1N/Awhich can then be followed with the other access methods. 1N/A=item amagic_generation 1N/AReturns the SV object corresponding to the C variable C<amagic_generation>. 1N/AReturns the AV object (i.e. in class B::AV) representing INIT blocks. 1N/AReturns the AV object (i.e. in class B::AV) representing CHECK blocks. 1N/AReturns the AV object (i.e. in class B::AV) representing BEGIN blocks. 1N/AReturns the AV object (i.e. in class B::AV) representing END blocks. 1N/AReturns the AV object (i.e. in class B::AV) of the global comppadlist. 1N/AOnly when perl was compiled with ithreads. 1N/AReturn the (faked) CV corresponding to the main part of the Perl 1N/A=head2 Functions for Examining the Symbol Table 1N/A=item walksymtable(SYMREF, METHOD, RECURSE, PREFIX) 1N/AWalk the symbol table starting at SYMREF and call METHOD on each 1N/Asymbol (a B::GV object) visited. When the walk reaches package 1N/Asymbols (such as "Foo::") it invokes RECURSE, passing in the symbol 1N/Aname, and only recurses into the package if that sub returns true. 1N/APREFIX is the name of the SYMREF you're walking. 1N/A # Walk CGI's symbol table calling print_subs on each symbol. 1N/A # Recurse only into CGI::Util:: 1N/A walksymtable(\%CGI::, 'print_subs', sub { $_[0] eq 'CGI::Util::' }, 1N/Aprint_subs() is a B::GV method you have declared. Also see L<"B::GV 1N/A=head2 Functions Returning C<B::OP> objects or for walking op trees 1N/AFor descriptions of the class hierachy of these objects and the 1N/Amethods that can be called on them, see below, L<"OVERVIEW OF 1N/ACLASSES"> and L<"OP-RELATED CLASSES">. 1N/AReturns the root op (i.e. an object in the appropriate B::OP-derived 1N/Aclass) of the main part of the Perl program. 1N/AReturns the starting op of the main part of the Perl program. 1N/A=item walkoptree(OP, METHOD) 1N/ADoes a tree-walk of the syntax tree based at OP and calls METHOD on 1N/Aeach op it visits. Each node is visited before its children. If 1N/AC<walkoptree_debug> (see below) has been called to turn debugging on then 1N/Athe method C<walkoptree_debug> is called on each op before METHOD is 1N/A=item walkoptree_debug(DEBUG) 1N/AReturns the current debugging flag for C<walkoptree>. If the optional 1N/ADEBUG argument is non-zero, it sets the debugging flag to that. See 1N/Athe description of C<walkoptree> above for what the debugging flag 1N/A=head2 Miscellaneous Utility Functions 1N/AReturn the PP function name (e.g. "pp_add") of op number OPNUM. 1N/AReturns a string in the form "0x..." representing the value of the 1N/Ainternal hash function used by perl on string STR. 1N/ACasts I to the internal I32 type used by that perl. 1N/ADoes the equivalent of the C<-c> command-line option. Obviously, this 1N/Ais only useful in a BEGIN block or else the flag is set too late. 1N/AReturns a double-quote-surrounded escaped version of STR which can 1N/Abe used as a string in C source code. 1N/A=item perlstring(STR) 1N/AReturns a double-quote-surrounded escaped version of STR which can 1N/Abe used as a string in Perl source code. 1N/AReturns the class of an object without the part of the classname 1N/Apreceding the first C<"::">. This is used to turn C<"B::UNOP"> into 1N/AC<"UNOP"> for example. 1N/AIn a perl compiled for threads, this returns a list of the special 1N/Aper-thread threadsv variables. 1N/A=head1 OVERVIEW OF CLASSES 1N/AThe C structures used by Perl's internals to hold SV and OP 1N/Ainformation (PVIV, AV, HV, ..., OP, SVOP, UNOP, ...) are modelled on a 1N/Aclass hierarchy and the C<B> module gives access to them via a true 1N/Aobject hierarchy. Structure fields which point to other objects 1N/A(whether types of SV or types of OP) are represented by the C<B> 1N/Amodule as Perl objects of the appropriate class. 1N/AThe bulk of the C<B> module is the methods for accessing fields of 1N/ANote that all access is read-only. You cannot modify the internals by 1N/A=head2 SV-RELATED CLASSES 1N/AB::IV, B::NV, B::RV, B::PV, B::PVIV, B::PVNV, B::PVMG, B::BM, B::PVLV, 1N/AB::AV, B::HV, B::CV, B::GV, B::FM, B::IO. These classes correspond in 1N/Athe obvious way to the underlying C structures of similar names. The 1N/Ainheritance hierarchy mimics the underlying C "inheritance": 1N/A +--------------+----------------------+ 1N/A +------+-----+----+------+-----+-----+ 1N/A B::PVLV B::BM B::AV B::GV B::HV B::CV B::IO 1N/AAccess methods correspond to the underlying C macros for field access, 1N/Ausually with the leading "class indication" prefix removed (Sv, Av, 1N/AHv, ...). The leading prefix is only left in cases where its removal 1N/Awould cause a clash in method name. For example, C<GvREFCNT> stays 1N/Aas-is since its abbreviation would clash with the "superclass" method 1N/AC<REFCNT> (corresponding to the C function C<SvREFCNT>). 1N/AReturns a reference to the regular scalar corresponding to this 1N/AB::SV object. In other words, this method is the inverse operation 1N/Ato the svref_2object() subroutine. This scalar and other data it points 1N/Aat should be considered read-only: modifying them is neither safe nor 1N/Aguaranteed to have a sensible effect. 1N/AReturns the value of the IV, I<interpreted as 1N/Aa signed integer>. This will be misleading 1N/Aif C<FLAGS & SVf_IVisUV>. Perhaps you want the 1N/AC<int_value> method instead? 1N/AThis method returns the value of the IV as an integer. 1N/AIt differs from C<IV> in that it returns the correct 1N/Avalue regardless of whether it's stored signed or 1N/AThis method is the one you usually want. It constructs a 1N/Astring using the length and offset information in the struct: 1N/Afor ordinary scalars it will return the string that you'd see 1N/Afrom Perl, even if it contains null characters. 1N/ASame as B::RV::RV, except that it will die() if the PV isn't 1N/AThis method is less often useful. It assumes that the string 1N/Astored in the struct is null-terminated, and disregards the 1N/AIt is the appropriate method to use if you need to get the name 1N/Aof a lexical variable from a padname array. Lexical variable names 1N/Aare always stored with a null terminator, and the length field 1N/A(SvCUR) is overloaded for other purposes and can't be relied on here. 1N/A=head2 B::PVMG Methods 1N/A=head2 B::MAGIC Methods 1N/AOnly valid on r-magic, returns the string that generated the regexp. 1N/AWill die() if called on r-magic. 1N/AOnly valid on r-magic, returns the integer value of the REGEX stored 1N/A=head2 B::PVLV Methods 1N/AThis method returns TRUE if the GP field of the GV is NULL. 1N/AThis method returns the name of the glob, but if the first 1N/Acharacter of the name is a control character, then it converts 1N/Ait to ^X first, so that *^G would return "^G" rather than "\cG". 1N/AIt's useful if you want to print out the name of a variable. 1N/AIf you restrict yourself to globs which exist at compile-time 1N/Athen the result ought to be unambiguous, because code like 1N/AC<${"^G"} = 1> is compiled as two ops - a constant string and 1N/Aa dereference (rv2gv) - so that the glob is created at runtime. 1N/AIf you're working with globs at runtime, and need to disambiguate 1N/A*^G from *{"^G"}, then you should use the raw NAME method. 1N/ATakes one arguments ( 'stdin' | 'stdout' | 'stderr' ) and returns true 1N/Aif the IoIFP of the object is equal to the handle whose name was 1N/Apassed as argument ( i.e. $io->IsSTD('stderr') is true if 1N/AIoIFP($io) == PerlIO_stdin() ). 1N/ALike C<ARRAY>, but takes an index as an argument to get only one element, 1N/Arather than a list of all of them. 1N/AFor constant subroutines, returns the constant SV returned by the subroutine. 1N/A=head2 OP-RELATED CLASSES 1N/AC<B::OP>, C<B::UNOP>, C<B::BINOP>, C<B::LOGOP>, C<B::LISTOP>, C<B::PMOP>, 1N/AC<B::SVOP>, C<B::PADOP>, C<B::PVOP>, C<B::LOOP>, C<B::COP>. 1N/AThese classes correspond in the obvious way to the underlying C 1N/Astructures of similar names. The inheritance hierarchy mimics the 1N/Aunderlying C "inheritance": 1N/A +---------------+--------+--------+ 1N/A B::UNOP B::SVOP B::PADOP B::COP 1N/AAccess methods correspond to the underlying C structre field names, 1N/Awith the leading "class indication" prefix (C<"op_">) removed. 1N/AThis returns the op name as a string (e.g. "add", "rv2av"). 1N/AThis returns the function name as a string (e.g. "PL_ppaddr[OP_ADD]", 1N/A"PL_ppaddr[OP_RV2AV]"). 1N/AThis returns the op description from the global C PL_op_desc array 1N/A(e.g. "addition" "array deref"). 1N/A=head2 B::UNOP METHOD 1N/A=head2 B::BINOP METHOD 1N/A=head2 B::LOGOP METHOD 1N/A=head2 B::LISTOP METHOD 1N/A=head2 B::PMOP Methods 1N/AOnly when perl was compiled with ithreads. 1N/A=head2 B::SVOP METHOD 1N/A=head2 B::PADOP METHOD 1N/A=head2 B::PVOP METHOD 1N/A=head2 B::LOOP Methods 1N/A=head2 B::COP Methods 1N/AMalcolm Beattie, C<mbeattie@sable.ox.ac.uk>