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.

153 lines
3.4 KiB

  1. package B::Terse;
  2. use strict;
  3. use B qw(peekop class walkoptree walkoptree_exec walkoptree_slow
  4. main_start main_root cstring svref_2object SVf_IVisUV);
  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. B::clearsym();
  19. if (@options) {
  20. return sub {
  21. my $objname;
  22. foreach $objname (@options) {
  23. $objname = "main::$objname" unless $objname =~ /::/;
  24. eval "terse(\$order, \\&$objname)";
  25. die "terse($order, \\&$objname) failed: $@" if $@;
  26. }
  27. }
  28. } else {
  29. if ($order eq "exec") {
  30. return sub { walkoptree_exec(main_start, "terse") }
  31. } else {
  32. return sub { walkoptree_slow(main_root, "terse") }
  33. }
  34. }
  35. }
  36. sub indent {
  37. my $level = @_ ? shift : 0;
  38. return " " x $level;
  39. }
  40. sub B::OP::terse {
  41. my ($op, $level) = @_;
  42. my $targ = $op->targ;
  43. $targ = ($targ > 0) ? " [$targ]" : "";
  44. print indent($level), peekop($op), $targ, "\n";
  45. }
  46. sub B::SVOP::terse {
  47. my ($op, $level) = @_;
  48. print indent($level), peekop($op), " ";
  49. $op->sv->terse(0);
  50. }
  51. sub B::PADOP::terse {
  52. my ($op, $level) = @_;
  53. print indent($level), peekop($op), " ", $op->padix, "\n";
  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->SAFENAME;
  93. }
  94. sub B::IV::terse {
  95. my ($sv, $level) = @_;
  96. print indent($level);
  97. my $v = $sv->FLAGS & SVf_IVisUV ? "%u" : "%d";
  98. printf "%s (0x%lx) $v\n", class($sv), $$sv, $sv->int_value;
  99. }
  100. sub B::NV::terse {
  101. my ($sv, $level) = @_;
  102. print indent($level);
  103. printf "%s (0x%lx) %s\n", class($sv), $$sv, $sv->NV;
  104. }
  105. sub B::NULL::terse {
  106. my ($sv, $level) = @_;
  107. print indent($level);
  108. printf "%s (0x%lx)\n", class($sv), $$sv;
  109. }
  110. sub B::SPECIAL::terse {
  111. my ($sv, $level) = @_;
  112. print indent($level);
  113. printf "%s #%d %s\n", class($sv), $$sv, $specialsv_name[$$sv];
  114. }
  115. 1;
  116. __END__
  117. =head1 NAME
  118. B::Terse - Walk Perl syntax tree, printing terse info about ops
  119. =head1 SYNOPSIS
  120. perl -MO=Terse[,OPTIONS] foo.pl
  121. =head1 DESCRIPTION
  122. See F<ext/B/README>.
  123. =head1 AUTHOR
  124. Malcolm Beattie, C<[email protected]>
  125. =cut