SFE.Compiler
Class Function

java.lang.Object
  extended by SFE.Compiler.Function
All Implemented Interfaces:
Multi2SingleBit

public class Function
extends java.lang.Object
implements Multi2SingleBit

A class for representing a function that can be defined in the program.


Field Summary
static Function currentFunction
           
 LvalExpression functionResult
           
static java.util.Vector inputFormat
           
 java.util.Vector parameters
           
 
Constructor Summary
Function(java.lang.String name, Type returnType)
          Constructs a new Function from a given name, returned type
 
Method Summary
 void addInputStatements()
           
 void addParameter(java.lang.String name, Type type)
          Adds a parameter to this function.
 void addStatement(Statement statement)
          Adds a statement to this function.
 void addStatements(java.util.Vector statements)
          Adds statements to this function.
static LvalExpression addTempLocalVar(java.lang.String name, Type type)
          Adds a temporary local varivable as single bit LvalExpression from a given varname and type and returns the LvalExpression that hold the whole (original) variable.
static void addVar(LvalExpression exp)
          Adds a local variable that was defined to this functioni, from a given LvalExpression.
static void addVar(java.lang.String name, Type type)
          Adds a local variable that was defined to this function.
 void buildUsedStatementsHash()
          create the list of all the needed statements to calculate the circuit.
 java.util.Vector getArguments()
          returns the arguments of this function.
 java.util.Vector getBody()
          returns the body of this function
 java.lang.String getName()
          Return the name of the function.
static LvalExpression getVar(LvalExpression lval)
          this method is used to get the last referance existing (unique var)
static LvalExpression getVar(java.lang.String name)
          Returns the LvalExpression from a given parameter or a local variable name.
static LvalExpression getVarBitAt(LvalExpression exp, int i)
          Returns the bit LvalExpression from a given Lvalexpression and the bit number.
static UniqueVariables getVars()
          Returns all variables and their references in all scopes.
 BlockStatement multi2SingleBit(java.lang.Object obj)
          Transfroms multibit statements in the function into single bit statements.
 void optimizePhaseI()
          Optimizes this function - phase I.
 void optimizePhaseII(java.util.Vector newBody)
          creates a list of the needed statements in this functions and removes all unneeded statements according to this list.
static java.util.HashMap popScope()
          Called when ending the current scope
static void pushScope()
          Called when begining a new scope (for example: if, for)
 int size()
          Returns the size of the value returned by the function in bits.
 void toCircuit(java.io.PrintWriter circuit)
          Prints this AssignmentStatement into the circuit.
 java.lang.String toFormat()
          Returns a String representing this object as it should appear in the format file.
 java.lang.String toString()
          Returns a string representation of the object.
 void uniqueVars()
          Unique vars transformations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parameters

public java.util.Vector parameters

functionResult

public LvalExpression functionResult

currentFunction

public static Function currentFunction

inputFormat

public static final java.util.Vector inputFormat
Constructor Detail

Function

public Function(java.lang.String name,
                Type returnType)
Constructs a new Function from a given name, returned type

Parameters:
name - the name of this function.
returnType - the type of this function's returned value.
Method Detail

getVars

public static UniqueVariables getVars()
Returns all variables and their references in all scopes.

Returns:
UniqueVariables all variables and their references in all scopes.

addParameter

public void addParameter(java.lang.String name,
                         Type type)
Adds a parameter to this function. Note that the function adds the LvalExpression for this parameter.

Parameters:
name - the name of the new parameter
type - the type of the new parameter

addVar

public static void addVar(java.lang.String name,
                          Type type)
Adds a local variable that was defined to this function. Note that the function adds the LvalExpression for this parameter.

Parameters:
name - the name of the new local variable
type - the type of the new local variable

addVar

public static void addVar(LvalExpression exp)
Adds a local variable that was defined to this functioni, from a given LvalExpression.

Parameters:
exp - the given expression.

addTempLocalVar

public static LvalExpression addTempLocalVar(java.lang.String name,
                                             Type type)
Adds a temporary local varivable as single bit LvalExpression from a given varname and type and returns the LvalExpression that hold the whole (original) variable. NOTE: this method is used during multi2singlebit trasformation where temp. vars are needed.

Parameters:
name - the name of the temp. variable.
type - the type of the temp. variable.
Returns:
the LvalExpression that represents the variable.

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.

getName

public java.lang.String getName()
Return the name of the function.

Returns:
the name of the function.

addStatement

public void addStatement(Statement statement)
Adds a statement to this function.

Parameters:
statement - the new statement.

addStatements

public void addStatements(java.util.Vector statements)
Adds statements to this function.

Parameters:
statements - the new statements.

getVar

public static LvalExpression getVar(java.lang.String name)
Returns the LvalExpression from a given parameter or a local variable name. If the given name does not exists, the returned value will be null.

Parameters:
name - the function, parameter or a local variable name.
Returns:
the LvalExpression representing the given name or null if the given name does not exists.

getVar

public static LvalExpression getVar(LvalExpression lval)
this method is used to get the last referance existing (unique var)


getVarBitAt

public static LvalExpression getVarBitAt(LvalExpression exp,
                                         int i)
Returns the bit LvalExpression from a given Lvalexpression and the bit number.

Parameters:
exp - the Lvalexpression
i - the bit number to be returned.
Returns:
LvalExpression holding the ith bit of exp.

multi2SingleBit

public BlockStatement multi2SingleBit(java.lang.Object obj)
Transfroms multibit statements in the function into single bit statements.

Specified by:
multi2SingleBit in interface Multi2SingleBit
Parameters:
obj - not needed (null).
Returns:
null.

addInputStatements

public void addInputStatements()

toCircuit

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

Parameters:
circuit - the circuit output file.

toFormat

public java.lang.String toFormat()
Returns a String representing this object as it should appear in the format file.

Returns:
a String representing this object as it should appear in the format file.

optimizePhaseI

public void optimizePhaseI()
Optimizes this function - phase I. Run phase I on all the functions statements.


optimizePhaseII

public void optimizePhaseII(java.util.Vector newBody)
creates a list of the needed statements in this functions and removes all unneeded statements according to this list.

Parameters:
newBody - newBody is always null (needed for other classes).

buildUsedStatementsHash

public void buildUsedStatementsHash()
create the list of all the needed statements to calculate the circuit. this list is used in the optimization.


uniqueVars

public void uniqueVars()
Unique vars transformations.


size

public int size()
Returns the size of the value returned by the function in bits.

Returns:
the size of the value returned by the function in bits.

pushScope

public static void pushScope()
Called when begining a new scope (for example: if, for)


popScope

public static java.util.HashMap popScope()
Called when ending the current scope

Returns:
HashMap that holds the variables of the scope and their references

getArguments

public java.util.Vector getArguments()
returns the arguments of this function.

Returns:
the arguments of this function.

getBody

public java.util.Vector getBody()
returns the body of this function

Returns:
the body of this function