Merge pull request #637 from litghost/add_bits_output

Add optional bits output for debugging.
This commit is contained in:
litghost 2019-02-08 15:07:23 -08:00 committed by GitHub
commit 5b7df9aea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@
Take bitstream .bit files and decode them to FASM.
'''
import contextlib
import os
import fasm
import fasm.output
@ -87,6 +88,10 @@ def main():
default_bitread = os.path.join(os.getenv("XRAY_TOOLS_DIR"), 'bitread')
parser.add_argument('--db-root', help="Database root.", **db_root_kwargs)
parser.add_argument(
'--bits-file',
help="Output filename for bitread output, default is deleted tempfile.",
default=None)
parser.add_argument(
'--part', help="Name of part being targetted.", **part_kwargs)
parser.add_argument(
@ -104,7 +109,12 @@ def main():
'--canonical', help='Output canonical bitstream.', action='store_true')
args = parser.parse_args()
with tempfile.NamedTemporaryFile() as bits_file:
with contextlib.ExitStack() as stack:
if args.bits_file:
bits_file = stack.enter_context(open(args.bits_file, 'wb'))
else:
bits_file = stack.enter_context(tempfile.NamedTemporaryFile())
bit_to_bits(
bitread=args.bitread,
part_yaml=os.path.join(args.db_root, '{}.yaml'.format(args.part)),