Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add stack-cleaning compiler wrappers
[simgrid.git] / tools / stack-cleaner / as
diff --git a/tools/stack-cleaner/as b/tools/stack-cleaner/as
new file mode 100755 (executable)
index 0000000..dcdb491
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/ruby
+# Wrapper around the real `as` which adds filtering capabilities.
+
+require "tempfile"
+require "fileutils"
+
+def wrapped_as(argv)
+
+  args=[]
+  input=nil
+
+  i = 0
+  while i<argv.size
+    case argv[i]
+    when "-o", "-I"
+      args.push(argv[i])
+      args.push(argv[i+1])
+      i = i + 1
+    when /^-/
+      args.push(argv[i])
+    else
+      if input
+        exit 1
+      else
+        input = argv[i]
+      end
+    end
+    i = i + 1
+  end
+
+  if input==nil
+    # We dont handle pipe yet:
+    exit 1
+  end
+
+  # Generate temp file
+  tempfile = Tempfile.new("as-filter")
+  unless system(File.dirname($0) + "/clean-stack-filter", 0 => input, 1 => tempfile)
+    status=$?.exitstatus
+    FileUtils.rm tempfile
+    exit status
+  end
+  args.push(tempfile.path)
+
+  # Call the real assembler:
+  res = system("as", *args)
+  status = if res != nil
+             $?.exitstatus
+           else
+             1
+           end
+  FileUtils.rm tempfile
+  exit status
+
+end
+
+wrapped_as(ARGV)