File: as

package info (click to toggle)
simgrid 3.21%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,972 kB
  • sloc: cpp: 88,193; ansic: 69,244; fortran: 6,089; f90: 5,162; xml: 4,861; java: 4,250; perl: 2,056; python: 1,193; sh: 1,159; makefile: 57; sed: 6
file content (53 lines) | stat: -rwxr-xr-x 1,592 bytes parent folder | download | duplicates (3)
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/env python
# Wrapper around the real `as` which adds filtering capabilities.

import os
import re
import subprocess
import sys
import tempfile

# Process the arguments:
# * build the argument array for calling the real assembler;
# * get the input file name.
args = []
input_filename = None
args.append('as')
i = 1
while i < len(sys.argv):
    if sys.argv[i] == '-o' or sys.argv[i] == '-I':
        args.append(sys.argv[i])
        if i + 1 >= len(sys.argv):
            sys.stderr.write("Missing argument\n")
            sys.exit(1)
        args.append(sys.argv[i + 1])
        i = i + 1
    elif re.match('^-', sys.argv[i][0]):
        args.append(sys.argv[i])
    elif input_filename:
        sys.stdout.write("Too many input files\n")
        sys.exit(1)
    else:
        input_filename = sys.argv[i]
    i = i + 1
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)