ld: now generates a full rom vhdl from template
This commit is contained in:
parent
e1557ad4b6
commit
790c08f1f2
13
tools/ld.py
13
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user