def b_cla_carry(p, g, i): o = ['or', 'F'] for j in range(0, i+1): b = ['and', 'T', g[j]] for k in range(j, i): b.append(p[k]) o.append(simplify(tuple(b))) return simplify(tuple(o))
def var_replace(expr, eval_table): if type(expr) == tuple and len(expr) == 2: return simplify((expr[0], var_replace(expr[1], eval_table))) elif type(expr) == tuple and len(expr) == 3: return simplify((expr[0], var_replace(expr[1], eval_table), var_replace(expr[2], eval_table))) if expr in ['T', 'F']: return expr elif expr in eval_table: return eval_table[expr] return expr
def writeyy(f, prefix, yy, ic, eval_table): for i in range(0, 32): name = prefix + "i" + str(ic) if not yy[i] in ['T', 'F']: clause = simplify(yy[i]) var = clause_dedupe(clause, prefix) if not name in eval_table: eval_table[name] = var if f != None: f.write(name + " := " + var + ";\n") elif name in eval_table and f != None: printf("Here - name in eval_table: " + eval_table[name]) if eval_table[name] in ['T', 'F']: f.write(name + " := " + var + ";\n") f.write("etc" + name + " := " + name + " == " + eval_table[name] + ";\n") elif type(eval_table[name]) == type(name): print("Here") f.write(eval_table[name] + " := " + var + ";\n") else: print("Unknown eval_table entry for `" + name + "`: " + eval_table[name]) else: #print("Here") eval_table[name] = yy[i] if f != None: f.write(name + " := " + yy[i] + ";\n") ic += 1 return ic, eval_table
def write_literal(f, dest, source, eval_table, prefix): if not source in ['T', 'F']: clause = simplify(source) var = clause_dedupe(clause, prefix) #print([dest, source, var]) if not dest in eval_table: eval_table[dest] = var if f != None: f.write(dest + " := " + var + ";\n") elif dest in eval_table and f != None: if eval_table[dest] in ['T', 'F']: f.write(dest + " := " + var + ";\n") f.write("etc" + dest + " := " + dest + " == " + eval_table[dest] + ";\n") elif type(eval_table[dest]) == type(dest): print("Here2") f.write(eval_table[dest] + " := " + translate(simplify(source)) + ";\n") else: print("Unknown eval_table entry for `" + dest + "`: " + eval_table[dest]) else: eval_table[dest] = source return eval_table
def writeo(f, prefix, zz, n, eval_table): for i in range(0, 32): name = prefix + str(n) + str(i) if not zz[i] in ['T', 'F']: clause = simplify(zz[i]) var = clause_dedupe(clause, prefix) if not name in eval_table: eval_table[name] = var if f != None: f.write(name + " := " + var + ";\n") elif name in eval_table and f != None: if eval_table[name] in ['T', 'F']: f.write(name + " := " + var + ";\n") f.write("etc" + name + " := " + name + " == " + eval_table[name] + ";\n") elif type(eval_table[name]) == type(name): print("Here2") f.write(eval_table[name] + " := " + translate(simplify(zz[i])) + ";\n") else: print("Unknown eval_table entry for `" + name + "`: " + eval_table[name]) else: eval_table[name] = zz[i] if f != None: f.write(name + " := " + zz[i] + ";\n") return eval_table
def b_or(x, y): return simplify(('or', x, y))
def b_and(x, y): return simplify(('and', x, y))
def b_xor(x, y): #return simplify(b_or(b_and(x, b_not(y)), b_and(b_not(x), y))) return simplify(('xor', x, y))
def b_not(x): return simplify(('not', x))
def b_mux(a, b, s): return simplify(b_or(b_and(b_not(s), a), b_and(s, b)))
def b_fav(x, y, c): return simplify(b_xor(b_xor(x, y), c))
def b_fac(x, y, c): return simplify(b_or(b_and(x, y), b_and(c, b_or(x, y))))