00001 #ifndef WALI_NWA_NWA_PDS_nwatopds_HPP 00002 #define WALI_NWA_NWA_PDS_nwatopds_HPP 00003 00004 00005 #include "opennwa/NwaFwd.hpp" 00006 #include "wali/wpds/WPDS.hpp" 00007 #include "opennwa/WeightGen.hpp" 00008 00009 #include "opennwa/deprecate.h" 00010 00011 #include <sstream> 00012 00013 namespace opennwa 00014 { 00015 namespace nwa_pds 00016 { 00017 00018 /** 00019 * 00020 * @brief constructs the PDS equivalent to this NWA 00021 * 00022 * This method constructs the PDS that is equivalent to this NWA. 00023 * Note: This version keeps returns on the stack. 00024 * 00025 * @param - wg: the functions to use in generating weights 00026 * @return the PDS equivalent to this NWA 00027 * 00028 */ 00029 extern wali::wpds::WPDS NwaToWpdsReturns( Nwa const & nwa, WeightGen const & wg ); 00030 00031 00032 00033 /** 00034 * 00035 * @brief constructs the backwards PDS equivalent to this NWA 00036 * 00037 * This method constructs the backwards PDS that is equivalent to this NWA. 00038 * Note: This version keeps returns on the stack. 00039 * 00040 * @param - wg: the functions to use in generating weights 00041 * @return the backwards PDS equivalent to this NWA 00042 * 00043 */ 00044 extern 00045 wali::wpds::WPDS 00046 NwaToWpdsCalls( Nwa const & nwa, 00047 WeightGen const & wg, 00048 ref_ptr<wali::wpds::Wrapper> wrapper ); 00049 00050 inline 00051 wali::wpds::WPDS 00052 NwaToWpdsCalls( Nwa const & nwa, WeightGen const & wg ) 00053 { 00054 return NwaToWpdsCalls(nwa, wg, NULL); 00055 } 00056 00057 00058 /** 00059 * 00060 * @brief constructs the PDS equivalent to this NWA 00061 * 00062 * This method constructs the PDS that is equivalent to this NWA. 00063 * Note: This version keeps calls on the stack. 00064 * 00065 * @param - wg: the functions to use in generating weights 00066 * @return the PDS equivalent to this NWA 00067 * 00068 */ 00069 extern wali::wpds::WPDS NwaToBackwardsWpdsReturns( Nwa const & nwa, WeightGen const & wg ); 00070 00071 00072 /** 00073 * 00074 * @brief constructs the backwards PDS equivalent to this NWA 00075 * 00076 * This method constructs the backwards PDS that is equivalent to this NWA. 00077 * Note: This version keeps calls on the stack. 00078 * 00079 * @param - wg: the functions to use in generating weights 00080 * @return the backwards PDS equivalent to this NWA 00081 * 00082 */ 00083 extern wali::wpds::WPDS NwaToBackwardsWpdsCalls( Nwa const & nwa, WeightGen const & wg ); 00084 00085 00086 /** 00087 * 00088 * @brief returns the default program control location for PDSs 00089 * 00090 * This method provides access to the default program control location for PDSs. 00091 * 00092 * @return the default program control location for PDSs 00093 * 00094 */ 00095 inline 00096 wali::Key 00097 getProgramControlLocation( ) 00098 { 00099 static Key key = getKey("program"); 00100 return key; 00101 } 00102 00103 /** 00104 * 00105 * @brief returns the program control location corresponding to the given states 00106 * 00107 * This method provides access to the program control location corresponding to 00108 * the given exit point/call site/return site triple. 00109 * 00110 * @param - exit: the exit point corresponding to this control location 00111 * @param - callSite: the call site corresponding to this control location 00112 * @param - returnSite: the return site corresponding to this control location 00113 * @return the program control location corresponding to the given states 00114 * 00115 */ 00116 inline 00117 wali::Key 00118 getControlLocation( Key exit, Key callSite, Key returnSite ) 00119 { 00120 //std::stringstream ss; 00121 //ss << "(key#" << exit << "," << callSite << "," << returnSite << ")"; 00122 //wali::Key key = getKey(getProgramControlLocation(), getKey(ss.str())); 00123 00124 State key = getKey(getProgramControlLocation(), 00125 getKey(exit, getKey(callSite, returnSite))); 00126 return key; 00127 } 00128 00129 00130 00131 /** 00132 * 00133 * @brief constructs the NWA equivalent to the given PDS 00134 * 00135 * This method constructs the NWA that is equivalent to the given 00136 * PDS. The NWA's state space tracks both the PDS's state and top stack 00137 * symbol; the NWA's "stack" tracks the remainder of the PDS's stack. 00138 * The symbol on each transition is the from_stack portion of the 00139 * corresponding PDS rule. 00140 * 00141 * 00142 * Let the PDS be (P, G, D). The NWA we create is (Q, Q_0, d, Q_f); d 00143 * is split up into the usual (for NWAs) components d_i, d_c, and d_r. 00144 * - Q = P x G (Tracking the PDS state + top stack symbol) 00145 * - d_i = { ((q,a), a, (q',a')) | <q, a> -> <q', a'> in D } 00146 * - d_c = { ((q,a), a, (q',b)) | <q, a> -> <q', b a'> in D } 00147 * - d_r = { ((q,a), (p,b), a, (q',a')) | <q, a> -> <q', *> in D and 00148 * <p, b> -> <_, _ a'> in D } 00149 * 00150 * The last rule is a little funky in a couple ways. First, it has two 00151 * conditions because the pop rule doesn't let you know what's on the 00152 * top of the stack, and we need to figure that out from the 00153 * corresponding push rule. 00154 * 00155 * Second, note that the push rules we look at in the condition is 00156 * totally unconstrained. This is because, with the exception of the 00157 * "revealed" stack symbol a', everything that the push rule talks 00158 * about concerns the call predecessor (p,b) and entry node (_,_); 00159 * nothing the pop rule talks about -- q, a, or q' -- has any relation 00160 * to those. 00161 * 00162 * This last fact means that the NWA we construct can potentially have 00163 * quadratically-many rules as the input PDS. If the PDS has M push 00164 * rules and N pop rules, the NWA will have M*N return transitions. 00165 * 00166 * @param - pds: the pds to convert 00167 * @return the NWA equivalent to the given PDS 00168 * 00169 */ 00170 void WpdsToNwa( Nwa & out, const wali::wpds::WPDS & pds ); 00171 00172 /** 00173 * 00174 * @brief constructs the NWA equivalent to the given PDS 00175 * 00176 * This method constructs the NWA that is equivalent to the given PDS. 00177 * 00178 * @param - pds: the pds to convert 00179 * @param - stuck: dummy parameter 00180 * @return the NWA equivalent to the given PDS 00181 * 00182 */ 00183 NwaRefPtr WpdsToNwa( const wali::wpds::WPDS & pds ); 00184 00185 } // namespace nwa_pds 00186 } 00187 00188 00189 // Yo, Emacs! 00190 // Local Variables: 00191 // c-file-style: "ellemtel" 00192 // c-basic-offset: 2 00193 // End: 00194 00195 #endif