diff --git a/prjxray/util.py b/prjxray/util.py index 390e0c81..3fa592c5 100644 --- a/prjxray/util.py +++ b/prjxray/util.py @@ -71,3 +71,23 @@ def db_root_arg(parser): db_root_kwargs['required'] = False db_root_kwargs['default'] = os.path.join(database_dir, database) parser.add_argument('--db-root', help="Database root.", **db_root_kwargs) + + +def parse_db_line(line): + parts = line.split() + # Ex: CLBLL_L.SLICEL_X0.AMUX.A5Q + assert len(parts), "Empty line" + tag = parts[0] + assert re.match(r'[A-Z0-9_.]+', + tag), "Invalid tag name: %s, line: %s" % (tag, line) + orig_bits = line.replace(tag + " ", "") + # <0 candidates> etc + if "<" in orig_bits: + return tag, set(), orig_bits + + # Ex: !30_06 !30_08 !30_11 30_07 + bits = frozenset(parts[1:]) + for bit in bits: + assert re.match( + r'[!]*[0-9][0-9]_[0-9][0-9]', bit), "Invalid bit: %s" % bit + return tag, bits, None diff --git a/utils/dbfixup.py b/utils/dbfixup.py index 1dd5f872..9d13bb07 100755 --- a/utils/dbfixup.py +++ b/utils/dbfixup.py @@ -17,20 +17,6 @@ clb_int_zero_db = [ ] -def parse_line(line): - parts = line.split() - # Ex: CLBLL_L.SLICEL_X0.AMUX.A5Q - tag = parts[0] - orig_bits = line.replace(tag + " ", "") - # <0 candidates> etc - if "<" in orig_bits: - return tag, set(), orig_bits - - # Ex: !30_06 !30_08 !30_11 30_07 - bits = set(parts[1:]) - return tag, bits, None - - def zero_range(bits, wordmin, wordmax): """ If any bits occur wordmin <= word <= wordmax, @@ -134,7 +120,7 @@ def add_zero_bits(fn_in, fn_out, zero_db, clb_int=False, verbose=False): if line == llast: continue - tag, bits, mode = parse_line(line) + tag, bits, mode = util.parse_db_line(line) assert mode not in ( "", ""), "Entries must be resolved. line: %s" % (line, )