chromium/third_party/dawn/third_party/dxc/include/dxc/WinAdapter.h

//===- WinAdapter.h - Windows Adapter for non-Windows platforms -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines Windows-specific types, macros, and SAL annotations used
// in the codebase for non-Windows platforms.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_SUPPORT_WIN_ADAPTER_H
#define LLVM_SUPPORT_WIN_ADAPTER_H

#ifndef _WIN32

#ifdef __cplusplus
#include <atomic>
#include <cassert>
#include <climits>
#include <cstring>
#include <cwchar>
#include <fstream>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>
#endif // __cplusplus

#define COM_NO_WINDOWS_H

//===----------------------------------------------------------------------===//
//
//                             Begin: Macro Definitions
//
//===----------------------------------------------------------------------===//
#define C_ASSERT(expr)
#define ATLASSERT

#define CoTaskMemAlloc
#define CoTaskMemFree

#define ARRAYSIZE(array)

#define _countof(a)

// If it is GCC, there is no UUID support and we must emulate it.
#ifndef __clang__
#define __EMULATE_UUID
#endif // __clang__

#ifdef __EMULATE_UUID
#define __declspec(x)
#endif // __EMULATE_UUID

#define DECLSPEC_SELECTANY

#ifdef __EMULATE_UUID
#define uuid(id)
#endif // __EMULATE_UUID

#define STDMETHODCALLTYPE
#define STDMETHODIMP_(type)
#define STDMETHODIMP
#define STDMETHOD_(type, name)
#define STDMETHOD(name)
#define EXTERN_C

#define UNREFERENCED_PARAMETER(P)

#define RtlEqualMemory(Destination, Source, Length)
#define RtlMoveMemory(Destination, Source, Length)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlFillMemory(Destination, Length, Fill)
#define RtlZeroMemory(Destination, Length)
#define MoveMemory
#define CopyMemory
#define FillMemory
#define ZeroMemory

#define FALSE
#define TRUE

// We ignore the code page completely on Linux.
#define GetConsoleOutputCP()

#define _HRESULT_TYPEDEF_(_sc)
#define DISP_E_BADINDEX
#define REGDB_E_CLASSNOTREG

// This is an unsafe conversion. If needed, we can later implement a safe
// conversion that throws exceptions for overflow cases.
#define UIntToInt(uint_arg, int_ptr_arg)

#define INVALID_HANDLE_VALUE

// Use errno to implement {Get|Set}LastError
#define GetLastError()
#define SetLastError(ERR)

// Map these errors to equivalent errnos.
#define ERROR_SUCCESS
#define ERROR_ARITHMETIC_OVERFLOW
#define ERROR_FILE_NOT_FOUND
#define ERROR_FUNCTION_NOT_CALLED
#define ERROR_IO_DEVICE
#define ERROR_INSUFFICIENT_BUFFER
#define ERROR_INVALID_HANDLE
#define ERROR_INVALID_PARAMETER
#define ERROR_OUT_OF_STRUCTURES
#define ERROR_NOT_CAPABLE
#define ERROR_NOT_FOUND
#define ERROR_UNHANDLED_EXCEPTION
#define ERROR_BROKEN_PIPE

// Used by HRESULT <--> WIN32 error code conversion
#define SEVERITY_ERROR
#define FACILITY_WIN32
#define HRESULT_CODE(hr)
#define MAKE_HRESULT(severity, facility, code)

#define FILE_TYPE_UNKNOWN
#define FILE_TYPE_DISK
#define FILE_TYPE_CHAR
#define FILE_TYPE_PIPE
#define FILE_TYPE_REMOTE

#define FILE_ATTRIBUTE_NORMAL
#define FILE_ATTRIBUTE_DIRECTORY
#define INVALID_FILE_ATTRIBUTES

#define STDOUT_FILENO
#define STDERR_FILENO

// STGTY ENUMS
#define STGTY_STORAGE
#define STGTY_STREAM
#define STGTY_LOCKBYTES
#define STGTY_PROPERTY

// Storage errors
#define STG_E_INVALIDFUNCTION
#define STG_E_ACCESSDENIED

#define STREAM_SEEK_SET
#define STREAM_SEEK_CUR
#define STREAM_SEEK_END

#define HEAP_NO_SERIALIZE
#define HEAP_ZERO_MEMORY

#define MB_ERR_INVALID_CHARS

// File IO

#define CREATE_ALWAYS
#define CREATE_NEW
#define OPEN_ALWAYS
#define OPEN_EXISTING
#define TRUNCATE_EXISTING

#define FILE_SHARE_DELETE
#define FILE_SHARE_READ
#define FILE_SHARE_WRITE

#define GENERIC_READ
#define GENERIC_WRITE

#define _atoi64
#define sprintf_s
#define _strdup
#define _strnicmp

