File: as

package info (click to toggle)
simgrid 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,192 kB
  • sloc: cpp: 124,913; ansic: 66,744; python: 8,560; java: 6,773; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,194; perl: 1,436; makefile: 111; lisp: 49; javascript: 7; sed: 6
file content (59 lines) | stat: -rwxr-xr-x 1,811 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
#!/usr/bin/env python

# Copyright (c) 2014-2025. The SimGrid Team. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the license (GNU LGPL) which comes with this package.

# 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 is 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)