|
| 1 | +import sys |
| 2 | + |
| 3 | + |
| 4 | +def check_duplicates(): |
| 5 | + auto_content = "" |
| 6 | + manual_content = "" |
| 7 | + |
| 8 | + with open("src/intrinsic/llvm.rs", "r", encoding="utf8") as f: |
| 9 | + manual_content = f.read() |
| 10 | + with open("src/intrinsic/archs.rs", "r", encoding="utf8") as f: |
| 11 | + auto_content = f.read() |
| 12 | + |
| 13 | + intrinsics_map = {} |
| 14 | + for line in auto_content.splitlines(): |
| 15 | + line = line.strip() |
| 16 | + if not line.startswith('"'): |
| 17 | + continue |
| 18 | + parts = line.split('"') |
| 19 | + if len(parts) != 5: |
| 20 | + continue |
| 21 | + intrinsics_map[parts[1]] = parts[3] |
| 22 | + |
| 23 | + if len(intrinsics_map) == 0: |
| 24 | + print("No intrinsics found in auto code... Aborting.") |
| 25 | + return 1 |
| 26 | + print("Found {} intrinsics in auto code".format(len(intrinsics_map))) |
| 27 | + errors = [] |
| 28 | + lines = manual_content.splitlines() |
| 29 | + pos = 0 |
| 30 | + found = 0 |
| 31 | + while pos < len(lines): |
| 32 | + line = lines[pos].strip() |
| 33 | + # This is our marker. |
| 34 | + if line == "let gcc_name = match name {": |
| 35 | + while pos < len(lines): |
| 36 | + line = lines[pos].strip() |
| 37 | + pos += 1 |
| 38 | + if line == "};": |
| 39 | + # We're done! |
| 40 | + if found == 0: |
| 41 | + print("No intrinsics found in manual code even though we found the " |
| 42 | + "marker... Aborting...") |
| 43 | + return 1 |
| 44 | + for error in errors: |
| 45 | + print("ERROR => {}".format(error)) |
| 46 | + return 1 if len(errors) != 0 else 0 |
| 47 | + parts = line.split('"') |
| 48 | + if len(parts) != 5: |
| 49 | + continue |
| 50 | + found += 1 |
| 51 | + if parts[1] in intrinsics_map: |
| 52 | + if parts[3] != intrinsics_map[parts[1]]: |
| 53 | + print("Same intrinsics (`{}` at line {}) but different GCC " |
| 54 | + "translations: `{}` != `{}`".format( |
| 55 | + parts[1], pos, intrinsics_map[parts[1]], parts[3])) |
| 56 | + else: |
| 57 | + errors.append("Duplicated intrinsics: `{}` at line {}. Please remove it " |
| 58 | + " from manual code".format(parts[1], pos)) |
| 59 | + # Weird but whatever... |
| 60 | + return 1 if len(errors) != 0 else 0 |
| 61 | + pos += 1 |
| 62 | + print("No intrinsics found in manual code... Aborting") |
| 63 | + return 1 |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + sys.exit(check_duplicates()) |
0 commit comments