SFE.Compiler
Class BinaryOpExpression

java.lang.Object
  extended by SFE.Compiler.Expression
      extended by SFE.Compiler.OperationExpression
          extended by SFE.Compiler.BinaryOpExpression
All Implemented Interfaces:
Multi2SingleBit

public class BinaryOpExpression
extends OperationExpression

A class for representing binary operation expressions that can be defined in the program.


Field Summary
static java.util.Vector inputFormat
           
 
Constructor Summary
BinaryOpExpression(Operator op, Expression left, Expression right)
          Constructs a new BinaryOpExpression from a given oparator and inputs.
 
Method Summary
 void changeReference(UniqueVariables unique)
          Changes references of variables to the last place they were changed
 OperationExpression combineConstInput()
          Combines an input expression that is constant and return the result expression.
 OperationExpression combineEqualInputs()
          Combines identical input expression an returns the result expression.
 OperationExpression combineSharedInput()
          Combines the gates that share an input pin into one gate.
 void combineUnaryInput()
          Combines an input expression that is the output of an unary operator into this Operation expression.
 Expression duplicate()
          returns a replica of this BinaryOpExpression.
 Expression getLeft()
          Returns the left input pin.
 java.util.Vector getLvalExpressionInputs()
          Returns an array of the input LvalExpressions of this gate.
 Expression getRight()
          Returns the right input pin.
 boolean hasConstantInput()
          Return true iff this OperationExpression has a constant input.
 boolean hasEqualInputs()
          Returns true iff this operator expression has at lease two identical input expression.
 boolean hasSharedInput()
          Returns true if the gates input pins share an input pin.
 boolean hasUnaryInput()
          Returns true iff one of the operands of this operator expression is a result of an unary operator.
 boolean isComplexIDOrNeg()
          returns true if this gate outputs true of false(constant output).
 BlockStatement multi2SingleBit(java.lang.Object obj)
          Transforms this multibit BinaryOpExpression into singlebit Statements and returns a BlockStatement containing the result.
 OperationExpression negate()
          returns the negate gate (OperatorExpression) of this OperatorExpression.
 OperationExpression simplify()
          Transformas this gate to a simple id or not gate.
 OperationExpression sortInputs()
          Sorts the input gates according to their names and returns the result OperationExpression.
 void toCircuit(java.io.PrintWriter circuit)
          Writes this Expression to the output circuit.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class SFE.Compiler.OperationExpression
evaluateExpression, getConstantOutput, getOperator, isConstant, size
 
Methods inherited from class SFE.Compiler.Expression
bitAt, hasSharedInput
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inputFormat

public static final java.util.Vector inputFormat
Constructor Detail

BinaryOpExpression

public BinaryOpExpression(Operator op,
                          Expression left,
                          Expression right)
Constructs a new BinaryOpExpression from a given oparator and inputs.

Parameters:
op - the binary operator.
left - the left input pin.
right - the right input pin.
Method Detail

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

multi2SingleBit

public BlockStatement multi2SingleBit(java.lang.Object obj)
Transforms this multibit BinaryOpExpression into singlebit Statements and returns a BlockStatement containing the result.

Parameters:
obj - the AssignmentStatement that holds this BinaryOpExpression.
Returns:
BlockStatement containing singlebit Statements of this BinaryOpExpression.

getRight

public Expression getRight()
Returns the right input pin.

Returns:
the right input pin.

getLeft

public Expression getLeft()
Returns the left input pin.

Returns:
the left input pin.

toCircuit

public void toCircuit(java.io.PrintWriter circuit)
Writes this Expression to the output circuit.

Parameters:
circuit - the output circuit file.

hasUnaryInput

public boolean hasUnaryInput()
Returns true iff one of the operands of this operator expression is a result of an unary operator.

Specified by:
hasUnaryInput in class OperationExpression
Returns:
true if one of the operands of this operator expression is a result of an unary operator.

combineUnaryInput

public void combineUnaryInput()
Combines an input expression that is the output of an unary operator into this Operation expression. NOTE: this method should be call only if hasUnaryInput() is true.

Specified by:
combineUnaryInput in class OperationExpression

hasConstantInput

public boolean hasConstantInput()
Return true iff this OperationExpression has a constant input.

Specified by:
hasConstantInput in class OperationExpression
Returns:
true iff this OperationExpression has a constant input.

combineConstInput

public OperationExpression combineConstInput()
Combines an input expression that is constant and return the result expression. This method reduces the arity of this OperationExpression. This method should be called only if hasConstantInput is true.

Specified by:
combineConstInput in class OperationExpression
Returns:
the result expression.

hasEqualInputs

public boolean hasEqualInputs()
Returns true iff this operator expression has at lease two identical input expression.

Specified by:
hasEqualInputs in class OperationExpression
Returns:
true iff this operator expression has at lease two identical input expression.

combineEqualInputs

public OperationExpression combineEqualInputs()
Combines identical input expression an returns the result expression. The resulting expression has an arity smaller by one then this expression arity. Note that this method should be called only if hasEqualInputs is true.

Specified by:
combineEqualInputs in class OperationExpression
Returns:
the result expression.

sortInputs

public OperationExpression sortInputs()
Sorts the input gates according to their names and returns the result OperationExpression. This method is used in the optimization process.

Specified by:
sortInputs in class OperationExpression
Returns:
the OperationExpression with the sorted inputs.

negate

public OperationExpression negate()
returns the negate gate (OperatorExpression) of this OperatorExpression.

Specified by:
negate in class OperationExpression
Returns:
the negate gate (OperatorExpression) of this OperatorExpression.

getLvalExpressionInputs

public java.util.Vector getLvalExpressionInputs()
Returns an array of the input LvalExpressions of this gate. This method is used in the second phase of the optimization.

Specified by:
getLvalExpressionInputs in class OperationExpression
Returns:
an array of the input LvalExpressions of this gate.

changeReference

public void changeReference(UniqueVariables unique)
Changes references of variables to the last place they were changed

Specified by:
changeReference in class OperationExpression
Parameters:
unique - holds all the variables and their references

isComplexIDOrNeg

public boolean isComplexIDOrNeg()
returns true if this gate outputs true of false(constant output). for any input.

Specified by:
isComplexIDOrNeg in class OperationExpression
Returns:
true if this gate outputs true of false(constant output). for any input.

simplify

public OperationExpression simplify()
Transformas this gate to a simple id or not gate. should be called only if isComplexIDOrNeg() if true

Specified by:
simplify in class OperationExpression
Returns:
the simplified gate.

duplicate

public Expression duplicate()
returns a replica of this BinaryOpExpression.

Specified by:
duplicate in class OperationExpression
Returns:
a replica of this BinaryOpExpression.

hasSharedInput

public boolean hasSharedInput()
Returns true if the gates input pins share an input pin.

Overrides:
hasSharedInput in class OperationExpression
Returns:
true if the gates input pins share an input pin.

combineSharedInput

public OperationExpression combineSharedInput()
Combines the gates that share an input pin into one gate. should be called only in hasSharedInput() is true.

Overrides:
combineSharedInput in class OperationExpression
Returns:
the combined gate (OperationExpression).