Changeset 327 for proto/parabix2


Ignore:
Timestamp:
Oct 29, 2009, 7:04:03 AM (10 years ago)
Author:
cameron
Message:

Recursive simplifier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/Compiler/bitexpr.py

    r323 r327  
    300300
    301301
     302#
     303# Recursive expression simplification using the simplifying constructors.
     304# Apply the inside-out simplification method to guarantee systematic
     305# simplification (assuming constructors always leave results in simplified
     306# form given arguments in simplified form).
     307#
     308def simplify_expr(expr):
     309    """
     310       simplifies a logical expression due to replacement of variables by constants
     311    """
     312    if isinstance(expr, TrueLiteral): return expr
     313    elif isinstance(expr, FalseLiteral): return expr
     314    elif isinstance(expr, Var): return expr
     315    elif isinstance(expr, Not): return make_not(simplify_expr(expr.operand))
     316    elif isinstance(expr, Or):
     317        return make_or(simplify_expr(expr.operand1), simplify_expr(expr.operand2))
     318    elif isinstance(expr, Xor):
     319        return make_xor(simplify_expr(expr.operand1), simplify_expr(expr.operand2))
     320    elif isinstance(expr, And):
     321        return make_and(simplify_expr(expr.operand1), simplify_expr(expr.operand2))
     322    elif isinstance(expr, Sel):
     323        return make_sel(simplify_expr(expr.sel), simplify_expr(expr.false_branch), simplify_expr(expr.true_branch))
     324    elif isinstance(expr, Add):
     325        return make_add(simplify_expr(expr.operand1), simplify_expr(expr.operand2))
     326    elif isinstance(expr, Sub):
     327        return make_sub(simplify_expr(expr.operand1), simplify_expr(expr.operand2))
     328    elif isinstance(expr, Andc):
     329        return make_and(simplify_expr(expr.operand1), make_not(simplify_expr(expr.operand2)))
     330
     331
Note: See TracChangeset for help on using the changeset viewer.