From 790c08f1f22331f86a6076aa4ea06bb937862227 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Sat, 13 Mar 2021 15:44:48 -0800 Subject: [PATCH] ld: now generates a full rom vhdl from template --- tools/ld.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/ld.py b/tools/ld.py index 13af449..7e1f16f 100644 --- a/tools/ld.py +++ b/tools/ld.py @@ -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)