+dttypes
[massrebuild.git] / dwarfredundant
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 $|=1;
5 my $quiet=shift @ARGV if ($ARGV[0]||"") eq "-q";
6 for my $argv (@ARGV) {
7   local *F;
8   open F,"llvm-dwarfdump --color=0 --verbose --debug-info '$argv'|" or die;
9   my $redundant;
10   my $redundant_text;
11   my $redundant_addr;
12   my $redundant_children;
13   my $die_addr;
14   my $die_text;
15   my $saved_total=0;
16   my $emptyline;
17   my $anydebug;
18   sub null($) {
19     my($addr)=@_;
20     die if !$redundant;
21     my $saved=eval($addr)+1-eval($redundant_addr);
22     $saved_total+=$saved;
23     print "saved=$saved:\n${redundant_text}saved_total=$saved_total\n\n" if !$quiet;
24     $redundant=0;
25   }
26   while (<F>) {
27     if (/^\s*$/s) {
28       $emptyline=1;
29       next;
30     }
31     my($addr,$spaces,$rest)=(/^(0x[0-9a-f]{8}:| {11})( +)(.*)$/) or do {
32       next;
33     };
34     $anydebug=1;
35     if ($addr ne " "x11) {
36       $addr=~s/:$// or die;
37     } else {
38       $addr=0;
39     }
40     if ($addr) {
41       if ($emptyline&&$redundant&&!$redundant_children) {
42         null($addr);
43       }
44       $die_addr=$addr;
45       $die_text=$_;
46     } else {
47       $die_text.=$_;
48     }
49     $emptyline=0;
50     if ($redundant) {
51       $redundant_text.=$_ if !$quiet;
52     }
53     my $spacesl=length $spaces or die;
54     if ($rest=~/\bDW_FORM_addr\b.*0x0000000000000000|\bDW_AT_signature\b/) {
55       next if $redundant;
56       $redundant=$spacesl;
57       $redundant_text=$die_text if !$quiet;
58       $redundant_children=($die_text=~/^.* [*]\n/);
59       $redundant_addr=$die_addr or die;
60       next;
61     }
62     if ($rest=~/DW_AT_stmt_list/) {
63       $redundant=0;
64       next;
65     }
66     if ($rest eq "NULL") {
67       next if !$redundant;
68       next if $spacesl>$redundant;
69       null($addr);
70     }
71   }
72   close F or die;
73   print "$saved_total ".(stat $argv)[7]." $argv\n" if $anydebug;
74 }