From: Florent Kermarrec Date: Fri, 14 Sep 2012 10:26:48 +0000 (+0200) Subject: migScope/tools/truthtable.py: add function to remove duplicate operands X-Git-Tag: 24jan2021_ls180~2575^2~145 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cde176a0b7d62fd76ccce12fad50d115cd6e240d;p=litex.git migScope/tools/truthtable.py: add function to remove duplicate operands --- diff --git a/migScope/tools/truthtable.py b/migScope/tools/truthtable.py index ed53e2d3..d38316b9 100644 --- a/migScope/tools/truthtable.py +++ b/migScope/tools/truthtable.py @@ -2,8 +2,14 @@ import os import re import sys +def remove_duplicates(seq): + seen = set() + seen_add = seen.add + return [ x for x in seq if x not in seen and not seen_add(x)] + def get_operands(s): - return sorted(re.findall("[A-z0-9_]+", s)) + operands = remove_duplicates(sorted(re.findall("[A-z0-9_]+", s))) + return operands def gen_truth_table(s): operands = get_operands(s) @@ -19,7 +25,7 @@ def gen_truth_table(s): for i in range(2**width): for j in range(width): exec("%s = stim[j][i]" %operands[j]) - truth_table.append(eval(s)) + truth_table.append(eval(s) != 0) return truth_table def main():