from openpower.decoder.power_svp64 import SVP64RM, get_regtype, decode_extra
from openpower.decoder.selectable_int import SelectableInt
from openpower.consts import SVP64MODE
-from openpower.decoder.power_insn import SVP64Instruction
+from openpower.decoder.power_insn import AssemblerError
+from openpower.decoder.power_insn import ByteOrder
from openpower.decoder.power_insn import Database
from openpower.decoder.power_insn import Style
-from openpower.decoder.power_insn import WordInstruction
from openpower.decoder.power_enums import find_wiki_dir
# for debug logging
DB = Database(find_wiki_dir())
-class AssemblerError(ValueError):
- pass
-
-
# decodes svp64 assembly listings and creates EXT001 svp64 prefixes
class SVP64Asm:
def __init__(self, lst, bigendian=False, macros=None):
if macros is None:
macros = {}
macros.update(self.macros)
- isa = self.isa
- svp64 = self.svp64
- insn_no_comments = insn.partition('#')[0].strip()
- if not insn_no_comments:
- return
-
- # find first space, to get opcode
- ls = insn_no_comments.split()
- opcode = ls[0]
- # now find opcode fields
- fields = ''.join(ls[1:]).split(',')
- mfields = list(filter(bool, map(str.strip, fields)))
- log("opcode, fields", ls, opcode, mfields)
- fields = []
- # macro substitution
- for field in mfields:
- fields.append(macro_subst(macros, field))
- log("opcode, fields substed", ls, opcode, fields)
-
- # identify if it is a word instruction
- record = DB[opcode]
- if record is not None:
- insn = WordInstruction.assemble(record=record, arguments=fields)
- yield from insn.disassemble(record=record, style=Style.LEGACY)
- return
- # identify if is a svp64 mnemonic
- if not opcode.startswith('sv.'):
- yield insn # unaltered
- return
- opcode = opcode[3:] # strip leading "sv"
-
- # start working on decoding the svp64 op: sv.basev30Bop/vec2/mode
- opmodes = opcode.split("/") # split at "/"
- v30b_op = opmodes.pop(0) # first is the v3.0B
-
- record = DB[v30b_op]
- if record is not None:
- insn = SVP64Instruction.assemble(record=record,
- arguments=fields, specifiers=opmodes)
- yield from insn.disassemble(record=record, style=Style.LEGACY)
- return
-
- raise AssemblerError(insn_no_comments)
+ try:
+ insn = DB.assemble(insn=insn, macros=self.macros)
+ yield "; ".join(DB.disassemble(insn=insn,
+ byteorder=ByteOrder.LITTLE,
+ style=Style.LEGACY))
+ except AssemblerError:
+ yield insn
def translate(self, lst):
for insn in lst:
lst = [
#"sv.cmp/ff=gt *0,*1,*2,0",
"dsld 5,4,5,3",
-
]
isa = SVP64Asm(lst, macros=macros)
log("list:\n", "\n\t".join(list(isa)))