winadapter.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //===- WinAdapter.h - Windows Adapter for non-Windows platforms -*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines Windows-specific types, macros, and SAL annotations used
  11. // in the codebase for non-Windows platforms.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_WIN_ADAPTER_H
  15. #define LLVM_SUPPORT_WIN_ADAPTER_H
  16. #ifndef _WIN32
  17. #include "../wsl/winadapter.h"
  18. constexpr uint8_t nybble_from_hex(char c) {
  19. return ((c >= '0' && c <= '9')
  20. ? (c - '0')
  21. : ((c >= 'a' && c <= 'f')
  22. ? (c - 'a' + 10)
  23. : ((c >= 'A' && c <= 'F') ? (c - 'A' + 10)
  24. : /* Should be an error */ -1)));
  25. }
  26. constexpr uint8_t byte_from_hex(char c1, char c2) {
  27. return nybble_from_hex(c1) << 4 | nybble_from_hex(c2);
  28. }
  29. constexpr uint8_t byte_from_hexstr(const char str[2]) {
  30. return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]);
  31. }
  32. constexpr GUID guid_from_string(const char str[37]) {
  33. return GUID{static_cast<uint32_t>(byte_from_hexstr(str)) << 24 |
  34. static_cast<uint32_t>(byte_from_hexstr(str + 2)) << 16 |
  35. static_cast<uint32_t>(byte_from_hexstr(str + 4)) << 8 |
  36. byte_from_hexstr(str + 6),
  37. static_cast<uint16_t>(
  38. static_cast<uint16_t>(byte_from_hexstr(str + 9)) << 8 |
  39. byte_from_hexstr(str + 11)),
  40. static_cast<uint16_t>(
  41. static_cast<uint16_t>(byte_from_hexstr(str + 14)) << 8 |
  42. byte_from_hexstr(str + 16)),
  43. {byte_from_hexstr(str + 19), byte_from_hexstr(str + 21),
  44. byte_from_hexstr(str + 24), byte_from_hexstr(str + 26),
  45. byte_from_hexstr(str + 28), byte_from_hexstr(str + 30),
  46. byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)}};
  47. }
  48. template <typename XX> inline GUID __emulated_uuidof();
  49. #define CROSS_PLATFORM_UUIDOF(interface, spec) \
  50. struct interface; \
  51. template <> inline GUID __emulated_uuidof<interface>() { \
  52. static const IID _IID = guid_from_string(spec); \
  53. return _IID; \
  54. }
  55. typedef wchar_t *BSTR;
  56. CROSS_PLATFORM_UUIDOF(INoMarshal, "ECC8691B-C1DB-4DC0-855E-65F6C551AF49")
  57. struct INoMarshal : public IUnknown {};
  58. CROSS_PLATFORM_UUIDOF(IMalloc, "00000002-0000-0000-C000-000000000046")
  59. struct IMalloc : public IUnknown {
  60. virtual void *Alloc(SIZE_T size) = 0;
  61. virtual void *Realloc(void *ptr, SIZE_T size) = 0;
  62. virtual void Free(void *ptr) = 0;
  63. virtual SIZE_T GetSize(void *pv) = 0;
  64. virtual int DidAlloc(void *pv) = 0;
  65. virtual void HeapMinimize(void) = 0;
  66. };
  67. CROSS_PLATFORM_UUIDOF(ISequentialStream, "0C733A30-2A1C-11CE-ADE5-00AA0044773D")
  68. struct ISequentialStream : public IUnknown {
  69. virtual HRESULT Read(void *pv, ULONG cb, ULONG *pcbRead) = 0;
  70. virtual HRESULT Write(const void *pv, ULONG cb, ULONG *pcbWritten) = 0;
  71. };
  72. CROSS_PLATFORM_UUIDOF(IStream, "0000000c-0000-0000-C000-000000000046")
  73. struct IStream : public ISequentialStream {
  74. virtual HRESULT Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin,
  75. ULARGE_INTEGER *plibNewPosition) = 0;
  76. virtual HRESULT SetSize(ULARGE_INTEGER libNewSize) = 0;
  77. virtual HRESULT CopyTo(IStream *pstm, ULARGE_INTEGER cb,
  78. ULARGE_INTEGER *pcbRead,
  79. ULARGE_INTEGER *pcbWritten) = 0;
  80. virtual HRESULT Commit(DWORD grfCommitFlags) = 0;
  81. virtual HRESULT Revert(void) = 0;
  82. virtual HRESULT LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,
  83. DWORD dwLockType) = 0;
  84. virtual HRESULT UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb,
  85. DWORD dwLockType) = 0;
  86. virtual HRESULT Stat(STATSTG *pstatstg, DWORD grfStatFlag) = 0;
  87. virtual HRESULT Clone(IStream **ppstm) = 0;
  88. };
  89. // These don't need stub implementations as they come from the DirectX Headers
  90. // They still need the __uuidof() though
  91. CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection,
  92. "8E349D19-54DB-4A56-9DC9-119D87BDB804")
  93. CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection,
  94. "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E")
  95. #endif // !WIN32
  96. #endif // LLVM_SUPPORT_WIN_ADAPTER_H