📄 concise.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>B::Concise - Walk Perl syntax tree, printing concise info about ops</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>B::Concise - Walk Perl syntax tree, printing concise info about ops</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#example">EXAMPLE</a></li>
<li><a href="#options">OPTIONS</a></li>
<ul>
<li><a href="#options_for_opcode_ordering">Options for Opcode Ordering</a></li>
<li><a href="#options_for_linestyle">Options for Line-Style</a></li>
<li><a href="#options_for_treespecific_formatting">Options for tree-specific formatting</a></li>
<li><a href="#options_controlling_sequence_numbering">Options controlling sequence numbering</a></li>
<li><a href="#other_options">Other options</a></li>
<li><a href="#option_stickiness">Option Stickiness</a></li>
</ul>
<li><a href="#abbreviations">ABBREVIATIONS</a></li>
<ul>
<li><a href="#op_class_abbreviations">OP class abbreviations</a></li>
<li><a href="#op_flags_abbreviations">OP flags abbreviations</a></li>
</ul>
<li><a href="#formatting_specifications">FORMATTING SPECIFICATIONS</a></li>
<ul>
<li><a href="#special_patterns">Special Patterns</a></li>
<li><a href="#__variables"># Variables</a></li>
</ul>
<li><a href="#using_b__concise_outside_of_the_o_framework">Using B::Concise outside of the O framework</a></li>
<ul>
<li><a href="#example__altering_concise_renderings">Example: Altering Concise Renderings</a></li>
<li><a href="#set_style__"><code>set_style()</code></a></li>
<li><a href="#set_style_standard__name_"><code>set_style_standard($name)</code></a></li>
<li><a href="#add_style__"><code>add_style()</code></a></li>
<li><a href="#add_callback__"><code>add_callback()</code></a></li>
<li><a href="#running_b__concise__compile__">Running B::Concise::compile()</a></li>
<li><a href="#b__concise__reset_sequence__">B::Concise::reset_sequence()</a></li>
<li><a href="#errors">Errors</a></li>
</ul>
<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>B::Concise - Walk Perl syntax tree, printing concise info about ops</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
perl -MO=Concise[,OPTIONS] foo.pl</pre>
<pre>
<span class="keyword">use</span> <span class="variable">B::Concise</span> <span class="string">qw(set_style add_callback)</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This compiler backend prints the internal OPs of a Perl program's syntax
tree in one of several space-efficient text formats suitable for debugging
the inner workings of perl or other compiler backends. It can print OPs in
the order they appear in the OP tree, in the order they will execute, or
in a text approximation to their tree structure, and the format of the
information displayed is customizable. Its function is similar to that of
perl's <strong>-Dx</strong> debugging flag or the <strong>B::Terse</strong> module, but it is more
sophisticated and flexible.</p>
<p>
</p>
<hr />
<h1><a name="example">EXAMPLE</a></h1>
<p>Here's an example of 2 outputs (aka 'renderings'), using the
-exec and -basic (i.e. default) formatting conventions on the same code
snippet.</p>
<pre>
<span class="operator">% </span><span class="variable">perl</span> <span class="operator">-</span><span class="variable">MO</span><span class="operator">=</span><span class="variable">Concise</span><span class="operator">,-</span><span class="keyword">exec</span> <span class="keyword">-e</span> <span class="string">'$a = $b + 42'</span>
<span class="number">1</span> <span class="operator"><</span><span class="number">0</span><span class="operator">></span> <span class="variable">enter</span>
<span class="number">2</span> <span class="operator"><;></span> <span class="variable">nextstate</span><span class="operator">(</span><span class="variable">main</span> <span class="number">1</span> <span class="keyword">-e</span><span class="operator">:</span><span class="number">1</span><span class="operator">)</span> <span class="variable">v</span>
<span class="number">3</span> <span class="operator"><</span><span class="comment">#> gvsv[*b] s</span>
<span class="number">4</span> <span class="operator"><</span><span class="variable">$></span> <span class="variable">const</span><span class="operator">[</span><span class="variable">IV</span> <span class="number">42</span><span class="operator">]</span> <span class="keyword">s</span>
<span class="operator">*</span> <span class="number">5</span> <span class="operator"><</span><span class="number">2</span><span class="operator">></span> <span class="variable">add</span><span class="operator">[</span><span class="variable">t3</span><span class="operator">]</span> <span class="variable">sK</span><span class="operator">/</span><span class="number">2</span>
<span class="number">6</span> <span class="operator"><</span><span class="comment">#> gvsv[*a] s</span>
<span class="number">7</span> <span class="operator"><</span><span class="number">2</span><span class="operator">></span> <span class="variable">sassign</span> <span class="variable">vKS</span><span class="operator">/</span><span class="number">2</span>
<span class="number">8</span> <span class="operator"><</span><span class="variable">@></span> <span class="variable">leave</span><span class="operator">[</span><span class="number">1</span> <span class="keyword">ref</span><span class="operator">]</span> <span class="variable">vKP</span><span class="operator">/</span><span class="variable">REFC</span>
</pre>
<p>Each line corresponds to an opcode. The opcode marked with '*' is used
in a few examples below.</p>
<p>The 1st column is the op's sequence number, starting at 1, and is
displayed in base 36 by default. This rendering is in -exec (i.e.
execution) order.</p>
<p>The symbol between angle brackets indicates the op's type, for
example; <2> is a BINOP, <@> a LISTOP, and <#> is a PADOP, which is
used in threaded perls. (see <a href="#op_class_abbreviations">OP class abbreviations</a>).</p>
<p>The opname, as in <strong>'add[t1]'</strong>, which may be followed by op-specific
information in parentheses or brackets (ex <strong>'[t1]'</strong>).</p>
<p>The op-flags (ex <strong>'sK/2'</strong>) follow, and are described in (<a href="#op_flags_abbreviations">OP flags abbreviations</a>).</p>
<pre>
<span class="operator">% </span><span class="variable">perl</span> <span class="operator">-</span><span class="variable">MO</span><span class="operator">=</span><span class="variable">Concise</span> <span class="keyword">-e</span> <span class="string">'$a = $b + 42'</span>
<span class="number">8</span> <span class="operator"><</span><span class="variable">@></span> <span class="variable">leave</span><span class="operator">[</span><span class="number">1</span> <span class="keyword">ref</span><span class="operator">]</span> <span class="variable">vKP</span><span class="operator">/</span><span class="variable">REFC</span> <span class="operator">->(</span><span class="variable">end</span><span class="operator">)</span>
<span class="number">1</span> <span class="operator"><</span><span class="number">0</span><span class="operator">></span> <span class="variable">enter</span> <span class="operator">-></span>2
<span class="number">2</span> <span class="operator"><;></span> <span class="variable">nextstate</span><span class="operator">(</span><span class="variable">main</span> <span class="number">1</span> <span class="keyword">-e</span><span class="operator">:</span><span class="number">1</span><span class="operator">)</span> <span class="variable">v</span> <span class="operator">-></span>3
<span class="number">7</span> <span class="operator"><</span><span class="number">2</span><span class="operator">></span> <span class="variable">sassign</span> <span class="variable">vKS</span><span class="operator">/</span><span class="number">2</span> <span class="operator">-></span>8
<span class="operator">*</span> <span class="number">5</span> <span class="operator"><</span><span class="number">2</span><span class="operator">></span> <span class="variable">add</span><span class="operator">[</span><span class="variable">t1</span><span class="operator">]</span> <span class="variable">sK</span><span class="operator">/</span><span class="number">2</span> <span class="operator">-></span>6
<span class="operator">-</span> <span class="operator"><</span><span class="number">1</span><span class="operator">></span> <span class="variable">ex</span><span class="operator">-</span><span class="variable">rv2sv</span> <span class="variable">sK</span><span class="operator">/</span><span class="number">1</span> <span class="operator">-></span>4
<span class="number">3</span> <span class="operator"><</span><span class="variable">$></span> <span class="variable">gvsv</span><span class="operator">(</span><span class="variable">*b</span><span class="operator">)</span> <span class="regex">s ->4
4 <$> const(IV 42) s ->5
-</span> <span class="operator"><</span><span class="number">1</span><span class="operator">></span> <span class="variable">ex</span><span class="operator">-</span><span class="variable">rv2sv</span> <span class="variable">sKRM</span><span class="operator">*/</span><span class="number">1</span> <span class="operator">-></span>7
<span class="number">6</span> <span class="operator"><</span><span class="variable">$></span> <span class="variable">gvsv</span><span class="operator">(</span><span class="variable">*a</span><span class="operator">)</span> <span class="regex">s ->7
</span>
</pre>
<p>The default rendering is top-down, so they're not in execution order.
This form reflects the way the stack is used to parse and evaluate
expressions; the add operates on the two terms below it in the tree.</p>
<p>Nullops appear as <code>ex-opname</code>, where <em>opname</em> is an op that has been
optimized away by perl. They're displayed with a sequence-number of
'-', because they are not executed (they don't appear in previous
example), they're printed here because they reflect the parse.</p>
<p>The arrow points to the sequence number of the next op; they're not
displayed in -exec mode, for obvious reasons.</p>
<p>Note that because this rendering was done on a non-threaded perl, the
PADOPs in the previous examples are now SVOPs, and some (but not all)
of the square brackets have been replaced by round ones. This is a
subtle feature to provide some visual distinction between renderings
on threaded and un-threaded perls.</p>
<p>
</p>
<hr />
<h1><a name="options">OPTIONS</a></h1>
<p>Arguments that don't start with a hyphen are taken to be the names of
subroutines to print the OPs of; if no such functions are specified,
the main body of the program (outside any subroutines, and not
including use'd or require'd files) is rendered. Passing <code>BEGIN</code>,
<code>CHECK</code>, <code>INIT</code>, or <code>END</code> will cause all of the corresponding
special blocks to be printed.</p>
<p>Options affect how things are rendered (ie printed). They're presented
here by their visual effect, 1st being strongest. They're grouped
according to how they interrelate; within each group the options are
mutually exclusive (unless otherwise stated).</p>
<p>
</p>
<h2><a name="options_for_opcode_ordering">Options for Opcode Ordering</a></h2>
<p>These options control the 'vertical display' of opcodes. The display
'order' is also called 'mode' elsewhere in this document.</p>
<dl>
<dt><strong><a name="item__2dbasic"><strong>-basic</strong></a></strong>
<dd>
<p>Print OPs in the order they appear in the OP tree (a preorder
traversal, starting at the root). The indentation of each OP shows its
level in the tree, and the '->' at the end of the line indicates the
next opcode in execution order. This mode is the default, so the flag
is included simply for completeness.</p>
</dd>
</li>
<dt><strong><a name="item__2dexec"><strong>-exec</strong></a></strong>
<dd>
<p>Print OPs in the order they would normally execute (for the majority
of constructs this is a postorder traversal of the tree, ending at the
root). In most cases the OP that usually follows a given OP will
appear directly below it; alternate paths are shown by indentation. In
cases like loops when control jumps out of a linear path, a 'goto'
line is generated.</p>
</dd>
</li>
<dt><strong><a name="item__2dtree"><strong>-tree</strong></a></strong>
<dd>
<p>Print OPs in a text approximation of a tree, with the root of the tree
at 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 wide
terminal).</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="options_for_linestyle">Options for Line-Style</a></h2>
<p>These options select the line-style (or just style) used to render
each opcode, and dictates what info is actually printed into each line.</p>
<dl>
<dt><strong><a name="item__2dconcise"><strong>-concise</strong></a></strong>
<dd>
<p>Use the author's favorite set of formatting conventions. This is the
default, of course.</p>
</dd>
</li>
<dt><strong><a name="item__2dterse"><strong>-terse</strong></a></strong>
<dd>
<p>Use formatting conventions that emulate the output of <strong>B::Terse</strong>. The
basic mode is almost indistinguishable from the real <strong>B::Terse</strong>, and the
exec mode looks very similar, but is in a more logical order and lacks
curly brackets. <strong>B::Terse</strong> doesn't have a tree mode, so the tree mode
is only vaguely reminiscent of <strong>B::Terse</strong>.</p>
</dd>
</li>
<dt><strong><a name="item__2dlinenoise"><strong>-linenoise</strong></a></strong>
<dd>
<p>Use formatting conventions in which the name of each OP, rather than being
written out in full, is represented by a one- or two-character abbreviation.
This is mainly a joke.</p>
</dd>
</li>
<dt><strong><a name="item__2ddebug"><strong>-debug</strong></a></strong>
<dd>
<p>Use formatting conventions reminiscent of <strong>B::Debug</strong>; these aren't
very concise at all.</p>
</dd>
</li>
<dt><strong><a name="item__2denv"><strong>-env</strong></a></strong>
<dd>
<p>Use formatting conventions read from the environment variables
<code>B_CONCISE_FORMAT</code>, <code>B_CONCISE_GOTO_FORMAT</code>, and <code>B_CONCISE_TREE_FORMAT</code>.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="options_for_treespecific_formatting">Options for tree-specific formatting</a></h2>
<dl>
<dt><strong><a name="item__2dcompact"><strong>-compact</strong></a></strong>
<dd>
<p>Use a tree format in which the minimum amount of space is used for the
lines connecting nodes (one character in most cases). This squeezes out
a few precious columns of screen real estate.</p>
</dd>
</li>
<dt><strong><a name="item__2dloose"><strong>-loose</strong></a></strong>
<dd>
<p>Use a tree format that uses longer edges to separate OP nodes. This format
tends to look better than the compact one, especially in ASCII, and is
the default.</p>
</dd>
</li>
<dt><strong><a name="item__2dvt"><strong>-vt</strong></a></strong>
<dd>
<p>Use tree connecting characters drawn from the VT100 line-drawing set.
This looks better if your terminal supports it.</p>
</dd>
</li>
<dt><strong><a name="item__2dascii"><strong>-ascii</strong></a></strong>
<dd>
<p>Draw the tree with standard ASCII characters like <code>+</code> and <code>|</code>. These don't
look as clean as the VT100 characters, but they'll work with almost any
terminal (or the horizontal scrolling mode of <code>less(1))</code> and are suitable
for text documentation or email. This is the default.</p>
</dd>
</li>
</dl>
<p>These are pairwise exclusive, i.e. compact or loose, vt or ascii.</p>
<p>
</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -