ld: now generates a full rom vhdl from template

This commit is contained in:
Paul Mathieu 2021-03-13 15:44:48 -08:00
parent e1557ad4b6
commit 790c08f1f2

View File

@ -1,4 +1,5 @@
import argparse
import string
import struct
import sys
@ -74,8 +75,7 @@ def parse_args():
help='input file (default: stdin)')
parser.add_argument('--output', '-o', type=argparse.FileType('wb'),
default=sys.stdout.buffer, help='output file')
parser.add_argument('--vhdl', action='store_true',
help='vhdl output')
parser.add_argument('--vhdl', help='vhdl output with given template')
return parser.parse_args()
@ -90,8 +90,13 @@ def main():
text = dump(sectionmap)
if args.vhdl:
args.output.write(',\n'.join(f'x"{x:04x}"' for x in
struct.unpack(f'>{len(text) // 2}H', text)).encode())
words = struct.unpack(f'>{len(text) // 2}H', text)
subd = dict(words=',\n'.join(f'x"{w:04x}"' for w in words), nwords=len(words))
with open(args.vhdl) as fin:
tpl = string.Template(fin.read())
args.output.write(tpl.substitute(subd).encode())
else:
args.output.write(text)