📄 concise.pm
字号:
$h{sibaddr} = sprintf("%#x", $ {$op->sibling}); $h{firstaddr} = sprintf("%#x", $ {$op->first}) if $op->can("first"); $h{lastaddr} = sprintf("%#x", $ {$op->last}) if $op->can("last"); $h{classsym} = $opclass{$h{class}}; $h{flagval} = $op->flags; $h{flags} = op_flags($op->flags); $h{privval} = $op->private; $h{private} = private_flags($h{name}, $op->private); $h{addr} = sprintf("%#x", $$op); $h{label} = $labels{$op->seq}; $h{typenum} = $op->type; $h{noise} = $linenoise[$op->type]; return fmt_line(\%h, $format, $level);}sub B::OP::concise { my($op, $level) = @_; if ($order eq "exec" and $lastnext and $$lastnext != $$op) { my $h = {"seq" => seq($lastnext), "class" => class($lastnext), "addr" => sprintf("%#x", $$lastnext)}; print fmt_line($h, $gotofmt, $level+1); } $lastnext = $op->next; print concise_op($op, $level, $format);}sub tree { my $op = shift; my $level = shift; my $style = $tree_decorations[$tree_style]; my($space, $single, $kids, $kid, $nokid, $last, $lead, $size) = @$style; my $name = concise_op($op, $level, $treefmt); if (not $op->flags & OPf_KIDS) { return $name . "\n"; } my @lines; for (my $kid = $op->first; $$kid; $kid = $kid->sibling) { push @lines, tree($kid, $level+1); } my $i; for ($i = $#lines; substr($lines[$i], 0, 1) eq " "; $i--) { $lines[$i] = $space . $lines[$i]; } if ($i > 0) { $lines[$i] = $last . $lines[$i]; while ($i-- > 1) { if (substr($lines[$i], 0, 1) eq " ") { $lines[$i] = $nokid . $lines[$i]; } else { $lines[$i] = $kid . $lines[$i]; } } $lines[$i] = $kids . $lines[$i]; } else { $lines[0] = $single . $lines[0]; } return("$name$lead" . shift @lines, map(" " x (length($name)+$size) . $_, @lines));}# This is a bit of a hack; the 2 and 15 were determined empirically.# These need to stay the last things in the module.$cop_seq_base = svref_2object(eval 'sub{0;}')->START->cop_seq + 2;$seq_base = svref_2object(eval 'sub{}')->START->seq + 15;1;__END__=head1 NAMEB::Concise - Walk Perl syntax tree, printing concise info about ops=head1 SYNOPSIS perl -MO=Concise[,OPTIONS] foo.pl=head1 DESCRIPTIONThis compiler backend prints the internal OPs of a Perl program's syntaxtree in one of several space-efficient text formats suitable for debuggingthe inner workings of perl or other compiler backends. It can print OPs inthe order they appear in the OP tree, in the order they will execute, orin a text approximation to their tree structure, and the format of theinformation displyed is customizable. Its function is similar to that ofperl's B<-Dx> debugging flag or the B<B::Terse> module, but it is moresophisticated and flexible.=head1 OPTIONSArguments that don't start with a hyphen are taken to be the names ofsubroutines to print the OPs of; if no such functions are specified, themain body of the program (outside any subroutines, and not including use'dor require'd files) is printed.=over 4=item B<-basic>Print OPs in the order they appear in the OP tree (a preordertraversal, starting at the root). The indentation of each OP shows itslevel in the tree. This mode is the default, so the flag is includedsimply for completeness.=item B<-exec>Print OPs in the order they would normally execute (for the majorityof constructs this is a postorder traversal of the tree, ending at theroot). In most cases the OP that usually follows a given OP willappear directly below it; alternate paths are shown by indentation. Incases like loops when control jumps out of a linear path, a 'goto'line is generated.=item B<-tree>Print OPs in a text approximation of a tree, with the root of the treeat the left and 'left-to-right' order of children transformed into'top-to-bottom'. Because this mode grows both to the right and down,it isn't suitable for large programs (unless you have a very wideterminal).=item B<-compact>Use a tree format in which the minimum amount of space is used for thelines connecting nodes (one character in most cases). This squeezes outa few precious columns of screen real estate.=item B<-loose>Use a tree format that uses longer edges to separate OP nodes. This formattends to look better than the compact one, especially in ASCII, and isthe default.=item B<-vt>Use tree connecting characters drawn from the VT100 line-drawing set.This looks better if your terminal supports it.=item B<-ascii>Draw the tree with standard ASCII characters like C<+> and C<|>. These don'tlook as clean as the VT100 characters, but they'll work with almost anyterminal (or the horizontal scrolling mode of less(1)) and are suitablefor text documentation or email. This is the default.=item B<-main>Include the main program in the output, even if subroutines were alsospecified.=item B<-base>I<n>Print OP sequence numbers in base I<n>. If I<n> is greater than 10, thedigit for 11 will be 'a', and so on. If I<n> is greater than 36, the digitfor 37 will be 'A', and so on until 62. Values greater than 62 are notcurrently supported. The default is 36.=item B<-bigendian>Print sequence numbers with the most significant digit first. This is theusual convention for Arabic numerals, and the default.=item B<-littleendian>Print seqence numbers with the least significant digit first.=item B<-concise>Use the author's favorite set of formatting conventions. This is thedefault, of course.=item B<-terse>Use formatting conventions that emulate the ouput of B<B::Terse>. Thebasic mode is almost indistinguishable from the real B<B::Terse>, and theexec mode looks very similar, but is in a more logical order and lackscurly brackets. B<B::Terse> doesn't have a tree mode, so the tree modeis only vaguely reminiscient of B<B::Terse>.=item B<-linenoise>Use formatting conventions in which the name of each OP, rather than beingwritten out in full, is represented by a one- or two-character abbreviation.This is mainly a joke.=item B<-debug>Use formatting conventions reminiscient of B<B::Debug>; these aren'tvery concise at all.=item B<-env>Use formatting conventions read from the environment variablesC<B_CONCISE_FORMAT>, C<B_CONCISE_GOTO_FORMAT>, and C<B_CONCISE_TREE_FORMAT>.=back=head1 FORMATTING SPECIFICATIONSFor each general style ('concise', 'terse', 'linenoise', etc.) there arethree specifications: one of how OPs should appear in the basic or execmodes, one of how 'goto' lines should appear (these occur in the execmode only), and one of how nodes should appear in tree mode. Each has thesame format, described below. Any text that doesn't match a specialpattern is copied verbatim.=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<#>I<var>Generates the value of the variable I<var>.=item B<#>I<var>I<N>Generates the value of I<var>, left jutified to fill I<N> spaces.=item B<~>Any number of tildes and surrounding whitespace will be collapsed toa single space.=backThe following variables are recognized:=over 4=item B<#addr>The address of the OP, in hexidecimal.=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 paretheses.=item B<#class>The B-determined class of the OP, in all caps.=item B<#classym>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 hexidecimal.=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<#hyphenseq>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 hexidecimal.=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 hexidecimal.=item B<#noise>The 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.=item B<#seqnum>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<#sibaddr>The address of the OP's next youngest sibling, in hexidecimal.=item B<#svaddr>The address of the OP's SV, if it has an SV, in hexidecimal.=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 ABBREVIATIONS=head2 OP flags abbreviations v OPf_WANT_VOID Want nothing (void context) s OPf_WANT_SCALAR Want single value (scalar context) l OPf_WANT_LIST Want list of any length (list context) K OPf_KIDS There is a firstborn child. P OPf_PARENS This operator was parenthesized. (Or block needs explicit scope entry.) R OPf_REF Certified reference. (Return container, not containee). M OPf_MOD Will modify (lvalue). S OPf_STACKED Some arg is arriving on the stack. * OPf_SPECIAL Do something weird for this op (see op.h)=head2 OP class abbreviations 0 OP (aka BASEOP) An OP with no children 1 UNOP An OP with one child 2 BINOP An OP with two children | LOGOP A control branch OP @ LISTOP An OP that could have lots of children / PMOP An OP with a regular expression $ SVOP An OP with an SV " PVOP An OP with a string { LOOP An OP that holds pointers for a loop ; COP An OP that marks the start of a statement=head1 AUTHORStephen McCamant, C<smcc@CSUA.Berkeley.EDU>=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -