Переглянути джерело

Move CreateOperationResultFromOutputs to dxcutil. (#361)

Xiang Li 8 роки тому
батько
коміт
19fc777bd4

+ 4 - 14
tools/clang/tools/dxcompiler/dxcompilerobj.cpp

@@ -790,19 +790,9 @@ static void CreateOperationResultFromOutputs(
   CComPtr<IStream> pErrorStream;
   CComPtr<IDxcBlobEncoding> pErrorBlob;
   msfPtr->GetStreamForHandle(StdOutHandle.Handle, &pErrorStream);
-  if (pErrorStream != nullptr) {
-    CComPtr<IDxcBlob> pErrorStreamBlob;
-    IFT(pErrorStream.QueryInterface(&pErrorStreamBlob));
-    IFT(DxcCreateBlobWithEncodingSet(pErrorStreamBlob, CP_UTF8, &pErrorBlob));
-  }
-  if (IsBlobNullOrEmpty(pErrorBlob)) {
-    pErrorBlob.Release();
-    IFT(DxcCreateBlobWithEncodingOnHeapCopy(warnings.c_str(), warnings.size(),
-                                            CP_UTF8, &pErrorBlob));
-  }
 
-  HRESULT status = diags.hasErrorOccurred() ? E_FAIL : S_OK;
-  IFT(DxcOperationResult::CreateFromResultErrorStatus(pResultBlob, pErrorBlob, status, ppResult));
+  dxcutil::CreateOperationResultFromOutputs(pResultBlob, pErrorStream, warnings,
+                                            diags.hasErrorOccurred(), ppResult);
 }
 
 static void CreateOperationResultFromOutputs(
@@ -811,10 +801,10 @@ static void CreateOperationResultFromOutputs(
     _COM_Outptr_ IDxcOperationResult **ppResult) {
   CComPtr<IDxcBlob> pResultBlob;
   IFT(pOutputStream->QueryInterface(&pResultBlob));
-  CreateOperationResultFromOutputs(pResultBlob, msfPtr, warnings, diags, ppResult);
+  CreateOperationResultFromOutputs(pResultBlob, msfPtr, warnings, diags,
+                                   ppResult);
 }
 
-
 class HLSLExtensionsCodegenHelperImpl : public HLSLExtensionsCodegenHelper {
 private:
   CompilerInstance &m_CI;

+ 23 - 0
tools/clang/tools/dxcompiler/dxcutil.cpp

@@ -22,6 +22,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Utils/Cloning.h"
+#include "dxc/Support/dxcapi.impl.h"
 
 using namespace llvm;
 using namespace hlsl;
@@ -173,4 +174,26 @@ HRESULT ValidateAndAssembleToContainer(
   return valHR;
 }
 
+void CreateOperationResultFromOutputs(
+    IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream,
+    const std::string &warnings, bool hasErrorOccurred,
+    _COM_Outptr_ IDxcOperationResult **ppResult) {
+  CComPtr<IDxcBlobEncoding> pErrorBlob;
+
+  if (pErrorStream != nullptr) {
+    CComPtr<IDxcBlob> pErrorStreamBlob;
+    IFT(pErrorStream.QueryInterface(&pErrorStreamBlob));
+    IFT(DxcCreateBlobWithEncodingSet(pErrorStreamBlob, CP_UTF8, &pErrorBlob));
+  }
+  if (IsBlobNullOrEmpty(pErrorBlob)) {
+    pErrorBlob.Release();
+    IFT(DxcCreateBlobWithEncodingOnHeapCopy(warnings.c_str(), warnings.size(),
+                                            CP_UTF8, &pErrorBlob));
+  }
+
+  HRESULT status = hasErrorOccurred ? E_FAIL : S_OK;
+  IFT(DxcOperationResult::CreateFromResultErrorStatus(pResultBlob, pErrorBlob,
+                                                      status, ppResult));
+}
+
 } // namespace dxcutil

+ 5 - 0
tools/clang/tools/dxcompiler/dxcutil.h

@@ -43,4 +43,9 @@ void AssembleToContainer(std::unique_ptr<llvm::Module> pM,
                          hlsl::SerializeDxilFlags SerializeFlags,
                          CComPtr<hlsl::AbstractMemoryStream> &pModuleBitcode);
 HRESULT Disassemble(IDxcBlob *pProgram, llvm::raw_string_ostream &Stream);
+
+void CreateOperationResultFromOutputs(
+    IDxcBlob *pResultBlob, CComPtr<IStream> &pErrorStream,
+    const std::string &warnings, bool hasErrorOccurred,
+    _COM_Outptr_ IDxcOperationResult **ppResult);
 } // namespace dxcutil

+ 1 - 1
tools/clang/unittests/HLSL/DxcTestUtils.h

@@ -101,7 +101,7 @@ inline std::string BlobToUtf8(_In_ IDxcBlob *pBlob) {
 std::wstring BlobToUtf16(_In_ IDxcBlob *pBlob);
 void CheckOperationSucceeded(IDxcOperationResult *pResult, IDxcBlob **ppBlob);
 bool CheckOperationResultMsgs(IDxcOperationResult *pResult,
-                              LPCSTR *pErrorMsgs, size_t errorMsgCount,
+                              const LPCSTR *pErrorMsgs, size_t errorMsgCount,
                               bool maySucceedAnyway, bool bRegex);
 std::string DisassembleProgram(dxc::DxcDllSupport &dllSupport, IDxcBlob *pProgram);
 void Utf8ToBlob(dxc::DxcDllSupport &dllSupport, const std::string &val, _Outptr_ IDxcBlob **ppBlob);

+ 3 - 3
tools/clang/unittests/HLSL/ValidationTest.cpp

@@ -78,9 +78,9 @@ bool CheckOperationResultMsgs(IDxcOperationResult *pResult,
   return true;
 }
 
-bool CheckOperationResultMsgs(IDxcOperationResult *pResult, LPCSTR *pErrorMsgs,
-                              size_t errorMsgCount, bool maySucceedAnyway,
-                              bool bRegex) {
+bool CheckOperationResultMsgs(IDxcOperationResult *pResult,
+                              const LPCSTR *pErrorMsgs, size_t errorMsgCount,
+                              bool maySucceedAnyway, bool bRegex) {
   return CheckOperationResultMsgs(
       pResult, llvm::ArrayRef<LPCSTR>(pErrorMsgs, errorMsgCount),
       maySucceedAnyway, bRegex);