- end
-
- if input==nil
- # We dont handle pipe yet:
- exit 1
- end
-
- # Generate temp file
- tempfile = Tempfile.new("as-filter")
- tempfile.close
- script = File.dirname($0) + "/clean-stack-filter"
- unless system([script, script], 0 => input, 1 => tempfile.path)
- 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)
+if input_filename == None:
+ sys.stderr.write("Missing input file\n")
+ sys.exit(1)
+
+temp_file, temp_filename = tempfile.mkstemp(suffix=".s", prefix="as_wrapper")
+try:
+ # Generate temporary file with modified assembly code:
+ script_file = os.path.join(
+ os.path.dirname(sys.argv[0]), "clean-stack-filter")
+ input_file = os.open(input_filename, os.O_RDONLY)
+ status = subprocess.call([script_file], stdin=input_file, stdout=temp_file)
+ os.close(input_file)
+ if status != 0:
+ sys.stderr.write("Filtering the assembly code failed.\n")
+ sys.exit(status)
+
+ # Call the real assembler on this modified assembly code:
+ args.append(temp_filename)
+ sys.exit(subprocess.call(args))
+finally:
+ os.remove(temp_filename)