From: Michael Nolan Date: Sat, 2 May 2020 19:27:34 +0000 (-0400) Subject: Read decoder tables from wiki submodule instead of web X-Git-Tag: div_pipeline~1401 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e014f0dec6a5ed4f5ed8947316a5f5d6870eaf58;p=soc.git Read decoder tables from wiki submodule instead of web --- diff --git a/src/soc/decoder/power_enums.py b/src/soc/decoder/power_enums.py index d1cad121..b480eaba 100644 --- a/src/soc/decoder/power_enums.py +++ b/src/soc/decoder/power_enums.py @@ -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) diff --git a/src/soc/decoder/power_fields.py b/src/soc/decoder/power_fields.py index 9dc07b8e..8fa21f29 100644 --- a/src/soc/decoder/power_fields.py +++ b/src/soc/decoder/power_fields.py @@ -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()