<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">hume npx</b> <span dir="ltr"><<a href="mailto:humeafo@gmail.com">humeafo@gmail.com</a>></span><br>Date: 2011/6/15<br>
Subject: a windows pass registration patch<br>To: <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><br><br><div>Is this the right place to commit the patch?</div>This patch make loadable pass on windows possible, because I'm new to llvm, so it maybe incomplete, but the similar method can be implemented to support windows loadable pass. the patch try not to break anything when not run on windows, tested under msvc 10, under mingw should also work, this require loadable pass module to define a macro when compiling, corresponding cmake files is not corrected, but if this is accepted, I'd like to work on similar problems.<div>

<div><div><br></div><div>------------------------------------------------------------------------------------------------------------------------</div><div><br></div><div><div>Index: include/llvm/PassRegistry.h</div><div>

<br></div><div>===================================================================</div><div><br></div><div>--- include/llvm/PassRegistry.h<span style="white-space:pre-wrap">  </span>(revision 133049)</div>
<div><br></div><div>+++ include/llvm/PassRegistry.h<span style="white-space:pre-wrap">  </span>(working copy)</div><div><br></div><div>@@ -41,7 +41,7 @@</div><div><br></div><div>   /// getPassRegistry - Access the global registry object, which is </div>

<div>   /// automatically initialized at application launch and destroyed by</div><div>   /// llvm_shutdown.</div><div>-  static PassRegistry *getPassRegistry();</div><div>+  static PassRegistry *getPassRegistry(bool sharedPass=false);</div>

<div>   </div><div>   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'</div><div>   /// type identifier (&MyPass::ID).</div><div>Index: include/llvm/PassSupport.h</div><div><br></div>

<div>===================================================================</div><div><br></div><div>--- include/llvm/PassSupport.h<span style="white-space:pre-wrap"> </span>(revision 133049)</div><div><br>
</div><div>+++ include/llvm/PassSupport.h<span style="white-space:pre-wrap">        </span>(working copy)</div><div><br></div><div>@@ -194,7 +194,13 @@</div><div><br></div><div> ///</div><div> /// static RegisterPass<PassClassName> tmp("passopt", "My Name");</div>

<div> ///</div><div>-template<typename passName></div><div>+template<typename passName, bool bSharedPass=</div><div>+#if defined(_WIN32) && defined(LLVM_SHARED_PASS)</div><div>+  true</div><div>+#else</div>

<div>+  false</div><div>+#endif</div><div>+></div><div> struct RegisterPass : public PassInfo {</div><div> </div><div>   // Register Pass using default constructor...</div><div>@@ -203,7 +209,7 @@</div><div><br></div>
<div>
     : PassInfo(Name, PassArg, &passName::ID,</div><div>                PassInfo::NormalCtor_t(callDefaultCtor<passName>),</div><div>                CFGOnly, is_analysis) {</div><div>-    PassRegistry::getPassRegistry()->registerPass(*this);</div>

<div>+    PassRegistry::getPassRegistry(bSharedPass)->registerPass(*this);</div><div>   }</div><div> };</div><div> </div><div>Index: lib/VMCore/PassRegistry.cpp</div><div><br></div><div>===================================================================</div>

<div><br></div><div>--- lib/VMCore/PassRegistry.cpp<span style="white-space:pre-wrap">  </span>(revision 133049)</div><div><br></div><div>+++ lib/VMCore/PassRegistry.cpp<span style="white-space:pre-wrap">        </span>(working copy)</div>

<div><br></div><div>@@ -30,7 +30,29 @@</div><div><br></div><div> // llvm_shutdown is run.  Ideally we should find a solution so that we don't</div><div> // leak the map, AND can still resurrect after shutdown.</div><div>

 static ManagedStatic<PassRegistry> PassRegistryObj;</div><div>-PassRegistry *PassRegistry::getPassRegistry() {</div><div>+#if defined(_WIN32) </div><div>+  #include <tchar.h></div><div>+  #include <windows.h></div>

<div>+  typedef PassRegistry* (*getPassRegistryPortablePtr)();</div><div>+  extern "C" __declspec(dllexport) llvm::PassRegistry *lapi_getPassRegistryPortable() {return &*PassRegistryObj;}</div><div>+#endif</div>

<div>+</div><div>+PassRegistry *PassRegistry::getPassRegistry(bool sharedPass) {</div><div>+#if defined(_WIN32)</div><div>+  std::vector<TCHAR> buf(MAX_PATH+1);</div><div>+  if (sharedPass) {</div><div>+    DWORD nSiz = GetModuleFileName(NULL, &buf[0], MAX_PATH);</div>

<div>+    if (nSiz) {</div><div>+      buf[nSiz] = 0;</div><div>+      HMODULE hMain = 0;</div><div>+      getPassRegistryPortablePtr pGetPassRegistryPortable = 0;</div><div>+      if ((hMain=LoadLibrary(&buf[0])) && </div>

<div>+          (pGetPassRegistryPortable=(getPassRegistryPortablePtr)GetProcAddress(hMain, _T("lapi_getPassRegistryPortable")))) {</div><div>+            return (*pGetPassRegistryPortable)();</div><div>+      }</div>

<div>+    }   </div><div>+  }</div><div>+#endif  </div><div>   return &*PassRegistryObj;</div><div> }</div><div> </div></div><div><br></div></div></div>
</div><br>