brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 612ae0d Raw
72 lines · python
1#!/usr/bin/env python32 3"""Compiles a source file with "-fdebug-unparse-with-symbols' and verifies4we get the right symbols in the output, i.e. the output should be5the same as the input, except for the copyright comment.6 7Parameters:8    sys.argv[1]: a source file with contains the input and expected output9    sys.argv[2]: the Flang frontend driver10    sys.argv[3:]: Optional arguments to the Flang frontend driver"""11 12import sys13import tempfile14import re15import subprocess16import common as cm17 18from difflib import unified_diff19 20cm.check_args(sys.argv)21src = cm.set_source(sys.argv[1])22diff1 = ""23diff2 = ""24 25flang_fc1 = cm.set_executable(sys.argv[2])26flang_fc1_args = sys.argv[3:]27flang_fc1_options = "-fdebug-unparse-with-symbols"28 29# Strips out blank lines and all comments except for "!DEF:", "!REF:", "!$acc" and "!$omp"30with open(src, "r") as text_in:31    for line in text_in:32        text = re.sub(r"!(?![DR]EF:|\$omp|\$acc).*", "", line, flags=re.I)33        text = re.sub(r"^\s*$", "", text)34        diff1 += text35 36# Strips out "!DEF:" and "!REF:" comments37for line in diff1:38    text = re.sub(r"![DR]EF:.*", "", line)39    diff2 += text40 41# Compiles, inserting comments for symbols:42cmd = [flang_fc1, *flang_fc1_args, flang_fc1_options]43with tempfile.TemporaryDirectory() as tmpdir:44    diff3 = subprocess.check_output(45        cmd, input=diff2, universal_newlines=True, cwd=tmpdir46    )47 48# Removes all whitespace to compare differences in files49diff1 = diff1.replace(" ", "")50diff3 = diff3.replace(" ", "")51diff_check = ""52 53# Compares the input with the output54diff_check = "\n".join(55    unified_diff(56        diff1.split("\n"),57        diff3.split("\n"),58        n=999999,59        fromfile="Expected_output",60        tofile="Actual_output",61    )62)63 64if diff_check != "":65    print(diff_check.replace(" ", ""))66    print()67    print("FAIL")68    sys.exit(1)69else:70    print()71    print("PASS")72