B::Concise - Walk Perl syntax tree, printing concise info about ops
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 displyed 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 an example of 2 outputs (aka '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
Each line corresponds to an opcode. The opcode marked with '*' is used in a few examples below.
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.
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 "OP class abbreviations").
The opname, as in 'add[t1]', which may be followed by op-specific information in parentheses or brackets (ex '[t1]').
The op-flags (ex 'sK/2') follow, and are described in ("OP flags abbreviations").
% 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.
Nullops appear as ex-opname, where opname 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.
The arrow points to the sequence number of the next op; they're not displayed in -exec mode, for obvious reasons.
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.
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 BEGIN, CHECK, INIT, or END will cause all of the corresponding special blocks to be printed.
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).