From: Dmitry Selyutin Date: Sun, 4 Sep 2022 12:31:35 +0000 (+0300) Subject: power_table: simplify the code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e46a5b946c01e9493db7f794bcd788c77149dee2;p=openpower-isa.git power_table: simplify the code --- diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index d65c8568..79a308b0 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -1308,7 +1308,7 @@ class FieldsDatabase: class PPCDatabase: - def __init__(self, root, mdwndb, fieldsdb): + def __init__(self, root, mdwndb): # The code below groups the instructions by section:identifier. # We use the comment as an identifier, there's nothing better. # The point is to capture different opcodes for the same instruction. @@ -1335,7 +1335,6 @@ class PPCDatabase: self.__db = db self.__mdwndb = mdwndb - self.__fieldsdb = fieldsdb return super().__init__() diff --git a/src/openpower/decoder/power_table.py b/src/openpower/decoder/power_table.py index 32f30866..59fc8996 100644 --- a/src/openpower/decoder/power_table.py +++ b/src/openpower/decoder/power_table.py @@ -1,31 +1,16 @@ -import pathlib +import collections from openpower.decoder.power_enums import find_wiki_dir -from openpower.decoder.power_insn import (Database, MarkdownDatabase, - FieldsDatabase, PPCDatabase, - IntegerOpcode, PatternOpcode, - parse, Section, BitSel, - FieldsOpcode) -root = find_wiki_dir() -root = pathlib.Path(root) -mdwndb = MarkdownDatabase() -fieldsdb = FieldsDatabase() +from openpower.decoder.power_insn import Database -# create by-sections first. these will be the markdown tables sections = {} -insns = {} -path = (root / "insndb.csv") -with open(path, "r", encoding="UTF-8") as stream: - for section in parse(stream, Section.CSV): - sections[str(section.path)] = section - insns[str(section.path)] = [] -for (name, section) in sections.items(): - print (name, section) +insns = collections.defaultdict(list) -# enumerate all instructions and drop them into sections -db = Database(root) -for insn in db: - insns[str(insn.section.path)].append(insn) - print (insn) +# create by-sections first. these will be the markdown tables +# then enumerate all instructions and drop them into sections +for insn in Database(find_wiki_dir()): + key = insn.section.path.name + sections[key] = insn.section + insns[key].append(insn) def maxme(num, s): return s.ljust(num)