ソースを参照

Added an internal interface to set a compiler on PdbUtils. (#3452)

Adam Yang 4 年 前
コミット
38e4ec9593
2 ファイル変更28 行追加15 行削除
  1. 2 0
      include/dxc/dxcapi.h
  2. 26 15
      tools/clang/tools/dxcompiler/dxcpdbutils.cpp

+ 2 - 0
include/dxc/dxcapi.h

@@ -603,6 +603,8 @@ struct IDxcPdbUtils : public IUnknown {
   virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) = 0;
 
   virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
+
+  virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
 };
 
 // Note: __declspec(selectany) requires 'extern'

+ 26 - 15
tools/clang/tools/dxcompiler/dxcpdbutils.cpp

@@ -26,6 +26,7 @@
 #include "llvm/Support/raw_ostream.h"
 
 #include "dxc/dxcapi.h"
+#include "dxc/dxcapi.internal.h"
 #include "dxc/dxcpix.h"
 #include "dxc/Support/microcom.h"
 #include "dxc/DxilContainer/DxilContainer.h"
@@ -260,6 +261,10 @@ private:
   std::string m_VersionCommitSha;
   std::string m_VersionString;
 
+  // NOTE: This is not set to null by Reset() since it doesn't
+  // necessarily change across different PDBs.
+  CComPtr<IDxcCompiler3> m_pCompiler;
+
   struct ArgPair {
     std::wstring Name;
     std::wstring Value;
@@ -570,24 +575,25 @@ public:
   }
 
   HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pPdbOrDxil) override {
-    DxcThreadMalloc TM(m_pMalloc);
-
-    ::llvm::sys::fs::MSFileSystem *msfPtr = nullptr;
-    IFT(CreateMSFileSystemForDisk(&msfPtr));
-    std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
-  
-    ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get());
-    IFTLLVM(pts.error_code());
 
     if (!pPdbOrDxil)
       return E_POINTER;
 
-    // Remove all the data
-    Reset();
+    try {
+      DxcThreadMalloc TM(m_pMalloc);
 
-    m_InputBlob = pPdbOrDxil;
+      ::llvm::sys::fs::MSFileSystem *msfPtr = nullptr;
+      IFT(CreateMSFileSystemForDisk(&msfPtr));
+      std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
+
+      ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get());
+      IFTLLVM(pts.error_code());
+
+      // Remove all the data
+      Reset();
+
+      m_InputBlob = pPdbOrDxil;
 
-    try {
       CComPtr<IStream> pStream;
       IFR(hlsl::CreateReadOnlyBlobStream(pPdbOrDxil, &pStream));
 
@@ -715,8 +721,8 @@ public:
       return m_InputBlob.QueryInterface(ppFullPDB);
     }
 
-    CComPtr<IDxcCompiler3> pCompiler;
-    IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&pCompiler)));
+    if (!m_pCompiler)
+      IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&m_pCompiler)));
 
     DxcThreadMalloc TM(m_pMalloc);
 
@@ -754,7 +760,7 @@ public:
     IFR(main_file->GetEncoding(&bEndodingKnown, &source_buf.Encoding));
 
     CComPtr<IDxcResult> pResult;
-    IFR(pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&pResult)));
+    IFR(m_pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&pResult)));
 
     CComPtr<IDxcOperationResult> pOperationResult;
     IFR(pResult.QueryInterface(&pOperationResult));
@@ -832,6 +838,11 @@ public:
     *ppVersionInfo = result.Detach();
     return S_OK;
   }
+
+  virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) override {
+    m_pCompiler = pCompiler;
+    return S_OK;
+  }
 };
 
 HRESULT CreateDxcPdbUtils(_In_ REFIID riid, _Out_ LPVOID *ppv) {