SFE.Compiler
Class TrinaryOpExpression

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

public class TrinaryOpExpression
extends OperationExpression

A class for representing trinary operator expressions that can be defined in the program.


Field Summary
static java.util.Vector inputFormat
           
 
Constructor Summary
TrinaryOpExpression(Operator op, Expression left, Expression middle, Expression right)
          Constructs a new TrinaryOpExpression 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()
          if hasSharedInput() is true, combine the gates into one simple gate.
 void combineUnaryInput()
          Combined an input expression the is the output of an unary operator into this Operation expression.
 Expression duplicate()
          returns a replica of this expression
 java.util.Vector getLvalExpressionInputs()
          Returns an array of the input LvalExpressions of this gate.
 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 if two legs of the trinary gate shares the same input.
 boolean hasUnaryInput()
          Returns true iff one of the operand of this operator expression is a result of an unary operator.
 boolean isComplexIDOrNeg()
          returns true if this gate is a id gate or neg gate of one of the inputs
 BlockStatement multi2SingleBit(java.lang.Object obj)
          Transforms this multibit expression into singlebit statements and returns the result
 OperationExpression negate()
          returns the negate gate (OperatorExpression) of this OperatorExpression.
 OperationExpression simplify()
          if isComplexIDOrNeg() is true, replaces the compex gate with the appropriate simple primitive gate.
 OperationExpression sortInputs()
          Sorts the input gates according to their names and returns the result OperationExpression.
 void toCircuit(java.io.PrintWriter circuit)
          Prints this AssignmentStatement into the 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

TrinaryOpExpression

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

Parameters:
op - the trinary operator.
left - the left input.
middle - the left input.
right - the right input.
Method Detail

toString

public java.lang.String toString()
Returns a string representation of the object. Returns a string representing this object as it appear at the output circuit.

Overrides:
toString in class java.lang.Object
Returns:
a string representing this object as it appear at the output circuit.

multi2SingleBit

public BlockStatement multi2SingleBit(java.lang.Object obj)
Transforms this multibit expression into singlebit statements and returns the result

Parameters:
obj - the AssignmentStatement that holds this TrinaryOpExpression.
Returns:
a BlockStatement containing the result statements

toCircuit

public void toCircuit(java.io.PrintWriter circuit)
Prints this AssignmentStatement into the circuit.

Parameters:
circuit - the circuit output file.

hasUnaryInput

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

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

combineUnaryInput

public void combineUnaryInput()
Combined an input expression the is the output of an unary operator into this Operation expression. 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 is a id gate or neg gate of one of the inputs

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

simplify

public OperationExpression simplify()
if isComplexIDOrNeg() is true, replaces the compex gate with the appropriate simple primitive 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 expression

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

hasSharedInput

public boolean hasSharedInput()
Returns if two legs of the trinary gate shares the same input.

Overrides:
hasSharedInput in class OperationExpression
Returns:
true if two legs of the trinary gate shares the same input.

combineSharedInput

public OperationExpression combineSharedInput()
if hasSharedInput() is true, combine the gates into one simple gate. and returns it. should be called only in hasSharedInput() is true.

Overrides:
combineSharedInput in class OperationExpression
Returns:
the simplified gate.