SFE.Compiler
Class OperationExpression

java.lang.Object
  extended by SFE.Compiler.Expression
      extended by SFE.Compiler.OperationExpression
All Implemented Interfaces:
Multi2SingleBit
Direct Known Subclasses:
BinaryOpExpression, TrinaryOpExpression, UnaryOpExpression

public abstract class OperationExpression
extends Expression
implements Multi2SingleBit

class OperationExpression defines expressions containing operatioins, that can be defined in the program.


Field Summary
static java.util.Vector inputFormat
           
 
Constructor Summary
OperationExpression(Operator op)
          Constracts a new OperationExpression from a given Operator.
 
Method Summary
abstract  void changeReference(UniqueVariables unique)
           
abstract  OperationExpression combineConstInput()
          Combines an input expression that is constant and return the result expression.
abstract  OperationExpression combineEqualInputs()
          Combines identical input expression an returns the result expression.
 OperationExpression combineSharedInput()
          should be called only in hasSharedInput() is true.
abstract  void combineUnaryInput()
          Combines an input expression the is the output of an unary operator into this Operation expression.
abstract  Expression duplicate()
          returns a replic of this Expression
 Expression evaluateExpression(AssignmentStatement as, BlockStatement result)
          recursivly calculates inner arithmetic expression and inserts them into the proper function.
 UnaryOpExpression getConstantOutput()
          Returns an unary op expression with a constant (constant expression).
abstract  java.util.Vector getLvalExpressionInputs()
          Returns an array of the input LvalExpressions of this gate.
 Operator getOperator()
          Returns this operator.
abstract  boolean hasConstantInput()
          Return true iff this OperationExpression has a constant input.
abstract  boolean hasEqualInputs()
          Returns true iff this operator expression has at lease two identical input expression.
 boolean hasSharedInput()
          Returns true if this expression has input pins that share an input.
abstract  boolean hasUnaryInput()
          Returns true iff one of the operand of this operator expression is a result of an unary operator.
abstract  boolean isComplexIDOrNeg()
          returns true if this gate outputs true of false(constant output).
 boolean isConstant()
          Returns true if the output of this operation is constant
abstract  OperationExpression negate()
          returns the negate gate (OperatorExpression) of this OperatorExpression.
abstract  OperationExpression simplify()
          Transformas this gate to a simple id or not gate.
 int size()
          Returns the number of bits needed to represent this expression.
abstract  OperationExpression sortInputs()
          Sorts the input gates according to their names and returns the result OperationExpression.
 void toCircuit(java.io.PrintWriter circuit)
          Prints this Object into the circuit.
 
Methods inherited from class SFE.Compiler.Expression
bitAt, hasSharedInput
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface SFE.Compiler.Multi2SingleBit
multi2SingleBit
 

Field Detail

inputFormat

public static final java.util.Vector inputFormat
Constructor Detail

OperationExpression

public OperationExpression(Operator op)
Constracts a new OperationExpression from a given Operator.

Parameters:
op - this OperationExpression operator.
Method Detail

size

public int size()
Returns the number of bits needed to represent this expression.

Specified by:
size in class Expression
Returns:
the number of bits needed to represent this expression.

hasSharedInput

public boolean hasSharedInput()
Returns true if this expression has input pins that share an input.

Returns:
true if this expression has input pins that share an input.

combineSharedInput

public OperationExpression combineSharedInput()
should be called only in hasSharedInput() is true.


hasUnaryInput

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

Returns:
true if one of the operand of this operator expression is a result of an unary operator.

combineUnaryInput

public abstract void combineUnaryInput()
Combines 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.


hasConstantInput

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

Returns:
true iff this OperationExpression has a constant input.

combineConstInput

public abstract 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.

Returns:
the result expression.

hasEqualInputs

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

Returns:
true iff this operator expression has at lease two identical input expression.

combineEqualInputs

public abstract 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.

Returns:
the result expression.

getOperator

public Operator getOperator()
Returns this operator.

Returns:
this operator.

sortInputs

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

Returns:
the OperationExpression with the sorted inputs.

negate

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

Returns:
the negate gate (OperatorExpression) of this OperatorExpression.

getLvalExpressionInputs

public abstract 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.

Returns:
an array of the input LvalExpressions of this gate.

isConstant

public boolean isConstant()
Returns true if the output of this operation is constant


getConstantOutput

public UnaryOpExpression getConstantOutput()
Returns an unary op expression with a constant (constant expression). this method should be called only if this.isConstant() is true.

Returns:
an unary op expression with a constant (constant expression).

changeReference

public abstract void changeReference(UniqueVariables unique)

evaluateExpression

public Expression evaluateExpression(AssignmentStatement as,
                                     BlockStatement result)
recursivly calculates inner arithmetic expression and inserts them into the proper function.

Overrides:
evaluateExpression in class Expression
Parameters:
as - the AssignmentStatement that holds this expression (as rhs).
result - a block statement to insert statments if needed.
Returns:
the new statement to use instead of as.

isComplexIDOrNeg

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

Returns:
true if this gate outputs true of false(constant output). for any input.

simplify

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

Returns:
the simplified gate.

duplicate

public abstract Expression duplicate()
returns a replic of this Expression

Overrides:
duplicate in class Expression
Returns:
a replic of this Expression

toCircuit

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

Parameters:
circuit - the circuit output file.