-
Notifications
You must be signed in to change notification settings - Fork 7
/
stoat-compile
executable file
·53 lines (51 loc) · 1.35 KB
/
stoat-compile
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
#!/usr/bin/ruby
#
# stoat - LLVM Based Static Analysis Tool
# Copyright (C) 2015 Mark McCurry
#
# This file is part of stoat.
#
# stoat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# stoat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with stoat. If not, see <http://www.gnu.org/licenses/>.
#
#Pretend to be clang
NARGV = ARGV.collect {|x| x.gsub(/(?=\W)/, '\\')}
print `clang #{NARGV.join(' ')}`
err_code = $?.to_i
if(err_code != 0)
exit(false)
end
modify_next = false
do_compile = false
modified = false
new_args = []
NARGV.each do |x|
if(x == "\\-c")
do_compile = true
end
if(modify_next)
modify_next = false
modified = true
x = x+".bc"
elsif(x=="\\-o")
modify_next = true
elsif(x=="\\-O3")
next
elsif(x=="\\-O2")
next
end
new_args << x
end
if(do_compile && modified)
`clang -emit-llvm #{new_args.join(' ')} 2>/dev/null`
end