common_funcs.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <algorithm>
  6. #include <array>
  7. #include <string>
  8. #if !defined(ARCHITECTURE_x86_64)
  9. #include <cstdlib> // for exit
  10. #endif
  11. #include "common/common_types.h"
  12. /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
  13. #define CONCAT2(x, y) DO_CONCAT2(x, y)
  14. #define DO_CONCAT2(x, y) x##y
  15. /// Helper macros to insert unused bytes or words to properly align structs. These values will be
  16. /// zero-initialized.
  17. #define INSERT_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__){};
  18. #define INSERT_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__){};
  19. /// These are similar to the INSERT_PADDING_* macros, but are needed for padding unions. This is
  20. /// because unions can only be initialized by one member.
  21. #define INSERT_UNION_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__);
  22. #define INSERT_UNION_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__);
  23. #ifndef _MSC_VER
  24. #ifdef ARCHITECTURE_x86_64
  25. #define Crash() __asm__ __volatile__("int $3")
  26. #else
  27. #define Crash() exit(1)
  28. #endif
  29. #else // _MSC_VER
  30. // Locale Cross-Compatibility
  31. #define locale_t _locale_t
  32. extern "C" {
  33. __declspec(dllimport) void __stdcall DebugBreak(void);
  34. }
  35. #define Crash() DebugBreak()
  36. #endif // _MSC_VER ndef
  37. // Generic function to get last error message.
  38. // Call directly after the command or use the error num.
  39. // This function might change the error code.
  40. // Defined in Misc.cpp.
  41. std::string GetLastErrorMsg();
  42. namespace Common {
  43. constexpr u32 MakeMagic(char a, char b, char c, char d) {
  44. return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
  45. }
  46. } // namespace Common