1 import argparse
as _argparse
6 from openpower
.decoder
.power_enums
import (
7 find_wiki_dir
as _find_wiki_dir
,
9 from openpower
.decoder
.power_insn
import (
10 Verbosity
as _Verbosity
,
11 Database
as _Database
,
12 WordInstruction
as _WordInstruction
,
13 PrefixedInstruction
as _PrefixedInstruction
,
14 SVP64Instruction
as _SVP64Instruction
,
18 class ByteOrder(_enum
.Enum
):
23 return self
.name
.lower()
26 def load(ifile
, byteorder
=ByteOrder
.LITTLE
, **_
):
27 byteorder
= str(byteorder
)
28 curpos
= ifile
.tell() # get file position
37 insn
= _WordInstruction
.integer(value
=insn
, byteorder
=byteorder
)
39 suffix
= ifile
.read(4)
48 suffix
= _WordInstruction
.integer(value
=suffix
, byteorder
=byteorder
)
49 insn
= _SVP64Instruction
.pair(prefix
=prefix
, suffix
=suffix
)
50 if insn
.prefix
.id != 0b11:
51 insn
= _PrefixedInstruction
.pair(prefix
=prefix
, suffix
=suffix
)
54 ifile
.seek(curpos
) # restore position so that generator can be reused
57 def dump(insns
, verbosity
, **_
):
58 db
= _Database(_find_wiki_dir())
60 yield from insn
.disassemble(db
=db
, verbosity
=verbosity
)
63 # this is the entry-point for the console-script pysvp64dis
65 parser
= _argparse
.ArgumentParser()
66 parser
.add_argument("ifile", nargs
="?",
67 type=_argparse
.FileType("rb"), default
=_sys
.stdin
.buffer)
68 parser
.add_argument("ofile", nargs
="?",
69 type=_argparse
.FileType("w"), default
=_sys
.stdout
)
70 parser
.add_argument("-b", "--byteorder",
71 type=ByteOrder
, default
=ByteOrder
.LITTLE
)
72 parser
.add_argument("-s", "--short",
73 dest
="verbosity", default
=_Verbosity
.NORMAL
,
74 action
="store_const", const
=_Verbosity
.SHORT
)
75 parser
.add_argument("-v", "--verbose",
76 dest
="verbosity", default
=_Verbosity
.NORMAL
,
77 action
="store_const", const
=_Verbosity
.VERBOSE
)
78 parser
.add_argument("-l", "--log",
79 action
="store_true", default
=False)
81 args
= dict(vars(parser
.parse_args()))
83 # if logging requested do not disable it.
85 os
.environ
['SILENCELOG'] = '1'
87 # load instructions and dump them
89 for line
in dump(insns
, **args
):
90 print(line
, file=args
["ofile"])
93 # still here but use "python3 setup.py develop" then run the
94 # command "pysvp64dis" instead of "python3 src/openpower/sv/trans/pysvp64dis.py"
95 if __name__
== "__main__":