Source code of Windows XP (NT5)
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.

152 lines
3.1 KiB

  1. package B::Terse;
  2. use strict;
  3. use B qw(peekop class walkoptree_slow walkoptree_exec
  4. main_start main_root cstring svref_2object);
  5. use B::Asmdata qw(@specialsv_name);
  6. sub terse {
  7. my ($order, $cvref) = @_;
  8. my $cv = svref_2object($cvref);
  9. if ($order eq "exec") {
  10. walkoptree_exec($cv->START, "terse");
  11. } else {
  12. walkoptree_slow($cv->ROOT, "terse");
  13. }
  14. }
  15. sub compile {
  16. my $order = shift;
  17. my @options = @_;
  18. if (@options) {
  19. return sub {
  20. my $objname;
  21. foreach $objname (@options) {
  22. $objname = "main::$objname" unless $objname =~ /::/;
  23. eval "terse(\$order, \\&$objname)";
  24. die "terse($order, \\&$objname) failed: $@" if $@;
  25. }
  26. }
  27. } else {
  28. if ($order eq "exec") {
  29. return sub { walkoptree_exec(main_start, "terse") }
  30. } else {
  31. return sub { walkoptree_slow(main_root, "terse") }
  32. }
  33. }
  34. }
  35. sub indent {
  36. my $level = shift;
  37. return " " x $level;
  38. }
  39. sub B::OP::terse {
  40. my ($op, $level) = @_;
  41. my $targ = $op->targ;
  42. $targ = ($targ > 0) ? " [$targ]" : "";
  43. print indent($level), peekop($op), $targ, "\n";
  44. }
  45. sub B::SVOP::terse {
  46. my ($op, $level) = @_;
  47. print indent($level), peekop($op), " ";
  48. $op->sv->terse(0);
  49. }
  50. sub B::GVOP::terse {
  51. my ($op, $level) = @_;
  52. print indent($level), peekop($op), " ";
  53. $op->gv->terse(0);
  54. }
  55. sub B::PMOP::terse {
  56. my ($op, $level) = @_;
  57. my $precomp = $op->precomp;
  58. print indent($level), peekop($op),
  59. defined($precomp) ? " /$precomp/\n" : " (regexp not compiled)\n";
  60. }
  61. sub B::PVOP::terse {
  62. my ($op, $level) = @_;
  63. print indent($level), peekop($op), " ", cstring($op->pv), "\n";
  64. }
  65. sub B::COP::terse {
  66. my ($op, $level) = @_;
  67. my $label = $op->label;
  68. if ($label) {
  69. $label = " label ".cstring($label);
  70. }
  71. print indent($level), peekop($op), $label, "\n";
  72. }
  73. sub B::PV::terse {
  74. my ($sv, $level) = @_;
  75. print indent($level);
  76. printf "%s (0x%lx) %s\n", class($sv), $$sv, cstring($sv->PV);
  77. }
  78. sub B::AV::terse {
  79. my ($sv, $level) = @_;
  80. print indent($level);
  81. printf "%s (0x%lx) FILL %d\n", class($sv), $$sv, $sv->FILL;
  82. }
  83. sub B::GV::terse {
  84. my ($gv, $level) = @_;
  85. my $stash = $gv->STASH->NAME;
  86. if ($stash eq "main") {
  87. $stash = "";
  88. } else {
  89. $stash = $stash . "::";
  90. }
  91. print indent($level);
  92. printf "%s (0x%lx) *%s%s\n", class($gv), $$gv, $stash, $gv->NAME;
  93. }
  94. sub B::IV::terse {
  95. my ($sv, $level) = @_;
  96. print indent($level);
  97. printf "%s (0x%lx) %d\n", class($sv), $$sv, $sv->IV;
  98. }
  99. sub B::NV::terse {
  100. my ($sv, $level) = @_;
  101. print indent($level);
  102. printf "%s (0x%lx) %s\n", class($sv), $$sv, $sv->NV;
  103. }
  104. sub B::NULL::terse {
  105. my ($sv, $level) = @_;
  106. print indent($level);
  107. printf "%s (0x%lx)\n", class($sv), $$sv;
  108. }
  109. sub B::SPECIAL::terse {
  110. my ($sv, $level) = @_;
  111. print indent($level);
  112. printf "%s #%d %s\n", class($sv), $$sv, $specialsv_name[$$sv];
  113. }
  114. 1;
  115. __END__
  116. =head1 NAME
  117. B::Terse - Walk Perl syntax tree, printing terse info about ops
  118. =head1 SYNOPSIS
  119. perl -MO=Terse[,OPTIONS] foo.pl
  120. =head1 DESCRIPTION
  121. See F<ext/B/README>.
  122. =head1 AUTHOR
  123. Malcolm Beattie, C<[email protected]>
  124. =cut