3 """Compiles a source file with "-fdebug-unparse-with-symbols' and verifies
4 we get the right symbols in the output, i.e. the output should be
5 the same as the input, except for the copyright comment.
8 sys.argv[1]: a source file with contains the input and expected output
9 sys.argv[2]: the Flang frontend driver
10 sys.argv[3:]: Optional arguments to the Flang frontend driver"""
18 from difflib
import unified_diff
20 cm
.check_args(sys
.argv
)
21 src
= cm
.set_source(sys
.argv
[1])
25 flang_fc1
= cm
.set_executable(sys
.argv
[2])
26 flang_fc1_args
= sys
.argv
[3:]
27 flang_fc1_options
= "-fdebug-unparse-with-symbols"
29 # Strips out blank lines and all comments except for "!DEF:", "!REF:", "!$acc" and "!$omp"
30 with
open(src
, 'r') as text_in
:
32 text
= re
.sub(r
"!(?![DR]EF:|\$omp|\$acc).*", "", line
)
33 text
= re
.sub(r
"^\s*$", "", text
)
36 # Strips out "!DEF:" and "!REF:" comments
38 text
= re
.sub(r
"![DR]EF:.*", "", line
)
41 # Compiles, inserting comments for symbols:
42 cmd
= [flang_fc1
, *flang_fc1_args
, flang_fc1_options
]
43 with tempfile
.TemporaryDirectory() as tmpdir
:
44 diff3
= subprocess
.check_output(cmd
, input=diff2
, universal_newlines
=True, cwd
=tmpdir
)
46 # Removes all whitespace to compare differences in files
47 diff1
= diff1
.replace(" ", "")
48 diff3
= diff3
.replace(" ", "")
51 # Compares the input with the output
52 diff_check
= "\n".join(unified_diff(diff1
.split("\n"), diff3
.split("\n"), n
=999999,
53 fromfile
="Expected_output", tofile
="Actual_output"))
56 print(diff_check
.replace(" ", ""))