Read decoder tables from wiki submodule instead of web
authorMichael Nolan <mtnolan2640@gmail.com>
Sat, 2 May 2020 19:27:34 +0000 (15:27 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Sat, 2 May 2020 20:31:12 +0000 (16:31 -0400)
src/soc/decoder/power_enums.py
src/soc/decoder/power_fields.py

index d1cad1211c556416321be0967cc6a6333f1eef9a..b480eabaf5550d74739aeb0aea0da2a26a77deae 100644 (file)
@@ -2,23 +2,21 @@ from enum import Enum, unique
 import csv
 import os
 import requests
+from os.path import dirname, join
 
+def find_wiki_file(name):
+    filedir = os.path.dirname(os.path.abspath(__file__))
+    basedir = dirname(dirname(dirname(filedir)))
+    tabledir = join(basedir, 'libreriscv')
+    tabledir = join(tabledir, 'openpower')
+    tabledir = join(tabledir, 'isatables')
 
-def download_wiki_file(name, name_on_wiki=None):
-    if name_on_wiki is None:
-        name_on_wiki = name
-    file_dir = os.path.dirname(os.path.realpath(__file__))
-    file_path = os.path.join(file_dir, name)
-    if not os.path.isfile(file_path):
-        url = 'https://libre-riscv.org/openpower/isatables/' + name_on_wiki
-        r = requests.get(url, allow_redirects=True)
-        with open(file_path, 'w') as outfile:
-            outfile.write(r.content.decode("utf-8"))
+    file_path = join(tabledir, name)
     return file_path
 
 
 def get_csv(name):
-    file_path = download_wiki_file(name)
+    file_path = find_wiki_file(name)
     with open(file_path, 'r') as csvfile:
         reader = csv.DictReader(csvfile)
         return list(reader)
index 9dc07b8ea554092b4228cc45f898c02646546744..8fa21f29329da122179b6181873604b05b3accff 100644 (file)
@@ -1,5 +1,5 @@
 from collections import OrderedDict, namedtuple
-from soc.decoder.power_enums import download_wiki_file
+from soc.decoder.power_enums import find_wiki_file
 
 
 class BitRange(OrderedDict):
@@ -115,7 +115,7 @@ class DecodeFields:
             assert name_on_wiki is None
             fname = "fields.txt"
             name_on_wiki = "fields.text"
-        self.fname = download_wiki_file(fname, name_on_wiki)
+        self.fname = find_wiki_file(name_on_wiki)
 
     def create_specs(self):
         self.forms, self.instrs = self.decode_fields()