#define vsnprintf_s
#define strcat_s
#define strcpy_s(dst, n, src)
#define _vscwprintf
#define vswprintf_s
#define swprintf_s

#define StringCchCopyW(dst, n, src)

#define OutputDebugStringW(msg)

#define OutputDebugStringA(msg)
#define OutputDebugFormatA(...)

// Event Tracing for Windows (ETW) provides application programmers the ability
// to start and stop event tracing sessions, instrument an application to
// provide trace events, and consume trace events.
#define DxcEtw_DXCompilerCreateInstance_Start()
#define DxcEtw_DXCompilerCreateInstance_Stop(hr)
#define DxcEtw_DXCompilerCompile_Start()
#define DxcEtw_DXCompilerCompile_Stop(hr)
#define DxcEtw_DXCompilerDisassemble_Start()
#define DxcEtw_DXCompilerDisassemble_Stop(hr)
#define DxcEtw_DXCompilerPreprocess_Start()
#define DxcEtw_DXCompilerPreprocess_Stop(hr)
#define DxcEtw_DxcValidation_Start()
#define DxcEtw_DxcValidation_Stop(hr)

#define UInt32Add
#define Int32ToUInt32

//===--------------------- HRESULT Related Macros -------------------------===//

#define S_OK
#define S_FALSE

#define E_ABORT
#define E_ACCESSDENIED
#define E_BOUNDS
#define E_FAIL
#define E_HANDLE
#define E_INVALIDARG
#define E_NOINTERFACE
#define E_NOTIMPL
#define E_NOT_VALID_STATE
#define E_OUTOFMEMORY
#define E_POINTER
#define E_UNEXPECTED

#define SUCCEEDED(hr)
#define FAILED(hr)
#define DXC_FAILED(hr)

#define HRESULT_FROM_WIN32(x)

//===----------------------------------------------------------------------===//
//
//                         Begin: Disable SAL Annotations
//
//===----------------------------------------------------------------------===//
#define _In_
#define _In_z_
#define _In_opt_
#define _In_opt_count_(size)
#define _In_opt_z_
#define _In_count_(size)
#define _In_bytecount_(size)

#define _Out_
#define _Out_opt_
#define _Outptr_
#define _Outptr_opt_
#define _Outptr_result_z_
#define _Outptr_opt_result_z_
#define _Outptr_result_maybenull_
#define _Outptr_result_nullonfailure_
#define _Outptr_result_buffer_maybenull_(ptr)
#define _Outptr_result_buffer_(ptr)

#define _COM_Outptr_
#define _COM_Outptr_opt_
#define _COM_Outptr_result_maybenull_
#define _COM_Outptr_opt_result_maybenull_

#define THIS_
#define THIS
#define PURE

#define _Maybenull_

#define __debugbreak()

// GCC produces erros on calling convention attributes.
#ifdef __GNUC__
#define __cdecl
#define __CRTDECL
#define __stdcall
#define __vectorcall
#define __thiscall
#define __fastcall
#define __clrcall
#endif // __GNUC__

//===----------------------------------------------------------------------===//
//
//                             Begin: Type Definitions
//
//===----------------------------------------------------------------------===//

#ifdef __cplusplus

UINT8;
LPBYTE;

BOOLEAN;
PBOOLEAN;

BOOL;
LPBOOL;

INT;
LONG;
UINT;
ULONG;
LONGLONG;
LONG_PTR;
ULONG_PTR;
ULONGLONG;

WORD;
DWORD;
LPDWORD;

UINT32;
UINT64;

PINT8;
PINT32;

SIZE_T;
LPCSTR;
PCSTR;

errno_t;

WCHAR;
LPWSTR;
PWCHAR;
LPCWSTR;
PCWSTR;

OLECHAR;
BSTR;
LPOLESTR;
LPSTR;

LPVOID;
LPCVOID;

nullptr_t;

HRESULT;

//===--------------------- Handle Types -----------------------------------===//

HANDLE;
RPC_IF_HANDLE;

#define DECLARE_HANDLE(name)
DECLARE_HANDLE();

HMODULE;

#define STD_INPUT_HANDLE
#define STD_OUTPUT_HANDLE
#define STD_ERROR_HANDLE

//===--------------------- ID Types and Macros for COM --------------------===//

#ifdef __EMULATE_UUID
struct GUID
#else  // __EMULATE_UUID
// These specific definitions are required by clang -fms-extensions.
typedef struct _GUID
#endif // __EMULATE_UUID
{}
#ifdef __EMULATE_UUID
;
#else  // __EMULATE_UUID
GUID;
#endif // __EMULATE_UUID
CLSID;
REFGUID;
REFCLSID;

IID;
LPIID;
REFIID;
inline bool IsEqualGUID(REFGUID rguid1, REFGUID rguid2) {}

