Browse Source

[linux-port] Minor changes towards cross-platform compilation. (#1352)

Ehsan 7 years ago
parent
commit
5bf6dd1840

+ 1 - 1
include/dxc/Support/ErrorCodes.h

@@ -17,7 +17,7 @@
 #define DXC_MAKE_HRESULT(sev,fac,code) \
     ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
 
-#define HRESULT_IS_WIN32ERR(hr) ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
+#define HRESULT_IS_WIN32ERR(hr) ((HRESULT)(hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
 #define HRESULT_AS_WIN32ERR(hr) (HRESULT_CODE(hr))
 
 // Error codes from C libraries (0n150) - 0x8096xxxx

+ 4 - 0
include/dxc/Support/Global.h

@@ -129,6 +129,8 @@ template<typename T> T *VerifyNullAndThrow(T *p) {
 }
 #define VNT(__p) VerifyNullAndThrow(__p)
 
+#ifdef _MSC_VER
+
 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(_In_opt_ const char *msg);
 
 inline void OutputDebugBytes(const void *ptr, size_t len) {
@@ -174,6 +176,8 @@ inline void OutputDebugFormatA(_In_ _Printf_format_string_ _Null_terminated_ con
   }
 }
 
+#endif // _MSC_VER
+
 #ifdef DBG
 
 #ifdef _WIN32

+ 28 - 21
include/dxc/Support/microcom.h

@@ -75,18 +75,20 @@ public:
   }
 };
 
