3722af0961a8043e6c10cd49078b89883586e2e9
1 import argparse
as _argparse
7 from openpower
.decoder
.power_enums
import (
8 find_wiki_dir
as _find_wiki_dir
,
10 from openpower
.decoder
.power_insn
import (
11 Verbosity
as _Verbosity
,
12 Database
as _Database
,
13 WordInstruction
as _WordInstruction
,
14 PrefixedInstruction
as _PrefixedInstruction
,
15 SVP64Instruction
as _SVP64Instruction
,
19 class ByteOrder(_enum
.Enum
):
24 return self
.name
.lower()
27 def load(ifile
, byteorder
=ByteOrder
.LITTLE
, **_
):
28 byteorder
= str(byteorder
)
30 # copy over to persistent binfile (BytesIO)
32 cpfile
.write(ifile
.read())
42 insn
= _WordInstruction
.integer(value
=insn
, byteorder
=byteorder
)
44 suffix
= cpfile
.read(4)
53 suffix
= _WordInstruction
.integer(value
=suffix
, byteorder
=byteorder
)
54 insn
= _SVP64Instruction
.pair(prefix
=prefix
, suffix
=suffix
)
55 if insn
.prefix
.id != 0b11:
56 insn
= _PrefixedInstruction
.pair(prefix
=prefix
, suffix
=suffix
)
59 cpfile
.seek(0) # restore position so that generator can be reused
62 def dump(insns
, verbosity
, **_
):
63 db
= _Database(_find_wiki_dir())
65 yield from insn
.disassemble(db
=db
, verbosity
=verbosity
)
68 # this is the entry-point for the console-script pysvp64dis
70 parser
= _argparse
.ArgumentParser()
71 parser
.add_argument("ifile", nargs
="?",
72 type=_argparse
.FileType("rb"), default
=_sys
.stdin
.buffer)
73 parser
.add_argument("ofile", nargs
="?",
74 type=_argparse
.FileType("w"), default
=_sys
.stdout
)
75 parser
.add_argument("-b", "--byteorder",
76 type=ByteOrder
, default
=ByteOrder
.LITTLE
)
77 parser
.add_argument("-s", "--short",
78 dest
="verbosity", default
=_Verbosity
.NORMAL
,
79 action
="store_const", const
=_Verbosity
.SHORT
)
80 parser
.add_argument("-v", "--verbose",
81 dest
="verbosity", default
=_Verbosity
.NORMAL
,
82 action
="store_const", const
=_Verbosity
.VERBOSE
)
83 parser
.add_argument("-l", "--log",
84 action
="store_true", default
=False)
86 args
= dict(vars(parser
.parse_args()))
88 # if logging requested do not disable it.
90 _os
.environ
['SILENCELOG'] = '1'
92 # load instructions and dump them
94 for line
in dump(insns
, **args
):
95 print(line
, file=args
["ofile"])
98 # still here but use "python3 setup.py develop" then run the
99 # command "pysvp64dis" instead of "python3 src/openpower/sv/trans/pysvp64dis.py"
100 if __name__
== "__main__":