next up previous
Next: Transfer functions Up: Dataflow Analysis Framework Previous: Methods

Specifying the flow problem

The FlowProblem class holds the transfer functions and provides an entry point for analysis. It designed using the same principles as the walker :

class FlowProblem
{
public:
  void iterate(Node * n);

public:

  typedef enum { Entry, Exit } Point;

  // -- Constructor

  FlowProblem(bool forw, FlowVal * top);
  inline bool last() const { return _last; }

  // -- Transfer functions

  virtual void flow_node(FlowVal * v, Node * the_node, Point p);
  // ...
  virtual void flow_def(FlowVal * v, defNode * the_def, Point p);
  virtual void flow_decl(FlowVal * v, declNode * the_decl, Point p);
  virtual void flow_proc(FlowVal * v, procNode * the_proc, Point p);
  // ...
  virtual void flow_expr(FlowVal * v, exprNode * the_expr, Point p);
  virtual void flow_const(FlowVal * v, constNode * the_const, Point p);
  virtual void flow_id(FlowVal * v, idNode * the_id, Point p);
  virtual void flow_binary(FlowVal * v, binaryNode * the_binary, Point p);
  virtual void flow_unary(FlowVal * v, unaryNode * the_unary, Point p);
  // ...
  virtual void flow_stmt(FlowVal * v, stmtNode * the_stmt, Point p);
  virtual void flow_if(FlowVal * v, ifNode * the_if, Point p);
  virtual void flow_ifelse(FlowVal * v, ifelseNode * the_ifelse, Point p);
  virtual void flow_switch(FlowVal * v, switchNode * the_switch, Point p);
  virtual void flow_loop(FlowVal * v, loopNode * the_loop, Point p);
  virtual void flow_while(FlowVal * v, whileNode * the_while, Point p);
};

The constructor takes two arguments. The first indicates the direction: true for a forward problem or false for a backward problem. The second is an instance of your flow value--specifically, a flow value that has been set to ``top.'' It is used as the initial value for each iteration.

The main entry point is the iterate method. When everything has been properly initialized, call the iterate method on the procedure to analyze. The method iterates the analysis framework until it converges.



 

Calvin Lin
2002-01-31