-#define DXC_MICROCOM_REF_FIELD(m_dwRef) volatile llvm::sys::cas_flag m_dwRef = 0;
-#define DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
-    ULONG STDMETHODCALLTYPE AddRef() override {\
-        return (ULONG)llvm::sys::AtomicIncrement(&m_dwRef); \
-    }
-#define DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) \
-    DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
-    ULONG STDMETHODCALLTYPE Release() override { \
-        ULONG result = (ULONG)llvm::sys::AtomicDecrement(&m_dwRef); \
-        if (result == 0) delete this; \
-        return result; \
-    }
+#define DXC_MICROCOM_REF_FIELD(m_dwRef)                                        \
+  volatile llvm::sys::cas_flag m_dwRef = 0;
+#define DXC_MICROCOM_ADDREF_IMPL(m_dwRef)                                      \
+  ULONG STDMETHODCALLTYPE AddRef() override {                                  \
+    return (ULONG)llvm::sys::AtomicIncrement(&m_dwRef);                        \
+  }
+#define DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef)                              \
+  DXC_MICROCOM_ADDREF_IMPL(m_dwRef)                                            \
+  ULONG STDMETHODCALLTYPE Release() override {                                 \
+    ULONG result = (ULONG)llvm::sys::AtomicDecrement(&m_dwRef);                \
+    if (result == 0)                                                           \
+      delete this;                                                             \
+    return result;                                                             \
+  }
 
 template <typename T, typename... Args>
 inline T *CreateOnMalloc(IMalloc * pMalloc, Args&&... args) {
@@ -123,15 +125,20 @@ void DxcCallDestructor(T *obj) {
 #define DXC_MICROCOM_TM_CTOR(T)                                                \
   DXC_MICROCOM_TM_CTOR_ONLY(T)                                                 \
   DXC_MICROCOM_TM_ALLOC(T)
-#define DXC_MICROCOM_TM_CTOR_ONLY(T) \
-  T(IMalloc *pMalloc) : m_dwRef(0), m_pMalloc(pMalloc) { }
-#define DXC_MICROCOM_TM_ALLOC(T) \
-  template <typename... Args> \
-  static T* Alloc(IMalloc *pMalloc, Args&&... args) { \
-    void *P = pMalloc->Alloc(sizeof(T)); \
-    try { if (P) new (P)T(pMalloc, std::forward<Args>(args)...); } \
-    catch (...) { pMalloc->Free(P); throw; } \
-    return (T *)P; \
+#define DXC_MICROCOM_TM_CTOR_ONLY(T)                                           \
+  T(IMalloc *pMalloc) : m_dwRef(0), m_pMalloc(pMalloc) {}
+#define DXC_MICROCOM_TM_ALLOC(T)                                               \
+  template <typename... Args>                                                  \
+  static T *Alloc(IMalloc *pMalloc, Args &&... args) {                         \
+    void *P = pMalloc->Alloc(sizeof(T));                                       \
+    try {                                                                      \
+      if (P)                                                                   \
+        new (P) T(pMalloc, std::forward<Args>(args)...);                       \
+    } catch (...) {                                                            \
+      pMalloc->Free(P);                                                        \
+      throw;                                                                   \
+    }                                                                          \
+    return (T *)P;                                                             \
   }
 
 /// <summary>

+ 3 - 3
include/dxc/dxcapi.internal.h

@@ -16,9 +16,9 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 // Forward declarations.
-typedef interface ITextFont ITextFont;
-typedef interface IEnumSTATSTG IEnumSTATSTG;
-typedef interface ID3D10Blob ID3D10Blob;
+typedef struct ITextFont ITextFont;
+typedef struct IEnumSTATSTG IEnumSTATSTG;
+typedef struct ID3D10Blob ID3D10Blob;
 
 ///////////////////////////////////////////////////////////////////////////////
 // Intrinsic definitions.

+ 2 - 2
lib/HLSL/HLOperationLower.cpp

@@ -1886,7 +1886,7 @@ Value *TranslateDot(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
 Value *TranslateReflect(CallInst *CI, IntrinsicOp IOP, OP::OpCode op,
                         HLOperationLowerHelper &helper,  HLObjectOperationLowerHelper *pObjHelper, bool &Translated) {
   hlsl::OP *hlslOP = &helper.hlslOP;
-  //  v = i - 2 * n * dot(in).
+  //  v = i - 2 * n * dot(i, n).
   IRBuilder<> Builder(CI);
   Value *i = CI->getArgOperand(HLOperandIndex::kReflectOpIIdx);
   Value *n = CI->getArgOperand(HLOperandIndex::kReflectOpNIdx);
@@ -1906,7 +1906,7 @@ Value *TranslateReflect(CallInst *CI, IntrinsicOp IOP, OP::OpCode op,
 Value *TranslateRefract(CallInst *CI, IntrinsicOp IOP, OP::OpCode op,
                         HLOperationLowerHelper &helper,  HLObjectOperationLowerHelper *pObjHelper, bool &Translated) {
   hlsl::OP *hlslOP = &helper.hlslOP;
-  //  d = dot(in);
+  //  d = dot(i, n);
   //  t = 1 - eta * eta * ( 1 - d*d);
   //  cond = t >= 1;
   //  r = eta * i - (eta * d + sqrt(t)) * n;

+ 4 - 0
lib/Linker/LinkModules.cpp

@@ -1808,7 +1808,11 @@ LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
 
   if (OutMessages && Result) {
     Stream.flush();
+#ifdef _WIN32
     *OutMessages = _strdup(Message.c_str()); // HLSL Change for strdup
+#else
+    *OutMessages = strdup(Message.c_str());
+#endif
   }
   return Result;
 }

+ 4 - 0
lib/Support/MSFileSystemBasic.cpp

@@ -10,6 +10,8 @@
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifdef _WIN32
+
 #include "dxc/Support/WinIncludes.h"
 #include <fcntl.h>
 #include <io.h>
@@ -1161,3 +1163,5 @@ HRESULT CreateMSFileSystemBlocked(::llvm::sys::fs::MSFileSystem** pResult) throw
   *pResult = new (std::nothrow) ::llvm::sys::fs::MSFileSystemBlocked();
   return (*pResult != nullptr) ? S_OK : E_OUTOFMEMORY;
 }
+
+#endif // _WIN32

+ 8 - 2
lib/Support/regerror.c

@@ -108,8 +108,11 @@ llvm_regerror(int errcode, const llvm_regex_t *preg, _Out_writes_all_(errbuf_siz
 				assert(strlen(r->name) < sizeof(convbuf));
 				(void) llvm_strlcpy(convbuf, r->name, sizeof convbuf);
 			} else
-				//(void)snprintf(convbuf, sizeof convbuf,
+#ifdef _WIN32
 				(void)_snprintf_s(convbuf, _countof(convbuf), _countof(convbuf),
+#else
+				(void)snprintf(convbuf, sizeof convbuf,
+#endif // WIN32
 				    "REG_0x%x", target);
 			s = convbuf;
 		} else
@@ -141,7 +144,10 @@ regatoi(
 	if (r->code == 0)
 		return("0");
 
-	//(void)snprintf(localbuf, localbufsize, "%d", r->code);
+#ifdef _WIN32
 	(void)_snprintf_s(localbuf, localbufsize, localbufsize, "%d", r->code);
+#else
+	(void)snprintf(localbuf, localbufsize, "%d", r->code);
+#endif // WIN32
 	return(localbuf);
 }

+ 1 - 1
tools/clang/include/clang/Frontend/FrontendActions.h

@@ -254,7 +254,7 @@ protected:
   void ExecuteAction() override;
 
 public:
-  HLSLRootSignatureAction(StringRef rootSigMacro, unsigned major,
+  HLSLRootSignatureAction(llvm::StringRef rootSigMacro, unsigned major,
                           unsigned minor);
   /// Take the generated LLVM module, for use after the action has been run.
   /// The result may be null on failure.

+ 8 - 0
tools/clang/lib/Basic/LangOptions.cpp

@@ -16,6 +16,14 @@
 ///////////////////////////////////////////////////////////////////////////////
 using namespace clang;
 
+#ifdef LLVM_ON_UNIX
+#ifndef MS_SUPPORT_VARIABLE_LANGOPTS
+#define LANGOPT(Name, Bits, Default, Description) const unsigned LangOptionsBase::Name;
+#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
+#include "clang/Basic/LangOptions.fixed.def"
+#endif // MS_SUPPORT_VARIABLE_LANGOPTS
+#endif // LLVM_ON_UNIX
+
 LangOptions::LangOptions() {
 #ifdef MS_SUPPORT_VARIABLE_LANGOPTS
 #define LANGOPT(Name, Bits, Default, Description) Name = Default;

+ 1 - 1
tools/clang/tools/dxcompiler/dxcfilesystem.cpp

@@ -364,7 +364,7 @@ public:
     }
     for (unsigned i = 0, e = entries.size(); i != e; ++i) {
       const clang::HeaderSearchOptions::Entry &E = entries[i];
-      if (IsAbsoluteOrCurDirRelative(E.Path.c_str())) {
+      if (dxcutil::IsAbsoluteOrCurDirRelative(E.Path.c_str())) {
         m_searchEntries.emplace_back(Unicode::UTF8ToUTF16StringOrThrow(E.Path.c_str()));
       }
       else {

+ 1 - 1
tools/clang/tools/dxcompiler/dxcutil.cpp

@@ -211,7 +211,7 @@ void CreateOperationResultFromOutputs(
                                                       status, ppResult));
 }
 
-bool IsAbsoluteOrCurDirRelative(const Twine &T) {
+bool IsAbsoluteOrCurDirRelative(const llvm::Twine &T) {
   if (llvm::sys::path::is_absolute(T)) {
     return true;
   }