Phi.hpp

Go to the documentation of this file.
00001 
00015 #ifndef OA_PHI_H
00016 #define OA_PHI_H
00017 
00018 //-----------------------------------------------------------------------------
00019 
00020 #include <iostream>
00021 
00022 // STL headers
00023 #include <map>
00024 
00025 // OpenAnalysis headers
00026 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00027 #include <OpenAnalysis/CFG/CFGInterface.hpp>
00028 #include <OpenAnalysis/Utils/Iterator.hpp>
00029 #include <OpenAnalysis/Utils/Exception.hpp>
00030 
00031 //-----------------------------------------------------------------------------
00032 
00033 namespace OA {
00034   namespace SSA {
00035 
00036 //-----------------------------------------------------------------------------
00037 class Phi {
00038 
00039 public:
00040   class ArgIterator;
00041   friend class ArgIterator;
00042 
00043   //--------------------------------------------------------------------
00044   class ArgIterator : public Iterator {
00045   public:
00046     ArgIterator(const Phi& p) 
00047       : center(const_cast<Phi&>(p)), iter(center.args.begin()) { }
00048     ~ArgIterator() { }
00049     
00050     OA_ptr<CFG::NodeInterface> currentSrc() const { return (*iter).first; }
00051     LeafHandle                   currentTarg() const { return (*iter).second; }
00052     bool isValid() const { return (iter != center.args.end()); }
00053     
00054     void operator++() { ++iter; }
00055     void reset() { iter = center.args.begin(); }
00056     
00057   private:
00058     Phi& center;
00059     std::map<OA_ptr<CFG::NodeInterface>, LeafHandle>::iterator iter;
00060   };
00061   //--------------------------------------------------------------------
00062 
00063 public:
00064   Phi(const SymHandle& var_name, OA_ptr<CFG::CFGInterface> cfg_)
00065     : sym(var_name), cfg(cfg_) { }
00066   ~Phi() { }
00067   
00068   void add_arg(OA_ptr<CFG::NodeInterface> c_n, LeafHandle a_n) 
00069     { args[c_n] = a_n; }
00070   LeafHandle arg(OA_ptr<CFG::NodeInterface> n) { return args[n]; }
00071   int num_args() { return args.size(); }
00072 
00073   bool operator==(Phi& other) { return &other == this; }
00074   bool operator<(Phi& other) { return this < &other; }
00075   
00076   void dump(std::ostream&);
00077   
00078   //-------------------------------------
00079   // Iterators
00080   //-------------------------------------
00081   OA_ptr<ArgIterator> getArgIterator() const {
00082     OA_ptr<ArgIterator> it; it = new ArgIterator(*this);
00083     return it;
00084   }
00085 
00086 private:
00087   SymHandle sym;
00088   OA_ptr<CFG::CFGInterface> cfg;
00089   
00090   std::map<OA_ptr<CFG::NodeInterface>, LeafHandle> args;
00091 };
00092 //-----------------------------------------------------------------------------
00093 
00094   } // end of SSA namespace
00095 } // end of OA namespace
00096 
00097 #endif