sv isatable prefix analyser
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 7 Oct 2020 14:34:06 +0000 (15:34 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 7 Oct 2020 14:34:11 +0000 (15:34 +0100)
openpower/sv_analysis.py [new file with mode: 0644]

diff --git a/openpower/sv_analysis.py b/openpower/sv_analysis.py
new file mode 100644 (file)
index 0000000..3ef2fd8
--- /dev/null
@@ -0,0 +1,117 @@
+#!/usr/bin/env python3
+import csv
+import os
+from os.path import dirname, join
+from glob import glob
+from collections import OrderedDict
+
+
+def find_wiki_file(name):
+    filedir = os.path.dirname(os.path.abspath(__file__))
+    tabledir = join(filedir, 'isatables')
+    file_path = join(tabledir, name) 
+    return file_path
+
+def get_csv(name):
+    file_path = find_wiki_file(name)
+    with open(file_path, 'r') as csvfile:
+        reader = csv.DictReader(csvfile)
+        return list(reader)
+
+def blank_key(row):
+    for v in row.items():
+        if v:
+            return False
+    return True
+
+def create_key(row):
+    res = OrderedDict()
+    #print ("row", row)
+    for key in ['in1', 'in2', 'in3', 'out', 'CR in', 'CR out',
+                 'ldst len', 'rc', 'lk']:
+        # registers
+        if key in ['in1', 'in2', 'in3', 'out']:
+            if row[key].startswith('R'):
+                res[key] = 'R'
+            else:
+                res[key] = '0'
+        # CRs
+        if key.startswith('CR'):
+            if row[key].startswith('NONE'):
+                res[key] = '0'
+            else:
+                res[key] = '1'
+        # LDST len
+        if key.startswith('ldst'):
+            if row[key].startswith('NONE'):
+                res[key] = '0'
+            else:
+                res[key] = '1'
+        # rc, lk
+        if key in ['rc', 'lk']:
+            if row[key] == 'ONE':
+                res[key] = '1'
+            elif row[key] == 'NONE':
+                res[key] = '0'
+            else:
+                res[key] = 'R'
+        if key == 'lk':
+            res[key] = row[key]
+
+    return res
+
+def dformat(d):
+    res = []
+    for k, v in d.items():
+        res.append("%s: %s" % (k, v))
+    return ' '.join(res)
+
+
+def process_csvs():
+    csvs = {}
+    bykey = {}
+    primarykeys = set()
+    dictkeys = {}
+
+    pth = find_wiki_file("*.csv")
+    for fname in glob(pth):
+        if 'valid' in fname:
+            continue
+        if 'test' in fname:
+            continue
+        if 'sprs' in fname:
+            continue
+        #print (fname)
+        csvname = os.path.split(fname)[1]
+        csv = get_csv(fname)
+        csvs[fname] = csv
+        for row in csv:
+            if blank_key(row):
+                continue
+            dkey = create_key(row)
+            key = tuple(dkey.values())
+            dictkeys[key] = dkey
+            primarykeys.add(key)
+            if key not in bykey:
+                bykey[key] = []
+            bykey[key].append((csvname, row['opcode'], row['comment']))
+
+    print ("# keys")
+    print ()
+    for key in primarykeys:
+        print (" * ", dformat(dictkeys[key]))
+    print ()
+
+    for key in primarykeys:
+        print ("## ", dformat(dictkeys[key]))
+        print ()
+        for row in bykey[key]:
+            print (" * ", row)
+        print ()
+
+    bykey = {}
+    for fname, csv in csvs.items():
+        key
+
+if __name__ == '__main__':
+    process_csvs()