ManagerCFG.hpp

Go to the documentation of this file.
00001 
00015 #ifndef MANAGERCFGSTANDARD_H
00016 #define MANAGERCFGSTANDARD_H
00017 
00018 //--------------------------------------------------------------------
00019 // standard headers
00020 #ifdef NO_STD_CHEADERS
00021 # include <string.h>
00022 #else
00023 # include <cstring>
00024 #endif
00025 
00026 // STL headers
00027 #include <list>
00028 #include <set>
00029 #include <map>
00030 
00031 // OpenAnalysis headers
00032 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00033 #include <OpenAnalysis/CFG/CFGInterface.hpp>
00034 #include <OpenAnalysis/CFG/CFG.hpp>
00035 #include <OpenAnalysis/IRInterface/CFGIRInterface.hpp>
00036 
00037 namespace OA {
00038   namespace CFG {
00039 
00040 
00041 //--------------------------------------------------------------------
00042 class Worklist;
00043 
00044 
00045 //--------------------------------------------------------------------
00050 class ManagerCFGStandard { //??? eventually public OA::AnnotationManager
00051 public:
00052   ManagerCFGStandard(OA_ptr<CFGIRInterface> _ir, bool _build_stmt_level_cfg = false);
00053   virtual ~ManagerCFGStandard () { }
00054 
00055   //??? don't think this guy need AQM, but will eventually have
00056   //to have one so is standard with other AnnotationManagers
00057   virtual OA_ptr<CFG> performAnalysis(ProcHandle);
00058 
00059 
00060 
00061   //------------------------------------------------------------------
00062   // Exceptions
00063   //------------------------------------------------------------------
00064 /*  class Unexpected_Break : public Exception {
00065   public:
00066     void report (std::ostream& os) const
00067     { os << "E!  Unexpected break statement." << std::endl; }
00068   };
00069   //------------------------------------------------------------------
00070   class Unexpected_Return : public Exception {
00071   public:
00072     void report (std::ostream& os) const
00073     { os << "E!  Unexpected return statement." << std::endl; }
00074   };
00075   //------------------------------------------------------------------
00076   class Unexpected_Continue : public Exception {
00077   public:
00078     void report (std::ostream& os) const
00079     { os << "E!  Unexpected continue statement." << std::endl; }
00080   };
00081   //------------------------------------------------------------------
00082 
00083 */
00084 
00085 private:
00086 
00087   //------------------------------------------------------------------
00088   // Methods that recursively build CFG
00089   //------------------------------------------------------------------
00090     IRStmtType build_block (OA_ptr<Node> prev_node,
00091                             OA_ptr<IRRegionStmtIterator> si,
00092                             std::list<CFG::NodeLabel>& exit_nodes,
00093                             OA_ptr<std::list<CFG::NodeLabel> > break_nodes,
00094                             OA_ptr<std::list<CFG::NodeLabel> > return_nodes,
00095                             OA_ptr<std::list<CFG::NodeLabel> > continue_nodes);
00096 
00097     IRStmtType build_stmt (OA_ptr<Node> prev_node, OA::StmtHandle,
00098                            std::list<CFG::NodeLabel>& exit_nodes,
00099                            OA_ptr<std::list<CFG::NodeLabel> > break_nodes,
00100                            OA_ptr<std::list<CFG::NodeLabel> > return_nodes,
00101                            OA_ptr<std::list<CFG::NodeLabel> > continue_nodes);
00102 
00103 
00104     IRStmtType build_CFG_loop (OA_ptr<Node> prev_node,
00105                                OA::StmtHandle th,
00106                                std::list<CFG::NodeLabel>& exit_nodes,
00107                                OA_ptr<std::list<CFG::NodeLabel> > return_nodes);
00108 
00109     IRStmtType build_CFG_twoway_branch (OA_ptr<Node> prev_node,
00110                                 OA::StmtHandle th,
00111                                 std::list<CFG::NodeLabel>& exit_nodes,
00112                                 OA_ptr<std::list<CFG::NodeLabel> > break_nodes,
00113                                 OA_ptr<std::list<CFG::NodeLabel> > return_nodes,
00114                                 OA_ptr<std::list<CFG::NodeLabel> > continue_nodes);
00115 
00116      IRStmtType build_CFG_multiway_branch (OA_ptr<Node> prev_node,
00117                                 StmtHandle th, std::list<CFG::NodeLabel>& exit_nodes,
00118                                 OA_ptr<std::list<CFG::NodeLabel> > break_nodes,
00119                                 OA_ptr<std::list<CFG::NodeLabel> > return_nodes,
00120                                 OA_ptr<std::list<CFG::NodeLabel> > continue_nodes);
00121                                 
00122       
00123      IRStmtType build_CFG_multiway_branch_with_fallthrough ( OA_ptr<Node> prev_node,
00124                                 StmtHandle th, std::list<CFG::NodeLabel>& exit_nodes,
00125                                 OA_ptr<std::list<CFG::NodeLabel> > return_nodes,
00126                                 OA_ptr<std::list<CFG::NodeLabel> > continue_nodes);
00127           
00128     IRStmtType build_CFG_end_tested_loop (OA_ptr<Node> prev_node,
00129                                 StmtHandle th, std::list<CFG::NodeLabel>& exit_nodes,
00130                                 OA_ptr<std::list<CFG::NodeLabel> > return_nodes);
00131  
00132     IRStmtType build_CFG_unconditional_jump ( OA_ptr<Node> prev_node,
00133                                 StmtHandle stmt);
00134 
00135     IRStmtType build_CFG_ustruct_twoway_branch (OA_ptr<Node>
00136         prev_node, StmtHandle stmt,  std::list<CFG::NodeLabel>& exit_nodes);
00137 
00138 
00139 
00140     IRStmtType build_CFG_unconditional_jump_i ( OA_ptr<Node> prev_node,
00141                                  StmtHandle stmt);
00142 
00143 
00144     IRStmtType build_CFG_ustruct_multiway_branch (OA_ptr<Node>
00145                                  prev_node, StmtHandle stmt);
00146 
00147   //******************************************
00148   // Support for building cfgs with delay slots.
00149   //******************************************
00150   void HandleDelayedBranches();
00151 //  bool isInternalBranch(StmtHandle);
00152 //  void processBlock(OA_ptr<CFGStandard::Node> );
00153   void createBasicCFG();
00154 //  void processBlock();
00155 
00156  
00157 
00158 
00159 private:
00160   OA_ptr<CFGIRInterface> mIR;
00161   OA_ptr<CFG> mCFG;
00162 
00163 
00164   //------------------------------------------
00165   // data structures for handling delay slots
00166   //------------------------------------------
00167   std::map<OA_ptr<Node>, OA_ptr<Node> > mFallThrough;
00168 
00169   //---------------------------------------------------------------
00170   // build a CFG for individual statements rather than basic blocks
00171   //---------------------------------------------------------------
00172   const bool mBuildStmtLevelCFG;
00173    };
00174 
00175   } // end of CFG namespace
00176 } // end of OA namespace
00177 
00178 #endif