Ran format-py

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
This commit is contained in:
Maciej Kurc 2019-08-05 13:49:41 +02:00
parent 078dda081b
commit eeed1fbfa9
2 changed files with 31 additions and 26 deletions

View File

@ -33,11 +33,15 @@ def load_just_bits(file_name):
if match is not None:
frm = int(match.group(2))
bit = int(match.group(3))
bits.add((frm, bit,))
bits.add((
frm,
bit,
))
return bits
# =============================================================================
@ -61,7 +65,7 @@ def main():
"\033[35m",
"\033[36m",
]
colors = {
"NONE": "\033[0m",
"DUPLICATE": "\033[101;97m",
@ -82,7 +86,7 @@ def main():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("files", nargs="*", type=str, help="Input files")
args = parser.parse_args()
@ -90,17 +94,17 @@ def main():
# Load bits
all_bits = []
for i, f in enumerate(args.files):
bits = load_just_bits(f)
bits = load_just_bits(f)
all_bits.append(bits)
cstr = bit_colors[i % len(bit_colors)]
bstr = "O" if len(args.files) == 1 else chr(65+i)
bstr = "O" if len(args.files) == 1 else chr(65 + i)
print(cstr + bstr + colors["NONE"] + ": %s #%d" % (f, len(bits)))
print("")
max_frames = max([bit[0] for bits in all_bits for bit in bits]) + 1
max_bits = max([bit[1] for bits in all_bits for bit in bits]) + 1
max_bits = max([bit[1] for bits in all_bits for bit in bits]) + 1
# Header
for r in range(3):
@ -120,22 +124,21 @@ def main():
bit_str = colors["NONE"] + "-"
for i, bits in enumerate(all_bits):
cstr = bit_colors[i % len(bit_colors)]
bstr = "O" if len(args.files) == 1 else chr(65+i)
bstr = "O" if len(args.files) == 1 else chr(65 + i)
if (r, c) in bits:
if not got_bit:
bit_str = cstr + bstr
else:
bit_str = colors["DUPLICATE"] + "#" + colors["NONE"]
got_bit = True
line += bit_str
line += colors["NONE"]
print(line)
# =============================================================================
# =============================================================================
if __name__ == "__main__":
main()

View File

@ -25,14 +25,14 @@ def tagmap(tag):
tag = tag.replace("CLBLM_L", "CLB")
tag = tag.replace("CLBLM_M", "CLB")
tag = tag.replace("SLICEL", "SLICE")
tag = tag.replace("SLICEM", "SLICE")
tag = tag.replace("SLICEL", "SLICE")
tag = tag.replace("SLICEM", "SLICE")
tag = tag.replace("LIOB33", "IOB33")
tag = tag.replace("RIOB33", "IOB33")
tag = tag.replace("LIOB33", "IOB33")
tag = tag.replace("RIOB33", "IOB33")
tag = tag.replace("LIOI3", "IOI3")
tag = tag.replace("RIOI3", "IOI3")
tag = tag.replace("LIOI3", "IOI3")
tag = tag.replace("RIOI3", "IOI3")
# TODO: Add other tag mappings
@ -53,7 +53,7 @@ def parse_bit(bit):
return frm, bit, val
def load_and_sort_segbits(file_name, tagmap = lambda tag: tag):
def load_and_sort_segbits(file_name, tagmap=lambda tag: tag):
"""
Loads a segbit file (.db or .rdb). Skips bits containing '<' or '>'
"""
@ -88,8 +88,10 @@ def load_and_sort_segbits(file_name, tagmap = lambda tag: tag):
return segbits
# =============================================================================
def make_header_lines(all_bits):
"""
Formats header lines
@ -102,7 +104,7 @@ def make_header_lines(all_bits):
for i in range(bit_len):
line = ""
for j in range(len(all_bits)):
bstr = bit_names[j].ljust(bit_len).replace("_", "|")
bstr = bit_names[j].ljust(bit_len).replace("_", "|")
line += bstr[i]
lines.append(line)
@ -164,7 +166,7 @@ def main():
# List of all features and all bits
all_tags = set()
all_bits = set()
for segbits in all_segbits:
all_tags |= set(segbits.keys())
for bits in segbits.values():
@ -173,10 +175,10 @@ def main():
all_tags = sorted(list(all_tags))
all_bits = sorted(list(all_bits))
# Convert bit lists to bit vectors
# Convert bit lists to bit vectors
for segbits in all_segbits:
for tag in segbits.keys():
vec = list([0]*len(all_bits))
vec = list([0] * len(all_bits))
for i, bit in enumerate(all_bits):
if (bit[0], bit[1], 0) in segbits[tag]:
vec[i] = -1
@ -184,10 +186,11 @@ def main():
vec[i] = +1
segbits[tag] = vec
# Make header and data lines
header_lines = make_header_lines(all_bits)
data_lines = [make_data_lines(all_tags, all_bits, segbits) for segbits in all_segbits]
data_lines = [
make_data_lines(all_tags, all_bits, segbits) for segbits in all_segbits
]
# Display
max_tag_len = max([len(tag) for tag in all_tags])
@ -218,9 +221,8 @@ def main():
print(line)
# =============================================================================
# =============================================================================
if __name__ == "__main__":
main()