From: Dmitry Selyutin Date: Fri, 12 May 2023 11:47:58 +0000 (+0300) Subject: power_insn: decouple disassemble routine X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=055a4fa5ca7e51d782e1f6fe65095fc69e88c5b0;p=openpower-isa.git power_insn: decouple disassemble routine --- diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index 6a34ccc4..a1c9a977 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -3647,6 +3647,37 @@ class AssemblerError(Exception): pass +class DisassemblerError(Exception): + pass + + + +def collect(stream, byteorder=ByteOrder.LITTLE): + while True: + insn = stream.read(4) + length = len(insn) + if length == 0: + return + elif length < 4: + raise IOError(insn) + insn = WordInstruction.integer(value=insn, byteorder=byteorder) + if insn.PO == 0x1: + suffix = stream.read(4) + length = len(suffix) + if length == 0: + yield insn + return + elif length < 4: + raise IOError(suffix) + + prefix = insn + suffix = WordInstruction.integer(value=suffix, byteorder=byteorder) + insn = SVP64Instruction.pair(prefix=prefix, suffix=suffix) + if insn.prefix.id != 0b11: + insn = PrefixedInstruction.pair(prefix=prefix, suffix=suffix) + yield insn + + class Database: def __init__(self, root): root = _pathlib.Path(root) @@ -3757,3 +3788,7 @@ class Database: arguments=arguments, specifiers=specifiers) raise AssemblerError(opcode) + + def disassemble(self, insn, byteorder=ByteOrder.LITTLE, style=Style.NORMAL): + return insn.disassemble(record=self[insn], + byteorder=byteorder, style=style)