⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concise.pm

📁 source of perl for linux application,
💻 PM
📖 第 1 页 / 共 4 页
字号:
Private flags, if any are set for an opcode, are displayed after a '/'    8  <@> leave[1 ref] vKP/REFC ->(end)    7     <2> sassign vKS/2 ->8They're opcode specific, and occur less often than the public ones, sothey're represented by short mnemonics instead of single-chars; seeF<op.h> for gory details, or try this quick 2-liner:  $> perl -MB::Concise -de 1  DB<1> |x \%B::Concise::priv=head1 FORMATTING SPECIFICATIONSFor each line-style ('concise', 'terse', 'linenoise', etc.) there are3 format-specs which control how OPs are rendered.The first is the 'default' format, which is used in both basic and execmodes to print all opcodes.  The 2nd, goto-format, is used in execmode when branches are encountered.  They're not real opcodes, and areinserted to look like a closing curly brace.  The tree-format is treespecific.When a line is rendered, the correct format-spec is copied and scannedfor the following items; data is substituted in, and othermanipulations like basic indenting are done, for each opcode rendered.There are 3 kinds of items that may be populated; special patterns,#vars, and literal text, which is copied verbatim.  (Yes, it's a setof s///g steps.)=head2 Special PatternsThese items are the primitives used to perform indenting, and toselect text from amongst alternatives.=over 4=item B<(x(>I<exec_text>B<;>I<basic_text>B<)x)>Generates I<exec_text> in exec mode, or I<basic_text> in basic mode.=item B<(*(>I<text>B<)*)>Generates one copy of I<text> for each indentation level.=item B<(*(>I<text1>B<;>I<text2>B<)*)>Generates one fewer copies of I<text1> than the indentation level, followedby one copy of I<text2> if the indentation level is more than 0.=item B<(?(>I<text1>B<#>I<var>I<Text2>B<)?)>If the value of I<var> is true (not empty or zero), generates thevalue of I<var> surrounded by I<text1> and I<Text2>, otherwisenothing.=item B<~>Any number of tildes and surrounding whitespace will be collapsed toa single space.=back=head2 # VariablesThese #vars represent opcode properties that you may want as part ofyour rendering.  The '#' is intended as a private sigil; a #var'svalue is interpolated into the style-line, much like "read $this".These vars take 3 forms:=over 4=item B<#>I<var>A property named 'var' is assumed to exist for the opcodes, and isinterpolated into the rendering.=item B<#>I<var>I<N>Generates the value of I<var>, left justified to fill I<N> spaces.Note that this means while you can have properties 'foo' and 'foo2',you cannot render 'foo2', but you could with 'foo2a'.  You would bewise not to rely on this behavior going forward ;-)=item B<#>I<Var>This ucfirst form of #var generates a tag-value form of itself fordisplay; it converts '#Var' into a 'Var => #var' style, which is thenhandled as described above.  (Imp-note: #Vars cannot be used forconditional-fills, because the => #var transform is done after the checkfor #Var's value).=backThe following variables are 'defined' by B::Concise; when they areused in a style, their respective values are plugged into therendering of each opcode.Only some of these are used by the standard styles, the others areprovided for you to delve into optree mechanics, should you wish toadd a new style (see L</add_style> below) that uses them.  You canalso add new ones using L</add_callback>.=over 4=item B<#addr>The address of the OP, in hexadecimal.=item B<#arg>The OP-specific information of the OP (such as the SV for an SVOP, thenon-local exit pointers for a LOOP, etc.) enclosed in parentheses.=item B<#class>The B-determined class of the OP, in all caps.=item B<#classsym>A single symbol abbreviating the class of the OP.=item B<#coplabel>The label of the statement or block the OP is the start of, if any.=item B<#exname>The name of the OP, or 'ex-foo' if the OP is a null that used to be a foo.=item B<#extarg>The target of the OP, or nothing for a nulled OP.=item B<#firstaddr>The address of the OP's first child, in hexadecimal.=item B<#flags>The OP's flags, abbreviated as a series of symbols.=item B<#flagval>The numeric value of the OP's flags.=item B<#hints>The COP's hint flags, rendered with abbreviated names if possible. An emptystring if this is not a COP. Here are the symbols used:    $ strict refs    & strict subs    * strict vars    i integers    l locale    b bytes    [ arybase    { block scope    % localise %^H    < open in    > open out    I overload int    F overload float    B overload binary    S overload string    R overload re    T taint    E eval    X filetest access    U utf-8=item B<#hintsval>The numeric value of the COP's hint flags, or an empty string if this is nota COP.=item B<#hyphseq>The sequence number of the OP, or a hyphen if it doesn't have one.=item B<#label>'NEXT', 'LAST', or 'REDO' if the OP is a target of one of those in execmode, or empty otherwise.=item B<#lastaddr>The address of the OP's last child, in hexadecimal.=item B<#name>The OP's name.=item B<#NAME>The OP's name, in all caps.=item B<#next>The sequence number of the OP's next OP.=item B<#nextaddr>The address of the OP's next OP, in hexadecimal.=item B<#noise>A one- or two-character abbreviation for the OP's name.=item B<#private>The OP's private flags, rendered with abbreviated names if possible.=item B<#privval>The numeric value of the OP's private flags.=item B<#seq>The sequence number of the OP. Note that this is a sequence numbergenerated by B::Concise.=item B<#seqnum>5.8.x and earlier only. 5.9 and later do not provide this.The real sequence number of the OP, as a regular number and not adjustedto be relative to the start of the real program. (This will generally bea fairly large number because all of B<B::Concise> is compiled beforeyour program is).=item B<#opt>Whether or not the op has been optimised by the peephole optimiser.Only available in 5.9 and later.=item B<#sibaddr>The address of the OP's next youngest sibling, in hexadecimal.=item B<#svaddr>The address of the OP's SV, if it has an SV, in hexadecimal.=item B<#svclass>The class of the OP's SV, if it has one, in all caps (e.g., 'IV').=item B<#svval>The value of the OP's SV, if it has one, in a short human-readable format.=item B<#targ>The numeric value of the OP's targ.=item B<#targarg>The name of the variable the OP's targ refers to, if any, otherwise theletter t followed by the OP's targ in decimal.=item B<#targarglife>Same as B<#targarg>, but followed by the COP sequence numbers that delimitthe variable's lifetime (or 'end' for a variable in an open scope) for avariable.=item B<#typenum>The numeric value of the OP's type, in decimal.=back=head1 One-Liner Command tips=over 4=item perl -MO=Concise,bar foo.plRenders only bar() from foo.pl.  To see main, drop the ',bar'.  To seeboth, add ',-main'=item perl -MDigest::MD5=md5 -MO=Concise,md5 -e1Identifies md5 as an XS function.  The export is needed so that BC canfind it in main.=item perl -MPOSIX -MO=Concise,_POSIX_ARG_MAX -e1Identifies _POSIX_ARG_MAX as a constant sub, optimized to an IV.Although POSIX isn't entirely consistent across platforms, this islikely to be present in virtually all of them.=item perl -MPOSIX -MO=Concise,a -e 'print _POSIX_SAVED_IDS'This renders a print statement, which includes a call to the function.It's identical to rendering a file with a use call and that singlestatement, except for the filename which appears in the nextstate ops.=item perl -MPOSIX -MO=Concise,a -e 'sub a{_POSIX_SAVED_IDS}'This is B<very> similar to previous, only the first two ops differ.  Thissubroutine rendering is more representative, insofar as a single mainprogram will have many subs.=item perl -MB::Concise -e 'B::Concise::compile("-exec","-src", \%B::Concise::)->()'This renders all functions in the B::Concise package with the sourcelines.  It eschews the O framework so that the stashref can be passeddirectly to B::Concise::compile().  See -stash option for a moreconvenient way to render a package.=back=head1 Using B::Concise outside of the O frameworkThe common (and original) usage of B::Concise was for command-linerenderings of simple code, as given in EXAMPLE.  But you can also useB<B::Concise> from your code, and call compile() directly, andrepeatedly.  By doing so, you can avoid the compile-time onlyoperation of O.pm, and even use the debugger to step throughB::Concise::compile() itself.Once you're doing this, you may alter Concise output by adding newrendering styles, and by optionally adding callback routines whichpopulate new variables, if such were referenced from those (justadded) styles.  =head2 Example: Altering Concise Renderings    use B::Concise qw(set_style add_callback);    add_style($yourStyleName => $defaultfmt, $gotofmt, $treefmt);    add_callback      ( sub {            my ($h, $op, $format, $level, $stylename) = @_;            $h->{variable} = some_func($op);        });    $walker = B::Concise::compile(@options,@subnames,@subrefs);    $walker->();=head2 set_style()B<set_style> accepts 3 arguments, and updates the three format-specscomprising a line-style (basic-exec, goto, tree).  It has one minordrawback though; it doesn't register the style under a new name.  Thiscan become an issue if you render more than once and switch styles.Thus you may prefer to use add_style() and/or set_style_standard()instead.=head2 set_style_standard($name)This restores one of the standard line-styles: C<terse>, C<concise>,C<linenoise>, C<debug>, C<env>, into effect.  It also accepts stylenames previously defined with add_style().=head2 add_style()This subroutine accepts a new style name and three style arguments asabove, and creates, registers, and selects the newly named style.  It isan error to re-add a style; call set_style_standard() to switch betweenseveral styles.=head2 add_callback()If your newly minted styles refer to any new #variables, you'll needto define a callback subroutine that will populate (or modify) thosevariables.  They are then available for use in the style you'vechosen.The callbacks are called for each opcode visited by Concise, in thesame order as they are added.  Each subroutine is passed fiveparameters.  1. A hashref, containing the variable names and values which are     populated into the report-line for the op  2. the op, as a B<B::OP> object  3. a reference to the format string  4. the formatting (indent) level  5. the selected stylenameTo define your own variables, simply add them to the hash, or changeexisting values if you need to.  The level and format are passed in asreferences to scalars, but it is unlikely that they will need to bechanged or even used.=head2 Running B::Concise::compile()B<compile> accepts options as described above in L</OPTIONS>, andarguments, which are either coderefs, or subroutine names.It constructs and returns a $treewalker coderef, which when invoked,traverses, or walks, and renders the optrees of the given arguments toSTDOUT.  You can reuse this, and can change the rendering style usedeach time; thereafter the coderef renders in the new style.B<walk_output> lets you change the print destination from STDOUT toanother open filehandle, or into a string passed as a ref (unlessyou've built perl with -Uuseperlio).    my $walker = B::Concise::compile('-terse','aFuncName', \&aSubRef);  # 1    walk_output(\my $buf);    $walker->();			# 1 renders -terse    set_style_standard('concise');	# 2    $walker->();			# 2 renders -concise    $walker->(@new);			# 3 renders whatever    print "3 different renderings: terse, concise, and @new: $buf\n";When $walker is called, it traverses the subroutines supplied when itwas created, and renders them using the current style.  You can changethe style afterwards in several different ways:  1. call C<compile>, altering style or mode/order  2. call C<set_style_standard>  3. call $walker, passing @new optionsPassing new options to the $walker is the easiest way to changeamongst any pre-defined styles (the ones you add are automaticallyrecognized as options), and is the only way to alter rendering orderwithout calling compile again.  Note however that rendering state isstill shared amongst multiple $walker objects, so they must still beused in a coordinated manner.=head2 B::Concise::reset_sequence()This function (not exported) lets you reset the sequence numbers (notethat they're numbered arbitrarily, their goal being to be humanreadable).  Its purpose is mostly to support testing, i.e. to comparethe concise output from two identical anonymous subroutines (butdifferent instances).  Without the reset, B::Concise, seeing thatthey're separate optrees, generates different sequence numbers inthe output.=head2 ErrorsErrors in rendering (non-existent function-name, non-existent coderef)are written to the STDOUT, or wherever you've set it viawalk_output().Errors using the various *style* calls, and bad args to walk_output(),result in die().  Use an eval if you wish to catch these errors andcontinue processing.=head1 AUTHORStephen McCamant, E<lt>smcc@CSUA.Berkeley.EDUE<gt>.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -