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

java.lang.Object
  extended by de.cau.cs.kieler.krep.compiler.ceq.Expression
Direct Known Subclasses:
BinOpExpression, ConstExpression, IfExpression, NotExpression, VarAccessExpression

public abstract class Expression
extends Object

Abstract superclass for all ceq Expressions. Note that every sub-expression should have a unique name.

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

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

Constructor Detail

Expression

protected Expression(String n,
                     Program p)
Generate new named expression, the actual expression is defined by the actual subclass.

Parameters:
n - name of the expression.
p - the program that contains the expression
Method Detail

getProg

public Program getProg()
Returns:
program that contains the expression

setProg

protected void setProg(Program p)
Parameters:
p - program that contains the expression

getType

public abstract Type getType()
Return the inferred type of the expression.

Returns:
type of the current expression

getVars

public abstract List<String> getVars()
compute list of all variables that syntactically occur in the expression.

Returns:
list of used variables

getDeps

public abstract List<Variable> getDeps()
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.

Returns:
list of variables this expression depends on

toString

public abstract String toString()
Show the expression in Lustre syntax.

Overrides:
toString in class Object
Returns:
textual description of the expression in Lustre

flatten

public abstract Expression flatten(String n,
                                   HashMap<String,Variable> vars,
                                   LinkedList<Expression> es)
extract sub-expressions from operations.

Parameters:
n - name of the expression
vars - holds additionally added variables
es - additionally added expression
Returns:
expression without complex operations

padDelay

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

Parameters:
delay - : delay for all variables
n - : delay of the output
Returns:
additional equation to store previous values

isAtom

public abstract boolean isAtom()
compute whether this is an atomic expression.

Returns:
true if expression contains no sub-expression

toKlp

public abstract LinkedList<AbstractInstruction> toKlp(Variable to)
compute instructions to execute this expression on the KLP.

Parameters:
to - Register to store the result
Returns:
list of KLP instructions that compute this expression

getName

public String getName()
Get unique name of the expression.

Returns:
name of the expression

propagateConst

public abstract ConstExpression propagateConst(HashMap<String,ConstExpression> con)
Propagate constant values, ie, replace all occurrences of a variable by a constant.

Parameters:
con - mapping variable to constant values, if they can be evaluated
Returns:
a constant when the expression can be completely evaluated

staticEval

public abstract Expression staticEval()
Perform static evaluation, remove operations on constant values by the result of the operation.

Returns:
evaluate static expressions.

replaceVar

public abstract void replaceVar(HashMap<String,Variable> equiv)
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.

Parameters:
equiv - list of equivalent variables.

wcrt

public abstract int wcrt()
Compute upper bound for the reaction time.

Returns:
estimated wcrt for the expression.

replace

public abstract Expression replace(String var,
                                   Expression expr)
Replace each occurrence of a variable by an expression.

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

setName

protected void setName(String n)
Set the unique name of the expression.

Parameters:
n - the name to set

getVar

public Variable getVar(String n)
Generate new variable. Implements singleton pattern.

Parameters:
n - name of the variable
Returns:
variable with same name if it exists, new temp variable otherwise

getVar

public Variable getVar(String n,
                       Variable.Kind k,
                       Type t)
Generate new, unique variable.

Parameters:
n - name of the variable
k - io kind of the variable
t - type of the variable
Returns:
variable with same name if it exists, new temp variable otherwise