de.cau.cs.kieler.krep.compiler.ceq
Class IfExpression

java.lang.Object
  extended by de.cau.cs.kieler.krep.compiler.ceq.Expression
      extended by de.cau.cs.kieler.krep.compiler.ceq.IfExpression

public class IfExpression
extends Expression

Conditional: if e1 then e2 else e3.

Rating yellow
(2010-02-05) review by cmot, msp, tam

Constructor Summary
IfExpression(String name, Expression e1, Expression e2, Expression e3, Program p)
          Generate new expression if e1 then e2 else e3.
 
Method Summary
 Expression flatten(String name, HashMap<String,Variable> vars, LinkedList<Expression> es)
          extract sub-expressions from operations.
 List<Variable> getDeps()
          compute List of all variables, on which current value the expression depends.
 Type getType()
          Return the inferred type of the expression.
 List<String> getVars()
          compute list of all variables that syntactically occur in the expression.
 boolean isAtom()
          compute whether this is an atomic expression.
 Expression padDelay(HashMap<String,Integer> delay, int n)
          add additional pre operators, to use all variables with the right tick.
 ConstExpression propagateConst(HashMap<String,ConstExpression> con)
          Propagate constant values, ie, replace all occurrences of a variable by a constant.
 Expression replace(String var, Expression expr)
          Replace each occurrence of a variable by an expression.
 void replaceVar(HashMap<String,Variable> equiv)
          Replace a variable by another one.
 Expression staticEval()
          Perform static evaluation, remove operations on constant values by the result of the operation.
 LinkedList<AbstractInstruction> toKlp(Variable r)
          compute instructions to execute this expression on the KLP.
 String toString()
          Show the expression in Lustre syntax.
 int wcrt()
          Compute upper bound for the reaction time.
 
Methods inherited from class de.cau.cs.kieler.krep.compiler.ceq.Expression
getName, getProg, getVar, getVar, setName, setProg
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfExpression

public IfExpression(String name,
                    Expression e1,
                    Expression e2,
                    Expression e3,
                    Program p)
Generate new expression if e1 then e2 else e3.

Parameters:
name - name of the expression
e1 - boolean test
e2 - expression for then case
e3 - expression for else case
p - program that contains the expression
Method Detail

getVars

public List<String> getVars()
Description copied from class: Expression
compute list of all variables that syntactically occur in the expression.

Specified by:
getVars in class Expression
Returns:
list of used variables

getDeps

public List<Variable> getDeps()
Description copied from class: Expression
compute List of all variables, on which current value the expression depends. This is the same as getVars without the variables which pre value is used.

Specified by:
getDeps in class Expression
Returns:
list of variables this expression depends on

toString

public String toString()
Description copied from class: Expression
Show the expression in Lustre syntax.

Specified by:
toString in class Expression
Returns:
textual description of the expression in Lustre

flatten

public Expression flatten(String name,
                          HashMap<String,Variable> vars,
                          LinkedList<Expression> es)
Description copied from class: Expression
extract sub-expressions from operations.

Specified by:
flatten in class Expression
Parameters:
name - name of the expression
vars - holds additionally added variables
es - additionally added expression
Returns:
expression without complex operations

isAtom

public boolean isAtom()
Description copied from class: Expression
compute whether this is an atomic expression.

Specified by:
isAtom in class Expression
Returns:
true if expression contains no sub-expression

toKlp

public LinkedList<AbstractInstruction> toKlp(Variable r)
Description copied from class: Expression
compute instructions to execute this expression on the KLP.

Specified by:
toKlp in class Expression
Parameters:
r - Register to store the result
Returns:
list of KLP instructions that compute this expression

getType

public Type getType()
Description copied from class: Expression
Return the inferred type of the expression.

Specified by:
getType in class Expression
Returns:
type of the current expression

padDelay

public Expression padDelay(HashMap<String,Integer> delay,
                           int n)
Description copied from class: Expression
add additional pre operators, to use all variables with the right tick.

Specified by:
padDelay in class Expression
Parameters:
delay - : delay for all variables
n - : delay of the output
Returns:
additional equation to store previous values

propagateConst

public ConstExpression propagateConst(HashMap<String,ConstExpression> con)
Description copied from class: Expression
Propagate constant values, ie, replace all occurrences of a variable by a constant.

Specified by:
propagateConst in class Expression
Parameters:
con - mapping variable to constant values, if they can be evaluated
Returns:
a constant when the expression can be completely evaluated

staticEval

public Expression staticEval()
Description copied from class: Expression
Perform static evaluation, remove operations on constant values by the result of the operation.

Specified by:
staticEval in class Expression
Returns:
evaluate static expressions.

replaceVar

public void replaceVar(HashMap<String,Variable> equiv)
Description copied from class: Expression
Replace a variable by another one. This is useful for Scade programs, where each port corresponds to one variable, but we want to have one variable per wire.

Specified by:
replaceVar in class Expression
Parameters:
equiv - list of equivalent variables.

wcrt

public int wcrt()
Description copied from class: Expression
Compute upper bound for the reaction time.

Specified by:
wcrt in class Expression
Returns:
estimated wcrt for the expression.

replace

public Expression replace(String var,
                          Expression expr)
Description copied from class: Expression
Replace each occurrence of a variable by an expression.

Specified by:
replace in class Expression
Parameters:
var - name of the expression to replace
expr - expression by which the variable is replaced.
Returns:
new expression