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
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