Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

dataflow.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_DATAFLOW_H
00038 #define CBZ_DATAFLOW_H
00039 
00040 
00041 class FlowProblem;
00042 
00043 class FlowVal
00044 {
00045 private:
00046 
00047 public:
00048 
00049   // -- Clone
00050 
00051   virtual FlowVal * clone() const =0;
00052 
00053   // -- Comparison
00054 
00055   virtual bool diff(FlowVal * other) const =0;
00056 
00057   // -- Meet "^" operator
00058   // Must satisfy the following:
00059   //    Associative: x ^ (y ^ z) = (x ^ y) ^ z
00060   //    Commutative: x ^ y = y ^ x
00061   //    Idempotent:  x ^ x = x
00062 
00063   virtual void meet(const FlowVal * other) =0;
00064 
00065   // -- "T" top element
00066   // Must satisfy : x ^ T = x
00067 
00068   virtual void to_top() =0;
00069 
00070   // -- Don't change this function...
00071 
00072   void meet_and_diff(const FlowVal * other, FlowProblem & fp);
00073 };
00074 
00075 class FlowProblem
00076 {
00077 
00078 public:
00079 
00080   // -- Entry point
00081 
00082   void iterate(Node * n, FlowVal * initial = 0);
00083 
00084 private:
00085 
00086   bool _forward;
00087   bool _changed;
00088   bool _last;
00089   bool _basicblocks;
00090   FlowVal * _top;
00091 
00092 public:
00093 
00094   typedef enum { Entry, Exit } Point;
00095 
00096   // -- Constructor
00097 
00098   FlowProblem(bool forw, FlowVal * top)
00099     : _forward(forw),
00100       _changed(true),
00101       _last(false),
00102       _basicblocks(false),
00103       _top(top)
00104   {}
00105 
00106   // -- Fields
00107 
00108   inline bool forward() const { return _forward; }
00109 
00110   inline bool changed() const { return _changed; }
00111   inline void changed(bool ch) { _changed = ch; }
00112 
00113   inline bool last() const { return _last; }
00114   inline void last(bool l) { _last = l; }
00115 
00116   inline bool basicblocks() const { return _basicblocks; }
00117   inline void basicblocks(bool a) { _basicblocks = a; }
00118 
00119   inline FlowVal * top() const { return _top; }
00120 
00121   // -- Special transfer function: this one is called at the top of
00122   // every expression subtree. These are not necessarily basic blocks
00123   // because they may contain operators like "?:" and "&&" which have
00124   // control-flow semantics. However, we can easily preprocess the
00125   // tree to remove these. NOTE: This isn't for "real" basicblockNodes;
00126   // this is for expressions which sort of act like basic blocks
00127 
00128   virtual void flow_basicblock(FlowVal * v, exprNode * the_expr, Point p)
00129      { flow_node(v, the_expr, p); }
00130 
00131   // -- AST-specific transfer functions
00132 
00133   virtual void flow_node(FlowVal * v, Node * the_node, Point p)
00134      { // Default: do nothing
00135      }
00136 
00137   virtual void flow_unit(FlowVal * v, unitNode * the_unit, Point p)
00138      { flow_node(v, the_unit, p); }
00139 
00140   virtual void flow_def(FlowVal * v, defNode * the_def, Point p)
00141      { flow_node(v, the_def, p); }
00142 
00143   virtual void flow_decl(FlowVal * v, declNode * the_decl, Point p)
00144      { flow_def(v, the_decl, p); }
00145 
00146   virtual void flow_proc(FlowVal * v, procNode * the_proc, Point p)
00147      { flow_def(v, the_proc, p); }
00148 
00149   virtual void flow_type(FlowVal * v, typeNode * the_type, Point p)
00150      { flow_node(v, the_type, p); }
00151 
00152   virtual void flow_prim(FlowVal * v, primNode * the_prim, Point p)
00153      { flow_type(v, the_prim, p); }
00154 
00155   virtual void flow_tdef(FlowVal * v, tdefNode * the_tdef, Point p)
00156      { flow_type(v, the_tdef, p); }
00157 
00158   virtual void flow_ptr(FlowVal * v, ptrNode * the_ptr, Point p)
00159      { flow_type(v, the_ptr, p); }
00160 
00161   virtual void flow_array(FlowVal * v, arrayNode * the_array, Point p)
00162      { flow_type(v, the_array, p); }
00163 
00164   virtual void flow_func(FlowVal * v, funcNode * the_func, Point p)
00165      { flow_type(v, the_func, p); }
00166 
00167   virtual void flow_sue(FlowVal * v, sueNode * the_sue, Point p)
00168      { flow_type(v, the_sue, p); }
00169 
00170   virtual void flow_struct(FlowVal * v, structNode * the_struct, Point p)
00171      { flow_sue(v, the_struct, p); }
00172 
00173   virtual void flow_union(FlowVal * v, unionNode * the_union, Point p)
00174      { flow_sue(v, the_union, p); }
00175 
00176   virtual void flow_enum(FlowVal * v, enumNode * the_enum, Point p)
00177      { flow_sue(v, the_enum, p); }
00178 
00179   virtual void flow_suespec(FlowVal * v, suespecNode * the_suespec, Point p)
00180      { flow_type(v, the_suespec, p); }
00181 
00182   virtual void flow_expr(FlowVal * v, exprNode * the_expr, Point p)
00183      { flow_node(v, the_expr, p); }
00184 
00185   virtual void flow_const(FlowVal * v, constNode * the_const, Point p)
00186      { flow_expr(v, the_const, p); }
00187 
00188   virtual void flow_id(FlowVal * v, idNode * the_id, Point p)
00189      { flow_expr(v, the_id, p); }
00190 
00191   virtual void flow_binary(FlowVal * v, binaryNode * the_binary, Point p)
00192      { flow_expr(v, the_binary, p); }
00193 
00194   virtual void flow_unary(FlowVal * v, unaryNode * the_unary, Point p)
00195      { flow_expr(v, the_unary, p); }
00196 
00197   virtual void flow_cast(FlowVal * v, castNode * the_cast, Point p)
00198      { flow_expr(v, the_cast, p); }
00199 
00200   virtual void flow_comma(FlowVal * v, commaNode * the_comma, Point p)
00201      { flow_expr(v, the_comma, p); }
00202 
00203   virtual void flow_ternary(FlowVal * v, ternaryNode * the_ternary, Point p)
00204      { flow_expr(v, the_ternary, p); }
00205 
00206   virtual void flow_call(FlowVal * v, callNode * the_call, Point p)
00207      { flow_expr(v, the_call, p); }
00208 
00209   virtual void flow_initializer(FlowVal * v, initializerNode * the_initializer, Point p)
00210      { flow_expr(v, the_initializer, p); }
00211 
00212   virtual void flow_stmt(FlowVal * v, stmtNode * the_stmt, Point p)
00213      { flow_node(v, the_stmt, p); }
00214 
00215   virtual void flow_block(FlowVal * v, blockNode * the_block, Point p)
00216      { flow_stmt(v, the_block, p); }
00217 
00218   virtual void flow_exprstmt(FlowVal * v, exprstmtNode * the_exprstmt, Point p)
00219      { flow_stmt(v, the_exprstmt, p); }
00220 
00221   virtual void flow_target(FlowVal * v, targetNode * the_target, Point p)
00222      { flow_stmt(v, the_target, p); }
00223 
00224   virtual void flow_label(FlowVal * v, labelNode * the_label, Point p)
00225      { flow_target(v, the_label, p); }
00226 
00227   virtual void flow_case(FlowVal * v, caseNode * the_case, Point p)
00228      { flow_target(v, the_case, p); }
00229 
00230   virtual void flow_selection(FlowVal * v, selectionNode * the_selection, Point p)
00231      { flow_stmt(v, the_selection, p); }
00232 
00233   virtual void flow_if(FlowVal * v, ifNode * the_if, Point p)
00234      { flow_selection(v, the_if, p); }
00235 
00236   virtual void flow_switch(FlowVal * v, switchNode * the_switch, Point p)
00237      { flow_selection(v, the_switch, p); }
00238 
00239   virtual void flow_loop(FlowVal * v, loopNode * the_loop, Point p)
00240      { flow_stmt(v, the_loop, p); }
00241 
00242   virtual void flow_while(FlowVal * v, whileNode * the_while, Point p)
00243      { flow_loop(v, the_while, p); }
00244 
00245   virtual void flow_do(FlowVal * v, doNode * the_do, Point p)
00246      { flow_loop(v, the_do, p); }
00247 
00248   virtual void flow_for(FlowVal * v, forNode * the_for, Point p)
00249      { flow_loop(v, the_for, p); }
00250 
00251   virtual void flow_jump(FlowVal * v, jumpNode * the_jump, Point p)
00252      { flow_stmt(v, the_jump, p); }
00253 
00254   virtual void flow_goto(FlowVal * v, gotoNode * the_goto, Point p)
00255      { flow_jump(v, the_goto, p); }
00256 
00257   virtual void flow_continue(FlowVal * v, continueNode * the_continue, Point p)
00258      { flow_jump(v, the_continue, p); }
00259 
00260   virtual void flow_break(FlowVal * v, breakNode * the_break, Point p)
00261      { flow_jump(v, the_break, p); }
00262 
00263   virtual void flow_return(FlowVal * v, returnNode * the_return, Point p)
00264      { flow_jump(v, the_return, p); }
00265 
00266   virtual void flow_attrib(FlowVal * v, attribNode * the_attrib, Point p)
00267      { flow_stmt(v, the_attrib, p); }
00268 
00269   virtual void flow_text(FlowVal * v, textNode * the_text, Point p)
00270      { flow_node(v, the_text, p); }
00271 
00272 };
00273 
00274 
00275 
00276 
00277 
00278 #endif // CBZ_DATAFLOW_H

Generated on Thu Jan 10 12:06:19 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001