migScope/tools/truthtable.py: add function to remove duplicate operands
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 14 Sep 2012 10:26:48 +0000 (12:26 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 14 Sep 2012 10:26:48 +0000 (12:26 +0200)
migScope/tools/truthtable.py

index ed53e2d3a5adf03ca473d0eeda0745e8c015378f..d38316b9dfcf75c62a7c200bcfd5418631fc1806 100644 (file)
@@ -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():