about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-07 19:57:45 +0100
committerGitHub <noreply@github.com>2023-03-07 19:57:45 +0100
commitc21a640c5a31d64a276cbb76e9e358623ec0ad17 (patch)
tree85da5a3b9a5b48f906bf78c4bd40f7a40072f4ff /compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py
parent63635880f6fe27fc291c7542bc7df03018f694bb (diff)
parent2c0c25dcc1598cd115838e1e1d74d9f32ffd8dbf (diff)
downloadrust-c21a640c5a31d64a276cbb76e9e358623ec0ad17.tar.gz
rust-c21a640c5a31d64a276cbb76e9e358623ec0ad17.zip
Rollup merge of #108783 - antoyo:sync-cg_gcc-2023-03-04, r=cjgillot
Sync rustc_codegen_gcc 2023/03/04

Hi.
This sync all the changes from rustc_codegen_gcc.
Thanks for the review.
Diffstat (limited to 'compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py')
-rw-r--r--compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py b/compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py
new file mode 100644
index 00000000000..c09fb3c759f
--- /dev/null
+++ b/compiler/rustc_codegen_gcc/tools/check_intrinsics_duplicates.py
@@ -0,0 +1,67 @@
+import sys
+
+
+def check_duplicates():
+    auto_content = ""
+    manual_content = ""
+
+    with open("src/intrinsic/llvm.rs", "r", encoding="utf8") as f:
+        manual_content = f.read()
+    with open("src/intrinsic/archs.rs", "r", encoding="utf8") as f:
+        auto_content = f.read()
+
+    intrinsics_map = {}
+    for line in auto_content.splitlines():
+        line = line.strip()
+        if not line.startswith('"'):
+            continue
+        parts = line.split('"')
+        if len(parts) != 5:
+            continue
+        intrinsics_map[parts[1]] = parts[3]
+
+    if len(intrinsics_map) == 0:
+        print("No intrinsics found in auto code... Aborting.")
+        return 1
+    print("Found {} intrinsics in auto code".format(len(intrinsics_map)))
+    errors = []
+    lines = manual_content.splitlines()
+    pos = 0
+    found = 0
+    while pos < len(lines):
+        line = lines[pos].strip()
+        # This is our marker.
+        if line == "let gcc_name = match name {":
+            while pos < len(lines):
+                line = lines[pos].strip()
+                pos += 1
+                if line == "};":
+                    # We're done!
+                    if found == 0:
+                        print("No intrinsics found in manual code even though we found the "
+                            "marker... Aborting...")
+                        return 1
+                    for error in errors:
+                        print("ERROR => {}".format(error))
+                    return 1 if len(errors) != 0 else 0
+                parts = line.split('"')
+                if len(parts) != 5:
+                    continue
+                found += 1
+                if parts[1] in intrinsics_map:
+                    if parts[3] != intrinsics_map[parts[1]]:
+                        print("Same intrinsics (`{}` at line {}) but different GCC "
+                            "translations: `{}` != `{}`".format(
+                                parts[1], pos, intrinsics_map[parts[1]], parts[3]))
+                    else:
+                        errors.append("Duplicated intrinsics: `{}` at line {}. Please remove it "
+                            " from manual code".format(parts[1], pos))
+            # Weird but whatever...
+            return 1 if len(errors) != 0 else 0
+        pos += 1
+    print("No intrinsics found in manual code... Aborting")
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(check_duplicates())