2 # Wrapper around the real `as` which adds filtering capabilities.
10 # Process the arguments:
11 # * build the argument array for calling the real assembler;
12 # * get the input file name.
17 while i < len(sys.argv):
18 if sys.argv[i] == '-o' or sys.argv[i] == '-I':
19 args.append(sys.argv[i])
20 if i + 1 >= len(sys.argv):
21 sys.stderr.write("Missing argument\n")
23 args.append(sys.argv[i + 1])
25 elif re.match('^-', sys.argv[i][0]):
26 args.append(sys.argv[i])
28 sys.stdout.write("Too many input files\n")
31 input_filename = sys.argv[i]
33 if input_filename is None:
34 sys.stderr.write("Missing input file\n")
37 temp_file, temp_filename = tempfile.mkstemp(suffix=".s", prefix="as_wrapper")
39 # Generate temporary file with modified assembly code:
40 script_file = os.path.join(
41 os.path.dirname(sys.argv[0]), "clean-stack-filter")
42 input_file = os.open(input_filename, os.O_RDONLY)
43 status = subprocess.call([script_file], stdin=input_file, stdout=temp_file)
46 sys.stderr.write("Filtering the assembly code failed.\n")
49 # Call the real assembler on this modified assembly code:
50 args.append(temp_filename)
51 sys.exit(subprocess.call(args))
53 os.remove(temp_filename)