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 argparse
|
||||||
|
import string
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -74,8 +75,7 @@ def parse_args():
|
|||||||
help='input file (default: stdin)')
|
help='input file (default: stdin)')
|
||||||
parser.add_argument('--output', '-o', type=argparse.FileType('wb'),
|
parser.add_argument('--output', '-o', type=argparse.FileType('wb'),
|
||||||
default=sys.stdout.buffer, help='output file')
|
default=sys.stdout.buffer, help='output file')
|
||||||
parser.add_argument('--vhdl', action='store_true',
|
parser.add_argument('--vhdl', help='vhdl output with given template')
|
||||||
help='vhdl output')
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -90,8 +90,13 @@ def main():
|
|||||||
text = dump(sectionmap)
|
text = dump(sectionmap)
|
||||||
|
|
||||||
if args.vhdl:
|
if args.vhdl:
|
||||||
args.output.write(',\n'.join(f'x"{x:04x}"' for x in
|
words = struct.unpack(f'>{len(text) // 2}H', text)
|
||||||
struct.unpack(f'>{len(text) // 2}H', text)).encode())
|
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:
|
else:
|
||||||
args.output.write(text)
|
args.output.write(text)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user