forked from google/souper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_import.in
94 lines (86 loc) · 2.31 KB
/
cache_import.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env perl
# Copyright 2014 The Souper Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use warnings;
use strict;
use Redis;
use Getopt::Long;
use File::Temp;
use Time::HiRes;
my $llvmas = "@LLVM_BINDIR@/llvm-as";
my $llvmopt = "@LLVM_BINDIR@/opt";
my $llvmdis = "@LLVM_BINDIR@/llvm-dis";
my $check = "@CMAKE_BINARY_DIR@/souper-check";
my $reducer = "@CMAKE_BINARY_DIR@/reduce";
my $triager = "@CMAKE_BINARY_DIR@/py_souper2llvm";
sub parse ($) {
(my $opt) = @_;
(my $fh, my $tmpfn) = File::Temp::tempfile();
print $fh $opt;
$fh->flush();
my $arg = "--parse-lhs-only";
open INF, "${check} $arg < $tmpfn 2>/dev/null |";
my $output = "";
my $success = 0;
while (my $line = <INF>) {
$success = 1 if ($line =~ /success/);
next if ($line =~ /^;/);
$output .= $line;
}
close INF;
close $fh;
unlink $tmpfn;
print "'$opt' does not parse as Souper\n\n" unless $success;
return $success;
}
sub runit ($) {
my $cmd = shift;
my $res = (system "$cmd");
return $? >> 8;
}
my $r = Redis->new();
$r->ping || die "no server?";
my $cur;
my $sprofile;
my $known;
my $n=0;
while (my $line = <STDIN>) {
chomp $line;
if ($line =~ /\(hits ([0-9]+)\)/) {
print "$line\n";
$sprofile = $1;
die if defined $cur;
$cur = "";
next;
}
if ($line =~ /\/\/ \(([x01]+)\)/) {
$known = $1;
next;
}
$cur .= "${line}\n" if defined $cur;
next unless $line =~ /infer/;
die unless defined $cur;
if (parse($cur)) {
$n++;
my $old_profile = $r->hget($cur, "sprofile ");
$old_profile = 0 unless defined $old_profile;
$r->hset($cur, "sprofile ", $sprofile + $old_profile);
$r->hset($cur, "known", $known) if defined $known;
}
undef $cur;
undef $sprofile;
undef $known;
}
$r->save();
print "imported $n LHSs\n";