inline bool operator==(REFGUID guidOne, REFGUID guidOther) {}

inline bool operator!=(REFGUID guidOne, REFGUID guidOther) {}

inline bool IsEqualIID(REFIID riid1, REFIID riid2) {}

inline bool IsEqualCLSID(REFCLSID rclsid1, REFCLSID rclsid2) {}

//===--------------------- Struct Types -----------------------------------===//

LPFILETIME;

LPBY_HANDLE_FILE_INFORMATION;

LPWIN32_FIND_DATAW;

LARGE_INTEGER;

PLARGE_INTEGER;

ULARGE_INTEGER;

PULARGE_INTEGER;

STATSTG;

enum tagSTATFLAG {};

//===--------------------- UUID Related Macros ----------------------------===//

#ifdef __EMULATE_UUID

// The following macros are defined to facilitate the lack of 'uuid' on Linux.

constexpr uint8_t nybble_from_hex(char c) {}

constexpr uint8_t byte_from_hex(char c1, char c2) {}

constexpr uint8_t byte_from_hexstr(const char str[2]) {}

constexpr GUID guid_from_string(const char str[37]) {}

template <typename interface> inline GUID __emulated_uuidof();

#define CROSS_PLATFORM_UUIDOF(interface, spec)

#define __uuidof(T)

#define IID_PPV_ARGS(ppType)

#else // __EMULATE_UUID

#ifndef CROSS_PLATFORM_UUIDOF
// Warning: This macro exists in dxcapi.h as well
#define CROSS_PLATFORM_UUIDOF
#endif

template <typename T> inline void **IID_PPV_ARGS_Helper(T **pp) {
  return reinterpret_cast<void **>(pp);
}
#define IID_PPV_ARGS

#endif // __EMULATE_UUID

// Needed for d3d headers, but fail to create actual interfaces
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
#define DECLSPEC_UUID(x)
#define MIDL_INTERFACE(x)
#define DECLARE_INTERFACE(iface)
#define DECLARE_INTERFACE_(iface, parent)

//===--------------------- COM Interfaces ---------------------------------===//

CROSS_PLATFORM_UUIDOF(IUnknown, "00000000-0000-0000-C000-000000000046")
struct IUnknown {};

CROSS_PLATFORM_UUIDOF(INoMarshal, "ECC8691B-C1DB-4DC0-855E-65F6C551AF49")
struct INoMarshal : public IUnknown {};

CROSS_PLATFORM_UUIDOF(IMalloc, "00000002-0000-0000-C000-000000000046")
struct IMalloc : public IUnknown {};

CROSS_PLATFORM_UUIDOF(ISequentialStream, "0C733A30-2A1C-11CE-ADE5-00AA0044773D")
struct ISequentialStream : public IUnknown {};

CROSS_PLATFORM_UUIDOF(IStream, "0000000c-0000-0000-C000-000000000046")
struct IStream : public ISequentialStream {};

// These don't need stub implementations as they come from the DirectX Headers
// They still need the __uuidof() though
CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection,
                      "8E349D19-54DB-4A56-9DC9-119D87BDB804")
CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection,
                      "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E")

//===--------------------- COM Pointer Types ------------------------------===//

class CAllocator {};

template <class T> class CComPtrBase {};

template <class T> class CComPtr : public CComPtrBase<T> {};

template <class T> class CSimpleArray : public std::vector<T> {};

template <class T, class Allocator = CAllocator> class CHeapPtrBase {};

template <typename T, class Allocator = CAllocator>
class CHeapPtr : public CHeapPtrBase<T, Allocator> {};

#define CComHeapPtr

//===--------------------------- BSTR Allocation --------------------------===//

void SysFreeString(BSTR bstrString);
// Allocate string with length prefix
BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui);

//===--------------------------- BSTR Length ------------------------------===//
unsigned int SysStringLen(const BSTR bstrString);

//===--------------------- UTF-8 Related Types ----------------------------===//

// Code Page
#define CP_ACP
#define CP_UTF8

// RAII style mechanism for setting/unsetting a locale for the specified Windows
// codepage
class ScopedLocale {};

// The t_nBufferLength parameter is part of the published interface, but not
// used here.
template <int t_nBufferLength = 128> class CW2AEX {};
CW2A;

// The t_nBufferLength parameter is part of the published interface, but not
// used here.
template <int t_nBufferLength = 128> class CA2WEX {};

CA2W;

//===--------- File IO Related Types ----------------===//

class CHandle {};

/////////////////////////////////////////////////////////////////////////////
// CComBSTR

class CComBSTR {};

//===--------- Convert argv to wchar ----------------===//
class WArgV {};

#endif // __cplusplus

#endif // _WIN32

#endif // LLVM_SUPPORT_WIN_ADAPTER_H