B::Concise(3perl) Perl Programmers Reference Guide B::Concise(3perl)
B::Concise - Walk Perl syntax tree, printing concise info about ops
| Use Case | Command | Description |
|---|---|---|
| Basic rendering (default) | perl -MO=Concise foo.pl | Print OPs in tree order (preorder) |
| Execution order rendering | perl -MO=Concise,-exec foo.pl | Print OPs in execution order (postorder) |
| Tree style rendering | perl -MO=Concise,-tree foo.pl | Print OPs as a left-to-right tree |
| Include source lines | perl -MO=Concise,-src foo.pl | Precede each statement with its source line |
| Render a specific subroutine | perl -MO=Concise,bar foo.pl | Only render bar() from the file |
| Render all functions in a package | perl -MO=Concise,-stash=SomePackage | Require and render all subs in the package |
| Switch to terse style | set_style_standard('terse') | Emulate B::Terse output |
| Add custom style | add_style($name => $default, $goto, $tree) | Define new rendering style |
| Add callback for custom variables | add_callback(sub { my ($h, $op, ...) = @_; ... }) | Populate #variables for style |
perl -MO=Concise[,OPTIONS] foo.pl
use B::Concise qw(set_style add_callback);
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 -Dx debugging flag or the B::Terse module, but it is more sophisticated and flexible.
Here's two outputs (or 'renderings'), using the -exec and -basic (i.e. default) formatting conventions on the same code snippet.
% perl -MO=Concise,-exec -e '$a = $b + 42'
1 <0> enter
2 <;> nextstate(main 1 -e:1) v
3 <#> gvsv[*b] s
4 <$> const[IV 42] s
* 5 <2> add[t3] sK/2
6 <#> gvsv[*a] s
7 <2> sassign vKS/2
8 <@> leave[1 ref] vKP/REFC
In this -exec rendering, each opcode is executed in the order shown. The add opcode, marked with '*', is discussed in more detail.
% perl -MO=Concise -e '$a = $b + 42'
8 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v ->3
7 <2> sassign vKS/2 ->8
* 5 <2> add[t1] sK/2 ->6
- <1> ex-rv2sv sK/1 ->4
3 <$> gvsv(*b) s ->4
4 <$> const(IV 42) s ->5
- <1> ex-rv2sv sKRM*/1 ->7
6 <$> gvsv(*a) s ->7
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.
Arguments that don't start with a hyphen are taken to be the names of subroutines or formats to render; 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 "BEGIN", "UNITCHECK", "CHECK", "INIT", or "END" will cause all of the corresponding special blocks to be printed. Arguments must follow options.
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).
Options are sticky across multiple invocations; change them by re-specifying.
0 OP (BASEOP) — No children1 UNOP — One child+ UNOP_AUX — UNOP with auxiliary fields2 BINOP — Two children| LOGOP — Control branch@ LISTOP — Many children/ PMOP — Regular expression$ SVOP — SV operand" PVOP — String operand{ LOOP — Loop pointers; COP — Start of statement# PADOP — GV on the pad. METHOP — Method call infov OPf_WANT_VOID — Want nothing (void context)s OPf_WANT_SCALAR — Want single value (scalar context)l OPf_WANT_LIST — Want list (list context)K OPf_KIDS — Has a firstborn child.P OPf_PARENS — ParenthesizedR OPf_REF — Certified referenceM OPf_MOD — Will modify (lvalue)S OPf_STACKED — Arg arriving on stack* OPf_SPECIAL — Do something weirdPrivate flags (after '/') are opcode-specific; see B::Op_private.
For each line-style, there are 3 format-specs: default (basic/exec), goto (exec mode), tree.
(x(exec_text;basic_text)x) — Select text based on mode.(*(text)*) — Repeat text per indentation level.(*(text1;text2)*) — text1 repeated (level-1) times, then text2.(?(text1#varText2)?) — Conditional inclusion if var is true.~ — Collapse tildes and whitespace to a single space.The following variables are available for use in style definitions:
#addr — Address of OP (hex)#arg — OP-specific info in parentheses#class — B-determined class (all caps)#classsym — Single symbol abbreviation for class#coplabel — Label of statement/block start#exname — OP name, or 'ex-foo' for nulled ops#extarg — Target of OP or empty for nulled#firstaddr — Address of first child (hex)#flags — Abbreviated flags#flagval — Numeric flags value#hints — COP hint flags (abbreviated)#hintsval — Numeric hints value#hyphseq — Sequence number or hyphen#label — 'NEXT', 'LAST', 'REDO' if target in exec mode#lastaddr — Address of last child (hex)#name — OP name#NAME — OP name (all caps)#next — Sequence number of next OP#nextaddr — Address of next OP (hex)#noise — 1-2 char abbreviation for OP name#private — Private flags (abbreviated)#privval — Numeric private flags#seq — Sequence number (from B::Concise)#opt — Whether optimized by peephole#sibaddr — Address of next youngest sibling (hex)#svaddr — Address of SV (hex)#svclass — Class of SV (e.g., 'IV')#svval — Value of SV (short format)#targ — Numeric targ value#targarg — Variable name for targ, or 't' + number#targarglife — #targarg with COP sequence boundaries#typenum — Numeric OP typeperl -MO=Concise,bar foo.pl — Renders only bar() from foo.pl.perl -MDigest::MD5=md5 -MO=Concise,md5 -e1 — Identifies md5 as an XS function.perl -MPOSIX -MO=Concise,_POSIX_ARG_MAX -e1 — Identifies _POSIX_ARG_MAX as constant sub.perl -MPOSIX -MO=Concise,a -e 'print _POSIX_SAVED_IDS' — Renders a print statement.perl -MPOSIX -MO=Concise,a -e 'sub a{_POSIX_SAVED_IDS}' — Similar, but for a subroutine.perl -MB::Concise -e 'B::Concise::compile("-exec","-src", \%B::Concise::)->()' — Renders all functions in B::Concise with source.The common usage is command-line, but you can call compile() directly and repeatedly.
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->();
Accepts 3 arguments (basic-exec, goto, tree). Prefer add_style() or set_style_standard().
Restores a predefined style: "terse", "concise", "linenoise", "debug", "env", or custom.
Registers a new style name with three format strings.
Registers a callback to populate #variables. Called for each op with parameters: hashref, op object, format ref, indent level, style name.
Returns a coderef that walks and renders the optrees. You can change style between calls. walk_output changes print destination.
my $walker = B::Concise::compile('-terse','aFuncName', \&aSubRef);
walk_output(\my $buf);
$walker->();
set_style_standard('concise');
$walker->();
Resets sequence numbers for testing (not exported).
Rendering errors are written to STDOUT or walk_output destination. Style and argument errors die().
Stephen McCamant, <smcc AT CSUA.EDU>.
perl v5.34.0 2026-06-23 B::Concise(3perl)
Generated by phpman v4.9.25-8-g32d6339 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-12 03:22 @216.73.217.22
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format