From cb6afb3a2d7fada2f5756e762c1d016e8ce859ec Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 5 Apr 2020 15:21:23 -0700 Subject: [PATCH] use fields.txt as the local file name and add to gitignore --- src/soc/decoder/.gitignore | 1 + src/soc/decoder/power_enums.py | 13 ++++++++----- src/soc/decoder/power_fields.py | 25 +++++++++++++++++-------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/soc/decoder/.gitignore b/src/soc/decoder/.gitignore index afed0735..8c872dd9 100644 --- a/src/soc/decoder/.gitignore +++ b/src/soc/decoder/.gitignore @@ -1 +1,2 @@ *.csv +fields.txt \ No newline at end of file diff --git a/src/soc/decoder/power_enums.py b/src/soc/decoder/power_enums.py index ab838132..d1cad121 100644 --- a/src/soc/decoder/power_enums.py +++ b/src/soc/decoder/power_enums.py @@ -4,11 +4,13 @@ import os import requests -def download_wiki_file(name): +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 + 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")) @@ -29,9 +31,10 @@ single_bit_flags = ['CR in', 'CR out', 'inv A', 'inv out', # default values for fields in the table default_values = {'unit': "NONE", 'internal op': "OP_ILLEGAL", - 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE', - 'ldst len': 'NONE', - 'rc' : 'NONE', 'cry in' : 'ZERO', 'form': 'NONE'} + 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE', + 'ldst len': 'NONE', + 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'} + def get_signal_name(name): if name[0].isdigit(): diff --git a/src/soc/decoder/power_fields.py b/src/soc/decoder/power_fields.py index e0c01427..26b59d46 100644 --- a/src/soc/decoder/power_fields.py +++ b/src/soc/decoder/power_fields.py @@ -5,12 +5,14 @@ from soc.decoder.power_enums import download_wiki_file class BitRange(OrderedDict): """BitRange: remaps from straight indices (0,1,2..) to bit numbers """ + def __getitem__(self, subscript): if isinstance(subscript, slice): return list(self)[subscript] else: return self[subscript] + def decode_instructions(form): res = {} accum = [] @@ -29,6 +31,7 @@ def decode_instructions(form): accum.append(l.strip()) return res + def decode_form_header(hdr): res = {} count = 0 @@ -42,6 +45,7 @@ def decode_form_header(hdr): count += len(f) + 1 return res + def find_unique(d, key): if key not in d: return key @@ -87,10 +91,10 @@ def decode_form(form): fields = {} falternate = {} for l in res: - for k, (start,end) in l.items(): + for k, (start, end) in l.items(): if k in fields: if (start, end) == fields[k]: - continue # already in and matching for this Form + continue # already in and matching for this Form if k in falternate: alternate = "%s_%d" % (k, falternate[k]) if (start, end) == fields[alternate]: @@ -104,10 +108,14 @@ def decode_form(form): class DecodeFields: - def __init__(self, bitkls=BitRange, bitargs=(), fname="fields.text"): + def __init__(self, bitkls=BitRange, bitargs=(), fname=None, name_on_wiki=None): self.bitkls = bitkls self.bitargs = bitargs - self.fname = download_wiki_file(fname) + if fname is None: + assert name_on_wiki is None + fname = "fields.txt" + name_on_wiki = "fields.text" + self.fname = download_wiki_file(fname, name_on_wiki) def create_specs(self): self.forms, self.instrs = self.decode_fields() @@ -178,8 +186,8 @@ class DecodeFields: if not reading_data: assert l[0] == '#' heading = l[1:].strip() - #if heading.startswith('1.6.28'): # skip instr fields for now - #break + # if heading.startswith('1.6.28'): # skip instr fields for now + # break heading = heading.split(' ')[-1] reading_data = True forms[heading] = [] @@ -192,8 +200,8 @@ class DecodeFields: i = decode_instructions(form) for form, field in i.items(): inst[form] = self.decode_instruction_fields(field) - #else: - # res[hdr] = decode_form(form) + # else: + # res[hdr] = decode_form(form) return res, inst def decode_instruction_fields(self, fields): @@ -220,6 +228,7 @@ class DecodeFields: return res + if __name__ == '__main__': dec = DecodeFields() dec.create_specs() -- 2.30.2