sv_analysis: decouple CSVs glob code
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 12 Aug 2022 13:16:05 +0000 (16:16 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 14 Aug 2022 19:07:43 +0000 (22:07 +0300)
src/openpower/sv/sv_analysis.py

index 88442047630c2e05e1fe3e8ba4e5f6e1a2179f6c..8dd1edd26cf52f673afe65406ed4d6263f770ae9 100644 (file)
@@ -33,6 +33,27 @@ from openpower.decoder.power_enums import find_wiki_file, get_csv
 from openpower.util import log
 
 
+# Ignore those containing: valid test sprs
+def glob_valid_csvs(root):
+    def check_csv(fname):
+        _, name = os.path.split(fname)
+        if '-' in name:
+            return False
+        if 'valid' in fname:
+            return False
+        if 'test' in fname:
+            return False
+        if fname.endswith('sprs.csv'):
+            return False
+        if fname.endswith('minor_19_valid.csv'):
+            return False
+        if 'RM' in fname:
+            return False
+        return True
+
+    yield from filter(check_csv, glob(root))
+
+
 # Write an array of dictionaries to the CSV file name:
 def write_csv(name, items, headers):
     file_path = find_wiki_file(name)
@@ -273,21 +294,7 @@ def read_csvs():
     pth = find_wiki_file("*.csv")
 
     # Ignore those containing: valid test sprs
-    for fname in glob(pth):
-        #print("sv analysis checking", fname)
-        _, name = os.path.split(fname)
-        if '-' in name:
-            continue
-        if 'valid' in fname:
-            continue
-        if 'test' in fname:
-            continue
-        if fname.endswith('sprs.csv'):
-            continue
-        if fname.endswith('minor_19_valid.csv'):
-            continue
-        if 'RM' in fname:
-            continue
+    for fname in glob_valid_csvs(pth):
         csvname = os.path.split(fname)[1]
         csvname_ = csvname.split(".")[0]
         # csvname is something like: minor_59.csv, fname the whole path
@@ -814,21 +821,7 @@ def process_csvs(format):
     pth = find_wiki_file("*.csv")
 
     # Ignore those containing: valid test sprs
-    for fname in glob(pth):
-        #print("post-checking", fname)
-        _, name = os.path.split(fname)
-        if '-' in name:
-            continue
-        if 'valid' in fname:
-            continue
-        if 'test' in fname:
-            continue
-        if fname.endswith('sprs.csv'):
-            continue
-        if fname.endswith('minor_19_valid.csv'):
-            continue
-        if 'RM' in fname:
-            continue
+    for fname in glob_valid_csvs(pth):
         svp64_csv = svt.get_svp64_csv(fname)
 
     csvcols = ['insn', 'mode', 'Ptype', 'Etype']