From: Dmitry Selyutin Date: Sat, 13 Jan 2024 15:30:02 +0000 (+0300) Subject: oppc/main: parse all insndb instructions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=818755e84ae90748f8844dbf93869cb38ac07162;p=openpower-isa.git oppc/main: parse all insndb instructions --- diff --git a/src/openpower/oppc/__main__.py b/src/openpower/oppc/__main__.py index 126125d2..90e29bc0 100644 --- a/src/openpower/oppc/__main__.py +++ b/src/openpower/oppc/__main__.py @@ -5,6 +5,7 @@ import re from openpower.decoder.power_enums import ( find_wiki_dir, ) +from openpower.insndb.core import Database import openpower.oppc.pc_code as pc_code import openpower.oppc.pc_lexer as pc_lexer @@ -12,45 +13,18 @@ import openpower.oppc.pc_parser as pc_parser import openpower.oppc.pc_pseudocode as pc_pseudocode -def dedent(line): - if line.startswith(" "): - return line[4:].rstrip() - return line.rstrip() - - -def parse(parser, origin): - origin = tuple(origin) - tree = parser.parse(code="\n".join(origin)) - stream = io.StringIO() - for (level, line) in pc_pseudocode.pseudocode(tree): - print(f"{' ' * 4 * level}{line}", file=stream) - stream.seek(0) - target = tuple(stream) - return (origin, target) - - lexer = pc_lexer.IndentLexer(debug=False) parser = pc_parser.Parser(lexer=lexer) -pattern = re.compile(r"Pseudo-code:(.*?)(?:Special Registers Altered|Description):", re.DOTALL) -for path in []: # glob.glob(f"{find_wiki_dir()}/../isa/*.mdwn"): - with open(path, "r", encoding="UTF-8") as stream: - data = stream.read() - for origin in pattern.findall(data): - try: - (stage0, stage1) = parse(parser, map(dedent, origin.split("\n"))) - (stage2, stage3) = parse(parser, map(dedent, stage1)) - stage1 = tuple(map(dedent, stage1)) - stage3 = tuple(map(dedent, stage3)) - assert stage1 == stage2 and stage2 == stage3 - except AssertionError as exc: - print(stage0) - print(stage1) - print(stage3) - raise exc - except Exception as exc: - print(path) - print(origin) - raise exc +db = Database(find_wiki_dir()) +for insn in db: + try: + tree = parser.parse(code="\n".join(insn.pcode)) + for (level, line) in pc_pseudocode.pseudocode(tree): + pass + except Exception as exc: + print(insn.name) + print(insn.pcode) + raise exc code = """ src <- [0]*64