mirror of https://github.com/openXC7/prjxray.git
parsedb: tool to validate database
Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
parent
5c3083d1a4
commit
7f95ce3996
|
|
@ -26,4 +26,5 @@ export XRAY_BITS2FASM="python3 ${XRAY_UTILS_DIR}/bits2fasm.py"
|
|||
export XRAY_FASM2FRAMES="python3 ${XRAY_UTILS_DIR}/fasm2frames.py"
|
||||
export XRAY_BITTOOL="${XRAY_TOOLS_DIR}/bittool"
|
||||
export XRAY_BLOCKWIDTH="python3 ${XRAY_UTILS_DIR}/blockwidth.py"
|
||||
export XRAY_PARSEDB="python3 ${XRAY_UTILS_DIR}/parsedb.py"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from prjxray import util
|
||||
|
||||
|
||||
def run(fnin, fnout=None, strict=False, verbose=False):
|
||||
lines = open(fnin, 'r').read().split('\n')
|
||||
tags = set()
|
||||
bitss = set()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line == '':
|
||||
continue
|
||||
tag, bits, mode = util.parse_db_line(line)
|
||||
if strict:
|
||||
assert not mode, "strict: got ill defined line: %s" % (line, )
|
||||
assert tag not in tags, "strict: got duplicate tag %s (ex: %s)" % (
|
||||
tag, line)
|
||||
assert bits not in bitss, "strict: got duplicate bits %s (ex: %s)" % (
|
||||
bits, line)
|
||||
tags.add(tag)
|
||||
bitss.add(bits)
|
||||
|
||||
if fnout:
|
||||
with open(fnout, "w") as fout:
|
||||
for line in sorted(lines):
|
||||
line = line.strip()
|
||||
if line == '':
|
||||
continue
|
||||
fout.write(line + '\n')
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Parse a db, check for consistency")
|
||||
|
||||
util.db_root_arg(parser)
|
||||
parser.add_argument('--verbose', action='store_true', help='')
|
||||
parser.add_argument(
|
||||
'--strict',
|
||||
action='store_true',
|
||||
help='Complain on unresolved entries (ex: <0 candidates>, <const0>)')
|
||||
parser.add_argument('fin', help='')
|
||||
parser.add_argument('fout', nargs='?', help='')
|
||||
args = parser.parse_args()
|
||||
|
||||
run(args.fin, args.fout, strict=args.strict, verbose=args.verbose)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue