Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

823 lines
26 KiB

  1. package B::Concise;
  2. # Copyright (C) 2000, 2001 Stephen McCamant. All rights reserved.
  3. # This program is free software; you can redistribute and/or modify it
  4. # under the same terms as Perl itself.
  5. our $VERSION = "0.51";
  6. use strict;
  7. use B qw(class ppname main_start main_root main_cv cstring svref_2object
  8. SVf_IOK SVf_NOK SVf_POK OPf_KIDS);
  9. my %style =
  10. ("terse" =>
  11. ["(?(#label =>\n)?)(*( )*)#class (#addr) #name (?([#targ])?) "
  12. . "#svclass~(?((#svaddr))?)~#svval~(?(label \"#coplabel\")?)\n",
  13. "(*( )*)goto #class (#addr)\n",
  14. "#class pp_#name"],
  15. "concise" =>
  16. ["#hyphseq2 (*( (x( ;)x))*)<#classsym> "
  17. . "#exname#arg(?([#targarglife])?)~#flags(?(/#private)?)(x(;~->#next)x)\n",
  18. " (*( )*) goto #seq\n",
  19. "(?(<#seq>)?)#exname#arg(?([#targarglife])?)"],
  20. "linenoise" =>
  21. ["(x(;(*( )*))x)#noise#arg(?([#targarg])?)(x( ;\n)x)",
  22. "gt_#seq ",
  23. "(?(#seq)?)#noise#arg(?([#targarg])?)"],
  24. "debug" =>
  25. ["#class (#addr)\n\top_next\t\t#nextaddr\n\top_sibling\t#sibaddr\n\t"
  26. . "op_ppaddr\tPL_ppaddr[OP_#NAME]\n\top_type\t\t#typenum\n\top_seq\t\t"
  27. . "#seqnum\n\top_flags\t#flagval\n\top_private\t#privval\n"
  28. . "(?(\top_first\t#firstaddr\n)?)(?(\top_last\t\t#lastaddr\n)?)"
  29. . "(?(\top_sv\t\t#svaddr\n)?)",
  30. " GOTO #addr\n",
  31. "#addr"],
  32. "env" => [$ENV{B_CONCISE_FORMAT}, $ENV{B_CONCISE_GOTO_FORMAT},
  33. $ENV{B_CONCISE_TREE_FORMAT}],
  34. );
  35. my($format, $gotofmt, $treefmt);
  36. my $curcv;
  37. my($seq_base, $cop_seq_base);
  38. sub concise_cv {
  39. my ($order, $cvref) = @_;
  40. my $cv = svref_2object($cvref);
  41. $curcv = $cv;
  42. if ($order eq "exec") {
  43. walk_exec($cv->START);
  44. } elsif ($order eq "basic") {
  45. walk_topdown($cv->ROOT, sub { $_[0]->concise($_[1]) }, 0);
  46. } else {
  47. print tree($cv->ROOT, 0)
  48. }
  49. }
  50. my $start_sym = "\e(0"; # "\cN" sometimes also works
  51. my $end_sym = "\e(B"; # "\cO" respectively
  52. my @tree_decorations =
  53. ([" ", "--", "+-", "|-", "| ", "`-", "-", 1],
  54. [" ", "-", "+", "+", "|", "`", "", 0],
  55. [" ", map("$start_sym$_$end_sym", "qq", "wq", "tq", "x ", "mq", "q"), 1],
  56. [" ", map("$start_sym$_$end_sym", "q", "w", "t", "x", "m"), "", 0],
  57. );
  58. my $tree_style = 0;
  59. my $base = 36;
  60. my $big_endian = 1;
  61. my $order = "basic";
  62. sub compile {
  63. my @options = grep(/^-/, @_);
  64. my @args = grep(!/^-/, @_);
  65. my $do_main = 0;
  66. ($format, $gotofmt, $treefmt) = @{$style{"concise"}};
  67. for my $o (@options) {
  68. if ($o eq "-basic") {
  69. $order = "basic";
  70. } elsif ($o eq "-exec") {
  71. $order = "exec";
  72. } elsif ($o eq "-tree") {
  73. $order = "tree";
  74. } elsif ($o eq "-compact") {
  75. $tree_style |= 1;
  76. } elsif ($o eq "-loose") {
  77. $tree_style &= ~1;
  78. } elsif ($o eq "-vt") {
  79. $tree_style |= 2;
  80. } elsif ($o eq "-ascii") {
  81. $tree_style &= ~2;
  82. } elsif ($o eq "-main") {
  83. $do_main = 1;
  84. } elsif ($o =~ /^-base(\d+)$/) {
  85. $base = $1;
  86. } elsif ($o eq "-bigendian") {
  87. $big_endian = 1;
  88. } elsif ($o eq "-littleendian") {
  89. $big_endian = 0;
  90. } elsif (exists $style{substr($o, 1)}) {
  91. ($format, $gotofmt, $treefmt) = @{$style{substr($o, 1)}};
  92. } else {
  93. warn "Option $o unrecognized";
  94. }
  95. }
  96. if (@args) {
  97. return sub {
  98. for my $objname (@args) {
  99. $objname = "main::" . $objname unless $objname =~ /::/;
  100. eval "concise_cv(\$order, \\&$objname)";
  101. die "concise_cv($order, \\&$objname) failed: $@" if $@;
  102. }
  103. }
  104. }
  105. if (!@args or $do_main) {
  106. if ($order eq "exec") {
  107. return sub { return if class(main_start) eq "NULL";
  108. $curcv = main_cv;
  109. walk_exec(main_start) }
  110. } elsif ($order eq "tree") {
  111. return sub { return if class(main_root) eq "NULL";
  112. $curcv = main_cv;
  113. print tree(main_root, 0) }
  114. } elsif ($order eq "basic") {
  115. return sub { return if class(main_root) eq "NULL";
  116. $curcv = main_cv;
  117. walk_topdown(main_root,
  118. sub { $_[0]->concise($_[1]) }, 0); }
  119. }
  120. }
  121. }
  122. my %labels;
  123. my $lastnext;
  124. my %opclass = ('OP' => "0", 'UNOP' => "1", 'BINOP' => "2", 'LOGOP' => "|",
  125. 'LISTOP' => "@", 'PMOP' => "/", 'SVOP' => "\$", 'GVOP' => "*",
  126. 'PVOP' => '"', 'LOOP' => "{", 'COP' => ";");
  127. my @linenoise =
  128. qw'# () sc ( @? 1 $* gv *{ m$ m@ m% m? p/ *$ $ $# & a& pt \\ s\\ rf bl
  129. ` *? <> ?? ?/ r/ c/ // qr s/ /c y/ = @= C sC Cp sp df un BM po +1 +I
  130. -1 -I 1+ I+ 1- I- ** * i* / i/ %$ i% x + i+ - i- . " << >> < i<
  131. > i> <= i, >= i. == i= != i! <? i? s< s> s, s. s= s! s? b& b^ b| -0 -i
  132. ! ~ a2 si cs rd sr e^ lg sq in %x %o ab le ss ve ix ri sf FL od ch cy
  133. uf lf uc lc qm @ [f [ @[ eh vl ky dl ex % ${ @{ uk pk st jn ) )[ a@
  134. a% sl +] -] [- [+ so rv GS GW MS MW .. f. .f && || ^^ ?: &= |= -> s{ s}
  135. v} ca wa di rs ;; ; ;d }{ { } {} f{ it {l l} rt }l }n }r dm }g }e ^o
  136. ^c ^| ^# um bm t~ u~ ~d DB db ^s se ^g ^r {w }w pf pr ^O ^K ^R ^W ^d ^v
  137. ^e ^t ^k t. fc ic fl .s .p .b .c .l .a .h g1 s1 g2 s2 ?. l? -R -W -X -r
  138. -w -x -e -o -O -z -s -M -A -C -S -c -b -f -d -p -l -u -g -k -t -T -B cd
  139. co cr u. cm ut r. l@ s@ r@ mD uD oD rD tD sD wD cD f$ w$ p$ sh e$ k$ g3
  140. g4 s4 g5 s5 T@ C@ L@ G@ A@ S@ Hg Hc Hr Hw Mg Mc Ms Mr Sg Sc So rq do {e
  141. e} {t t} g6 G6 6e g7 G7 7e g8 G8 8e g9 G9 9e 6s 7s 8s 9s 6E 7E 8E 9E Pn
  142. Pu GP SP EP Gn Gg GG SG EG g0 c$ lk t$ ;s n>';
  143. my $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  144. sub op_flags {
  145. my($x) = @_;
  146. my(@v);
  147. push @v, "v" if ($x & 3) == 1;
  148. push @v, "s" if ($x & 3) == 2;
  149. push @v, "l" if ($x & 3) == 3;
  150. push @v, "K" if $x & 4;
  151. push @v, "P" if $x & 8;
  152. push @v, "R" if $x & 16;
  153. push @v, "M" if $x & 32;
  154. push @v, "S" if $x & 64;
  155. push @v, "*" if $x & 128;
  156. return join("", @v);
  157. }
  158. sub base_n {
  159. my $x = shift;
  160. return "-" . base_n(-$x) if $x < 0;
  161. my $str = "";
  162. do { $str .= substr($chars, $x % $base, 1) } while $x = int($x / $base);
  163. $str = reverse $str if $big_endian;
  164. return $str;
  165. }
  166. sub seq { return $_[0]->seq ? base_n($_[0]->seq - $seq_base) : "-" }
  167. sub walk_topdown {
  168. my($op, $sub, $level) = @_;
  169. $sub->($op, $level);
  170. if ($op->flags & OPf_KIDS) {
  171. for (my $kid = $op->first; $$kid; $kid = $kid->sibling) {
  172. walk_topdown($kid, $sub, $level + 1);
  173. }
  174. }
  175. if (class($op) eq "PMOP" and $ {$op->pmreplroot}
  176. and $op->pmreplroot->isa("B::OP")) {
  177. walk_topdown($op->pmreplroot, $sub, $level + 1);
  178. }
  179. }
  180. sub walklines {
  181. my($ar, $level) = @_;
  182. for my $l (@$ar) {
  183. if (ref($l) eq "ARRAY") {
  184. walklines($l, $level + 1);
  185. } else {
  186. $l->concise($level);
  187. }
  188. }
  189. }
  190. sub walk_exec {
  191. my($top, $level) = @_;
  192. my %opsseen;
  193. my @lines;
  194. my @todo = ([$top, \@lines]);
  195. while (@todo and my($op, $targ) = @{shift @todo}) {
  196. for (; $$op; $op = $op->next) {
  197. last if $opsseen{$$op}++;
  198. push @$targ, $op;
  199. my $name = $op->name;
  200. if ($name
  201. =~ /^(or|and|(map|grep)while|entertry|range|cond_expr)$/) {
  202. my $ar = [];
  203. push @$targ, $ar;
  204. push @todo, [$op->other, $ar];
  205. } elsif ($name eq "subst" and $ {$op->pmreplstart}) {
  206. my $ar = [];
  207. push @$targ, $ar;
  208. push @todo, [$op->pmreplstart, $ar];
  209. } elsif ($name =~ /^enter(loop|iter)$/) {
  210. $labels{$op->nextop->seq} = "NEXT";
  211. $labels{$op->lastop->seq} = "LAST";
  212. $labels{$op->redoop->seq} = "REDO";
  213. }
  214. }
  215. }
  216. walklines(\@lines, 0);
  217. }
  218. sub fmt_line {
  219. my($hr, $fmt, $level) = @_;
  220. my $text = $fmt;
  221. $text =~ s/\(\?\(([^\#]*?)\#(\w+)([^\#]*?)\)\?\)/
  222. $hr->{$2} ? $1.$hr->{$2}.$3 : ""/eg;
  223. $text =~ s/\(x\((.*?);(.*?)\)x\)/$order eq "exec" ? $1 : $2/egs;
  224. $text =~ s/\(\*\(([^;]*?)\)\*\)/$1 x $level/egs;
  225. $text =~ s/\(\*\((.*?);(.*?)\)\*\)/$1 x ($level - 1) . $2 x ($level>0)/egs;
  226. $text =~ s/#([a-zA-Z]+)(\d+)/sprintf("%-$2s", $hr->{$1})/eg;
  227. $text =~ s/#([a-zA-Z]+)/$hr->{$1}/eg;
  228. $text =~ s/[ \t]*~+[ \t]*/ /g;
  229. return $text;
  230. }
  231. my %priv;
  232. $priv{$_}{128} = "LVINTRO"
  233. for ("pos", "substr", "vec", "threadsv", "gvsv", "rv2sv", "rv2hv", "rv2gv",
  234. "rv2av", "rv2arylen", "aelem", "helem", "aslice", "hslice", "padsv",
  235. "padav", "padhv");
  236. $priv{$_}{64} = "REFC" for ("leave", "leavesub", "leavesublv", "leavewrite");
  237. $priv{"aassign"}{64} = "COMMON";
  238. $priv{"aassign"}{32} = "PHASH";
  239. $priv{"sassign"}{64} = "BKWARD";
  240. $priv{$_}{64} = "RTIME" for ("match", "subst", "substcont");
  241. @{$priv{"trans"}}{1,2,4,8,16,64} = ("<UTF", ">UTF", "IDENT", "SQUASH", "DEL",
  242. "COMPL", "GROWS");
  243. $priv{"repeat"}{64} = "DOLIST";
  244. $priv{"leaveloop"}{64} = "CONT";
  245. @{$priv{$_}}{32,64,96} = ("DREFAV", "DREFHV", "DREFSV")
  246. for ("entersub", map("rv2${_}v", "a", "s", "h", "g"), "aelem", "helem");
  247. $priv{"entersub"}{16} = "DBG";
  248. $priv{"entersub"}{32} = "TARG";
  249. @{$priv{$_}}{4,8,128} = ("INARGS","AMPER","NO()") for ("entersub", "rv2cv");
  250. $priv{"gv"}{32} = "EARLYCV";
  251. $priv{"aelem"}{16} = $priv{"helem"}{16} = "LVDEFER";
  252. $priv{$_}{16} = "OURINTR" for ("gvsv", "rv2sv", "rv2av", "rv2hv", "r2gv");
  253. $priv{$_}{16} = "TARGMY"
  254. for (map(($_,"s$_"),"chop", "chomp"),
  255. map(($_,"i_$_"), "postinc", "postdec", "multiply", "divide", "modulo",
  256. "add", "subtract", "negate"), "pow", "concat", "stringify",
  257. "left_shift", "right_shift", "bit_and", "bit_xor", "bit_or",
  258. "complement", "atan2", "sin", "cos", "rand", "exp", "log", "sqrt",
  259. "int", "hex", "oct", "abs", "length", "index", "rindex", "sprintf",
  260. "ord", "chr", "crypt", "quotemeta", "join", "push", "unshift", "flock",
  261. "chdir", "chown", "chroot", "unlink", "chmod", "utime", "rename",
  262. "link", "symlink", "mkdir", "rmdir", "wait", "waitpid", "system",
  263. "exec", "kill", "getppid", "getpgrp", "setpgrp", "getpriority",
  264. "setpriority", "time", "sleep");
  265. @{$priv{"const"}}{8,16,32,64,128} = ("STRICT","ENTERED", "$[", "BARE", "WARN");
  266. $priv{"flip"}{64} = $priv{"flop"}{64} = "LINENUM";
  267. $priv{"list"}{64} = "GUESSED";
  268. $priv{"delete"}{64} = "SLICE";
  269. $priv{"exists"}{64} = "SUB";
  270. $priv{$_}{64} = "LOCALE"
  271. for ("sort", "prtf", "sprintf", "slt", "sle", "seq", "sne", "sgt", "sge",
  272. "scmp", "lc", "uc", "lcfirst", "ucfirst");
  273. @{$priv{"sort"}}{1,2,4} = ("NUM", "INT", "REV");
  274. $priv{"threadsv"}{64} = "SVREFd";
  275. $priv{$_}{16} = "INBIN" for ("open", "backtick");
  276. $priv{$_}{32} = "INCR" for ("open", "backtick");
  277. $priv{$_}{64} = "OUTBIN" for ("open", "backtick");
  278. $priv{$_}{128} = "OUTCR" for ("open", "backtick");
  279. $priv{"exit"}{128} = "VMS";
  280. sub private_flags {
  281. my($name, $x) = @_;
  282. my @s;
  283. for my $flag (128, 96, 64, 32, 16, 8, 4, 2, 1) {
  284. if ($priv{$name}{$flag} and $x & $flag and $x >= $flag) {
  285. $x -= $flag;
  286. push @s, $priv{$name}{$flag};
  287. }
  288. }
  289. push @s, $x if $x;
  290. return join(",", @s);
  291. }
  292. sub concise_op {
  293. my ($op, $level, $format) = @_;
  294. my %h;
  295. $h{exname} = $h{name} = $op->name;
  296. $h{NAME} = uc $h{name};
  297. $h{class} = class($op);
  298. $h{extarg} = $h{targ} = $op->targ;
  299. $h{extarg} = "" unless $h{extarg};
  300. if ($h{name} eq "null" and $h{targ}) {
  301. $h{exname} = "ex-" . substr(ppname($h{targ}), 3);
  302. $h{extarg} = "";
  303. } elsif ($h{targ}) {
  304. my $padname = (($curcv->PADLIST->ARRAY)[0]->ARRAY)[$h{targ}];
  305. if (defined $padname and class($padname) ne "SPECIAL") {
  306. $h{targarg} = $padname->PVX;
  307. my $intro = $padname->NVX - $cop_seq_base;
  308. my $finish = int($padname->IVX) - $cop_seq_base;
  309. $finish = "end" if $finish == 999999999 - $cop_seq_base;
  310. $h{targarglife} = "$h{targarg}:$intro,$finish";
  311. } else {
  312. $h{targarglife} = $h{targarg} = "t" . $h{targ};
  313. }
  314. }
  315. $h{arg} = "";
  316. $h{svclass} = $h{svaddr} = $h{svval} = "";
  317. if ($h{class} eq "PMOP") {
  318. my $precomp = $op->precomp;
  319. $precomp = defined($precomp) ? "/$precomp/" : "";
  320. my $pmreplroot = $op->pmreplroot;
  321. my ($pmreplroot, $pmreplstart);
  322. if ($ {$pmreplroot = $op->pmreplroot} && $pmreplroot->isa("B::GV")) {
  323. # with C<@stash_array = split(/pat/, str);>,
  324. # *stash_array is stored in pmreplroot.
  325. $h{arg} = "($precomp => \@" . $pmreplroot->NAME . ")";
  326. } elsif ($ {$op->pmreplstart}) {
  327. undef $lastnext;
  328. $pmreplstart = "replstart->" . seq($op->pmreplstart);
  329. $h{arg} = "(" . join(" ", $precomp, $pmreplstart) . ")";
  330. } else {
  331. $h{arg} = "($precomp)";
  332. }
  333. } elsif ($h{class} eq "PVOP" and $h{name} ne "trans") {
  334. $h{arg} = '("' . $op->pv . '")';
  335. $h{svval} = '"' . $op->pv . '"';
  336. } elsif ($h{class} eq "COP") {
  337. my $label = $op->label;
  338. $h{coplabel} = $label;
  339. $label = $label ? "$label: " : "";
  340. my $loc = $op->file;
  341. $loc =~ s[.*/][];
  342. $loc .= ":" . $op->line;
  343. my($stash, $cseq) = ($op->stash->NAME, $op->cop_seq - $cop_seq_base);
  344. my $arybase = $op->arybase;
  345. $arybase = $arybase ? ' $[=' . $arybase : "";
  346. $h{arg} = "($label$stash $cseq $loc$arybase)";
  347. } elsif ($h{class} eq "LOOP") {
  348. $h{arg} = "(next->" . seq($op->nextop) . " last->" . seq($op->lastop)
  349. . " redo->" . seq($op->redoop) . ")";
  350. } elsif ($h{class} eq "LOGOP") {
  351. undef $lastnext;
  352. $h{arg} = "(other->" . seq($op->other) . ")";
  353. } elsif ($h{class} eq "SVOP") {
  354. my $sv = $op->sv;
  355. $h{svclass} = class($sv);
  356. $h{svaddr} = sprintf("%#x", $$sv);
  357. if ($h{svclass} eq "GV") {
  358. my $gv = $sv;
  359. my $stash = $gv->STASH->NAME;
  360. if ($stash eq "main") {
  361. $stash = "";
  362. } else {
  363. $stash = $stash . "::";
  364. }
  365. $h{arg} = "(*$stash" . $gv->SAFENAME . ")";
  366. $h{svval} = "*$stash" . $gv->SAFENAME;
  367. } else {
  368. while (class($sv) eq "RV") {
  369. $h{svval} .= "\\";
  370. $sv = $sv->RV;
  371. }
  372. if (class($sv) eq "SPECIAL") {
  373. $h{svval} = ["Null", "sv_undef", "sv_yes", "sv_no"]->[$$sv];
  374. } elsif ($sv->FLAGS & SVf_NOK) {
  375. $h{svval} = $sv->NV;
  376. } elsif ($sv->FLAGS & SVf_IOK) {
  377. $h{svval} = $sv->IV;
  378. } elsif ($sv->FLAGS & SVf_POK) {
  379. $h{svval} = cstring($sv->PV);
  380. }
  381. $h{arg} = "($h{svclass} $h{svval})";
  382. }
  383. }
  384. $h{seq} = $h{hyphseq} = seq($op);
  385. $h{seq} = "" if $h{seq} eq "-";
  386. $h{seqnum} = $op->seq;
  387. $h{next} = $op->next;
  388. $h{next} = (class($h{next}) eq "NULL") ? "(end)" : seq($h{next});
  389. $h{nextaddr} = sprintf("%#x", $ {$op->next});
  390. $h{sibaddr} = sprintf("%#x", $ {$op->sibling});
  391. $h{firstaddr} = sprintf("%#x", $ {$op->first}) if $op->can("first");
  392. $h{lastaddr} = sprintf("%#x", $ {$op->last}) if $op->can("last");
  393. $h{classsym} = $opclass{$h{class}};
  394. $h{flagval} = $op->flags;
  395. $h{flags} = op_flags($op->flags);
  396. $h{privval} = $op->private;
  397. $h{private} = private_flags($h{name}, $op->private);
  398. $h{addr} = sprintf("%#x", $$op);
  399. $h{label} = $labels{$op->seq};
  400. $h{typenum} = $op->type;
  401. $h{noise} = $linenoise[$op->type];
  402. return fmt_line(\%h, $format, $level);
  403. }
  404. sub B::OP::concise {
  405. my($op, $level) = @_;
  406. if ($order eq "exec" and $lastnext and $$lastnext != $$op) {
  407. my $h = {"seq" => seq($lastnext), "class" => class($lastnext),
  408. "addr" => sprintf("%#x", $$lastnext)};
  409. print fmt_line($h, $gotofmt, $level+1);
  410. }
  411. $lastnext = $op->next;
  412. print concise_op($op, $level, $format);
  413. }
  414. sub tree {
  415. my $op = shift;
  416. my $level = shift;
  417. my $style = $tree_decorations[$tree_style];
  418. my($space, $single, $kids, $kid, $nokid, $last, $lead, $size) = @$style;
  419. my $name = concise_op($op, $level, $treefmt);
  420. if (not $op->flags & OPf_KIDS) {
  421. return $name . "\n";
  422. }
  423. my @lines;
  424. for (my $kid = $op->first; $$kid; $kid = $kid->sibling) {
  425. push @lines, tree($kid, $level+1);
  426. }
  427. my $i;
  428. for ($i = $#lines; substr($lines[$i], 0, 1) eq " "; $i--) {
  429. $lines[$i] = $space . $lines[$i];
  430. }
  431. if ($i > 0) {
  432. $lines[$i] = $last . $lines[$i];
  433. while ($i-- > 1) {
  434. if (substr($lines[$i], 0, 1) eq " ") {
  435. $lines[$i] = $nokid . $lines[$i];
  436. } else {
  437. $lines[$i] = $kid . $lines[$i];
  438. }
  439. }
  440. $lines[$i] = $kids . $lines[$i];
  441. } else {
  442. $lines[0] = $single . $lines[0];
  443. }
  444. return("$name$lead" . shift @lines,
  445. map(" " x (length($name)+$size) . $_, @lines));
  446. }
  447. # This is a bit of a hack; the 2 and 15 were determined empirically.
  448. # These need to stay the last things in the module.
  449. $cop_seq_base = svref_2object(eval 'sub{0;}')->START->cop_seq + 2;
  450. $seq_base = svref_2object(eval 'sub{}')->START->seq + 15;
  451. 1;
  452. __END__
  453. =head1 NAME
  454. B::Concise - Walk Perl syntax tree, printing concise info about ops
  455. =head1 SYNOPSIS
  456. perl -MO=Concise[,OPTIONS] foo.pl
  457. =head1 DESCRIPTION
  458. This compiler backend prints the internal OPs of a Perl program's syntax
  459. tree in one of several space-efficient text formats suitable for debugging
  460. the inner workings of perl or other compiler backends. It can print OPs in
  461. the order they appear in the OP tree, in the order they will execute, or
  462. in a text approximation to their tree structure, and the format of the
  463. information displyed is customizable. Its function is similar to that of
  464. perl's B<-Dx> debugging flag or the B<B::Terse> module, but it is more
  465. sophisticated and flexible.
  466. =head1 OPTIONS
  467. Arguments that don't start with a hyphen are taken to be the names of
  468. subroutines to print the OPs of; if no such functions are specified, the
  469. main body of the program (outside any subroutines, and not including use'd
  470. or require'd files) is printed.
  471. =over 4
  472. =item B<-basic>
  473. Print OPs in the order they appear in the OP tree (a preorder
  474. traversal, starting at the root). The indentation of each OP shows its
  475. level in the tree. This mode is the default, so the flag is included
  476. simply for completeness.
  477. =item B<-exec>
  478. Print OPs in the order they would normally execute (for the majority
  479. of constructs this is a postorder traversal of the tree, ending at the
  480. root). In most cases the OP that usually follows a given OP will
  481. appear directly below it; alternate paths are shown by indentation. In
  482. cases like loops when control jumps out of a linear path, a 'goto'
  483. line is generated.
  484. =item B<-tree>
  485. Print OPs in a text approximation of a tree, with the root of the tree
  486. at the left and 'left-to-right' order of children transformed into
  487. 'top-to-bottom'. Because this mode grows both to the right and down,
  488. it isn't suitable for large programs (unless you have a very wide
  489. terminal).
  490. =item B<-compact>
  491. Use a tree format in which the minimum amount of space is used for the
  492. lines connecting nodes (one character in most cases). This squeezes out
  493. a few precious columns of screen real estate.
  494. =item B<-loose>
  495. Use a tree format that uses longer edges to separate OP nodes. This format
  496. tends to look better than the compact one, especially in ASCII, and is
  497. the default.
  498. =item B<-vt>
  499. Use tree connecting characters drawn from the VT100 line-drawing set.
  500. This looks better if your terminal supports it.
  501. =item B<-ascii>
  502. Draw the tree with standard ASCII characters like C<+> and C<|>. These don't
  503. look as clean as the VT100 characters, but they'll work with almost any
  504. terminal (or the horizontal scrolling mode of less(1)) and are suitable
  505. for text documentation or email. This is the default.
  506. =item B<-main>
  507. Include the main program in the output, even if subroutines were also
  508. specified.
  509. =item B<-base>I<n>
  510. Print OP sequence numbers in base I<n>. If I<n> is greater than 10, the
  511. digit for 11 will be 'a', and so on. If I<n> is greater than 36, the digit
  512. for 37 will be 'A', and so on until 62. Values greater than 62 are not
  513. currently supported. The default is 36.
  514. =item B<-bigendian>
  515. Print sequence numbers with the most significant digit first. This is the
  516. usual convention for Arabic numerals, and the default.
  517. =item B<-littleendian>
  518. Print seqence numbers with the least significant digit first.
  519. =item B<-concise>
  520. Use the author's favorite set of formatting conventions. This is the
  521. default, of course.
  522. =item B<-terse>
  523. Use formatting conventions that emulate the ouput of B<B::Terse>. The
  524. basic mode is almost indistinguishable from the real B<B::Terse>, and the
  525. exec mode looks very similar, but is in a more logical order and lacks
  526. curly brackets. B<B::Terse> doesn't have a tree mode, so the tree mode
  527. is only vaguely reminiscient of B<B::Terse>.
  528. =item B<-linenoise>
  529. Use formatting conventions in which the name of each OP, rather than being
  530. written out in full, is represented by a one- or two-character abbreviation.
  531. This is mainly a joke.
  532. =item B<-debug>
  533. Use formatting conventions reminiscient of B<B::Debug>; these aren't
  534. very concise at all.
  535. =item B<-env>
  536. Use formatting conventions read from the environment variables
  537. C<B_CONCISE_FORMAT>, C<B_CONCISE_GOTO_FORMAT>, and C<B_CONCISE_TREE_FORMAT>.
  538. =back
  539. =head1 FORMATTING SPECIFICATIONS
  540. For each general style ('concise', 'terse', 'linenoise', etc.) there are
  541. three specifications: one of how OPs should appear in the basic or exec
  542. modes, one of how 'goto' lines should appear (these occur in the exec
  543. mode only), and one of how nodes should appear in tree mode. Each has the
  544. same format, described below. Any text that doesn't match a special
  545. pattern is copied verbatim.
  546. =over 4
  547. =item B<(x(>I<exec_text>B<;>I<basic_text>B<)x)>
  548. Generates I<exec_text> in exec mode, or I<basic_text> in basic mode.
  549. =item B<(*(>I<text>B<)*)>
  550. Generates one copy of I<text> for each indentation level.
  551. =item B<(*(>I<text1>B<;>I<text2>B<)*)>
  552. Generates one fewer copies of I<text1> than the indentation level, followed
  553. by one copy of I<text2> if the indentation level is more than 0.
  554. =item B<(?(>I<text1>B<#>I<var>I<Text2>B<)?)>
  555. If the value of I<var> is true (not empty or zero), generates the
  556. value of I<var> surrounded by I<text1> and I<Text2>, otherwise
  557. nothing.
  558. =item B<#>I<var>
  559. Generates the value of the variable I<var>.
  560. =item B<#>I<var>I<N>
  561. Generates the value of I<var>, left jutified to fill I<N> spaces.
  562. =item B<~>
  563. Any number of tildes and surrounding whitespace will be collapsed to
  564. a single space.
  565. =back
  566. The following variables are recognized:
  567. =over 4
  568. =item B<#addr>
  569. The address of the OP, in hexidecimal.
  570. =item B<#arg>
  571. The OP-specific information of the OP (such as the SV for an SVOP, the
  572. non-local exit pointers for a LOOP, etc.) enclosed in paretheses.
  573. =item B<#class>
  574. The B-determined class of the OP, in all caps.
  575. =item B<#classym>
  576. A single symbol abbreviating the class of the OP.
  577. =item B<#coplabel>
  578. The label of the statement or block the OP is the start of, if any.
  579. =item B<#exname>
  580. The name of the OP, or 'ex-foo' if the OP is a null that used to be a foo.
  581. =item B<#extarg>
  582. The target of the OP, or nothing for a nulled OP.
  583. =item B<#firstaddr>
  584. The address of the OP's first child, in hexidecimal.
  585. =item B<#flags>
  586. The OP's flags, abbreviated as a series of symbols.
  587. =item B<#flagval>
  588. The numeric value of the OP's flags.
  589. =item B<#hyphenseq>
  590. The sequence number of the OP, or a hyphen if it doesn't have one.
  591. =item B<#label>
  592. 'NEXT', 'LAST', or 'REDO' if the OP is a target of one of those in exec
  593. mode, or empty otherwise.
  594. =item B<#lastaddr>
  595. The address of the OP's last child, in hexidecimal.
  596. =item B<#name>
  597. The OP's name.
  598. =item B<#NAME>
  599. The OP's name, in all caps.
  600. =item B<#next>
  601. The sequence number of the OP's next OP.
  602. =item B<#nextaddr>
  603. The address of the OP's next OP, in hexidecimal.
  604. =item B<#noise>
  605. The two-character abbreviation for the OP's name.
  606. =item B<#private>
  607. The OP's private flags, rendered with abbreviated names if possible.
  608. =item B<#privval>
  609. The numeric value of the OP's private flags.
  610. =item B<#seq>
  611. The sequence number of the OP.
  612. =item B<#seqnum>
  613. The real sequence number of the OP, as a regular number and not adjusted
  614. to be relative to the start of the real program. (This will generally be
  615. a fairly large number because all of B<B::Concise> is compiled before
  616. your program is).
  617. =item B<#sibaddr>
  618. The address of the OP's next youngest sibling, in hexidecimal.
  619. =item B<#svaddr>
  620. The address of the OP's SV, if it has an SV, in hexidecimal.
  621. =item B<#svclass>
  622. The class of the OP's SV, if it has one, in all caps (e.g., 'IV').
  623. =item B<#svval>
  624. The value of the OP's SV, if it has one, in a short human-readable format.
  625. =item B<#targ>
  626. The numeric value of the OP's targ.
  627. =item B<#targarg>
  628. The name of the variable the OP's targ refers to, if any, otherwise the
  629. letter t followed by the OP's targ in decimal.
  630. =item B<#targarglife>
  631. Same as B<#targarg>, but followed by the COP sequence numbers that delimit
  632. the variable's lifetime (or 'end' for a variable in an open scope) for a
  633. variable.
  634. =item B<#typenum>
  635. The numeric value of the OP's type, in decimal.
  636. =back
  637. =head1 ABBREVIATIONS
  638. =head2 OP flags abbreviations
  639. v OPf_WANT_VOID Want nothing (void context)
  640. s OPf_WANT_SCALAR Want single value (scalar context)
  641. l OPf_WANT_LIST Want list of any length (list context)
  642. K OPf_KIDS There is a firstborn child.
  643. P OPf_PARENS This operator was parenthesized.
  644. (Or block needs explicit scope entry.)
  645. R OPf_REF Certified reference.
  646. (Return container, not containee).
  647. M OPf_MOD Will modify (lvalue).
  648. S OPf_STACKED Some arg is arriving on the stack.
  649. * OPf_SPECIAL Do something weird for this op (see op.h)
  650. =head2 OP class abbreviations
  651. 0 OP (aka BASEOP) An OP with no children
  652. 1 UNOP An OP with one child
  653. 2 BINOP An OP with two children
  654. | LOGOP A control branch OP
  655. @ LISTOP An OP that could have lots of children
  656. / PMOP An OP with a regular expression
  657. $ SVOP An OP with an SV
  658. " PVOP An OP with a string
  659. { LOOP An OP that holds pointers for a loop
  660. ; COP An OP that marks the start of a statement
  661. =head1 AUTHOR
  662. Stephen McCamant, C<[email protected]>
  663. =cut