Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix the previous stack-cleaning optimisation
[simgrid.git] / tools / stack-cleaner / as
1 #!/usr/bin/ruby
2 # Wrapper around the real `as` which adds filtering capabilities.
3
4 require "tempfile"
5 require "fileutils"
6
7 def wrapped_as(argv)
8
9   args=[]
10   input=nil
11
12   i = 0
13   while i<argv.size
14     case argv[i]
15     when "-o", "-I"
16       args.push(argv[i])
17       args.push(argv[i+1])
18       i = i + 1
19     when /^-/
20       args.push(argv[i])
21     else
22       if input
23         exit 1
24       else
25         input = argv[i]
26       end
27     end
28     i = i + 1
29   end
30
31   if input==nil
32     # We dont handle pipe yet:
33     exit 1
34   end
35
36   # Generate temp file
37   tempfile = Tempfile.new("as-filter")
38   unless system(File.dirname($0) + "/clean-stack-filter", 0 => input, 1 => tempfile)
39     status=$?.exitstatus
40     FileUtils.rm tempfile
41     exit status
42   end
43   args.push(tempfile.path)
44
45   # Call the real assembler:
46   res = system("as", *args)
47   status = if res != nil
48              $?.exitstatus
49            else
50              1
51            end
52   FileUtils.rm tempfile
53   exit status
54
55 end
56
57 wrapped_as(ARGV)